Repository navigation
Description
I am receiving the following error message:
`
Unknown exception: Unknown OpenSSL error. This error is commonly encountered when another library is not cleaning up the OpenSSL error stack. If you are using cryptography with another library that uses OpenSSL try disabling it before reporting a bug. Otherwise please file an issue at https://github.com/pyca/cryptography/issues with information on how to reproduce this. ([_OpenSSLErrorWithText(code=50905205, lib=3, func=140, reason=117, reason_text=b'error:0308C075:bignum routines:BN_generate_dsa_nonce:private key too large'), _OpenSSLErrorWithText(code=168210435, lib=10, func=107, reason=3, reason_text=b'error:0A06B003:dsa routines:DSA_sign_setup:BN lib'), _OpenSSLErrorWithText(code=168230915, lib=10, func=112, reason=3, reason_text=b'error:0A070003:dsa routines:DSA_do_sign:BN lib')])
Traceback (most recent call last):
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/transport.py", line 2109, in run
handler(self.auth_handler, m)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/auth_handler.py", line 298, in _parse_service_accept
sig = self.private_key.sign_ssh_data(blob)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/dsskey.py", line 117, in sign_ssh_data
sig = key.sign(data, hashes.SHA1())
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/dsa.py", line 194, in sign
return _dsa_sig_sign(self._backend, self, data)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/dsa.py", line 29, in _dsa_sig_sign
backend.openssl_assert(res == 1)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 131, in openssl_assert
return binding._openssl_assert(self._lib, ok)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 70, in _openssl_assert
raise InternalError(
cryptography.exceptions.InternalError: Unknown OpenSSL error. This error is commonly encountered when another library is not cleaning up the OpenSSL error stack. If you are using cryptography with another library that uses OpenSSL try disabling it before reporting a bug. Otherwise please file an issue at https://github.com/pyca/cryptography/issues with information on how to reproduce this. ([_OpenSSLErrorWithText(code=50905205, lib=3, func=140, reason=117, reason_text=b'error:0308C075:bignum routines:BN_generate_dsa_nonce:private key too large'), _OpenSSLErrorWithText(code=168210435, lib=10, func=107, reason=3, reason_text=b'error:0A06B003:dsa routines:DSA_sign_setup:BN lib'), _OpenSSLErrorWithText(code=168230915, lib=10, func=112, reason=3, reason_text=b'error:0A070003:dsa routines:DSA_do_sign:BN lib')])
Traceback (most recent call last):
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/client.py", line 680, in _auth
self._transport.auth_publickey(username, key)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/transport.py", line 1580, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/auth_handler.py", line 236, in wait_for_response
raise e
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/transport.py", line 2109, in run
handler(self.auth_handler, m)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/auth_handler.py", line 298, in _parse_service_accept
sig = self.private_key.sign_ssh_data(blob)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/dsskey.py", line 117, in sign_ssh_data
sig = key.sign(data, hashes.SHA1())
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/dsa.py", line 194, in sign
return _dsa_sig_sign(self._backend, self, data)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/dsa.py", line 29, in _dsa_sig_sign
backend.openssl_assert(res == 1)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 131, in openssl_assert
return binding._openssl_assert(self._lib, ok)
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 70, in _openssl_assert
raise InternalError(
cryptography.exceptions.InternalError: Unknown OpenSSL error. This error is commonly encountered when another library is not cleaning up the OpenSSL error stack. If you are using cryptography with another library that uses OpenSSL try disabling it before reporting a bug. Otherwise please file an issue at https://github.com/pyca/cryptography/issues with information on how to reproduce this. ([_OpenSSLErrorWithText(code=50905205, lib=3, func=140, reason=117, reason_text=b'error:0308C075:bignum routines:BN_generate_dsa_nonce:private key too large'), _OpenSSLErrorWithText(code=168210435, lib=10, func=107, reason=3, reason_text=b'error:0A06B003:dsa routines:DSA_sign_setup:BN lib'), _OpenSSLErrorWithText(code=168230915, lib=10, func=112, reason=3, reason_text=b'error:0A070003:dsa routines:DSA_do_sign:BN lib')])
`
I'm really at a loss here because I have no experience with SSH. I just want to SSH into a remote google cloud virtual instance and I want to do it with Paramiko because you can't log in with python with the google-api-client. In any case, the first error message I got was that when I put in the following code:
`
import paramiko
username = 'me'
hostname = '99.99.99.99'
client = paramiko.SSHClient()
key_filename = "/Users/kylefoley/.ssh/ssh_key"
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.load_system_host_keys()
c = client.connect(username=username,
hostname=hostname,
key_filename=key_filename,
look_for_keys=False,
allow_agent=False)
`
(Ignore the identation errors.)
I was hit with the following error:
Traceback (most recent call last): File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/client.py", line 676, in _auth key = self._key_from_filepath( File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/client.py", line 586, in _key_from_filepath key = klass.from_private_key_file(key_path, password) File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/pkey.py", line 235, in from_private_key_file key = cls(filename=filename, password=password) File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/ed25519key.py", line 63, in __init__ signing_key = self._parse_signing_key_data(data, password) File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/paramiko/ed25519key.py", line 96, in _parse_signing_key_data raise PasswordRequiredException( paramiko.ssh_exception.PasswordRequiredException: Private key file is encrypted
I then used Python's SSH-agent and I was able to get a password but
I'm not sure if I used it correctly. These were the commandlines I used
(venv) Admins-MacBook-Pro-4:byu_corpus kylefoley$ eval 'ssh-agent' SSH_AUTH_SOCK=/var/folders/vd/5ccxv4957f1_prjqt1l_ppsw0000gq/T//ssh-goky0gUep80V/agent.4526; export SSH_AUTH_SOCK; SSH_AGENT_PID=4527; export SSH_AGENT_PID; echo Agent pid 4527; (venv) Admins-MacBook-Pro-4:byu_corpus kylefoley$ ssh-add ~/.ssh/ssh_key Enter passphrase for /Users/kylefoley/.ssh/ssh_key: Bad passphrase, try again for /Users/kylefoley/.ssh/ssh_key: Bad passphrase, try again for /Users/kylefoley/.ssh/ssh_key: Identity added: /Users/kylefoley/.ssh/ssh_key (kfoley76)
I then added this line
password='my_password'
And the following parameter like so:
c = client.connect(username=username, hostname=hostname, key_filename=key_filename, look_for_keys=False, allow_agent=False, password=password)
I then got some errors in the def _check_dsa_parameters(parameters): function. I applied the patch recommended on this site but it did not work, so I just commented out that function. And that's when I hit the above error. Any suggestions would be appreciated.
Activity
kylefoley76 commentedon Jan 8, 2020
Also, I should add that I change my password to something wrong just to see what would happen and I did get the error:
paramiko.ssh_exception.BadAuthenticationType: Bad authentication typewhich is what is supposed to happen. So it appears that the bug does not lie with the way I generated the password.Further, I don't understand what the following means:
ploxiln commentedon Jan 8, 2020
To do a multi-line code-quote, surround it with triple-backticks on their own lines, like this:
You can edit your existing issue text and comments to make them more readable.
The root problem seems to be this error reported from openssl:
It looks like the DSS key is on your side:
Something is weird about it - maybe it's not really a DSS key, or maybe support for DSS keys has sort of "bitrotted" because those are very rarely used anymore ...
kylefoley76 commentedon Jan 9, 2020
Please bear in mind that you're talking to someone who has almost no experience with SSH. Can you please dumb it down a little and give me some instructions. Thanks.
ploxiln commentedon Jan 9, 2020
Don't apply "the patch" you saw in the other issue, that was for working-around an issue with old network appliances. (Those odd-sized DSS keys are very inadvisable, but if you just want to interoperate with the device and don't care about modern-internet-grade security, that's what that patch was for.) You're connecting to a more modern server, that is not the problem. I suggest uninstalling "cryptography" and then reinstalling it to undo any changes.
If you successfully started ssh-agent and added your key, then try
allow_agent=Trueand don't specifykey_filenameorpasswordtoclient.connect().Can you generate and use a 2048-bit or bigger RSA key instead? Or an ed25519 key? What version of paramiko are you using? cryptography version? python version? OS version?
kylefoley76 commentedon Jan 9, 2020
Thanks for the quick response. Also thanks for the tip about the triple back ticks, that always irritated me in the past, now I can get around that issue.
Cryptography Version (which I uninstalled and reinstalled): 2.8
Python Version: 3.8
Mac OS version: 10.14.4 Mojave
Paramiko Version: 2.7.1
I rewrote my code as:
And I'm getting the error:
But I don't see how this code can find out that I'm using an SSH agent and further get the information that the SSH agent has gotten. Also back when I was getting the error about the number of bytes of
parameter.qI was only getting the number 17 whereasparameter.pwas a very large number. When I performed the command line instructions forssh-addI just added an 8 letter word as my password. Was I supposed to put it in the large 10 line or so string that is found on the SSH file?kylefoley76 commentedon Jan 9, 2020
Also, I'm little worried that when I get to this line
It will throw an error since that assumes Linux. I'm using a Mac to ssh into a Linux. Is that going to matter?
ploxiln commentedon Jan 9, 2020
That line is fine, the command runs on the remote host, not the local one.
macOS comes with openssh installed, which includes the commands
ssh,ssh-add,ssh-agent,ssh-keygenand a few more. Your short script is pretty much equivalent to:Both the openssh
sshcommand, and paramiko's client, by default will try to use the ssh-agent if they see the environment variableSSH_AUTH_SOCK. But you don't have to use the ssh-agent, that is optional, there are a few other ways to access keys. (I thought it looked like you had successfully loaded your key withssh-addso that's why I suggested trying to just use the agent.)An ssh private key can be encrypted with a password, but this also is optional. The command
ssh-adddoes not add a password to the private key - you have to specify the correct password if needed in order to decrypt the key so it can add the unprotected and usable private key to thessh-agent. To add, change, or remove a password for a private key file (by encrypting or decrypting the private key) you can use thessh-keygencommand. Encrypted keys can also be used by the ssh client directly, without going through the agent, but you have to specify the password every time.SSH keys have public and private parts, and the public part needs to be already configured on the server-side in order for the private key to be granted access. Where did you get this key from?
I suggest getting the plain
sshcommand to work first. If that doesn't work, paramiko won't work either, and paramiko isn't the simplest way ...ploxiln commentedon Jan 9, 2020
To specify a private key file directly to the
sshcommand, use the-iflag, like:(that's simpler than trying to use the ssh-agent)
kylefoley76 commentedon Jan 9, 2020
When I did
Changing 'me' and the ip address of course, I got a permission denied (public key) error, same when I put
sudoin front of it and same when I change ssh_key to ssh_key.pub. Also I performed the instructions yesterdayAnd did them again to no avail.
ploxiln commentedon Jan 9, 2020
That means the key or the username is wrong, so the server rejects you.
kylefoley76 commentedon Jan 9, 2020
Well, I'm clearly able to ssh into that computer with the gcloud command line using the following
And then the following demonstrates that I'm using the correct external ip address:

And this is the exact command line I'm using:
kylefoley76 commentedon Jan 9, 2020
Maybe when I ssh into that computer I have to do chmod or something like that.
ploxiln commentedon Jan 9, 2020
https://cloud.google.com/sdk/gcloud/reference/compute/ssh says that the keyfile it uses is
~/.ssh/google_compute_enginekylefoley76 commentedon Jan 9, 2020
Ok, I'm making progress but still not there. I got the permissions error removed:
But it is still the case that when I run:
I get the error:
And when I explicitly state keyfile like so:
I get the error:
And here the value for q is 65537
ploxiln commentedon Jan 9, 2020
quick note:
eval 'ssh-agent'does not achieve anything. it should be:but it doesn't matter because macOS already runs an ssh-agent in the background for you by default (so that's why the agent has seemed to work thus far).
You can use the command
ssh-add -lto see the type of key you have loaded, this may be interesting.You should not have to specify the key if you loaded it into the ssh-agent and allow using the agent. It's good to know exactly which way is being used, while debugging. So try both individually to see if there is any difference, and then just pick one thereafter if not.
In other cases of "unusual DSS/DSA keys", it was just
p, the familiar bit-length, which was not one of the usual values. Different values forqdon't really make sense ... it must be a mis-parsed key or just a very weird key somehow. (Which is why I wondered if going through the ssh-agent would work-around some kind of bug parsing the file directly.) What generated these key files anyway?I suggest making a new RSA key instead, and then get the gcloud command to set up the public part on the server side (the docs say "gcloud compute ssh ensures that the user's public SSH key is present in the project's metadata.")
See also: https://security.stackexchange.com/questions/112802/why-openssh-deprecated-dsa-keys
kylefoley76 commentedon Jan 10, 2020
When I type ssh-add -l I get:
2048 [secret string] kfoley76 (RSA)
2048 [secret string] [email protected] (RSA)
As far as what generated the ssh keys, that was
ssh-keygen -t rsa -f ~/.ssh/ssh_key -C kfoley76
When you say the following I do not know how to pick an ssh key.
I'm not exactly sure what you mean by "get the gcloud command to set up the public part on the server side" but I did generate a new RSA key and SSH'ed into the vm instance again. I also checked the metadata of the vm instance where it says what SSH pub key is and its string matches the string found in the ssh_key.pub file. This was the syntax I used
I also added the new ssh_key to ssh agent and tried running the paramiko code again and got the same error. I'm wondering why when I typed
It generated a new fingerprint the fingerprint it generated was different than the one found with
Also only two new files where generated. Is this a problem? Should google_compute_engine also be created? Here is a screenshot of my .ssh folder:
ploxiln commentedon Jan 10, 2020
I mean, for
client.connect(), either specifyallow_agent=Truewithkey_filename=None, or specifyallow_agent=Falsewithkey_filename="/path/to/key", so when we get some error, we know for sure which it was trying to use.But anyway, I think I know what's going on. Your RSA key is being loaded as a DSS/DSA key. It's a long-standing historical issue with this paramiko client code, that when you specify a key file, it just tries loading it as all possible key types in turn, and uses whatever seems to work. In this case it seemed to load as a DSA key, but not work as a DSA key, because it's actually an RSA key.
Try something like this:
(but do also try with
allow_agent=Trueand no key specified toclient.connect())So I think there is a pretty bad bug in paramiko's support for new-format private keys which was added in paramiko-2.7.0, but we'll see if these last attempts confirm it.
kylefoley76 commentedon Jan 10, 2020
I'm getting the same error with both methods
ploxiln commentedon Jan 10, 2020
... but that's not the openssl error "BN_generate_dsa_nonce:private key too large" nor the cryptography error "q must be exactly 160, 224, or 256 bits long".
What caused confusion at the beginning was trying to use the wrong key (along with paramiko's error handling in this area being bad and confusing). At this point you have two different keys loaded into the ssh-agent which macOS started for you by default (and probably 10 other ssh-agents you started later also hanging around but not really hurting).
So I suggest clearing all keys from the ssh-agent with
ssh-add -Dand then not using ssh-add or ssh-agent anymore, just to simplify as much as possible. Just confirm that thesshcommand with an explicit key file works, and then try to make that same explicit key file work with paramiko (by explicitly loading it as anRSAKeyto work around the DSA key confusion in paramiko). Thesshcommand will ask you for a password to decrypt the key if needed, and if it is needed then you'll have to specify it toparamiko.RSAKeyas well.If at that point the
sshcommand works but paramiko still doesn't, I'd just usessh.kylefoley76 commentedon Jan 10, 2020
I performed the command
ssh-add -D, but then I was not exactly sure what you wanted me to do. So I performed:But that got the same error as last time. Also, if this is the end of the road as far as suggestions go, is this a confirmed bug that paramiko is working on and will be removed in the future? If so, when do you think it will be removed?
ploxiln commentedon Jan 10, 2020
The request was to, after clearing the ssh-agent, do
ssh -i /path/to/key user@host some-commandto confirm again the exact key and password (or lack thereof) that is needed.The paramiko bug I suspect is: you just specify a key filename, and paramiko attempts to load your RSA key as a DSA key, and does not detect the error in the right way, causing all the strange DSA errors which you started with. But if you use the
paramiko.RSAKeyconstructor like in the latest example, that avoids this suspected bug. If the explicitRSAKeyconstructor doesn't work, I have no idea what the issue is, and it won't be fixed.kylefoley76 commentedon Jan 12, 2020
I'm getting permission denied errors.
But I was able to log in with gcloud. I looked at the info generated by the gcloud initilization and this is all of it except for the actual ssh key.
I also tried:
ploxiln commentedon Jan 12, 2020
The gcloud command helper used the username
kylefoley(and the ssh key/Users/kylefoley/.ssh/google_compute_engine, but the correct username is the new discovery)."known_hosts" is not a private key, it's something else. You don't have to do anything explicit with it right now, and hopefully not for a while, one topic at a time ...
kylefoley76 commentedon Jan 12, 2020
Ok, I was able to execute the program without throwing an error but I'm not given command line access to the new computer. I had to use
[email protected]but I don't understand why since the name of my instance is clearlykfoley76as seen here:After I run the program and
pwdI still get the same directory that I started from.The command
bbyu m2c ipruns the program:ploxiln commentedon Jan 12, 2020
That is working as expected.
kylefoley76 commentedon Jan 13, 2020
I figured out how it works. Thanks very much for helping me with my problem.