Certificates
Load, issue and verify OpenSSH user and host certificates.
Warning
Experimental: built on the pinned pre-release ssh-key 0.7.0-rc.12.
from oxcrypto.signature.ed25519 import ED25519
from oxcrypto.ssh.openssh import OPENSSH
ca = ED25519.ED25519.generate()
user = ED25519.ED25519.generate().public_key()
certificate = OPENSSH.OPENSSH.sign_certificate(
ca,
user,
principals=["alice"],
valid_after=1704067200,
valid_before=1735689600,
key_id="alice@example.com",
extensions={"permit-pty": ""},
)
assert certificate.verify(ca.public_key(), timestamp=1704067200)
line = certificate.to_bytes() # ssh-ed25519-cert-v01@openssh.com AAAA...load_certificate reads one *-cert-v01@openssh.com line and returns a
Certificate. Its properties are algorithm, cert_type ("user" or
"host"), serial, key_id, principals, valid_after and
valid_before (Unix seconds), critical_options, extensions, comment
and nonce. public_key() returns the certified key and signature_key()
the CA key, both as oxcrypto public keys. to_bytes() encodes the
certificate line.
verify(ca_public_key, timestamp=None) returns True only if the
certificate's signature verifies, the CA key matches ca_public_key, and
timestamp (default: now) is at least valid_after and before
valid_before. It does not check principals, critical options or revocation.
sign_certificate issues a certificate for any supported public key, signed
by an Ed25519, ECDSA or RSA CA key, with a random 32-byte nonce. principals
must not be empty, cert_type must be "user" (the default) or "host",
and valid_after must be earlier than valid_before; otherwise it raises
ValueError.