AppEngine上的SignedJwtAssertionCredentials无法识别PEM密钥

luc*_*uca 10 google-app-engine openssl pkcs#12 pem pycrypto

关于appengine的SignedJwtAssertionCredentials(使用pycrypto 2.6)不支持PKCS12格式,因此我正在尝试使用PEM密钥,正如所建议的那样.

这是我的代码:

  f = file(os.path.join(os.path.dirname(__file__), KEY_FILE), "r")
  key = f.read()
  f.close()

  credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
      scope="https://www.googleapis.com/auth/drive"
  http = httplib2.Http()
  http = credentials.authorize(http)
Run Code Online (Sandbox Code Playgroud)

并且KEY_FILE是一个PEM键,使用以下命令转换:

openssl pkcs12 -in privatekey.p12 -nodes -nocerts > privatekey.pem
Run Code Online (Sandbox Code Playgroud)

但我仍然得到这个错误,好像它没有认识到这是一个PEM密钥:

NotImplementedError: PKCS12 format is not supported by the PyCrpto library. 
Try converting to a "PEM" (openssl pkcs12 -in xxxxx.p12 -nodes -nocerts > privatekey.pem) or using PyOpenSSL if native code is an option.
Run Code Online (Sandbox Code Playgroud)

如果我只将文件名传递给构造函数(不读取文件的内容),则会出现同样的错误

任何的想法?

Jai*_*mez 17

是的,这个错误极具误导性.你做的很好; 只需从PEM文件中删除标题,使其开头-----BEGIN PRIVATE KEY-----,或对其运行以下命令:

openssl pkcs8 -nocrypt -in privatekey.pem -passin pass:notasecret -topk8 -out pk.pem
Run Code Online (Sandbox Code Playgroud)


luc*_*uca 6

对于那些感兴趣的人,我最终编写了一个关于如何在App Engine上使用Google+域名API和python的简短教程,你可以在这里找到它:https: //gist.github.com/vircheck/6292176

它也适用于基于服务帐户的其他API,例如Drive API等.