pub struct EndEntityCert<'a> { /* private fields */ }Expand description
An end-entity certificate.
Server certificate processing in a TLS connection consists of several steps. All of these steps are necessary:
- Build a
VerifiedPathusing a PathBuilder: verify that the peer’s certificate is valid for the current usage scenario. For server authentication, usecrate::ExtendedKeyUsage::SERVER_AUTH. EndEntityCert::verify_is_valid_for_subject_name(): Verify that the server’s certificate is valid for the host or IP address that is being connected to.EndEntityCert::verify_signature(): Verify that the signature of server’sServerKeyExchangemessage is valid for the server’s certificate.
Client certificate processing in a TLS connection consists of analogous steps. All of these steps are necessary:
- Build a
VerifiedPathusing a PathBuilder: verify that the peer’s certificate is valid for the current usage scenario. For client authentication, usecrate::ExtendedKeyUsage::CLIENT_AUTH. EndEntityCert::verify_signature(): Verify that the signature of client’sCertificateVerifymessage is valid using the public key from the client’s certificate.
Although it would be less error-prone to combine all these steps into a
single function call, some significant optimizations are possible if the
three steps are processed separately (in parallel). It does not matter much
which order the steps are done in, but all of these steps must completed
before application data is sent and before received application data is
processed. The TryFrom conversion from &CertificateDer<'_> is an
inexpensive operation and is deterministic, so if these tasks are done in
multiple threads, it is probably best to just create multiple EndEntityCert
instances for the same DER-encoded ASN.1 certificate bytes.
Implementations§
Source§impl EndEntityCert<'_>
impl EndEntityCert<'_>
Sourcepub fn verify_is_valid_for_subject_name(
&self,
server_name: &ServerName<'_>,
) -> Result<(), Error>
pub fn verify_is_valid_for_subject_name( &self, server_name: &ServerName<'_>, ) -> Result<(), Error>
Verifies that the certificate is valid for the given Subject Name.
Sourcepub fn verify_signature(
&self,
signature_alg: &dyn SignatureVerificationAlgorithm,
msg: &[u8],
signature: &[u8],
) -> Result<(), Error>
pub fn verify_signature( &self, signature_alg: &dyn SignatureVerificationAlgorithm, msg: &[u8], signature: &[u8], ) -> Result<(), Error>
Verifies the signature signature of message msg using the
certificate’s public key.
signature_alg is the algorithm to use to
verify the signature; the certificate’s public key is verified to be
compatible with this algorithm.
For TLS 1.2, signature corresponds to TLS’s
DigitallySigned.signature and signature_alg corresponds to TLS’s
DigitallySigned.algorithm of TLS type SignatureAndHashAlgorithm. In
TLS 1.2 a single SignatureAndHashAlgorithm may map to multiple
SignatureVerificationAlgorithms. For example, a TLS 1.2
SignatureAndHashAlgorithm of (ECDSA, SHA-256) may map to any or all
of {ECDSA_P256_SHA256, ECDSA_P384_SHA256}, depending on how the TLS
implementation is configured.
For TLS 1.3 (RFC 8446), signature_alg corresponds to TLS’s
algorithm field of type SignatureScheme. There is (currently) a
one-to-one correspondence between TLS 1.3’s SignatureScheme and
SignatureVerificationAlgorithm.
Sourcepub fn sct_log_timestamps<'a>(
&'a self,
) -> Result<impl Iterator<Item = Result<LogIdAndTimestamp, Error>> + 'a, Error>
pub fn sct_log_timestamps<'a>( &'a self, ) -> Result<impl Iterator<Item = Result<LogIdAndTimestamp, Error>> + 'a, Error>
Returns the CT logs that contributed to the SCTs included in the certificate.
Note this method does not verify the SCTs themselves.
If the certificate does not contain an SCT extension, this method returns an empty iterator.
Methods from Deref<Target = Cert<'a>>§
Sourcepub fn valid_dns_names(&self) -> impl Iterator<Item = &'a str>
pub fn valid_dns_names(&self) -> impl Iterator<Item = &'a str>
Returns a list of valid DNS names provided in the subject alternative names extension
This function must not be used to implement custom DNS name verification. Checking that a certificate is valid for a given subject name should always be done with EndEntityCert::verify_is_valid_for_subject_name.
Sourcepub fn valid_uri_names(&self) -> impl Iterator<Item = &'a str>
pub fn valid_uri_names(&self) -> impl Iterator<Item = &'a str>
Returns a list of valid URI names provided in the subject alternative names extension
This function returns URIs as strings without performing validation beyond checking that they are valid UTF-8.
Sourcepub fn serial(&self) -> &[u8] ⓘ
pub fn serial(&self) -> &[u8] ⓘ
Raw certificate serial number.
This is in big-endian byte order, in twos-complement encoding.
If the caller were to add an INTEGER tag and suitable length, this
would become a valid DER encoding.
Sourcepub fn issuer(&self) -> &[u8] ⓘ
pub fn issuer(&self) -> &[u8] ⓘ
Raw DER-encoded certificate issuer.
This does not include the outer SEQUENCE tag or length.
Sourcepub fn subject(&self) -> &[u8] ⓘ
pub fn subject(&self) -> &[u8] ⓘ
Raw DER encoded certificate subject.
This does not include the outer SEQUENCE tag or length.
Sourcepub fn subject_public_key_info(&self) -> SubjectPublicKeyInfoDer<'static>
Available on crate feature alloc only.
pub fn subject_public_key_info(&self) -> SubjectPublicKeyInfoDer<'static>
alloc only.Get the RFC 5280-compliant SubjectPublicKeyInfoDer (SPKI) of this Cert.
This does include the outer SEQUENCE tag and length.
Sourcepub fn der(&self) -> CertificateDer<'a>
pub fn der(&self) -> CertificateDer<'a>
Raw DER-encoded representation of the certificate.