Skip to content

Commit

Permalink
fixup! Allow multiple issuer items of the same kind
Browse files Browse the repository at this point in the history
  • Loading branch information
da-kami committed Jan 21, 2025
1 parent c33ce90 commit dd62f8c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions rcgen/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl CertificateParams {
let der = subject_key.sign_der(|writer| {
// Write version
writer.next().write_u8(0);
write_distinguished_name(writer.next(), distinguished_name.clone());
write_distinguished_name(writer.next(), distinguished_name);
serialize_public_key_der(subject_key, writer.next());

// According to the spec in RFC 2986, even if attributes are empty we need the empty attribute tag
Expand Down Expand Up @@ -673,7 +673,7 @@ impl CertificateParams {
// Write signature algorithm
issuer.key_pair.alg.write_alg_ident(writer.next());
// Write issuer name
write_distinguished_name(writer.next(), issuer.distinguished_name.clone());
write_distinguished_name(writer.next(), issuer.distinguished_name);
// Write validity
writer.next().write_sequence(|writer| {
// Not before
Expand All @@ -683,7 +683,7 @@ impl CertificateParams {
Ok::<(), Error>(())
})?;
// Write subject
write_distinguished_name(writer.next(), self.distinguished_name.clone());
write_distinguished_name(writer.next(), &self.distinguished_name);
// Write subjectPublicKeyInfo
serialize_public_key_der(pub_key, writer.next());
// write extensions
Expand Down Expand Up @@ -872,7 +872,7 @@ fn write_general_subtrees(writer: DERWriter, tag: u64, general_subtrees: &[Gener
GeneralSubtree::Rfc822Name(name)
| GeneralSubtree::DnsName(name) => writer.write_ia5_string(name),
GeneralSubtree::DirectoryName(name) => {
write_distinguished_name(writer, name.clone())
write_distinguished_name(writer, name)
},
GeneralSubtree::IpAddress(subnet) => {
writer.write_bytes(&subnet.to_bytes())
Expand Down
2 changes: 1 addition & 1 deletion rcgen/src/crl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl CertificateRevocationListParams {
// Write issuer.
// RFC 5280 §5.1.2.3:
// The issuer field MUST contain a non-empty X.500 distinguished name (DN).
write_distinguished_name(writer.next(), issuer.distinguished_name.clone());
write_distinguished_name(writer.next(), issuer.distinguished_name);

// Write thisUpdate date.
// RFC 5280 §5.1.2.4:
Expand Down
6 changes: 3 additions & 3 deletions rcgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ impl DistinguishedName {
self.entries.push((ty, s.into()));
}

/// Replaces the *fist occurrence* of a type with a new value.
/// Replaces the *first occurrence* of a type with a new value.
/// This is a convenience function to avoid duplicating values.
///
/// If there are multiple occurrences of a type there is currently no way of changing the besides iterating over the types and values of an existing instance and creating a new instance.
/// If there are multiple occurrences of a type there is currently no way of changing them besides iterating over the types and values of an existing instance and creating a new instance.
///
/// ```
/// # use rcgen::{DistinguishedName, DnType, DnValue};
Expand Down Expand Up @@ -586,7 +586,7 @@ fn write_dt_utc_or_generalized(writer: DERWriter, dt: OffsetDateTime) {
}
}

fn write_distinguished_name(writer: DERWriter, dn: DistinguishedName) {
fn write_distinguished_name(writer: DERWriter, dn: &DistinguishedName) {
writer.write_sequence(|writer| {
for (ty, content) in dn.iter() {
writer.next().write_set(|writer| {
Expand Down
15 changes: 9 additions & 6 deletions rcgen/tests/openssl.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#![cfg(feature = "pem")]

use std::cell::RefCell;
use std::io::{Error, ErrorKind, Read, Result as ioResult, Write};
use std::rc::Rc;
#[cfg(feature = "x509-parser")]
use std::str::FromStr;

use openssl::asn1::{Asn1Integer, Asn1Time};
use openssl::bn::BigNum;
use openssl::pkey::PKey;
use openssl::ssl::{HandshakeError, SslAcceptor, SslConnector, SslMethod};
use openssl::stack::Stack;
use openssl::x509::store::{X509Store, X509StoreBuilder};
use openssl::x509::{CrlStatus, X509Crl, X509Req, X509StoreContext, X509};

#[cfg(feature = "x509-parser")]
use rcgen::Ia5String;
use rcgen::{
BasicConstraints, Certificate, CertificateParams, DnType, DnValue, GeneralSubtree, IsCa,
KeyPair, NameConstraints,
};
use std::cell::RefCell;
use std::io::{Error, ErrorKind, Read, Result as ioResult, Write};
use std::rc::Rc;

mod util;

Expand Down Expand Up @@ -542,9 +548,6 @@ fn test_openssl_pkcs1_and_sec1_keys() {
#[test]
#[cfg(feature = "x509-parser")]
fn test_parse_certificate_with_multiple_domain_components() {
use rcgen::Ia5String;
use std::str::FromStr;

/// Command used to generate:
/// `openssl req -x509 -newkey rsa:4096 -nodes -out mycert.pem -keyout mykey.pem -days 365 -subj "/C=US/ST=California/L=San Francisco/O=Example Company/OU=IT Department/CN=www.example.com/DC=example/DC=com"`
/// Contains two distinct "DC" entries.
Expand Down

0 comments on commit dd62f8c

Please sign in to comment.