首页 > 解决方案 > 在 AWS SAML 联合登录中使用时 win32crypt.CryptUnprotectData 引发错误

问题描述

我正在尝试使用 AWS SAML 进行联邦登录,但下面有一个函数调用:

cookiesObj = getCookiesObj(
    domain=args.domain,
    username=args.username,
    cookiefile=args.cookiefile,
    useKeyring=args.keyring,
    chromeprofile=args.chromeprofile
)

此调用转到以下代码:

c = sqlite3.connect(cookiefile)
        sql = "SELECT name,encrypted_value FROM cookies " + \
              "WHERE  name IN ('" + ("','".join(requiredCookies)) + "')" + \
              "AND    host_key like '%{}%'".format(domain)

        rows = c.cursor().execute(sql)
        rowCount = 0
        for k, ev in rows:
            val = None
            *val = win32crypt.CryptUnprotectData(ev, None, None, None, 0)[1]*
            cookiesObj['cookies'][k] = val
            rowCount += 1

尽管 sql 查询也返回带有 value(ev) 的 cookie MSISAuth,MSISAuth1,但 win32crypt 调用会引发错误:

Traceback (most recent call last):
  File "aws_saml.py", line 435, in <module>
    chromeprofile=args.chromeprofile
  File "aws_saml.py", line 251, in getCookiesObj
    val = win32crypt.CryptUnprotectData(ev, None, None, None, 0)[1]
pywintypes.error: (13, 'CryptProtectData', 'The data is invalid.')

使用的版本: pypiwin32==220 也尝试使用 223 pywin32==227

标签: python-3.xamazon-web-servicescookiessamlpywin32

解决方案


推荐阅读