Class SshCertificateBuilder
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
Issues an OpenSSH certificate (PROTOCOL.certkeys) as its certificate authority, as ssh-keygen -s does: set what the
certificate allows, then sign it with the authority's key (SignAsync(SshPrivateKey, CancellationToken)). The key can be one an SSH agent, a key vault or
a KMS holds (FromSigner(SshKeySigner, string?)), so the authority's private key need never be in the process.
public sealed class SshCertificateBuilder
- Inheritance
-
SshCertificateBuilder
- Inherited Members
Remarks
The validity window has no default end: set ValidBefore, as short as the use allows (minutes to hours for a CI job or a bastion session). A certificate is hard to take back once issued; one that expires on its own needs no revocation.
A user certificate starts with the extensions ssh-keygen gives one (permit-X11-forwarding, permit-agent-forwarding,
permit-port-forwarding, permit-pty, permit-user-rc); remove the ones the user does not need, or call
Extensions.Clear() for none, as ssh-keygen -O clear does. A host certificate starts with none.
The builder checks what it signs: at least one principal and at most 256 (OpenSSH's limit), option and extension names that are
the standard ones or a vendor's own (name@example.com), values where the option needs one (and none where it takes none),
parseable source-address lists, no critical options on a host certificate, and a validity window that is not empty. Names are written sorted and once each, as
PROTOCOL.certkeys requires. A builder is not thread-safe; it can sign any number of certificates, each with a fresh nonce.
Constructors
- SshCertificateBuilder(SshPublicKey, SshCertificateType, string)
Creates a builder for a certificate of
typeforpublicKey.
Fields
- ForceCommand
The
force-commandcritical option: the command the server runs instead of the one the user asks for.
- SourceAddress
The
source-addresscritical option: the client addresses, as a comma-separated CIDR list, the certificate is valid from.
- VerifyRequired
The
verify-requiredcritical option: a FIDO key must verify its user (a PIN) for each signature, not only see a touch.
Properties
- CriticalOptions
Critical options, by name, with their values: ForceCommand and SourceAddress take a value, VerifyRequired takes none (an empty string). A server refuses a certificate with a critical option it does not know, so a vendor's own (
name@example.com) works only with servers that know it. Host certificates have none.
- Extensions
Extensions, by name, with their values (an empty string for none; the standard ones take none). A user certificate starts with those
ssh-keygensets by default, a host certificate with none. The standard ones arepermit-X11-forwarding,permit-agent-forwarding,permit-port-forwarding,permit-pty,permit-user-rcandno-touch-required; servers ignore extensions they do not know, so a vendor's own (name@example.com) may carry a value.
- KeyId
The key identifier, which sshd logs when the certificate is used.
- Principals
The user names (for a user certificate) or host names (for a host certificate, where
*and?are wildcards) the certificate is valid for (ssh-keygen -n). At least one is required: a certificate without principals would be valid for any user where a server'sauthorized_keystrusts the authority withoutprincipals=. At most 256: OpenSSH refuses a certificate with more.
- PublicKey
The key the certificate certifies.
- Serial
The serial number (
ssh-keygen -z), 0 by default. Give each certificate its own, from a counter you keep: a revocation list (ssh-keygen -k) revokes certificates by serial.
- Type
Whether the certificate is for a user or a host.
- ValidAfter
When the certificate becomes valid. Null (the default) is one minute before signing, so that a server whose clock is a little behind accepts a new certificate at once. UnixEpoch or earlier is "always".
- ValidBefore
When the certificate stops being valid (exclusive). Required: there is no default, so that no certificate is valid forever by accident. MaxValue is "forever", as
ssh-keygenissues without-V.
Methods
- SignAsync(SshPrivateKey, CancellationToken)
Signs the certificate with
authority, the certificate authority's key, asssh-keygen -sdoes. An RSA authority signs withrsa-sha2-512(asssh-keygenby default) or, when its signer offers only that,rsa-sha2-256; never with SHA-1ssh-rsa. The signer is asked with Certificate, and the signature is checked against the authority's public key before the certificate is returned.