Skip to main content

SSH public key parser

Project description

https://travis-ci.org/ojarva/python-sshpubkeys.svg?branch=master

This library validates OpenSSH public keys.

Currently ssh-rsa, ssh-dss (DSA), ssh-ed25519 and ecdsa keys with NIST curves are supported.

Installation:

pip install sshpubkeys

or clone the repository and use

python setup.py install

Usage:

import sshpubkeys
ssh = SSHKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAYQCxO38tKAJXIs9ivPxt7AY"
      "dfybgtAR1ow3Qkb9GPQ6wkFHQqcFDe6faKCxH6iDRteo4D8L8B"
      "xwzN42uZSB0nfmjkIxFTcEU3mFSXEbWByg78aoddMrAAjatyrh"
      "H1pON6P0= ojarva@ojar-laptop")
print(ssh.bits) # 768
print(ssh.hash()) # 56:84:1e:90:08:3b:60:c7:29:70:5f:5e:25:a6:3b:86

Exceptions

  • NotImplementedError if invalid ecdsa curve or unknown key type is encountered.

  • InvalidKeyException if any other error is encountered:
    • TooShortKeyException if key is too short (<768 bits for RSA, <1024 for DSA, <256 for ED25519)

    • TooLongKeyException if key is too long (>16384 for RSA, >1024 for DSA, >256 for ED25519)

    • InvalidTypeException if key type (“ssh-rsa” in above example) does not match to what is included in base64 encoded data.

    • MalformedDataException if decoding and extracting the data fails.

Tests

See “tests/” folder for unit tests. Use

python setup.py test

or

python3 setup.py test

to run test suite. If you have keys that are not parsed properly, or malformed keys that raise incorrect exception, please send your public key to olli@jarva.fi, and I’ll include it. Alternatively, create a new issue or make a pull request in github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sshpubkeys-1.0.5.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sshpubkeys-1.0.5-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sshpubkeys-1.0.5.tar.gz.

File metadata

  • Download URL: sshpubkeys-1.0.5.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sshpubkeys-1.0.5.tar.gz
Algorithm Hash digest
SHA256 21155c9c2988c7f0bb16ba252105546e4049b83e50d9ee1c2cccb5252b7d253f
MD5 340d01663c0e15c71436b9cdce4dff7d
BLAKE2b-256 35193b4dcfe228d3bc11e070239b348ae860163d62d3b9a3d04322e13c907376

See more details on using hashes here.

File details

Details for the file sshpubkeys-1.0.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sshpubkeys-1.0.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5ccc3b4740f8ac55cbadcde3c1292b94e0862516ea8b0e1d2444df00057bf571
MD5 823356323e95074391ccda9e074f638a
BLAKE2b-256 0860a69330f4a8f3f4155e028eb4967bf130ee1e835e1e4d2dfd1539fb7d1b4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page