Repository navigation
Open
Labels
Description
Hi all,
I know paramiko does not support "custom"/vendor SSH implementations, however, the recent version 2.0.0 seems to be breaking things previously working. I can connect fine using paramiko's 1.17.0 invoke_shell to an Alcatel (Nokia now) ISAM (old, complex and a bit slow devices...).
With 2.0.0 I get the following error, which originates from cryptography
transport.py: starting thread (client mode): 0xcf6bc780
transport.py: Local version/idstring: SSH-2.0-paramiko_2.0.0
transport.py: Remote version/idstring: SSH-2.0-IPSSH-1.12.0
transport.py: Connected (version 2.0, client IPSSH-1.12.0)
transport.py: kex algos:['diffie-hellman-group1-sha1'] server key:['ssh-dss'] client encrypt:['aes128-cbc', 'blowfish-cbc', '3des-cbc', 'des-cbc'] server encrypt:['aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'blowfish-cbc', 'cast128-cbc', '3des-cbc', 'des-cbc', 'des-cbc', 'arcfour'] client mac:['hmac-sha1', 'hmac-sha1-96'] server mac:['hmac-sha1', 'hmac-sha1-96', 'hmac-md5', 'hmac-md5-96'] client compress:['none'] server compress:['none'] client lang:[''] server lang:[''] kex follows?False
transport.py: Kex agreed: diffie-hellman-group1-sha1
transport.py: Cipher agreed: aes128-cbc
transport.py: MAC agreed: local=hmac-sha1-96, remote=hmac-md5
transport.py: Compression agreed: none
transport.py: Unknown exception: p must be exactly 1024, 2048, or 3072 bits long
transport.py: Traceback (most recent call last):
transport.py: File ".../site-packages/paramiko/transport.py", line 1757, in run
transport.py: self.kex_engine.parse_next(ptype, m)
transport.py: File ".../site-packages/paramiko/kex_group1.py", line 75, in parse_next
transport.py: return self._parse_kexdh_reply(m)
transport.py: File ".../site-packages/paramiko/kex_group1.py", line 111, in _parse_kexdh_reply
transport.py: self.transport._verify_key(host_key, sig)
transport.py: File ".../site-packages/paramiko/transport.py", line 1605, in _verify_key
transport.py: if not key.verify_ssh_sig(self.H, Message(sig)):
transport.py: File ".../site-packages/paramiko/dsskey.py", line 153, in verify_ssh_sig
transport.py: ).public_key(backend=default_backend())
transport.py: File ".../site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 187, in public_key
transport.py: return backend.load_dsa_public_numbers(self)
transport.py: File ".../site-packages/cryptography/hazmat/backends/multibackend.py", line 198, in load_dsa_public_numbers
transport.py: return b.load_dsa_public_numbers(numbers)
transport.py: File ".../site-packages/cryptography/hazmat/backends/openssl/backend.py", line 656, in load_dsa_public_numbers
transport.py: dsa._check_dsa_parameters(numbers.parameter_numbers)
transport.py: File ".../site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py", line 120, in _check_dsa_parameters
transport.py: raise ValueError("p must be exactly 1024, 2048, or 3072 bits long")
transport.py: ValueError: p must be exactly 1024, 2048, or 3072 bits long
Let me know if this belongs to cryptography rather than paramiko and I will move it
Cheers,
Andreas
Activity
girlpunk commentedon May 26, 2016
I'm having the same issue with Draytek routers
bitprophet commentedon Jun 11, 2016
cc @alex / @reaperhulk from PyCA (p.s. do you guys have a catchall group like Graphite's
@graphite-committers? >_>)alex commentedon Jun 11, 2016
Are you able to modify
paramiko/dsskey.py:verify_ssh_sigto print the locals so we can see more info about the public key.Natrinicle commentedon Jul 12, 2016
Not a permanent fix but a workaround for now. I was attempting to use a Sentry Switched CDU from Paramiko and hit the same error. Added code to cryptography/hazmat/primitives/asymmetric/dsa.py that allowed me to find out that the Sentry CDU was using a 641 bit p dsa key. Commented out the few lines in _check_dsa_parameters that check parameters.p's bit_length and it worked fine. For anyone needing to make this work and not concerned with the security aspect of it, you can add this code to your script to pass these insecure server keys.
rbthomp commentedon Mar 24, 2017
Hello, I've been using netmiko to manage some Alcatel Lucent AOS switches I found anything older then AOS version 6.7 requires I include the work around provided by Natrinicle with one correction. I had to use
exhuma commentedon Aug 2, 2017
I've run into the same problem with another vendor (Actelis) using 768 bits. I was able to use the workaround by @Natrinicle as well.
mrinterestfull commentedon Feb 9, 2018
Gentleman,
Sorry for posting it here, Not sure if there is a better place.
We are running a python2 program using paramiko to upload files via sftp to bank which works fine.
We are in the process of converting all to python3. We updated it, but now we are getting below error. I can't figure out what parameters we need to specify to get this fixed or bypass this check. Regardless of what the cert is, I think there is an issue with paramiko for python3 where something has changes and no longer works for "some conditions" If there is a parameter on the connection I need to set to fix this? or make other changes please let me know. :
PYTHON3 - setup
Below does not have this problem:
PYTHON2 setup which
pip show paramiko
Name: paramiko
Version: 1.15.2
Location: /home/zzzzz/FIS_positivepay/venv/lib/python2.7/site-packages
Requires: pycrypto, ecdsa
(venv)lucas@myserverzzz:~/positivepay$ pip show cryptography
no results for this package
MY BANK using openssl, but I can't be sure this is the correct command to check what is the length of the cert. Regardless of what the cert is, I think there is an issue with paramiko for python3 where something has changes.
Reference to other related comments:
#909
Natrinicle commentedon Feb 9, 2018
In my comment above there is an override for the dsa._check_dsa_parameters method. In the commented out section, you can see that I've changed what is raised. You could use that to determine what the size of p is.
I also noticed that you have very different versions of Paramiko between Python 2 and 3 and that your Python 2 doesn't seem to show Cryptography via Pip. Can you confirm versions of Cryptography as well as attempt using the latest Paramiko in Python2 to see if you start getting the same error?
mrinterestfull commentedon Feb 13, 2018
Hello,
The python2 was written a long time ago, so it probably would get the same error in current python2 version.
Just to confirm:
You are saying I should add: below right above the pysft.Connect()
When I do that I get:
Which package I need to import from to get ?
Natrinicle commentedon Feb 14, 2018
from cryptography import utils as crypto_utils
mrinterestfull commentedon Feb 15, 2018
Thank you for your help!
For the google reference:
If you have below error after you did above:
Then you need the following :
kylefoley76 commentedon Jan 8, 2020
I've followed all of the instructions and right now the value of
crypto_utils.bit_length(parameters.q)is 17. I don't know anything about SSH. I'm just trying to automate the log in to a google cloud instance using Python'sParamikokylefoley76 commentedon Jan 8, 2020
That means I'm getting the error
ValueError: q must be exactly 160 or 256 bits long
2 remaining items
ClorenceMan commentedon Feb 11, 2020
Are you still receiving the same issue?
I'm receiving the same error and the p value of 17 when trying to authenticate through Paramiko to an AWS SFTP. I also have an error saying the publickey is not valid. My private key exactly matches the public key on the host server.
ploxiln commentedon Feb 11, 2020
try with #1606 (or paramiko-ng)
jadore801120 commentedon May 27, 2020
Hi all,
I also meet the
q must be exactly 160, 224, or 256 bits longissue when I use dvc.I specified the ssh username and password to let dvc access my files on remote server, and bumped into this issue.
It was quite confusing.
It looked like it was break on the connection/auth part, so I decided to follow the related call stack.
At last, I printed the input parameters of
self._authused inclient.py.And I found out that although I already specified the user/pwd, it still collected a private key file (
key_filenames) for building up ssh connection, which was not necessary.Turns out, I had my
.ssh/configset up with using a specified private key to all the hosts like below.And that's why the
self._authused it during auth and failed.After I removed this setting in ssh configuration, everything works.
It is a dumb situation. Write it down just in case if there is someone in the same situation.
jpiironen commentedon Oct 14, 2020
In case someone still encounters this, I had the same issues, but solution by @jadore801120 worked for me. I would imagine some other people would run into this as well, since Github advices Mac users to put something like this into the ssh config file, see https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent.
bjom8 commentedon Oct 28, 2020
Hello @rbthomp
I am working with Alcatel switches as well and I've applied Natrinicle modifications to the file, but it is not working. Could you please share with me the whole section of the code you used? Thank you in advance
Natrinicle commentedon Oct 28, 2020
Leaving in all the imports just in case there's one that I missed previously. This is the code with the excess stuff removed and replaced with ellipsis. Don't judge it too harshly, it's pretty old stuff. I figured I might need this hack in the future, glad I documented and kept it just in case.
bjom8 commentedon Oct 30, 2020
Thanks a lot. That is very useful.
UberN3rD commentedon Nov 16, 2020
@Natrinicle - I've found this works for some older Ciena devices as well. I am curious, though. What potential security risks come with this? I would only assume the crypto algorithm is just not as secure, even though you are already going over SSH. Any info would be appreciated.
telcoserf commentedon Nov 16, 2020
Running into this with some Linux boxes, but it's only happening for certain users. Trying to nail down what keys they're using, key size, etc. We're also using agent forwarding, so I'm sure that complicates things.
Played with specifying certain versions of cryptography and pycryptodome -- saw a different error with one combination, but after we bumped cryptography to 3.0.0, paramiko to 2.7.1, and pycryptodome to 3.9.8, it was the same result:
Giving @Natrinicle's temporary fix a try next...
exhuma commentedon Nov 17, 2020
I also had this fix in my code-base for some time and needed to updated it since paramiko changed a bit. At the same time I decided to make it a tiny bit more secure using a context manager. It gives you precise control where/when to apply the patch and restores the original implementation on context-exit.
You can then simply wrap any problematic section using:
Here's the implementation:
domibarton commentedon Nov 30, 2020
I am running into the same issue and I've absolutely no idea why this isn't working. What's even stranger, a key I've created a few days ago works, but a fresh key doens't.
I created an RSA 4096bit key like this:
When I'm using that one from a few days back (i.e.
id_rsa) it works. Now when I'm creating a new RSA key w/ 4096 bits again and when I want to use that one, it fails:Error when connecting to it:
When I check the keys they look alike:
The keys in question are:
telcoserf commentedon Dec 2, 2020
So in my case, the issue ended up being similar to what someone else reported -- that the user had the following in their ~/.ssh/config file but the hadn't actually generated keys on that host, so it was failing due to keys being referred to that didn't exist:
IdentityFile ~/.ssh/id_rsaRemoving that config line corrected the problem, in our case.
andyljones commentedon Jan 23, 2021
Similar to previous reports - the fix for me was passing
allow_agents=False, look_for_keys=Falsewhen creating the connection. Seems the client hoovered up something that it choked on.Ignore errors "p/q must be exactly ..." when attempting SSH connections.
Ignore errors "p/q must be exactly ..." when attempting SSH connections.