Table of Contents

Class SshCertificate

Namespace
SshSharp
Assembly
SshSharp.dll

An OpenSSH certificate (PROTOCOL.certkeys): a public key signed by a certificate authority, limited to some principals, a validity window, and options. Presented by servers as host keys and used by clients for public-key authentication. Read one with Parse(string), check one with IsValidFor(SshPublicKey, SshCertificateType, string, DateTimeOffset, out string?) (or its parts, VerifySignature() and IsValidAt(DateTimeOffset)), and issue one with SshCertificateBuilder.

public sealed class SshCertificate
Inheritance
SshCertificate
Inherited Members

Remarks

A certificate proves only that the holder of AuthorityKey signed it. Anyone can make a certificate authority, so what makes a certificate trustworthy is that its authority is one you trust: compare GetAuthorityKey() with it, as IsValidFor(SshPublicKey, SshCertificateType, string, DateTimeOffset, out string?) does.

Properties

Algorithm

The certificate's type name, for example ssh-ed25519-cert-v01@openssh.com.

AuthorityFingerprint

The certificate authority's SHA-256 fingerprint.

AuthorityKey

The certificate authority's public key, in SSH wire format (what @cert-authority lines hold).

Blob

The certificate in SSH wire format.

Comment

The comment after the certificate on its line (Parse(string)), often the certified key's; null when there is none.

CriticalOptions

Critical options (for example force-command, source-address); a verifier must refuse ones it does not understand.

ExtensionValues

The extensions by name, with their values: an empty string for one without a value, as the standard ones are (permit-pty), and the value a vendor's own extension carries (login@github.com), as Extensions writes it. Names are compared as written (ordinal).

Extensions

The extensions' names (for example permit-pty), in the certificate's order; ExtensionValues has their values.

Fingerprint

The certified key's SHA-256 fingerprint.

KeyId

The key identifier the authority chose (it appears in server logs).

KeyType

The certified key's type, for example ssh-ed25519.

Principals

The user or host names the certificate is valid for. An empty list is refused by IsValidFor(SshPublicKey, SshCertificateType, string, DateTimeOffset, out string?), by sshd for TrustedUserCAKeys and by ssh for host certificates; only an authorized_keys cert-authority line without principals= takes it as any user. A certificate lists at most 256, as OpenSSH allows; one with more is refused when it is read.

PublicKey

The certified public key, in SSH wire format.

Serial

The serial number the authority gave the certificate.

Type

Whether this certifies a user or a host.

ValidAfter

The start of the validity window (inclusive): UnixEpoch for "always".

ValidBefore

The end of the validity window (exclusive): MaxValue for "forever".

Methods

GetAuthorityKey()

AuthorityKey, the certificate authority's key, as an SshPublicKey: compare it with the authority you trust (certificate.GetAuthorityKey() == trustedCa).

GetPublicKey()

PublicKey, the certified key, as an SshPublicKey.

IsValidAt(DateTimeOffset)

Whether time is within the validity window, as OpenSSH has it: valid_after <= time < valid_before, in whole seconds. The window's start is inclusive and its end exclusive; "always" and "forever" (0xffffffffffffffff) are the ends of time.

IsValidFor(SshPublicKey, SshCertificateType, string, DateTimeOffset, out string?)

Checks the certificate as sshd checks a user certificate from a TrustedUserCAKeys authority, and ssh a host certificate from an @cert-authority: issued by authority, of type, with a valid signature (VerifySignature()), valid at time (IsValidAt(DateTimeOffset)), for principal, and without critical options.

Parse(string)

Parses a certificate from an OpenSSH -cert.pub file's contents (type base64 [comment]).

ToAuthorizedKeysLine()

The certificate as its -cert.pub file holds it: the certificate type, the base64 certificate and the comment, if any.

ToString()

The certificate as ToAuthorizedKeysLine() writes it.

VerifySignature()

Whether AuthorityKey's signature over the certificate is valid, with the rules the library applies to every certificate it checks: SHA-1 (ssh-rsa) signatures are refused, an RSA authority must have at least 2048 bits, and Ed25519 signatures are checked strictly (RFC 8032: a non-canonical signature or a small-order key fails).