Skip to Content
oxcrypto

SSH

OpenSSH keys, authorized_keys, known_hosts, certificates and SSH signatures.

Warning

Experimental: the SSH family is built on ssh-key 0.7.0-rc.12, a pinned pre-release.

The SSH family reads and writes OpenSSH formats with the existing oxcrypto key classes. Loading returns an Ed25519PrivateKey, ECDSAPrivateKey, RSAPrivateKey or DSAPrivateKey (or the matching public key), and encoding accepts those same objects, so a key loaded from an OpenSSH file signs with ED25519.ED25519, ECDSA.P256 or RSA.PKCS1V15_SHA256 like any other key.

from oxcrypto.signature.ed25519 import ED25519
from oxcrypto.ssh.openssh import OPENSSH

private_key = ED25519.ED25519.generate()
pem = OPENSSH.OPENSSH.encode_private_key(private_key, password=b"pw", comment="me")
assert OPENSSH.OPENSSH.load_private_key(pem, password=b"pw") == private_key
line = OPENSSH.OPENSSH.encode_public_key(private_key.public_key(), comment="me")
SSH algorithmoxcrypto key
ssh-ed25519ED25519.ED25519 keys (not ED25519PH)
ecdsa-sha2-nistp256, -nistp384, -nistp521ECDSA.P256, ECDSA.P384, ECDSA.P521 keys
ssh-rsa (signing as rsa-sha2-512)two-prime RSA keys
ssh-dssDSA keys, load and encode only

Other key types raise TypeError; ECDSA curves other than P-256, P-384 and P-521, Ed25519ph keys and multi-prime RSA keys raise ValueError. Loading a file with another SSH algorithm, such as sk-ssh-ed25519@openssh.com, raises ValueError. DSA keys cannot sign SSH signatures or certificates, because OpenSSH disabled ssh-dss signatures by default in 7.0.

Malformed input raises ValueError, and text input must be UTF-8. A wrong password for an encrypted private key raises oxcrypto.InvalidTag.

Formats

Zeroization

Note

Private keys loaded from OpenSSH files are held by the existing oxcrypto key classes and wiped like them. ssh-key wipes its own private key types, decryption buffers and derived keys on drop, and oxcrypto computes the RSA iqmp coefficient in a wiped buffer. Decoding and encoding make short-lived copies on the stack and in the ssh-key encryption buffer that are not guaranteed to be wiped. Python bytes, including returned PEM files, are not wiped.

StandardOpenSSH PROTOCOL, PROTOCOL.key, PROTOCOL.certkeys and PROTOCOL.sshsig; RFC 4253, RFC 5656, RFC 8332 and RFC 8709
Cratessh-key 0.7.0-rc.12 (RustCrypto, Apache-2.0 OR MIT), pre-release, with ssh-encoding 0.3.0, ssh-cipher 0.3.0 and bcrypt-pbkdf 0.11.0
AuditNo published audit
MSRV1.87, builds with the project MSRV 1.88
ExperimentalYes
Test vectorsKeys, certificates and signatures generated with OpenSSH 8.9p1 ssh-keygen; output checked with ssh-keygen when it is installed

On this page