silk.tls.certificate_identities.
Decode the subject alternative names (SAN) of a certificate: the DNS names and IP addresses that it is for.
When to use#
Use CertificateSan.decode to read the SAN list of a certificate, and pass the result to
HttpsIdentity.verify to check a host name. Use CertificateSan.decodeValue when you have
only the DER of a GeneralNames value.
Details#
The functions write one PresentedIdentity for each name into storage that you give, in source
order, and return how many they wrote. The names borrow the input. Nothing allocates. Forms
other than DNS names and IP addresses are returned as Other with their raw bytes.
Errors#
SanDecodeErrorif the DER is not valid, there are two SAN extensions, the SAN is empty, the storage is too small, or a limit is exceeded.
Gotchas#
After an error, the storage can hold some names. Do not use them. These functions check the
encoding only. HttpsIdentity.verify checks DNS syntax and IP lengths.
Examples#
Decode a SAN value#
import silk.tls.certificate_identities {
CertificateSan,
SanDecodeError,
SanDecodeLimits,
SanDecodeSummary
}
import silk.tls.https_identity { PresentedIdentity }
import silk.core.result { Result }
pub fn main() -> i32 {
// GeneralNames with one dNSName: SEQUENCE { [2] "a.example" }.
let der = b"\x30\x0b\x82\x09a.example"
let mut storage: [PresentedIdentity; 4] = [PresentedIdentity.Other { tag: 0, bytes: b"" }; 4]
return match CertificateSan.decodeValue(der, &mut storage, SanDecodeLimits.standard()) {
Result<SanDecodeSummary, SanDecodeError>.Success { value } => {
if value.count != 1 {
return 1
}
return match storage[0] {
PresentedIdentity.Dns { bytes } => {
if bytes.length != 9 {
return 1
}
return 0
}
_ => 1
}
}
Result<SanDecodeSummary, SanDecodeError>.Failure { error: _ } => 1
}
}Import as CertificateSan with import silk.tls.certificate_identities { CertificateSan }.
Public declarations: 6.
SanDecodeLimits#
pub struct SanDecodeLimitsFinite resource budgets for one SAN decode operation.
Field extensions#
pub extensions: usizeMaximum extension count scanned, including unrelated extensions.
Field inputBytes#
pub inputBytes: usizeMaximum sum of all extension OID and value lengths, or raw GeneralNames length.
Field identities#
pub identities: usizeMaximum number of GeneralName descriptors.
Field nodes#
pub nodes: usizeMaximum number of traversed DER nodes.
Field depth#
pub depth: usizeMaximum DER depth. The implementation also enforces a ceiling of 32.
Implementation Copy for SanDecodeLimits#
impl Copy for SanDecodeLimitsImplementation SanDecodeLimits#
impl SanDecodeLimitsAssociated function standard#
pub fn standard() -> SanDecodeLimitsReturns budgets of 256 extensions, 1 MiB input, 256 identities, 4096 nodes, and depth 32.
SanDecodeClass#
pub enum SanDecodeClassThe category of a SAN adapter failure.
Malformed#
MalformedThe SAN DER or GeneralName schema is malformed.
ResourceLimit#
ResourceLimitInput, traversal, or descriptor storage exceeds a budget.
Implementation Debug for SanDecodeClass#
impl Debug for SanDecodeClassOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant, such as Malformed.
SanDecodeReason#
pub enum SanDecodeReasonThe adapter-specific cause of a SAN failure.
InvalidDer#
InvalidDerDER encoding or GeneralName schema is invalid.
DuplicateSan#
DuplicateSanMore than one subjectAltName extension is present.
EmptySan#
EmptySanA present SAN contains no names.
Extensions#
ExtensionsThe extension count exceeds its budget.
InputBytes#
InputBytesInput bytes exceed their budget.
Identities#
IdentitiesThe descriptor count exceeds its budget.
Storage#
StorageCaller storage cannot hold every descriptor.
Nodes#
NodesDER node count exceeds its budget.
Depth#
DepthDER depth exceeds its budget or the hard ceiling of 32.
Implementation Debug for SanDecodeReason#
impl Debug for SanDecodeReasonOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant, such as InvalidDer.
SanDecodeError#
pub struct SanDecodeErrorAn owned SAN error with an offset in GeneralNames DER, or zero for extension-list failures.
Field kind#
pub kind: SanDecodeClassThe category of this failure.
Field reason#
pub reason: SanDecodeReasonThe failed adapter rule.
Field offset#
pub offset: usizeThe failed DER offset. Extension-list failures use zero.
Implementation Debug for SanDecodeError#
impl Debug for SanDecodeErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the fields, as SanDecodeError { kind: ..., reason: ..., ... }.
SanDecodeSummary#
pub struct SanDecodeSummaryThe initialized descriptor prefix after successful decoding.
Field present#
pub present: boolWhether a subjectAltName extension was present.
Field count#
pub count: usizeNumber of initialized entries in caller storage.
Field nodes#
pub nodes: usizeNumber of DER nodes traversed while validating the selected GeneralNames value.
CertificateSan#
pub struct CertificateSanOperations that decode the subject alternative names (SAN) of a certificate: the DNS names and IP addresses that it is for.
When to use#
Use CertificateSan.decode to read the SAN list of a certificate, and pass the result to
HttpsIdentity.verify to check a host name. Use CertificateSan.decodeValue when you have
only the DER of a GeneralNames value.
Details#
The functions write one PresentedIdentity for each name into storage that you give, in source
order, and return how many they wrote. The names borrow the input. Nothing allocates. Forms
other than DNS names and IP addresses are returned as Other with their raw bytes.
Gotchas#
After an error, the storage can hold some names. Do not use them. These functions check the
encoding only. HttpsIdentity.verify checks DNS syntax and IP lengths.
Implementation CertificateSan#
impl CertificateSanAssociated function validateValue#
pub fn validateValue(
value: &[u8],
limits: SanDecodeLimits,
) -> Result<SanDecodeSummary, SanDecodeError>Checks one DER GeneralNames value and returns the number of names, without storage.
The DER structure and the encoding of each GeneralName are checked. Some ASN.1 types inside
otherName and x400Address are not checked. Nothing allocates.
Errors#
Failurewith aSanDecodeErrorif the DER is not valid or a limit is exceeded.
Associated function decodeValue#
pub fn decodeValue<'a>(
value: &'a [u8],
storage: &mut [PresentedIdentity<'a>],
limits: SanDecodeLimits,
) -> Result<SanDecodeSummary, SanDecodeError>Decodes the DER GeneralNames value value into storage, and returns the number of names.
The names borrow value. The DER structure and the encoding of each GeneralName are checked.
Some ASN.1 types inside otherName and x400Address are not checked.
Errors#
Failurewith aSanDecodeErrorif the DER is not valid,storageis too small, or a limit is exceeded.
Gotchas#
After an error, storage can hold some names. Do not use them. This function checks the
encoding only. HttpsIdentity.verify checks DNS syntax and IP lengths.
Associated function decode#
pub fn decode<'a>(
certificate: &'a Certificate,
storage: &mut [PresentedIdentity<'a>],
limits: SanDecodeLimits,
) -> Result<SanDecodeSummary, SanDecodeError>Finds the SAN extension of certificate, decodes it into storage, and returns a summary.
If the certificate has no SAN extension, present is false and count is 0. The function
writes one PresentedIdentity for each name into storage, in source order. The names
borrow certificate. Nothing allocates. Forms other than DNS names and IP addresses are
returned as Other with their raw bytes.
Errors#
Failurewith aSanDecodeErrorif there are two SAN extensions, the SAN is empty or not valid,storageis too small, or a limit is exceeded.
Gotchas#
After an error, storage can hold some names. Do not use them. This function checks the
encoding only. HttpsIdentity.verify checks DNS syntax and IP lengths.
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.