|
66 | 66 |
|
67 | 67 | /// This builder builds certificates of type [`CertificatePair`].
|
68 | 68 | ///
|
69 |
| -/// Example code to construct a certificate: |
| 69 | +/// Currently you are required to specify a [`CertificateAuthority`], which is used to create a leaf |
| 70 | +/// certificate, which is signed by this CA. |
| 71 | +/// |
| 72 | +/// These leaf certificates can be used for client/server authentication, because they include |
| 73 | +/// [`ID_KP_CLIENT_AUTH`] and [`ID_KP_SERVER_AUTH`] in the extended key usage extension. |
| 74 | +/// |
| 75 | +/// This builder has many default values, notably; |
| 76 | +/// |
| 77 | +/// - A default validity of [`DEFAULT_CERTIFICATE_VALIDITY`] |
| 78 | +/// - A randomly generated serial number |
| 79 | +/// - In case no `key_pair` was provided, a fresh keypair will be created. The algorithm |
| 80 | +/// (`rsa`/`ecdsa`) is chosen by the generic [`CertificateKeypair`] type of this struct, |
| 81 | +/// which is normally inferred from the [`CertificateAuthority`]. |
| 82 | +/// |
| 83 | +/// Example code to construct a CA and a signed certificate: |
70 | 84 | ///
|
71 | 85 | /// ```no_run
|
72 | 86 | /// use stackable_certs::{
|
|
92 | 106 | KP: CertificateKeypair,
|
93 | 107 | <KP::SigningKey as signature::Keypair>::VerifyingKey: EncodePublicKey,
|
94 | 108 | {
|
95 |
| - /// Required subject of the certificate, usually starts with `CN=`. |
| 109 | + /// Required subject of the certificate, usually starts with `CN=`, e.g. `CN=mypod`. |
96 | 110 | subject: &'a str,
|
97 | 111 |
|
98 | 112 | /// Optional list of subject alternative name DNS entries
|
@@ -151,6 +165,9 @@ where
|
151 | 165 | Some(key_pair) => key_pair,
|
152 | 166 | None => SKP::new().context(CreateKeyPairSnafu)?,
|
153 | 167 | };
|
| 168 | + |
| 169 | + // By choosing a random serial number we can make the reasonable assumption that we generate |
| 170 | + // a unique serial for each certificate. |
154 | 171 | let serial_number = SerialNumber::from(rand::random::<u64>());
|
155 | 172 |
|
156 | 173 | let ca_validity = self.signed_by.ca_cert().tbs_certificate.validity;
|
|
0 commit comments