@@ -6,10 +6,25 @@ use std::{
66} ;
77
88use super :: {
9- AddCertToStoreSnafu , AddExtraChainCertSnafu , CaStackPushSnafu , EncodeAlpnProtocolsSnafu ,
10- FileOpenFailedSnafu , FileReadFailedSnafu , MaybeTls , NewCaStackSnafu , NewStoreBuilderSnafu ,
11- ParsePkcs12Snafu , PrivateKeyParseSnafu , Result , SetAlpnProtocolsSnafu , SetCertificateSnafu ,
12- SetPrivateKeySnafu , SetVerifyCertSnafu , TlsError , X509ParseSnafu ,
9+ AddCertToStoreSnafu ,
10+ AddExtraChainCertSnafu ,
11+ CaStackPushSnafu ,
12+ EncodeAlpnProtocolsSnafu ,
13+ FileOpenFailedSnafu ,
14+ FileReadFailedSnafu ,
15+ MaybeTls ,
16+ NewCaStackSnafu ,
17+ NewStoreBuilderSnafu ,
18+ ParsePkcs12Snafu ,
19+ PrivateKeyParseSnafu ,
20+ Result ,
21+ SetAlpnProtocolsSnafu ,
22+ SetCertificateSnafu ,
23+ SetPrivateKeySnafu ,
24+ SetVerifyCertSnafu ,
25+ TlsError ,
26+ X509ParseSnafu ,
27+ apply_tls_security_profile, // RED HAT - TLS security profile support (LOG-3398)
1328} ;
1429use cfg_if:: cfg_if;
1530use lookup:: lookup_v2:: OptionalValuePath ;
@@ -157,11 +172,13 @@ pub struct TlsConfig {
157172 #[ configurable( metadata( docs:: human_name = "Server Name" ) ) ]
158173 pub server_name : Option < String > ,
159174
175+ // BEGIN RED HAT - TLS security profile support (LOG-3398)
160176 /// Minimal enabled TLS version.
161177 pub min_tls_version : Option < String > ,
162178
163179 /// TLS ciphersuites to enable.
164180 pub ciphersuites : Option < String > ,
181+ // END RED HAT - TLS security profile support (LOG-3398)
165182}
166183
167184impl TlsConfig {
@@ -184,8 +201,10 @@ pub struct TlsSettings {
184201 pub ( super ) identity : Option < IdentityStore > ,
185202 alpn_protocols : Option < Vec < u8 > > ,
186203 server_name : Option < String > ,
204+ // BEGIN RED HAT - TLS security profile support (LOG-3398)
187205 pub min_tls_version : Option < String > ,
188206 pub ciphersuites : Option < String > ,
207+ // END RED HAT - TLS security profile support (LOG-3398)
189208}
190209
191210/// Identity store in PEM format
@@ -228,6 +247,7 @@ impl TlsSettings {
228247 identity : options. load_identity ( ) ?,
229248 alpn_protocols : options. parse_alpn_protocols ( ) ?,
230249 server_name : options. server_name . clone ( ) ,
250+ // RED HAT - TLS security profile support (LOG-3398)
231251 min_tls_version : options. min_tls_version . clone ( ) ,
232252 ciphersuites : options. ciphersuites . clone ( ) ,
233253 } )
@@ -347,6 +367,9 @@ impl TlsSettings {
347367 }
348368 }
349369
370+ // RED HAT - TLS security profile support (LOG-3398)
371+ apply_tls_security_profile ( context, & self . min_tls_version , & self . ciphersuites ) ?;
372+
350373 Ok ( ( ) )
351374 }
352375
@@ -662,7 +685,7 @@ fn open_read(filename: &Path, note: &'static str) -> Result<(Vec<u8>, PathBuf)>
662685
663686#[ cfg( test) ]
664687mod test {
665- use openssl:: ssl:: { ErrorEx , SslMethod , SslVersion } ;
688+ use openssl:: ssl:: { SslMethod , SslVersion } ;
666689
667690 use super :: * ;
668691
@@ -831,102 +854,108 @@ mod test {
831854 assert ! ( config. is_tls( ) ) ;
832855 }
833856
857+ // BEGIN RED HAT - TLS security profile tests (LOG-3398)
834858 #[ test]
835859 fn from_min_tls_version ( ) {
836- use std :: result :: Result ;
860+ use super :: super :: apply_tls_security_profile ;
837861
838862 struct TlsVersionTest {
839863 text : Option < String > ,
840864 num : Option < SslVersion > ,
841- want : Result < ( ) , ErrorEx > ,
865+ want_ok : bool ,
842866 }
843- let mut builder = SslContextBuilder :: new ( SslMethod :: tls ( ) ) . unwrap ( ) ;
844- let orig_min_proto_version = builder. min_proto_version ( ) ;
845867 let tests = [
846868 TlsVersionTest {
847869 text : None ,
848- num : orig_min_proto_version ,
849- want : Ok ( ( ) ) ,
870+ num : None ,
871+ want_ok : true ,
850872 } ,
851873 TlsVersionTest {
852874 text : Some ( String :: new ( ) ) ,
853- num : orig_min_proto_version ,
854- want : Err ( ErrorEx :: InvalidTlsVersion ) ,
875+ num : None ,
876+ want_ok : false ,
855877 } ,
856878 TlsVersionTest {
857879 text : Some ( "foobar" . to_string ( ) ) ,
858- num : Some ( SslVersion :: TLS1 ) ,
859- want : Err ( ErrorEx :: InvalidTlsVersion ) ,
880+ num : None ,
881+ want_ok : false ,
860882 } ,
861883 TlsVersionTest {
862884 text : Some ( "VersionTLS10" . to_string ( ) ) ,
863885 num : Some ( SslVersion :: TLS1 ) ,
864- want : Ok ( ( ) ) ,
886+ want_ok : true ,
865887 } ,
866888 TlsVersionTest {
867889 text : Some ( "VersionTLS11" . to_string ( ) ) ,
868890 num : Some ( SslVersion :: TLS1_1 ) ,
869- want : Ok ( ( ) ) ,
891+ want_ok : true ,
870892 } ,
871893 TlsVersionTest {
872894 text : Some ( "VersionTLS12" . to_string ( ) ) ,
873895 num : Some ( SslVersion :: TLS1_2 ) ,
874- want : Ok ( ( ) ) ,
896+ want_ok : true ,
875897 } ,
876898 TlsVersionTest {
877899 text : Some ( "VersionTLS13" . to_string ( ) ) ,
878900 num : Some ( SslVersion :: TLS1_3 ) ,
879- want : Ok ( ( ) ) ,
901+ want_ok : true ,
880902 } ,
881903 ] ;
882904 for t in tests {
883- match builder. set_min_tls_version_and_ciphersuites ( & t. text , & None ) {
905+ let mut builder = SslContextBuilder :: new ( SslMethod :: tls ( ) ) . unwrap ( ) ;
906+ let orig_min = builder. min_proto_version ( ) ;
907+ match apply_tls_security_profile ( & mut builder, & t. text , & None ) {
884908 Ok ( ( ) ) => {
885- assert ! ( t. want. is_ok( ) ) ;
886- assert_eq ! ( builder. min_proto_version( ) , t. num) ;
909+ assert ! ( t. want_ok, "expected error for {:?}" , t. text) ;
910+ if let Some ( expected) = t. num {
911+ assert_eq ! ( builder. min_proto_version( ) , Some ( expected) ) ;
912+ } else {
913+ assert_eq ! ( builder. min_proto_version( ) , orig_min) ;
914+ }
887915 }
888- Err ( e ) => assert_eq ! ( t . want . err ( ) . unwrap ( ) , e ) ,
916+ Err ( _ ) => assert ! ( !t . want_ok , "unexpected error for {:?}" , t . text ) ,
889917 }
890918 }
891919 }
892920
893921 #[ test]
894922 fn from_min_tls_version_and_ciphersuites ( ) {
895- use std :: result :: Result ;
923+ use super :: super :: apply_tls_security_profile ;
896924
897925 struct TlsCiphersuiteTest {
898926 min_tls_version : Option < String > ,
899927 ciphersuite : Option < String > ,
900- want : Result < ( ) , ErrorEx > ,
928+ want_ok : bool ,
901929 }
902930
903- let mut builder = SslContextBuilder :: new ( SslMethod :: tls ( ) ) . unwrap ( ) ;
904931 let tests = [
905932 TlsCiphersuiteTest {
906933 min_tls_version : Some ( "VersionTLS10" . to_string ( ) ) ,
907934 ciphersuite : Some ( String :: new ( ) ) ,
908- want : Err ( ErrorEx :: InvalidCiphersuite ) ,
935+ want_ok : false ,
909936 } ,
910937 TlsCiphersuiteTest {
911938 min_tls_version : Some ( "VersionTLS12" . to_string ( ) ) ,
912939 ciphersuite : Some ( "AES128-SHA256" . to_string ( ) ) ,
913- want : Ok ( ( ) ) ,
940+ want_ok : true ,
914941 } ,
915942 TlsCiphersuiteTest {
916943 min_tls_version : Some ( "VersionTLS13" . to_string ( ) ) ,
917944 ciphersuite : Some (
918945 "TLS_CHACHA20_POLY1305_SHA256,TLS_AES_256_GCM_SHA384" . to_string ( ) ,
919946 ) ,
920- want : Ok ( ( ) ) ,
947+ want_ok : true ,
921948 } ,
922949 ] ;
923950 for t in tests {
924- match builder. set_min_tls_version_and_ciphersuites ( & t. min_tls_version , & t. ciphersuite ) {
925- Ok ( ( ) ) => assert ! ( t. want. is_ok( ) ) ,
926- Err ( e) => assert_eq ! ( t. want. err( ) . unwrap( ) , e) ,
951+ let mut builder = SslContextBuilder :: new ( SslMethod :: tls ( ) ) . unwrap ( ) ;
952+ match apply_tls_security_profile ( & mut builder, & t. min_tls_version , & t. ciphersuite ) {
953+ Ok ( ( ) ) => assert ! ( t. want_ok, "expected error for {:?}" , t. ciphersuite) ,
954+ Err ( _) => assert ! ( !t. want_ok, "unexpected error for {:?}" , t. ciphersuite) ,
927955 }
928956 }
929957 }
958+ // END RED HAT - TLS security profile tests (LOG-3398)
930959
931960 fn settings_from_config (
932961 enabled : Option < bool > ,
0 commit comments