-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: support x509-parser Ia5String DistinguishedNames
This commit updates the logic for converting from the x509-parser distinguished name types into the rcgen equivalent in order to support `Ia5String` values. A small unit test is added that shows round-tripping a certificate with a subject containing an `Ia5String`, serializing it, parsing with x509-parser, and then recreating `CertificateParams` from the DER using `from_ca_cert_der`.
- Loading branch information
Showing
2 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,3 +299,40 @@ mod test_parse_crl_dps { | |
); | ||
} | ||
} | ||
|
||
#[cfg(feature = "x509-parser")] | ||
mod test_parse_ia5string_subject { | ||
use crate::util; | ||
use rcgen::DnType::CustomDnType; | ||
use rcgen::{Certificate, CertificateParams, DistinguishedName, DnValue, KeyPair}; | ||
|
||
#[test] | ||
fn parse_ia5string_subject() { | ||
// Create and serialize a certificate with a subject containing an IA5String email address. | ||
let email_address_dn_type = CustomDnType(vec![1, 2, 840, 113549, 1, 9, 1]); // id-emailAddress | ||
let email_address_dn_value = DnValue::Ia5String("[email protected]".into()); | ||
let mut params = util::default_params(); | ||
params.distinguished_name = DistinguishedName::new(); | ||
params.distinguished_name.push( | ||
email_address_dn_type.clone(), | ||
email_address_dn_value.clone(), | ||
); | ||
let cert = Certificate::from_params(params).unwrap(); | ||
let cert_der = cert.serialize_der().unwrap(); | ||
|
||
// We should be able to parse the certificate with x509-parser. | ||
assert!(x509_parser::parse_x509_certificate(&cert_der).is_ok()); | ||
|
||
// We should be able to reconstitute params from the DER using x509-parser. | ||
let key_pair = KeyPair::generate(&rcgen::PKCS_ECDSA_P256_SHA256).unwrap(); | ||
let params_from_cert = CertificateParams::from_ca_cert_der(&cert_der, key_pair).unwrap(); | ||
|
||
// We should find the expected distinguished name in the reconstituted params. | ||
let expected_names = &[(&email_address_dn_type, &email_address_dn_value)]; | ||
let names = params_from_cert | ||
.distinguished_name | ||
.iter() | ||
.collect::<Vec<(_, _)>>(); | ||
assert_eq!(names, expected_names); | ||
} | ||
} |