Skip to content

Commit 6cdcd7b

Browse files
committed
lib: fix custom exts for CSR w/o SANs.
Previously when writing CSR DER from `CertificateParams` that specified custom extensions, but did not specify any SANs, the serialization code would skip over writing the PKCS9 extension request attribute. This commit updates the serialization logic to ensure the attribute is written when either SANs are provided, or custom extensions are present. Prior to this update, the modified `test_x509_custom_ext` test fails, reproducing the problem reported in the issue tracker: ``` 'test_x509_custom_ext::custom_ext' panicked at 'missing requested extensions' ``` With the update, it passes again.
1 parent 4a47e30 commit 6cdcd7b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ impl CertificateParams {
911911
// Write extensions
912912
// According to the spec in RFC 2986, even if attributes are empty we need the empty attribute tag
913913
writer.next().write_tagged(Tag::context(0), |writer| {
914-
if !subject_alt_names.is_empty() {
914+
if !subject_alt_names.is_empty() || !custom_extensions.is_empty() {
915915
writer.write_sequence(|writer| {
916916
let oid = ObjectIdentifier::from_slice(OID_PKCS_9_AT_EXTENSION_REQUEST);
917917
writer.next().write_oid(&oid);

tests/generic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ mod test_x509_custom_ext {
111111
// Generate a certificate with the custom extension, parse it with x509-parser.
112112
let mut params = util::default_params();
113113
params.custom_extensions = vec![custom_ext];
114+
// Ensure the custom exts. being omitted into a CSR doesn't require SAN ext being present.
115+
// See https://github.com/rustls/rcgen/issues/122
116+
params.subject_alt_names = Vec::default();
114117
let test_cert = Certificate::from_params(params).unwrap();
115118
let test_cert_der = test_cert.serialize_der().unwrap();
116119
let (_, x509_test_cert) = X509Certificate::from_der(&test_cert_der).unwrap();

0 commit comments

Comments
 (0)