File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
bindings/rust/extended/s2n-tls Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ unstable-fingerprint = ["s2n-tls-sys/unstable-fingerprint"]
14
14
unstable-ktls = [" s2n-tls-sys/unstable-ktls" ]
15
15
unstable-renegotiate = [" s2n-tls-sys/unstable-renegotiate" ]
16
16
unstable-cert_authorities = [" s2n-tls-sys/unstable-cert_authorities" ]
17
+ unstable-custom_x509_extensions = [" s2n-tls-sys/unstable-custom_x509_extensions" ]
17
18
quic = [" s2n-tls-sys/quic" ]
18
19
fips = [" s2n-tls-sys/fips" ]
19
20
pq = [" s2n-tls-sys/pq" ]
Original file line number Diff line number Diff line change @@ -604,6 +604,18 @@ impl Builder {
604
604
Ok ( self )
605
605
}
606
606
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
+
607
619
/// Set a custom callback function which is run after parsing the client hello.
608
620
///
609
621
/// Corresponds to [s2n_config_set_client_hello_cb].
Original file line number Diff line number Diff line change @@ -580,6 +580,44 @@ mod tests {
580
580
Ok ( ( ) )
581
581
}
582
582
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
+
583
621
#[ cfg( feature = "unstable-ktls" ) ]
584
622
#[ test]
585
623
fn key_updates ( ) -> Result < ( ) , Error > {
You can’t perform that action at this time.
0 commit comments