@@ -45,10 +45,10 @@ fn system_time_to_cfdate(time: pki_types::UnixTime) -> Result<CFDate, TlsError>
45
45
pub struct Verifier {
46
46
/// Extra trust anchors to add to the verifier above and beyond those provided by
47
47
/// the system-provided trust stores.
48
- extra_roots : Vec < pki_types :: CertificateDer < ' static > > ,
48
+ extra_roots : Vec < SecCertificate > ,
49
49
/// Testing only: The root CA certificate to trust.
50
50
#[ cfg( any( test, feature = "ffi-testing" , feature = "dbg" ) ) ]
51
- test_only_root_ca_override : Option < Vec < u8 > > ,
51
+ test_only_root_ca_override : Option < SecCertificate > ,
52
52
pub ( super ) crypto_provider : OnceCell < Arc < CryptoProvider > > ,
53
53
}
54
54
@@ -72,21 +72,30 @@ impl Verifier {
72
72
/// facilities with the addition of extra root certificates to trust.
73
73
///
74
74
/// See [Verifier::new] for the external requirements the verifier needs.
75
- pub fn new_with_extra_roots ( roots : Vec < pki_types:: CertificateDer < ' static > > ) -> Self {
76
- Self {
77
- extra_roots : roots,
75
+ pub fn new_with_extra_roots (
76
+ roots : Vec < pki_types:: CertificateDer < ' static > > ,
77
+ ) -> Result < Self , TlsError > {
78
+ let extra_roots = roots
79
+ . into_iter ( )
80
+ . map ( |root| {
81
+ SecCertificate :: from_der ( & root)
82
+ . map_err ( |_| TlsError :: InvalidCertificate ( CertificateError :: BadEncoding ) )
83
+ } )
84
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
85
+ Ok ( Self {
86
+ extra_roots,
78
87
#[ cfg( any( test, feature = "ffi-testing" , feature = "dbg" ) ) ]
79
88
test_only_root_ca_override : None ,
80
89
crypto_provider : OnceCell :: new ( ) ,
81
- }
90
+ } )
82
91
}
83
92
84
93
/// Creates a test-only TLS certificate verifier which trusts our fake root CA cert.
85
94
#[ cfg( any( test, feature = "ffi-testing" , feature = "dbg" ) ) ]
86
95
pub ( crate ) fn new_with_fake_root ( root : & [ u8 ] ) -> Self {
87
96
Self {
88
97
extra_roots : Vec :: new ( ) ,
89
- test_only_root_ca_override : Some ( root. into ( ) ) ,
98
+ test_only_root_ca_override : Some ( SecCertificate :: from_der ( root) . unwrap ( ) ) ,
90
99
crypto_provider : OnceCell :: new ( ) ,
91
100
}
92
101
}
@@ -141,29 +150,24 @@ impl Verifier {
141
150
. map_err ( |e| invalid_certificate ( e. to_string ( ) ) ) ?;
142
151
}
143
152
144
- let raw_extra_roots = self . extra_roots . iter ( ) ;
153
+ #[ cfg( not( any( test, feature = "ffi-testing" , feature = "dbg" ) ) ) ]
154
+ let extra_roots = self . extra_roots . as_slice ( ) ;
145
155
146
156
#[ cfg( any( test, feature = "ffi-testing" , feature = "dbg" ) ) ]
147
- let extra_root = self
148
- . test_only_root_ca_override
149
- . as_ref ( )
150
- . map ( |root| pki_types:: CertificateDer :: from_slice ( root) ) ;
151
-
157
+ let extra_roots: Vec < _ > = self
158
+ . extra_roots
159
+ . iter ( )
160
+ . chain ( self . test_only_root_ca_override . as_ref ( ) )
161
+ . cloned ( )
162
+ . collect ( ) ;
152
163
#[ cfg( any( test, feature = "ffi-testing" , feature = "dbg" ) ) ]
153
- let raw_extra_roots = raw_extra_roots. chain ( & extra_root) . to_owned ( ) ;
154
-
155
- let extra_roots = raw_extra_roots
156
- . map ( |root| {
157
- SecCertificate :: from_der ( root)
158
- . map_err ( |_| TlsError :: InvalidCertificate ( CertificateError :: BadEncoding ) )
159
- } )
160
- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
164
+ let extra_roots = extra_roots. as_slice ( ) ;
161
165
162
166
// If any extra roots were provided by the user (or tests), provide them to the trust
163
167
// evaluation regardless of their system trust settings or status.
164
168
if !extra_roots. is_empty ( ) {
165
169
trust_evaluation
166
- . set_anchor_certificates ( & extra_roots)
170
+ . set_anchor_certificates ( extra_roots)
167
171
. map_err ( |e| TlsError :: Other ( OtherError ( Arc :: new ( e) ) ) ) ?;
168
172
169
173
// We want to trust both the system-installed and the extra roots. This must be set
0 commit comments