Library to work with SSH public keys

D

Darren Spruell

I'd like to work with user submitted/uploaded SSH public keys from
Python. I'm trying to solve what I'd thought might be a simple need:
given a user's OpenSSH formatted _public_ key (RSA, or DSA, or
whatever), how do you obtain information about it such as: key type
(e.g. ssh-rsa, etc.); bit length (e.g. 2048); key comment (e.g.
user@hostname); key fingerprint? I've been fiddling with the Paramiko
API and looked at PyCrypto (supports OpenSSH keys) and Twisted Conch
but didn't see anything that looked like it did this.

I'm looking for the equivalent to this:

$ ssh-keygen -l -f tmp.key.pub
2048 9b:31:06:6a:a4:79:97:33:d7:20:15:1f:cd:b4:86:4d (e-mail address removed) (RSA)

....to get the attributes of the public key: key type, bit length,
fingerprint and comment.

Is there an SSH library capable of doing this from Python? Can break
out to shell commands to parse them but I'd prefer not to.
 
R

Roy Smith

Darren Spruell said:
I'd like to work with user submitted/uploaded SSH public keys from
Python. I'm trying to solve what I'd thought might be a simple need:
given a user's OpenSSH formatted _public_ key (RSA, or DSA, or
whatever), how do you obtain information about it such as: key type
(e.g. ssh-rsa, etc.); bit length (e.g. 2048); key comment (e.g.
user@hostname); key fingerprint? I've been fiddling with the Paramiko
API and looked at PyCrypto (supports OpenSSH keys) and Twisted Conch
but didn't see anything that looked like it did this.

I'm looking for the equivalent to this:

$ ssh-keygen -l -f tmp.key.pub
2048 9b:31:06:6a:a4:79:97:33:d7:20:15:1f:cd:b4:86:4d (e-mail address removed)
(RSA)

...to get the attributes of the public key: key type, bit length,
fingerprint and comment.

Is there an SSH library capable of doing this from Python? Can break
out to shell commands to parse them but I'd prefer not to.

The first hit on googling "paramiko fingerprint" got me this:

http://www.lag.net/paramiko/docs/paramiko.PKey-class.html
 
D

Darren Spruell

The first hit on googling "paramiko fingerprint" got me this:

http://www.lag.net/paramiko/docs/paramiko.PKey-class.html

Indeed, and I seem to find it's not suited for the need. Many of the
methods appear to assume deriving information about public key parts
from private key input or for handling public keys sent by server when
connecting from client. I can't manage to wrangle desired or accurate
data out of passing in OpenSSH format public keys from a user keypair
(authentication key, not host key).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top