ssh-key 0.7.0

Pure Rust implementation of SSH key file format decoders/encoders as described in RFC4251/RFC4253 and OpenSSH key formats, as well as "sshsig" signatures and certificates (including certificate validation and certificate authority support), with further support for the `authorized_keys` and `known_hosts` file formats.
Documentation

RustCrypto: SSH Keys and Certificates

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Documentation

About

Pure Rust implementation of SSH key file format decoders/encoders as described in RFC4251 and RFC4253 as well as OpenSSH's PROTOCOL.key format specification.

Additionally provides support for SSH signatures as described in PROTOCOL.sshsig, OpenSSH certificates as specified in PROTOCOL.certkeys including certificate validation and certificate authority (CA) support, FIDO/U2F keys as specified in PROTOCOL.u2f (and certificates thereof), and also the authorized_keys and known_hosts file formats.

Supports a minimal profile which works on heapless no_std targets. See "Supported algorithms" table below for which key formats work on heapless targets and which algorithms require alloc.

When the ed25519, p256, and/or rsa features of this crate are enabled, provides key generation and certificate signing/verification support for that respective SSH key algorithm.

Key fingerprints, certificate validation, and sshsig signing/verification of messages compute SHA-2 hashes using the sha2 crate, and are only available when the sha2 feature is enabled. It's on by default and implied by the ed25519, p256, p384, p521, ppk, and rsa features. With it disabled, sshsig signatures can still be created and verified from a digest computed by another SHA-2 implementation, using the *_prehash methods, or the *_digest methods with a type that implements AssociatedHashAlg.

Features

  • Constant-time Base64 decoder/encoder using base64ct/pem-rfc7468 crates
  • OpenSSH-compatible decoder/encoders for the following formats:
    • OpenSSH public keys
    • OpenSSH private keys (i.e. BEGIN OPENSSH PRIVATE KEY)
    • OpenSSH certificates
    • OpenSSH signatures (a.k.a. "sshsig")
  • OpenSSH certificate support
    • OpenSSH certificate validation
    • OpenSSH certificate authority (CA) support i.e. cert builder/signer
  • Private key encryption/decryption (bcrypt-pbkdf + aes256-ctr only)
  • Private key generation support: DSA, Ed25519, ECDSA (P-256/P-384/P-521), RSA, MLDSA44-Ed25519, and MLDSA87-P384
  • FIDO/U2F key support (sk-*) as specified in PROTOCOL.u2f
  • Fingerprint support
    • "randomart" fingerprint visualizations
  • no_std support including support for "heapless" (no-alloc) targets
  • Parsing authorized_keys files
  • Parsing known_hosts files
  • serde support
  • zeroize support for private keys

TODO

  • FIDO/U2F signature support
  • Legacy (pre-OpenSSH) SSH key format support
    • PKCS#1 SSH private keys (i.e. RSA-only)
    • PKCS#8 SSH private keys
    • RFC4716 SSH public keys
    • SEC1 SSH public keys

Supported Signature Algorithms

Name Decode Encode Cert Keygen Sign Verify Feature Alloc?
ecdsa‑sha2‑nistp256 ✅ ✅ ✅ ✅️ ✅️ ✅️ p256 no_alloc
ecdsa‑sha2‑nistp384 ✅ ✅ ✅ ✅️ ✅️ ✅️ p384 no_alloc
ecdsa‑sha2‑nistp521 ✅ ✅ ✅ ✅️️ ✅️ ️ ✅️️ p521 no_alloc
ssh‑dsa ✅ ✅ ✅ ✅ ✅️ ✅️ dsa alloc ️
ssh‑ed25519 ✅ ✅ ✅ ✅️ ✅️ ✅ ed25519 no_alloc
ssh‑rsa ✅ ✅ ✅ ✅️ ✅️ ✅ rsa alloc
sk‑ecdsa‑sha2‑nistp256@openssh.com ✅ ✅ ✅ ⛔ ⛔️ ✅️ ⛔ alloc
sk‑ssh‑ed25519@openssh.com ✅ ✅ ✅ ⛔ ⛔️ ✅️️ ed25519 alloc
ssh-mldsa44-ed25519 ✅ ✅ ✅ ✅️ ✅️ ✅️ mldsa44-ed25519 no_alloc
ssh-mldsa87-p384 ✅ ✅ ✅ ✅️ ✅️ ✅️ mldsa87-p384 no_alloc

By default no SSH signature algorithms are enabled and you will get an Error::AlgorithmUnsupported error if you try to use them.

Enable the crypto feature or the "Feature" for specific algorithms in the chart above (e.g. p256, rsa) in order to use cryptographic functionality.

The "Feature" column lists the name of ssh-key crate features which can be enabled to provide full support for the "Keygen", "Sign", and "Verify" functionality for a particular SSH key algorithm.

mldsa enables the SSH composite for each enabled curve and requires at least one of ed25519 or p384. Use mldsa44-ed25519 or mldsa87-p384 to select a pair, or combine mldsa with crypto to enable both composites.

Both composites are specified in draft-ietf-sshm-composite-sigs-01. The Ed25519 variant shipped in OpenSSH 10.6.

With default features disabled, both composites support key generation, OpenSSH key encoding and decoding, and signing and verification with Signature. Heapless builds store the public key and signature bytes inline. ML-DSA also uses stack space for its working buffers. Certificates and SshSig require the alloc feature.

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.