Table of Contents

Method IsValidFor

Namespace
SshSharp
Assembly
SshSharp.dll

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.

public bool IsValidFor(SshPublicKey authority, SshCertificateType type, string principal, DateTimeOffset time, out string? reason)

Parameters

authority SshPublicKey

The certificate authority you trust.

type SshCertificateType

The type the certificate must be: User for a user logging in, Host for a server.

principal string

The user name, or the host name, the certificate is presented for. A user certificate's principals must include it exactly; a host certificate's principals are patterns (*.example.com), matched without regard to case as DNS names are. A certificate without principals is no one's, as sshd and ssh have it (not everyone's).

time DateTimeOffset

The time to check at, usually UtcNow.

reason string

Why the certificate is not acceptable, as a short phrase (for example "it is valid only from ... to ..."), or null when it is.

Returns

bool

Whether the certificate is acceptable.

Remarks

A certificate with critical options (force-command, source-address, verify-required) is refused: they restrict what the certificate allows, and this check cannot enforce them. An application that does enforce them checks the parts itself: GetAuthorityKey(), Type, VerifySignature(), IsValidAt(DateTimeOffset), Principals and CriticalOptions. Revocation is not checked.