@@ -25,11 +25,19 @@ impl Config {
2525 }
2626}
2727
28- /// TLS encryption details.
28+ /// TLS encryption details with configurable trust store .
2929#[ derive( Clone , Debug , Deserialize , PartialEq ) ]
30- pub struct TlsConfig {
31- /// The path to the CA certificate.
32- pub ca_certificate_path : String ,
30+ #[ serde( tag = "trust_store" , rename_all = "snake_case" ) ]
31+ pub enum TlsConfig {
32+ /// Use a custom CA certificate file (PEM format).
33+ File {
34+ /// Path to the CA certificate file.
35+ ca_certificate_path : String ,
36+ } ,
37+ /// Use the operating system's native certificate store.
38+ Native ,
39+ /// Use Mozilla's bundled root certificates (via webpki-roots).
40+ Webpki ,
3341}
3442
3543/// Session schedule configuration
@@ -123,6 +131,7 @@ data_dictionary_path = "./spec/FIX44.xml"
123131
124132connection_port = 443
125133connection_host = "127.0.0.1"
134+ trust_store = "file"
126135ca_certificate_path = "my_cert.crt"
127136heartbeat_interval = 30
128137reset_on_logon = false
@@ -142,14 +151,67 @@ reset_on_logon = false
142151 assert_eq ! ( session_config. connection_port, 443 ) ;
143152 assert_eq ! ( session_config. connection_host, "127.0.0.1" ) ;
144153 assert_eq ! ( session_config. heartbeat_interval, 30 ) ;
145- let expected_tls_config = TlsConfig {
154+ let expected_tls_config = TlsConfig :: File {
146155 ca_certificate_path : "my_cert.crt" . to_string ( ) ,
147156 } ;
148157 assert_eq ! ( session_config. tls_config, Some ( expected_tls_config) ) ;
149158 assert_eq ! ( session_config. reconnect_interval, 30 ) ;
150159 assert_eq ! ( session_config. logon_timeout, 10 ) ;
151160 }
152161
162+ #[ test]
163+ fn test_tls_config_native ( ) {
164+ let config_contents = r#"
165+ [[sessions]]
166+ begin_string = "FIX.4.4"
167+ sender_comp_id = "send-comp-id"
168+ target_comp_id = "target-comp-id"
169+ connection_port = 443
170+ connection_host = "127.0.0.1"
171+ heartbeat_interval = 30
172+ trust_store = "native"
173+ "# ;
174+
175+ let config: Config = toml:: from_str ( config_contents) . unwrap ( ) ;
176+ let session_config = config. sessions . first ( ) . unwrap ( ) ;
177+ assert_eq ! ( session_config. tls_config, Some ( TlsConfig :: Native ) ) ;
178+ }
179+
180+ #[ test]
181+ fn test_tls_config_webpki ( ) {
182+ let config_contents = r#"
183+ [[sessions]]
184+ begin_string = "FIX.4.4"
185+ sender_comp_id = "send-comp-id"
186+ target_comp_id = "target-comp-id"
187+ connection_port = 443
188+ connection_host = "127.0.0.1"
189+ heartbeat_interval = 30
190+ trust_store = "webpki"
191+ "# ;
192+
193+ let config: Config = toml:: from_str ( config_contents) . unwrap ( ) ;
194+ let session_config = config. sessions . first ( ) . unwrap ( ) ;
195+ assert_eq ! ( session_config. tls_config, Some ( TlsConfig :: Webpki ) ) ;
196+ }
197+
198+ #[ test]
199+ fn test_no_tls_config ( ) {
200+ let config_contents = r#"
201+ [[sessions]]
202+ begin_string = "FIX.4.4"
203+ sender_comp_id = "send-comp-id"
204+ target_comp_id = "target-comp-id"
205+ connection_port = 9880
206+ connection_host = "127.0.0.1"
207+ heartbeat_interval = 30
208+ "# ;
209+
210+ let config: Config = toml:: from_str ( config_contents) . unwrap ( ) ;
211+ let session_config = config. sessions . first ( ) . unwrap ( ) ;
212+ assert_eq ! ( session_config. tls_config, None ) ;
213+ }
214+
153215 #[ test]
154216 fn test_schedule_config_weekdays ( ) {
155217 let config_contents = r#"
@@ -327,6 +389,7 @@ end_day = "Friday"
327389
328390 connection_port = 443
329391 connection_host = "127.0.0.1"
392+ trust_store = "file"
330393 ca_certificate_path = "my_cert.crt"
331394 heartbeat_interval = 30
332395 logon_timeout = 20
@@ -350,6 +413,7 @@ end_day = "Friday"
350413
351414 connection_port = 443
352415 connection_host = "127.0.0.1"
416+ trust_store = "file"
353417 ca_certificate_path = "my_cert.crt"
354418 heartbeat_interval = 30
355419 reconnect_interval = 15
0 commit comments