Skip to content

Commit c1d6fcd

Browse files
committed
Expose custom critical extension API
1 parent 94da38d commit c1d6fcd

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

bindings/rust/extended/s2n-tls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ unstable-fingerprint = ["s2n-tls-sys/unstable-fingerprint"]
1414
unstable-ktls = ["s2n-tls-sys/unstable-ktls"]
1515
unstable-renegotiate = ["s2n-tls-sys/unstable-renegotiate"]
1616
unstable-cert_authorities = ["s2n-tls-sys/unstable-cert_authorities"]
17+
unstable-custom_x509_extensions = ["s2n-tls-sys/unstable-custom_x509_extensions"]
1718
quic = ["s2n-tls-sys/quic"]
1819
fips = ["s2n-tls-sys/fips"]
1920
pq = ["s2n-tls-sys/pq"]

bindings/rust/extended/s2n-tls/src/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,18 @@ impl Builder {
604604
Ok(self)
605605
}
606606

607+
/// Corresponds to [s2n_config_add_custom_x509_extension].
608+
#[cfg(feature = "unstable-custom_x509_extensions")]
609+
pub fn add_custom_x509_extension(&mut self, extension_oid: &str) -> Result<&mut Self, Error> {
610+
let extension_oid_len: u32 = extension_oid
611+
.len()
612+
.try_into()
613+
.map_err(|_| Error::INVALID_INPUT)?;
614+
let extension_oid = extension_oid.as_ptr() as *mut u8;
615+
unsafe { s2n_config_add_custom_x509_extension(self.as_mut_ptr(), extension_oid, extension_oid_len).into_result() }?;
616+
Ok(self)
617+
}
618+
607619
/// Set a custom callback function which is run after parsing the client hello.
608620
///
609621
/// Corresponds to [s2n_config_set_client_hello_cb].

bindings/rust/extended/s2n-tls/src/testing/s2n_tls.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,44 @@ mod tests {
580580
Ok(())
581581
}
582582

583+
#[cfg(feature = "unstable-custom_x509_extensions")]
584+
#[test]
585+
fn custom_critical_extensions() -> Result<(), Error> {
586+
let certs = CertKeyPair::from_path(
587+
"custom_oids/",
588+
"single_oid_cert_chain",
589+
"single_oid_key",
590+
"ca-cert",
591+
);
592+
let single_oid = "1.3.187.25240.2";
593+
594+
for add_oid in [true, false] {
595+
let config = {
596+
let mut config = Builder::new();
597+
config.set_security_policy(&security::DEFAULT_TLS13)?;
598+
config.set_verify_host_callback(InsecureAcceptAllCertificatesHandler {})?;
599+
600+
if add_oid {
601+
config.add_custom_x509_extension(single_oid)?;
602+
}
603+
604+
config.load_pem(certs.cert(), certs.key())?;
605+
config.trust_pem(certs.cert())?;
606+
config.build()?
607+
};
608+
let mut pair = TestPair::from_config(&config);
609+
610+
if add_oid {
611+
pair.handshake()?;
612+
} else {
613+
let s2n_err = pair.handshake().unwrap_err();
614+
assert_eq!(s2n_err.name(), "S2N_ERR_CERT_UNHANDLED_CRITICAL_EXTENSION");
615+
}
616+
}
617+
618+
Ok(())
619+
}
620+
583621
#[cfg(feature = "unstable-ktls")]
584622
#[test]
585623
fn key_updates() -> Result<(), Error> {

0 commit comments

Comments
 (0)