@@ -77,6 +77,17 @@ impl Verifier {
77
77
}
78
78
}
79
79
80
+ // Safety: There's no way for the mutex to be locked multiple times, so this is
81
+ // an infallible operation.
82
+ let mut extra_roots = self . extra_roots . try_lock ( ) . unwrap ( ) ;
83
+ if !extra_roots. is_empty ( ) {
84
+ let count = extra_roots. len ( ) ;
85
+ root_store. add_trust_anchors ( & mut extra_roots. drain ( ..) ) ;
86
+ log:: debug!(
87
+ "Loaded {count} extra CA certificates in addition to possible system roots" ,
88
+ ) ;
89
+ }
90
+
80
91
#[ cfg( all( target_os = "linux" , not( target_arch = "wasm32" ) ) ) ]
81
92
match rustls_native_certs:: load_native_certs ( ) {
82
93
Ok ( certs) => {
@@ -92,25 +103,19 @@ impl Verifier {
92
103
} else {
93
104
log:: debug!( "Loaded {added} CA certificates from the system" ) ;
94
105
}
95
-
96
- // Safety: There's no way for the mutex to be locked multiple times, so this is
97
- // an infallible operation.
98
- let mut extra_roots = self . extra_roots . try_lock ( ) . unwrap ( ) ;
99
- if !extra_roots. is_empty ( ) {
100
- let count = extra_roots. len ( ) ;
101
- root_store. add_trust_anchors ( & mut extra_roots. drain ( ..) ) ;
102
- log:: debug!(
103
- "Loaded {count} extra CA certificates in addition to roots from the system" ,
104
- ) ;
105
- }
106
106
}
107
107
Err ( err) => {
108
108
// This only contains a path to a system directory:
109
109
// https://github.com/rustls/rustls-native-certs/blob/bc13b9a6bfc2e1eec881597055ca49accddd972a/src/lib.rs#L91-L94
110
- return Err ( rustls:: Error :: General ( format ! (
111
- "failed to load system root certificates: {}" ,
112
- err
113
- ) ) ) ;
110
+ const MSG : & str = "failed to load system root certificates: " ;
111
+
112
+ // Don't return an error if this fails when other roots have already been loaded via
113
+ // `new_with_extra_roots`. It leads to extra failure cases where connections would otherwise still work.
114
+ if root_store. is_empty ( ) {
115
+ return Err ( rustls:: Error :: General ( format ! ( "{MSG}{err}" ) ) ) ;
116
+ } else {
117
+ log:: error!( "{MSG}{err}" ) ;
118
+ }
114
119
}
115
120
} ;
116
121
0 commit comments