Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42890 > unrolled thread

Library to work with SSH public keys

Started byDarren Spruell <phatbuckett@gmail.com>
First post2013-04-05 22:49 -0700
Last post2013-04-07 00:51 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Library to work with SSH public keys Darren Spruell <phatbuckett@gmail.com> - 2013-04-05 22:49 -0700
    Re: Library to work with SSH public keys Roy Smith <roy@panix.com> - 2013-04-06 08:49 -0400
      Re: Library to work with SSH public keys Darren Spruell <phatbuckett@gmail.com> - 2013-04-07 00:51 -0700

#42890 — Library to work with SSH public keys

FromDarren Spruell <phatbuckett@gmail.com>
Date2013-04-05 22:49 -0700
SubjectLibrary to work with SSH public keys
Message-ID<mailman.187.1365227369.3114.python-list@python.org>
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 dspruell@Sydney.local (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.

-- 
Darren Spruell
phatbuckett@gmail.com

[toc] | [next] | [standalone]


#42908

FromRoy Smith <roy@panix.com>
Date2013-04-06 08:49 -0400
Message-ID<roy-C210AD.08490906042013@news.panix.com>
In reply to#42890
In article <mailman.187.1365227369.3114.python-list@python.org>,
 Darren Spruell <phatbuckett@gmail.com> wrote:

> 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 dspruell@Sydney.local 
> (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

[toc] | [prev] | [next] | [standalone]


#42981

FromDarren Spruell <phatbuckett@gmail.com>
Date2013-04-07 00:51 -0700
Message-ID<mailman.234.1365321118.3114.python-list@python.org>
In reply to#42908
On Sat, Apr 6, 2013 at 5:49 AM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.187.1365227369.3114.python-list@python.org>,
>  Darren Spruell <phatbuckett@gmail.com> wrote:
>
>> 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 dspruell@Sydney.local
>> (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

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).

-- 
Darren Spruell
phatbuckett@gmail.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web