@@ -66,7 +66,10 @@ pub enum CertificateSource {
66
66
} ,
67
67
}
68
68
69
- pub fn build_server_config ( cert_source : CertificateSource ) -> anyhow:: Result < rustls:: ServerConfig > {
69
+ pub fn build_server_config (
70
+ cert_source : CertificateSource ,
71
+ strict_checks : bool ,
72
+ ) -> anyhow:: Result < rustls:: ServerConfig > {
70
73
let builder = rustls:: ServerConfig :: builder ( ) . with_no_client_auth ( ) ;
71
74
72
75
match cert_source {
@@ -76,18 +79,20 @@ pub fn build_server_config(cert_source: CertificateSource) -> anyhow::Result<rus
76
79
} => {
77
80
let first_certificate = certificates. first ( ) . context ( "empty certificate list" ) ?;
78
81
79
- if let Ok ( report) = check_certificate_now ( & first_certificate) {
80
- if report. issues . intersects (
81
- CertIssues :: MISSING_SERVER_AUTH_EXTENDED_KEY_USAGE | CertIssues :: MISSING_SUBJECT_ALT_NAME ,
82
- ) {
83
- let serial_number = report. serial_number ;
84
- let subject = report. subject ;
85
- let issuer = report. issuer ;
86
- let not_before = report. not_before ;
87
- let not_after = report. not_after ;
88
- let issues = report. issues ;
89
-
90
- anyhow:: bail!( "found significant issues with the certificate: serial_number = {serial_number}, subject = {subject}, issuer = {issuer}, not_before = {not_before}, not_after = {not_after}, issues = {issues}" ) ;
82
+ if strict_checks {
83
+ if let Ok ( report) = check_certificate_now ( & first_certificate) {
84
+ if report. issues . intersects (
85
+ CertIssues :: MISSING_SERVER_AUTH_EXTENDED_KEY_USAGE | CertIssues :: MISSING_SUBJECT_ALT_NAME ,
86
+ ) {
87
+ let serial_number = report. serial_number ;
88
+ let subject = report. subject ;
89
+ let issuer = report. issuer ;
90
+ let not_before = report. not_before ;
91
+ let not_after = report. not_after ;
92
+ let issues = report. issues ;
93
+
94
+ anyhow:: bail!( "found significant issues with the certificate: serial_number = {serial_number}, subject = {subject}, issuer = {issuer}, not_before = {not_before}, not_after = {not_after}, issues = {issues}" ) ;
95
+ }
91
96
}
92
97
}
93
98
@@ -103,9 +108,14 @@ pub fn build_server_config(cert_source: CertificateSource) -> anyhow::Result<rus
103
108
store_location,
104
109
store_name,
105
110
} => {
106
- let resolver =
107
- windows:: ServerCertResolver :: new ( machine_hostname, cert_subject_name, store_location, store_name)
108
- . context ( "create ServerCertResolver" ) ?;
111
+ let resolver = windows:: ServerCertResolver :: new (
112
+ machine_hostname,
113
+ cert_subject_name,
114
+ store_location,
115
+ store_name,
116
+ strict_checks,
117
+ )
118
+ . context ( "create ServerCertResolver" ) ?;
109
119
Ok ( builder. with_cert_resolver ( Arc :: new ( resolver) ) )
110
120
}
111
121
#[ cfg( not( windows) ) ]
@@ -146,6 +156,7 @@ pub mod windows {
146
156
store_type : CertStoreType ,
147
157
store_name : String ,
148
158
cached_key : Mutex < Option < KeyCache > > ,
159
+ strict_checks : bool ,
149
160
}
150
161
151
162
#[ derive( Debug ) ]
@@ -160,6 +171,7 @@ pub mod windows {
160
171
cert_subject_name : String ,
161
172
store_type : dto:: CertStoreLocation ,
162
173
store_name : String ,
174
+ strict_checks : bool ,
163
175
) -> anyhow:: Result < Self > {
164
176
let store_type = match store_type {
165
177
dto:: CertStoreLocation :: LocalMachine => CertStoreType :: LocalMachine ,
@@ -173,6 +185,7 @@ pub mod windows {
173
185
store_type,
174
186
store_name,
175
187
cached_key : Mutex :: new ( None ) ,
188
+ strict_checks,
176
189
} )
177
190
}
178
191
@@ -255,14 +268,18 @@ pub mod windows {
255
268
cert_issues |= report. issues ;
256
269
257
270
// Skip the certificate if any of the following is true:
258
- // - The certificate is not yet valid.
259
- // - The certificate is missing the server auth extended key usage.
260
- // - The certificate is missing a subject alternative name (SAN) extension.
261
- let skip = report . issues . intersects (
271
+ // - the certificate is not yet valid,
272
+ // - (if strict) the certificate is missing the server auth extended key usage,
273
+ // - (if strict) the certificate is missing a subject alternative name (SAN) extension.
274
+ let issues_to_check = if self . strict_checks {
262
275
CertIssues :: NOT_YET_VALID
263
276
| CertIssues :: MISSING_SERVER_AUTH_EXTENDED_KEY_USAGE
264
- | CertIssues :: MISSING_SUBJECT_ALT_NAME ,
265
- ) ;
277
+ | CertIssues :: MISSING_SUBJECT_ALT_NAME
278
+ } else {
279
+ CertIssues :: NOT_YET_VALID
280
+ } ;
281
+
282
+ let skip = report. issues . intersects ( issues_to_check) ;
266
283
267
284
if skip {
268
285
debug ! (
0 commit comments