alex / letsencrypt-aws

BSD 3-Clause "New" or "Revised" License
728 stars 121 forks source link

Could not unserialize key data (use .p8 file as private key file, use ES256 algorithm) #96

Open chenhongws opened 7 years ago

chenhongws commented 7 years ago

Such was the code: APNS_AUTH_KEY = './APNsAuthKey_SP7C6832EZ.p8' f = open(APNS_AUTH_KEY) secret = f.read() token = jwt.encode( payload={ "iss": "8X2A38Q9VD", "iat": time.time() }, key= secret, algorithm= 'ES256', headers={ "alg": "ES256", "kid": "SP7C6832EZ", } )

But it run with error: Traceback (most recent call last): File "Http2AuthToken.py", line 31, in "kid": "SP7C6832EZ", File "/usr/lib/python2.7/site-packages/jwt/api_jwt.py", line 56, in encode json_payload, key, algorithm, headers, json_encoder File "/usr/lib/python2.7/site-packages/jwt/api_jws.py", line 98, in encode key = alg_obj.prepare_key(key) File "/usr/lib/python2.7/site-packages/jwt/algorithms.py", line 226, in prepare_key key = load_pem_private_key(key, password=None, backend=default_backend()) File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/serialization.py", line 20, in load_pem_private_key return backend.load_pem_private_key(data, password) File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/multibackend.py", line 303, in load_pem_private_key return b.load_pem_private_key(data, password) File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1048, in load_pem_private_key password, File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1217, in _load_key self._handle_key_loading_error() File "/usr/lib64/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1289, in _handle_key_loading_error raise ValueError("Could not unserialize key data.") ValueError: Could not unserialize key data.

Is there somebody can explain?

wayland commented 7 years ago

Try updating your acme and boto libraries; I had a similar sort of error, and it worked for me.