Skip to content

ssh2.session.Session.userauth_publickey_frommemory() - TypeError: object of type 'NoneType' has no len() #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PhenomPBG opened this issue Oct 1, 2019 · 13 comments · Fixed by #104

Comments

@PhenomPBG
Copy link

PhenomPBG commented Oct 1, 2019

host = "127.0.0.1"
port = 22
user_name = "user"
privatekey_data = "..."
passphrase = ""

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
session = Session()
session.handshake(s)

session.userauth_publickey_frommemory(user_name, privatekey_data.encode('ascii'), passphrase=passphrase)

Last line from stack trace:

File "ssh2/session.pyx", line 240, in ssh2.session.Session.userauth_publickey_frommemory
TypeError: object of type 'NoneType' has no len()

Seems like the optional argument publickeyfiledata defaults to None, but its len() is always checked anyway.

Tested on both 0.17 and 0.18 with Python 3.7.1 on CentOS 7.

@PhenomPBG
Copy link
Author

Cleaned up the sample code a bit.

@j3pic
Copy link

j3pic commented Dec 4, 2019

@PhenomPBG the bug remains. #90 doesn't fix it either. I've made a new PR that should fix it.

@PhenomPBG
Copy link
Author

@PhenomPBG the bug remains. #90 doesn't fix it either. I've made a new PR that should fix it.

Thanks!

@Red-M

This comment was marked as spam.

Red-M added a commit to Red-M/ssh2-python that referenced this issue Dec 8, 2019
Add enums to clean up any symbols from libssh2 and make interacting with them much easier to do.
Add additional unit tests for ParallelSSH#86
@Red-M

This comment was marked as spam.

@j3pic
Copy link

j3pic commented Dec 18, 2019

@Red-M Will your fork become the version of ssh2-python that installs from PyPI?

@Red-M

This comment was marked as spam.

@j3pic
Copy link

j3pic commented Dec 18, 2019

There's another problem with my patch: It doesn't compile under Python 3.7 and higher because the C source files were built with the wrong version of Cython (but if I upgrade and generate the C files again, they'll be incompatible with Python 3.6 and below.

@Red-M

This comment was marked as spam.

@Red-M

This comment was marked as spam.

@j3pic
Copy link

j3pic commented Dec 21, 2019

@Red-M Reading the code for #90 it looks like this bug should be fixed there. I'm not sure why I still saw it when I tested manually. Probably because of the bug in Pip I found that affects the use of Git repos from requirements.txt. There's a nonzero chance I was still running the version of ssh2-python from PyPI.

@basegodfelix
Copy link

still experiencing this issue.

On a side note, if I use the same key and auth from file, it works. Same error thrown as above poster:

File "ssh2/session.pyx", line 237, in ssh2.session.Session.userauth_publickey_frommemory
TypeError: object of type 'NoneType' has no len()

Private key provided

Red-M added a commit to Red-M/ssh2-python that referenced this issue Jun 27, 2020
Add enums to clean up any symbols from libssh2 and make interacting with them much easier to do.
Add additional unit tests for ParallelSSH#86
@kdart
Copy link

kdart commented Jul 17, 2020

A workaround that seems to work for me is to set the publickeyfiledata to an empty bytestring (b'').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants