Browse the docs

silk.tls.certificate_profile.

Check one certificate against the TLS server certificate profile, and read its extensions.

When to use#

silk.tls.certificate_path uses this module for each certificate of a chain. Use CertificateProfile.inspect directly to check one certificate for a role (leaf, intermediate, or anchor) and to read its basic constraints, key usage, and other extensions. Use CertificateProfile.verifyIssuedBy to check that one certificate signed another.

Details#

The profile is strict. Keys and signatures must be ECDSA P-256 with SHA-256, ECDSA P-384 with SHA-384, or RSA with SHA-256 (2048 to 4096 bits). An unknown critical extension or another algorithm is an error. The result borrows the certificate and does not allocate.

Errors#

  • ProfileError with the reason, the extension, and the position of the problem.

Gotchas#

A certificate that passes does not mean that you can trust it. This module does not check dates, the chain, the host name, or revocation.

Import as CertificateProfile with import silk.tls.certificate_profile { CertificateProfile }.

Public declarations: 10.

CertificateRole#

silk
pub enum CertificateRole

The certificate's intended position in the restricted TLS-server profile.

ServerLeaf#

silk
ServerLeaf

A peer end-entity certificate inspected for admission to later TLS-server validation.

Intermediate#

silk
Intermediate

A non-anchor CA certificate below the trust endpoint.

Anchor#

silk
Anchor

An explicitly configured trust endpoint outside the returned path.

CertificateKeyKind#

silk
pub enum CertificateKeyKind

The admitted public-key algorithm and bounded key profile.

P256#

silk
P256

An uncompressed validated secp256r1 point.

P384#

silk
P384

An uncompressed validated secp384r1 point.

Rsa#

silk
Rsa

An odd 2048..4096-bit RSA modulus with exponent 65537.

ProfileLimits#

silk
pub struct ProfileLimits

Inclusive budgets for one semantic inspection or configured-constraint validation.

Field extensions#

silk
pub extensions: usize

Maximum number of certificate extensions, including unknown and duplicate OIDs.

Field extensionBytes#

silk
pub extensionBytes: usize

Maximum bytes in each extension value, including opaque unknown noncritical values.

Field sanNames#

silk
pub sanNames: usize

Maximum names in one subjectAltName value.

Field constraintSubtrees#

silk
pub constraintSubtrees: usize

Maximum GeneralSubtree values across one NameConstraints value.

Field nodes#

silk
pub nodes: usize

Maximum traversed extension-value TLV nodes across one operation.

Field depth#

silk
pub depth: usize

Maximum traversed extension-value TLV depth. A value root has depth one.

Implementation Copy for ProfileLimits#

silk
impl Copy for ProfileLimits

Implementation ProfileLimits#

silk
impl ProfileLimits

Associated function defaults#

silk
pub fn defaults() -> ProfileLimits

Returns 64 extensions, 16384 bytes per value, 256 SAN names, 256 constraint subtrees, 4096 traversed nodes, and depth 16.

ProfileClass#

silk
pub enum ProfileClass

The broad category of a semantic profile failure.

Malformed#

silk
Malformed

DER or recognized extension content violates the selected schema.

Unsupported#

silk
Unsupported

A well-formed value is outside the deliberately restricted profile.

ResourceLimit#

silk
ResourceLimit

A configured finite budget or target size bound is exceeded.

Implementation Debug for ProfileClass#

silk
impl Debug for ProfileClass

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as Malformed.

ProfileOffsetSpace#

silk
pub enum ProfileOffsetSpace

The byte sequence in which a profile error offset is measured.

CertificateDer#

silk
CertificateDer

Offset in the complete decoded certificate DER.

ConfiguredConstraintDer#

silk
ConfiguredConstraintDer

Offset in caller-supplied configured NameConstraints DER.

Implementation Debug for ProfileOffsetSpace#

silk
impl Debug for ProfileOffsetSpace

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as CertificateDer.

ProfileReason#

silk
pub enum ProfileReason

The stable semantic reason for a profile rejection.

Version#

silk
Version

The certificate version is invalid for the selected role.

Serial#

silk
Serial

A path-certificate serial is nonpositive, zero, or longer than 20 content octets.

UniqueIdentifier#

silk
UniqueIdentifier

An issuer or subject unique identifier is present.

PublicKey#

silk
PublicKey

The public-key algorithm, encoding, parameters, or mathematical key is not admitted.

SignatureAlgorithm#

silk
SignatureAlgorithm

The signature algorithm OID or signature BIT STRING metadata is not admitted.

SignatureParameters#

silk
SignatureParameters

A recognized signature algorithm has forbidden, missing, or unsupported parameters.

SignatureAlgorithmMismatch#

silk
SignatureAlgorithmMismatch

Inner and outer signature identifiers do not denote the same admitted effective algorithm.

Extensions#

silk
Extensions

More certificate extensions are present than the configured bound.

ExtensionBytes#

silk
ExtensionBytes

One extension value exceeds its configured byte bound.

DuplicateExtension#

silk
DuplicateExtension

A duplicate extension OID is present.

UnknownCriticalExtension#

silk
UnknownCriticalExtension

A critical extension has no supported semantics in this profile.

MalformedExtension#

silk
MalformedExtension

A recognized extension violates strict DER or its selected schema.

BasicConstraints#

silk
BasicConstraints

BasicConstraints conflicts with the role or path-length rules.

KeyUsage#

silk
KeyUsage

KeyUsage encoding or dependent bits are invalid.

MissingKeyUsage#

silk
MissingKeyUsage

A present KeyUsage does not authorize the selected role.

ExtendedKeyUsage#

silk
ExtendedKeyUsage

ExtendedKeyUsage is empty or malformed.

MissingServerAuth#

silk
MissingServerAuth

A present ExtendedKeyUsage omits id-kp-serverAuth.

SubjectAltName#

silk
SubjectAltName

subjectAltName is malformed or contains an invalid DNS/IP identity.

EmptySubject#

silk
EmptySubject

An empty subject lacks a nonempty critical subjectAltName.

UnsupportedCriticalName#

silk
UnsupportedCriticalName

A critical subjectAltName contains an unsupported GeneralName alternative.

NameConstraints#

silk
NameConstraints

NameConstraints is malformed, empty, noncritical, or used on an end entity.

UnsupportedNameConstraint#

silk
UnsupportedNameConstraint

A NameConstraints subtree form is outside the DNS/IP subset.

PolicyProcessing#

silk
PolicyProcessing

A certificate-policy feature requiring policy-tree processing is present.

TlsFeature#

silk
TlsFeature

TLS Feature is present although this profile cannot satisfy must-staple semantics.

Role#

silk
Role

The certificate role's CA or BasicConstraints policy is violated.

SanNames#

silk
SanNames

A SAN name count exceeds its configured bound.

ConstraintSubtrees#

silk
ConstraintSubtrees

A NameConstraints subtree count exceeds its configured bound.

Nodes#

silk
Nodes

The traversed extension-value node count exceeds its configured bound.

Depth#

silk
Depth

The traversed extension-value depth exceeds its configured bound.

SizeOverflow#

silk
SizeOverflow

Checked size or counter arithmetic cannot be represented.

IssuerName#

silk
IssuerName

The subject issuer Name DER does not exactly equal the issuer subject Name DER.

SignatureRejected#

silk
SignatureRejected

An admitted cryptographic primitive rejected the retained signature.

NameConstraintViolation#

silk
NameConstraintViolation

A subordinate DNS or IP subjectAltName violates one NameConstraints source.

NameComparisons#

silk
NameComparisons

The caller-supplied name/subtree comparison budget is exhausted.

Implementation Debug for ProfileReason#

silk
impl Debug for ProfileReason

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the name of the variant, such as Version.

ProfileError#

silk
pub struct ProfileError

The error when a certificate does not fit the TLS server certificate profile, with the reason, the extension, and the byte offset of the problem. It owns its values.

Field kind#

silk
pub kind: ProfileClass

Broad failure category.

Field reason#

silk
pub reason: ProfileReason

Stable semantic failure reason.

Field extensionIndex#

silk
pub extensionIndex: Option<usize>

Zero-based extension index when the failure belongs to one certificate extension.

Field offsetSpace#

silk
pub offsetSpace: ProfileOffsetSpace

Coordinate system for offset.

Field offset#

silk
pub offset: usize

Byte offset in the selected coordinate system.

Implementation Debug for ProfileError#

silk
impl Debug for ProfileError

Operation debug#

silk
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut Writer

Writes the fields, as ProfileError { kind: ..., reason: ..., ... }.

KeyUsage#

silk
pub struct KeyUsage

Parsed KeyUsage bits retained independently of their original DER positions.

Field digitalSignature#

silk
pub digitalSignature: bool

digitalSignature bit.

Field contentCommitment#

silk
pub contentCommitment: bool

contentCommitment/nonRepudiation bit.

Field keyEncipherment#

silk
pub keyEncipherment: bool

keyEncipherment bit.

Field dataEncipherment#

silk
pub dataEncipherment: bool

dataEncipherment bit.

Field keyAgreement#

silk
pub keyAgreement: bool

keyAgreement bit.

Field keyCertSign#

silk
pub keyCertSign: bool

keyCertSign bit.

Field crlSign#

silk
pub crlSign: bool

cRLSign bit.

Field encipherOnly#

silk
pub encipherOnly: bool

encipherOnly bit.

Field decipherOnly#

silk
pub decipherOnly: bool

decipherOnly bit.

Implementation Copy for KeyUsage#

silk
impl Copy for KeyUsage

ExtendedKeyUsage#

silk
pub struct ExtendedKeyUsage

Parsed ExtendedKeyUsage facts used by the restricted TLS-server profile.

Field serverAuth#

silk
pub serverAuth: bool

Whether id-kp-serverAuth occurs.

Field anyExtendedKeyUsage#

silk
pub anyExtendedKeyUsage: bool

Whether anyExtendedKeyUsage occurs. It never substitutes for serverAuth.

Field purposeCount#

silk
pub purposeCount: usize

Number of key-purpose identifiers in the original extension.

Implementation Copy for ExtendedKeyUsage#

silk
impl Copy for ExtendedKeyUsage

CertificateProfile#

silk
pub struct CertificateProfile<'a>

A checked view of one decoded certificate for the TLS server certificate profile, with its extensions.

When to use#

Make one with CertificateProfile.inspect to check one certificate for a role (leaf, intermediate, or anchor) and to read its basic constraints, key usage, and other extensions. silk.tls.certificate_path does this for each certificate of a chain.

Details#

The profile is strict. Keys and signatures must be ECDSA P-256 with SHA-256, ECDSA P-384 with SHA-384, or RSA with SHA-256 (2048 to 4096 bits). An unknown critical extension or another algorithm is an error. The view borrows the certificate and does not allocate.

Gotchas#

A certificate that passes does not mean that you can trust it. The profile does not check dates, the chain, the host name, or revocation.

Implementation Copy for CertificateProfile<'a>#

silk
impl<'a> Copy for CertificateProfile<'a>

Implementation CertificateProfile<'a>#

silk
impl<'a> CertificateProfile<'a>

Associated function inspect#

silk
pub fn inspect(
    certificate: &'a Certificate,
    selectedRole: CertificateRole,
    limits: ProfileLimits,
  ) -> Result<CertificateProfile<'a>, ProfileError>

Checks certificate for the role selectedRole, and returns a view of its checked fields.

For a leaf or an intermediate, the inner and outer signature algorithms must match and be supported. For an anchor, the signature, serial number, dates, and self-signature are not checked, because you chose to trust it.

The profile is strict. Keys and signatures must be ECDSA P-256 with SHA-256, ECDSA P-384 with SHA-384, or RSA with SHA-256 (2048 to 4096 bits). An unknown critical extension or another algorithm is an error. The result borrows certificate and does not allocate.

Errors#

  • Failure with a ProfileError if the certificate does not fit the profile for the role or goes over limits.

Gotchas#

It does not verify a signature or check dates, the chain, the host name, or revocation. A certificate that passes does not mean that you can trust it.

Method certificate#

silk
pub fn certificate(self: &Self) -> &'a Certificate

Borrows the structurally decoded certificate retained by this view.

Method certificateRole#

silk
pub fn certificateRole(self: &Self) -> CertificateRole

Returns the role under which this certificate was inspected.

Method keyKind#

silk
pub fn keyKind(self: &Self) -> CertificateKeyKind

Returns the admitted public-key profile.

Method ca#

silk
pub fn ca(self: &Self) -> bool

Returns the admitted BasicConstraints CA value, or false when absent.

Method pathLength#

silk
pub fn pathLength(self: &Self) -> Option<usize>

Returns the admitted BasicConstraints path length when present.

Method keyUsage#

silk
pub fn keyUsage(self: &Self) -> Option<KeyUsage>

Returns admitted KeyUsage facts when the extension was present.

Method extendedKeyUsage#

silk
pub fn extendedKeyUsage(self: &Self) -> Option<ExtendedKeyUsage>

Returns admitted ExtendedKeyUsage facts when the extension was present.

Method subjectAltNamesDer#

silk
pub fn subjectAltNamesDer(self: &Self) -> Option<&'a [u8]>

Borrows the exact subjectAltName extension-value DER when present.

Method nameConstraintsDer#

silk
pub fn nameConstraintsDer(self: &Self) -> Option<&'a [u8]>

Borrows the exact embedded NameConstraints extension-value DER when present.

Associated function validateConfiguredNameConstraints#

silk
pub fn validateConfiguredNameConstraints(
    value: &[u8],
    limits: ProfileLimits,
  ) -> Result<(), ProfileError>

Validates strict configured DNS/IP NameConstraints without allocating or retaining input.

Associated function checkNameConstraints#

silk
pub fn checkNameConstraints(
    subject: &CertificateProfile,
    constraintDer: &[u8],
    comparisons: &mut usize,
    maximumComparisons: usize,
    offsetSpace: ProfileOffsetSpace,
  ) -> Result<(), ProfileError>

Checks every DNS and IP subjectAltName against one strict NameConstraints value.

Details#

Exclusions run before permissions. The operation consumes one comparison before each same-form name/subtree comparison and updates comparisons across calls. offsetSpace identifies the coordinate system used by any returned constraint error.

Gotchas#

The constraint value must first pass validateConfiguredNameConstraints or profile inspection. The operation checks only one constraint source. Callers must apply all sources.

Associated function verifyIssuedBy#

silk
pub fn verifyIssuedBy(
    subject: &CertificateProfile,
    issuer: &CertificateProfile,
  ) -> Result<(), ProfileError>

Verifies exact issuer-name linkage and the subject's retained original TBS signature.

Gotchas#

This checks only one edge. It does not establish path, time, constraint, trust, or identity authentication.

Category: TLS and certificates.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.

View the source of this page