You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RSAKey.from_private_key fails to load key with "Bag Attributes" #1601
openssl adds "Bag Attributes" to private keys extracted from pfx, Paramiko fails to parse these keys. These used to work long ago, not sure which paramiko release. bagkey.pem.zip
$ python keybag.pyTraceback (most recent call last): File "keybag.py", line 4, in <module> key = paramiko.RSAKey.from_private_key(f) File "/private/tmp/venv/lib/python3.7/site-packages/paramiko/pkey.py", line 256, in from_private_key key = cls(file_obj=file_obj, password=password) File "/private/tmp/venv/lib/python3.7/site-packages/paramiko/rsakey.py", line 52, in __init__ self._from_private_key(file_obj, password) File "/private/tmp/venv/lib/python3.7/site-packages/paramiko/rsakey.py", line 179, in _from_private_key data = self._read_private_key("RSA", file_obj, password) File "/private/tmp/venv/lib/python3.7/site-packages/paramiko/pkey.py", line 324, in _read_private_key raise SSHException("not a valid {} private key file".format(tag))paramiko.ssh_exception.SSHException: not a valid RSA private key file
Yes, it was in paramiko-2.7.0 when support for new-format openssh private keys was added, that support was lost for any private keys with some stuff before the key starts. The key you included starts like this:
Bag Attributes
localKeyID: 32 CB FA 64 B9 D8 C5 D3 BC 4B 20 04 3D EC 38 6B 32 2D C4 9A
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCcJTduzIlepEYo
I plan to get around to submitting a pretty simple fix for that soon ...
... although "BEGIN PRIVATE KEY" rather than "BEGIN RSA PRIVATE KEY" is not expected, I don't think that will work even after fixing the bug, and not sure it worked before, I think paramiko expects/needs the RSA in there ...
Activity
ploxiln commentedon Jan 16, 2020
Yes, it was in paramiko-2.7.0 when support for new-format openssh private keys was added, that support was lost for any private keys with some stuff before the key starts. The key you included starts like this:
I plan to get around to submitting a pretty simple fix for that soon ...
... although "BEGIN PRIVATE KEY" rather than "BEGIN RSA PRIVATE KEY" is not expected, I don't think that will work even after fixing the bug, and not sure it worked before, I think paramiko expects/needs the RSA in there ...