webpki/
lib.rs

1// Copyright 2015 Brian Smith.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
10// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15//! webpki: Web PKI X.509 Certificate Validation.
16//!
17//! See `EndEntityCert`'s documentation for a description of the certificate
18//! processing steps necessary for a TLS connection.
19//!
20//! # Features
21//!
22//! | Feature | Description |
23//! | ------- | ----------- |
24//! | `alloc` | Enable features that require use of the heap. Currently all RSA signature algorithms require this feature. |
25//! | `std` | Enable features that require libstd. Implies `alloc`. |
26//! | `ring` | Enable use of the *ring* crate for cryptography. |
27//! | `aws-lc-rs` | Enable use of the aws-lc-rs crate for cryptography. Previously this feature was named `aws_lc_rs`. |
28
29#![no_std]
30#![warn(
31    clippy::alloc_instead_of_core,
32    clippy::use_self,
33    clippy::std_instead_of_core
34)]
35#![deny(missing_docs, clippy::as_conversions)]
36// Enable documentation for all features on docs.rs
37#![cfg_attr(webpki_docsrs, feature(doc_cfg))]
38
39#[cfg(any(feature = "std", test))]
40extern crate std;
41
42#[cfg(any(test, feature = "alloc"))]
43#[cfg_attr(test, macro_use)]
44extern crate alloc;
45
46#[macro_use]
47mod der;
48
49#[cfg(feature = "aws-lc-rs")]
50mod aws_lc_rs_algs;
51mod cert;
52mod end_entity;
53mod error;
54#[cfg(feature = "ring")]
55mod ring_algs;
56mod rpk_entity;
57/// Processing of certificate transparency SCTs.
58pub mod sct;
59mod signed_data;
60mod subject_name;
61mod time;
62mod trust_anchor;
63
64mod crl;
65mod verify_cert;
66mod x509;
67
68#[cfg(test)]
69pub(crate) mod test_utils;
70
71pub use {
72    cert::Cert,
73    crl::{
74        BorrowedCertRevocationList, BorrowedRevokedCert, CertRevocationList, CrlsRequired,
75        ExpirationPolicy, RevocationCheckDepth, RevocationOptions, RevocationOptionsBuilder,
76        RevocationReason, UnknownStatusPolicy,
77    },
78    der::DerIterator,
79    end_entity::EndEntityCert,
80    error::{
81        DerTypeId, Error, InvalidNameContext, UnsupportedSignatureAlgorithmContext,
82        UnsupportedSignatureAlgorithmForPublicKeyContext,
83    },
84    rpk_entity::RawPublicKeyEntity,
85    trust_anchor::anchor_from_trusted_cert,
86    verify_cert::{
87        ExtendedKeyUsage, ExtendedKeyUsageValidator, IntermediateIterator, KeyPurposeId,
88        KeyPurposeIdIter, RequiredEkuNotFoundContext, VerifiedPath,
89    },
90};
91
92#[cfg(feature = "alloc")]
93pub use trust_anchor::spki_for_anchor;
94
95#[cfg(feature = "alloc")]
96pub use crl::{OwnedCertRevocationList, OwnedRevokedCert};
97
98#[cfg(feature = "ring")]
99/// Signature verification algorithm implementations using the *ring* crypto library.
100pub mod ring {
101    pub use super::ring_algs::{
102        ECDSA_P256_SHA256, ECDSA_P256_SHA384, ECDSA_P384_SHA256, ECDSA_P384_SHA384, ED25519,
103    };
104
105    #[cfg(feature = "alloc")]
106    pub use super::ring_algs::{
107        RSA_PKCS1_2048_8192_SHA256, RSA_PKCS1_2048_8192_SHA256_ABSENT_PARAMS,
108        RSA_PKCS1_2048_8192_SHA384, RSA_PKCS1_2048_8192_SHA384_ABSENT_PARAMS,
109        RSA_PKCS1_2048_8192_SHA512, RSA_PKCS1_2048_8192_SHA512_ABSENT_PARAMS,
110        RSA_PKCS1_3072_8192_SHA384, RSA_PSS_2048_8192_SHA256_LEGACY_KEY,
111        RSA_PSS_2048_8192_SHA384_LEGACY_KEY, RSA_PSS_2048_8192_SHA512_LEGACY_KEY,
112    };
113}
114
115#[cfg(feature = "aws-lc-rs")]
116/// Signature verification algorithm implementations using the aws-lc-rs crypto library.
117pub mod aws_lc_rs {
118    pub use super::aws_lc_rs_algs::{
119        ECDSA_P256_SHA256, ECDSA_P256_SHA384, ECDSA_P256_SHA512, ECDSA_P384_SHA256,
120        ECDSA_P384_SHA384, ECDSA_P384_SHA512, ECDSA_P521_SHA256, ECDSA_P521_SHA384,
121        ECDSA_P521_SHA512, ED25519, RSA_PKCS1_2048_8192_SHA256,
122        RSA_PKCS1_2048_8192_SHA256_ABSENT_PARAMS, RSA_PKCS1_2048_8192_SHA384,
123        RSA_PKCS1_2048_8192_SHA384_ABSENT_PARAMS, RSA_PKCS1_2048_8192_SHA512,
124        RSA_PKCS1_2048_8192_SHA512_ABSENT_PARAMS, RSA_PKCS1_3072_8192_SHA384,
125        RSA_PSS_2048_8192_SHA256_LEGACY_KEY, RSA_PSS_2048_8192_SHA384_LEGACY_KEY,
126        RSA_PSS_2048_8192_SHA512_LEGACY_KEY,
127    };
128    #[cfg(all(feature = "aws-lc-rs-unstable", not(feature = "aws-lc-rs-fips")))]
129    pub use super::aws_lc_rs_algs::{ML_DSA_44, ML_DSA_65, ML_DSA_87};
130}
131
132/// An array of all the verification algorithms exported by this crate.
133///
134/// This will be empty if the crate is built without the `ring` and `aws-lc-rs` features.
135pub static ALL_VERIFICATION_ALGS: &[&dyn pki_types::SignatureVerificationAlgorithm] = &[
136    #[cfg(feature = "ring")]
137    ring::ECDSA_P256_SHA256,
138    #[cfg(feature = "ring")]
139    ring::ECDSA_P256_SHA384,
140    #[cfg(feature = "ring")]
141    ring::ECDSA_P384_SHA256,
142    #[cfg(feature = "ring")]
143    ring::ECDSA_P384_SHA384,
144    #[cfg(feature = "ring")]
145    ring::ED25519,
146    #[cfg(all(feature = "ring", feature = "alloc"))]
147    ring::RSA_PKCS1_2048_8192_SHA256,
148    #[cfg(all(feature = "ring", feature = "alloc"))]
149    ring::RSA_PKCS1_2048_8192_SHA384,
150    #[cfg(all(feature = "ring", feature = "alloc"))]
151    ring::RSA_PKCS1_2048_8192_SHA512,
152    #[cfg(all(feature = "ring", feature = "alloc"))]
153    ring::RSA_PKCS1_2048_8192_SHA256_ABSENT_PARAMS,
154    #[cfg(all(feature = "ring", feature = "alloc"))]
155    ring::RSA_PKCS1_2048_8192_SHA384_ABSENT_PARAMS,
156    #[cfg(all(feature = "ring", feature = "alloc"))]
157    ring::RSA_PKCS1_2048_8192_SHA512_ABSENT_PARAMS,
158    #[cfg(all(feature = "ring", feature = "alloc"))]
159    ring::RSA_PKCS1_3072_8192_SHA384,
160    #[cfg(all(feature = "ring", feature = "alloc"))]
161    ring::RSA_PSS_2048_8192_SHA256_LEGACY_KEY,
162    #[cfg(all(feature = "ring", feature = "alloc"))]
163    ring::RSA_PSS_2048_8192_SHA384_LEGACY_KEY,
164    #[cfg(all(feature = "ring", feature = "alloc"))]
165    ring::RSA_PSS_2048_8192_SHA512_LEGACY_KEY,
166    #[cfg(feature = "aws-lc-rs")]
167    aws_lc_rs::ECDSA_P256_SHA256,
168    #[cfg(feature = "aws-lc-rs")]
169    aws_lc_rs::ECDSA_P256_SHA384,
170    #[cfg(feature = "aws-lc-rs")]
171    aws_lc_rs::ECDSA_P256_SHA512,
172    #[cfg(feature = "aws-lc-rs")]
173    aws_lc_rs::ECDSA_P384_SHA256,
174    #[cfg(feature = "aws-lc-rs")]
175    aws_lc_rs::ECDSA_P384_SHA384,
176    #[cfg(feature = "aws-lc-rs")]
177    aws_lc_rs::ECDSA_P384_SHA512,
178    #[cfg(feature = "aws-lc-rs")]
179    aws_lc_rs::ECDSA_P521_SHA256,
180    #[cfg(feature = "aws-lc-rs")]
181    aws_lc_rs::ECDSA_P521_SHA384,
182    #[cfg(feature = "aws-lc-rs")]
183    aws_lc_rs::ECDSA_P521_SHA512,
184    #[cfg(feature = "aws-lc-rs")]
185    aws_lc_rs::ED25519,
186    #[cfg(feature = "aws-lc-rs")]
187    aws_lc_rs::RSA_PKCS1_2048_8192_SHA256,
188    #[cfg(feature = "aws-lc-rs")]
189    aws_lc_rs::RSA_PKCS1_2048_8192_SHA384,
190    #[cfg(feature = "aws-lc-rs")]
191    aws_lc_rs::RSA_PKCS1_2048_8192_SHA512,
192    #[cfg(feature = "aws-lc-rs")]
193    aws_lc_rs::RSA_PKCS1_2048_8192_SHA256_ABSENT_PARAMS,
194    #[cfg(feature = "aws-lc-rs")]
195    aws_lc_rs::RSA_PKCS1_2048_8192_SHA384_ABSENT_PARAMS,
196    #[cfg(feature = "aws-lc-rs")]
197    aws_lc_rs::RSA_PKCS1_2048_8192_SHA512_ABSENT_PARAMS,
198    #[cfg(feature = "aws-lc-rs")]
199    aws_lc_rs::RSA_PKCS1_3072_8192_SHA384,
200    #[cfg(feature = "aws-lc-rs")]
201    aws_lc_rs::RSA_PSS_2048_8192_SHA256_LEGACY_KEY,
202    #[cfg(feature = "aws-lc-rs")]
203    aws_lc_rs::RSA_PSS_2048_8192_SHA384_LEGACY_KEY,
204    #[cfg(feature = "aws-lc-rs")]
205    aws_lc_rs::RSA_PSS_2048_8192_SHA512_LEGACY_KEY,
206    #[cfg(all(feature = "aws-lc-rs-unstable", not(feature = "aws-lc-rs-fips")))]
207    aws_lc_rs::ML_DSA_44,
208    #[cfg(all(feature = "aws-lc-rs-unstable", not(feature = "aws-lc-rs-fips")))]
209    aws_lc_rs::ML_DSA_65,
210    #[cfg(all(feature = "aws-lc-rs-unstable", not(feature = "aws-lc-rs-fips")))]
211    aws_lc_rs::ML_DSA_87,
212];
213
214fn public_values_eq(a: untrusted::Input<'_>, b: untrusted::Input<'_>) -> bool {
215    a.as_slice_less_safe() == b.as_slice_less_safe()
216}