Skip to content

Commit

Permalink
fix(command): retrieve name and san from slice
Browse files Browse the repository at this point in the history
Signed-off-by: Florentin Dubois <florentin.dubois@clever-cloud.com>
  • Loading branch information
FlorentinDUBOIS committed Sep 21, 2023
1 parent 24c4407 commit a5412b9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions command/src/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ use crate::proto::command::TlsVersion;
pub enum CertificateError {
#[error("Could not parse PEM certificate from bytes: {0}")]
InvalidCertificate(String),
#[error("failed to parse certificate common name attribute, {0}")]
InvalidCommonName(String),
#[error("failed to parse certificate subject alternate names attribute, {0}")]
InvalidSubjectAlternateNames(String),
#[error("failed to parse tls version '{0}'")]
InvalidTlsVersion(String),
}
Expand Down Expand Up @@ -52,15 +48,15 @@ pub fn get_cn_and_san_attributes(pem: &Pem) -> Result<HashSet<String>, Certifica
names.insert(
name.as_str()
.map(String::from)
.map_err(|err| CertificateError::InvalidCommonName(err.to_string()))?,
.unwrap_or_else(|_| String::from_utf8_lossy(name.as_slice()).to_string()),
);
}

for name in x509.subject().iter_by_oid(&OID_X509_EXT_SUBJECT_ALT_NAME) {
names.insert(
name.as_str()
.map(String::from)
.map_err(|err| CertificateError::InvalidSubjectAlternateNames(err.to_string()))?,
.unwrap_or_else(|_| String::from_utf8_lossy(name.as_slice()).to_string()),
);
}

Expand Down

0 comments on commit a5412b9

Please sign in to comment.