From 0c15f260f11a5c3f63a6963a9c5fb156d6c4df10 Mon Sep 17 00:00:00 2001 From: Carl Wallace Date: Mon, 7 Mar 2022 13:45:55 -0500 Subject: [PATCH] feat(x509): add CRL type support --- x509/src/crl.rs | 86 ++++++++++++++++++++++++++ x509/src/lib.rs | 1 + x509/tests/crl.rs | 17 +++++ x509/tests/examples/tscpbcasha256.crl | Bin 0 -> 660 bytes 4 files changed, 104 insertions(+) create mode 100644 x509/src/crl.rs create mode 100644 x509/tests/crl.rs create mode 100644 x509/tests/examples/tscpbcasha256.crl diff --git a/x509/src/crl.rs b/x509/src/crl.rs new file mode 100644 index 000000000..bc2538ac1 --- /dev/null +++ b/x509/src/crl.rs @@ -0,0 +1,86 @@ +//! Certificate Revocation List types + +use crate::ext::Extensions; +use crate::name::Name; +use crate::time::Time; +use crate::Version; + +use alloc::vec::Vec; + +use der::asn1::{BitString, UIntBytes}; +use der::Sequence; +use spki::AlgorithmIdentifier; + +/// `CertificateList` as defined in [RFC 5280 Section 5.1]. +/// +///```text +/// CertificateList ::= SEQUENCE { +/// tbsCertList TBSCertList, +/// signatureAlgorithm AlgorithmIdentifier, +/// signatureValue BIT STRING +/// } +/// ``` +/// +/// [RFC 5280 Section 5.1]: https://datatracker.ietf.org/doc/html/rfc5280#section-5.1 +#[derive(Clone, Debug, Eq, PartialEq, Sequence)] +#[allow(missing_docs)] +pub struct CertificateList<'a> { + pub tbs_cert_list: TbsCertList<'a>, + pub signature_algorithm: AlgorithmIdentifier<'a>, + pub signature: BitString<'a>, +} + +/// Implicit intermediate structure from the ASN.1 definition of `TBSCertList`. +/// +/// This type is used for the `revoked_certificates` field of `TbsCertList`. +/// See [RFC 5280 Section 5.1]. +/// +///```text +/// RevokedCert ::= SEQUENCE { +/// userCertificate CertificateSerialNumber, +/// revocationDate Time, +/// crlEntryExtensions Extensions OPTIONAL +/// } +/// ``` +/// +/// [RFC 5280 Section 5.1]: https://datatracker.ietf.org/doc/html/rfc5280#section-5.1 +#[derive(Clone, Debug, Eq, PartialEq, Sequence)] +#[allow(missing_docs)] +pub struct RevokedCert<'a> { + pub serial_number: UIntBytes<'a>, + pub revocation_date: Time, + pub crl_entry_extensions: Option>, +} + +/// `TbsCertList` as defined in [RFC 5280 Section 5.1]. +/// +/// ```text +/// TBSCertList ::= SEQUENCE { +/// version Version OPTIONAL, -- if present, MUST be v2 +/// signature AlgorithmIdentifier, +/// issuer Name, +/// thisUpdate Time, +/// nextUpdate Time OPTIONAL, +/// revokedCertificates SEQUENCE OF SEQUENCE { +/// userCertificate CertificateSerialNumber, +/// revocationDate Time, +/// crlEntryExtensions Extensions OPTIONAL -- if present, version MUST be v2 +/// } OPTIONAL, +/// crlExtensions [0] EXPLICIT Extensions OPTIONAL -- if present, version MUST be v2 +/// } +/// ``` +/// +/// [RFC 5280 Section 5.1]: https://datatracker.ietf.org/doc/html/rfc5280#section-5.1 +#[derive(Clone, Debug, Eq, PartialEq, Sequence)] +#[allow(missing_docs)] +pub struct TbsCertList<'a> { + pub version: Version, + pub signature: AlgorithmIdentifier<'a>, + pub issuer: Name<'a>, + pub this_update: Time, + pub next_update: Option