@@ -10,9 +10,8 @@ mod cert_compression;
10
10
pub mod connector;
11
11
pub mod extension;
12
12
mod profile;
13
+ mod settings;
13
14
14
- pub ( crate ) use self :: profile:: tls_settings;
15
- use crate :: async_impl:: client:: HttpVersionPref ;
16
15
use crate :: connect:: HttpConnector ;
17
16
use crate :: tls:: extension:: { SslConnectExtension , SslExtension } ;
18
17
use boring:: ssl:: { SslConnector , SslMethod } ;
@@ -21,112 +20,21 @@ use boring::{
21
20
ssl:: { ConnectConfiguration , SslConnectorBuilder } ,
22
21
} ;
23
22
use connector:: { HttpsConnector , HttpsLayer , HttpsLayerSettings } ;
24
- use hyper :: { PseudoOrder , SettingsOrder , StreamDependency } ;
23
+ pub ( crate ) use profile :: tls_settings ;
25
24
pub use profile:: Impersonate ;
26
25
use profile:: TypedImpersonate ;
26
+
27
+ pub use settings:: { Http2Settings , SslBuilderSettings , SslContextSettings , SslSettings } ;
27
28
use std:: any:: Any ;
28
29
use std:: fmt:: { self , Debug } ;
29
30
30
31
type TlsResult < T > = std:: result:: Result < T , ErrorStack > ;
31
32
32
- /// The TLS connector configuration.
33
- #[ derive( Clone ) ]
34
- pub struct SslSettings {
35
- /// The client to impersonate.
36
- pub impersonate : Impersonate ,
37
- /// The minimum TLS version to use.
38
- pub min_tls_version : Option < Version > ,
39
- /// The maximum TLS version to use.
40
- pub max_tls_version : Option < Version > ,
41
- /// Enable ECH grease.
42
- pub enable_ech_grease : bool ,
43
- /// Permute extensions.
44
- pub permute_extensions : bool ,
45
- /// Verify certificates.
46
- pub certs_verification : bool ,
47
- /// Use a pre-shared key.
48
- pub pre_shared_key : bool ,
49
- /// The HTTP version preference.
50
- pub http_version_pref : HttpVersionPref ,
51
- }
52
-
53
- /// Connection settings
54
- pub struct SslBuilderSettings {
55
- /// The SSL connector builder.
56
- pub ssl_builder : SslConnectorBuilder ,
57
- /// Enable PSK.
58
- pub enable_psk : bool ,
59
- /// HTTP/2 settings.
60
- pub http2 : Http2Settings ,
61
- }
62
-
63
- impl Debug for SslBuilderSettings {
64
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
65
- f. debug_struct ( "TlsSettings" )
66
- . field ( "tls_builder" , & self . ssl_builder . type_id ( ) )
67
- . field ( "http2" , & self . http2 )
68
- . finish ( )
69
- }
70
- }
71
-
72
- /// HTTP/2 settings.
73
- #[ derive( Debug ) ]
74
- pub struct Http2Settings {
75
- /// The initial stream window size.
76
- pub initial_stream_window_size : Option < u32 > ,
77
- /// The initial connection window size.
78
- pub initial_connection_window_size : Option < u32 > ,
79
- /// The maximum concurrent streams.
80
- pub max_concurrent_streams : Option < u32 > ,
81
- /// The maximum header list size.
82
- pub max_header_list_size : Option < u32 > ,
83
- /// The header table size.
84
- pub header_table_size : Option < u32 > ,
85
- /// Enable push.
86
- pub enable_push : Option < bool > ,
87
- /// The priority of the headers.
88
- pub headers_priority : Option < StreamDependency > ,
89
- /// The pseudo header order.
90
- pub headers_pseudo_header : Option < [ PseudoOrder ; 4 ] > ,
91
- /// The settings order.
92
- pub settings_order : Option < [ SettingsOrder ; 2 ] > ,
93
- }
94
-
95
- impl Default for SslSettings {
96
- fn default ( ) -> Self {
97
- Self {
98
- min_tls_version : None ,
99
- max_tls_version : None ,
100
- impersonate : Default :: default ( ) ,
101
- enable_ech_grease : false ,
102
- permute_extensions : false ,
103
- certs_verification : true ,
104
- pre_shared_key : false ,
105
- http_version_pref : HttpVersionPref :: All ,
106
- }
107
- }
108
- }
109
-
110
- impl Debug for SslSettings {
111
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
112
- f. debug_struct ( "TlsConnector" )
113
- . field ( "min_tls_version" , & self . min_tls_version )
114
- . field ( "max_tls_version" , & self . max_tls_version )
115
- . field ( "impersonate" , & self . impersonate )
116
- . field ( "enable_ech_grease" , & self . enable_ech_grease )
117
- . field ( "permute_extensions" , & self . permute_extensions )
118
- . field ( "certs_verification" , & self . certs_verification )
119
- . field ( "pre_shared_key" , & self . pre_shared_key )
120
- . field ( "http_version_pref" , & self . http_version_pref )
121
- . finish ( )
122
- }
123
- }
124
-
125
33
/// A wrapper around a `SslConnectorBuilder` that allows for additional settings.
126
34
#[ derive( Clone ) ]
127
35
pub struct TlsConnector {
128
- /// The TLS connector builder settings.
129
- settings : SslSettings ,
36
+ /// The TLS connector context settings.
37
+ settings : SslContextSettings ,
130
38
/// The TLS connector layer.
131
39
layer : HttpsLayer ,
132
40
}
@@ -139,7 +47,7 @@ impl TlsConnector {
139
47
None => SslConnector :: builder ( SslMethod :: tls_client ( ) ) ?,
140
48
} ;
141
49
Ok ( Self {
142
- settings : settings . clone ( ) ,
50
+ settings : SslContextSettings :: from ( & settings ) ,
143
51
layer : Self :: build_layer ( settings, ssl) ?,
144
52
} )
145
53
}
@@ -154,8 +62,8 @@ impl TlsConnector {
154
62
let mut http = HttpsConnector :: with_connector_layer ( http, self . layer . clone ( ) ) ;
155
63
156
64
// Set the callback to add application settings.
157
- let builder = self . settings . clone ( ) ;
158
- http. set_callback ( move |conf, _| configure_ssl_context ( conf, & builder ) ) ;
65
+ let ctx = self . settings . clone ( ) ;
66
+ http. set_callback ( move |conf, _| configure_ssl_context ( conf, & ctx ) ) ;
159
67
160
68
Ok ( http)
161
69
}
@@ -166,7 +74,8 @@ impl TlsConnector {
166
74
. configure_alpn_protos ( & settings. http_version_pref ) ?
167
75
. configure_cert_verification ( settings. certs_verification ) ?
168
76
. configure_min_tls_version ( settings. min_tls_version ) ?
169
- . configure_max_tls_version ( settings. max_tls_version ) ?;
77
+ . configure_max_tls_version ( settings. max_tls_version ) ?
78
+ . configure_ca_cert_file ( settings. ca_cert_file . as_deref ( ) ) ?;
170
79
171
80
// Create the `HttpsLayerSettings` with the default session cache capacity.
172
81
let settings = HttpsLayerSettings :: builder ( )
@@ -178,11 +87,11 @@ impl TlsConnector {
178
87
}
179
88
180
89
/// Add application settings to the given `ConnectConfiguration`.
181
- fn configure_ssl_context ( conf : & mut ConnectConfiguration , ctx : & SslSettings ) -> TlsResult < ( ) > {
182
- if matches ! (
183
- ctx. impersonate . profile ( ) ,
184
- TypedImpersonate :: Chrome | TypedImpersonate :: Edge
185
- ) {
90
+ fn configure_ssl_context (
91
+ conf : & mut ConnectConfiguration ,
92
+ ctx : & SslContextSettings ,
93
+ ) -> TlsResult < ( ) > {
94
+ if matches ! ( ctx . typed , TypedImpersonate :: Chrome | TypedImpersonate :: Edge ) {
186
95
conf. configure_permute_extensions ( ctx. permute_extensions ) ?
187
96
. configure_enable_ech_grease ( ctx. enable_ech_grease ) ?
188
97
. configure_add_application_settings ( ctx. http_version_pref ) ?;
0 commit comments