question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with private_key.pem

See original GitHub issue

I have done some tests with push notification and works. But when I integrate with django, I get this error:

File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/pywebpush/__init__.py", line 359, in webpush
    vv = Vapid.from_string(private_key=vapid_private_key)
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/py_vapid/__init__.py", line 142, in from_string
    return cls.from_der(pkey)
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/py_vapid/__init__.py", line 99, in from_der
    backend=default_backend())
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/primitives/serialization.py", line 28, in load_der_private_key
    return backend.load_der_private_key(data, password)
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/multibackend.py", line 323, in load_der_private_key
    return b.load_der_private_key(data, password)
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1018, in load_der_private_key
    password,
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1160, in _load_key
    self._handle_key_loading_error()
  File "/Users/myuser/.virtualenvs/myenv/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1229, in _handle_key_loading_error
    raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.

Why?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jrconlincommented, Nov 30, 2017

Cool. No worries about the keys, I’m sure I can duplicate the problem.

1reaction
jrconlincommented, Nov 30, 2017

I’m not sure. The error is happening inside of the cryptography library, so there could be a number of reasons.

  1. Is the private key data a valid PEM file? You can use a command like openssl ec -inform pem -in YourKeyFile.pem -text -noout

it should produce something like:

read EC key
Private-Key: (256 bit)
priv:
    00:96:70:09:fd:aa:7b:ff:29:22:fd:c3:af:5b:4e:
    4a:41:f2:0f:07:6f:89:9b:a5:46:d2:f0:64:d0:95:
    87:77:83
pub:
    04:46:cb:95:b6:e2:dd:7a:ed:eb:88:5a:00:bc:96:
    4a:41:f2:0f:07:6f:89:9b:a5:46:d2:f0:64:d0:95:
    00:96:70:09:fd:aa:7b:ff:29:22:fd:c3:af:5b:4e:
    56:4f:66:95:4d:0f:29:7d:12:ea:2f:4f:39:b0:4a:
    ef:e6:3d:43:ac
ASN1 OID: prime256v1
NIST CURVE: P-256

If not, the file may not be a proper key.

If that does work, (and if I understand that you’re able to send push notifications using something like pywebpush, just not if the library is integrated into django), then I’ve no idea. It may be a library version conflict, or some monkey patch, or anything, really. (cryptography and openssl can be terrible about randomly changing how things work via “minor” updates)

I don’t have a lot of time right now to dig into this, but I’ll try to get to it as soon as I can.

Read more comments on GitHub >

github_iconTop Results From Across the Web

For valid PEM I get unable to load private key by openssh
The issue is that ssh-keygen generates an SSH key, while openssl rsa doesn't read SSH keys - it can read PKCS#1 or PKCS#8....
Read more >
Import of OpenSSl private key (pem) fails · Issue #191 - GitHub
I got an RSA private key in pem format that can't be loaded by KeyStore Explorer, however openssl rsa -text -in filename works...
Read more >
Unable to load Private Key. (PEM routines:PEM_read_bio:no ...
Open the key file in Notepad++ and verify the encoding. If it says UTF-8-BOM then change it to UTF-8. Save the file and...
Read more >
Error: "Invalid private key, or PEM pass phrase required for ...
4. Reinstall the certificate key pair. Problem Cause. This issue is caused because of hidden space control characters within the key.
Read more >
What to Do if OpenSSL Does Not Find Your Private Key
The file for the private key contained a private key, but OpenSSL could somehow not find it. As it turns out, OpenSSL needs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found