11//! Configuration types for the SDK.
22
33use serde:: { Deserialize , Serialize } ;
4+ use tlsn:: webpki:: { CertificateDer , RootCertStore } ;
5+
6+ use crate :: error:: Result ;
7+ #[ cfg( not( feature = "mozilla-certs" ) ) ]
8+ use crate :: error:: SdkError ;
49
510/// Configuration for the Prover.
611#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -23,6 +28,10 @@ pub struct ProverConfig {
2328 pub network : NetworkSetting ,
2429 /// Optional client authentication credentials (certificates, private key).
2530 pub client_auth : Option < ClientAuth > ,
31+ /// Custom root certificates (DER-encoded) for TLS server verification.
32+ ///
33+ /// If `None`, the Mozilla root certificates are used.
34+ pub root_certs : Option < Vec < Vec < u8 > > > ,
2635}
2736
2837impl ProverConfig {
@@ -44,6 +53,7 @@ pub struct ProverConfigBuilder {
4453 defer_decryption_from_start : Option < bool > ,
4554 network : NetworkSetting ,
4655 client_auth : Option < ClientAuth > ,
56+ root_certs : Option < Vec < Vec < u8 > > > ,
4757}
4858
4959impl ProverConfigBuilder {
@@ -59,6 +69,7 @@ impl ProverConfigBuilder {
5969 defer_decryption_from_start : None ,
6070 network : NetworkSetting :: Latency ,
6171 client_auth : None ,
72+ root_certs : None ,
6273 }
6374 }
6475
@@ -110,6 +121,14 @@ impl ProverConfigBuilder {
110121 self
111122 }
112123
124+ /// Sets custom root certificates (DER-encoded) for TLS server verification.
125+ ///
126+ /// If not set, the Mozilla root certificates are used.
127+ pub fn root_certs ( mut self , certs : Vec < Vec < u8 > > ) -> Self {
128+ self . root_certs = Some ( certs) ;
129+ self
130+ }
131+
113132 /// Builds the ProverConfig.
114133 pub fn build ( self ) -> ProverConfig {
115134 ProverConfig {
@@ -122,6 +141,7 @@ impl ProverConfigBuilder {
122141 defer_decryption_from_start : self . defer_decryption_from_start ,
123142 network : self . network ,
124143 client_auth : self . client_auth ,
144+ root_certs : self . root_certs ,
125145 }
126146 }
127147}
@@ -137,6 +157,10 @@ pub struct VerifierConfig {
137157 pub max_sent_records : Option < usize > ,
138158 /// Maximum number of received records during online phase.
139159 pub max_recv_records_online : Option < usize > ,
160+ /// Custom root certificates (DER-encoded) for TLS server verification.
161+ ///
162+ /// If `None`, the Mozilla root certificates are used.
163+ pub root_certs : Option < Vec < Vec < u8 > > > ,
140164}
141165
142166impl Default for VerifierConfig {
@@ -146,6 +170,7 @@ impl Default for VerifierConfig {
146170 max_recv_data : 16384 ,
147171 max_sent_records : None ,
148172 max_recv_records_online : None ,
173+ root_certs : None ,
149174 }
150175 }
151176}
@@ -164,6 +189,7 @@ pub struct VerifierConfigBuilder {
164189 max_recv_data : usize ,
165190 max_sent_records : Option < usize > ,
166191 max_recv_records_online : Option < usize > ,
192+ root_certs : Option < Vec < Vec < u8 > > > ,
167193}
168194
169195impl Default for VerifierConfigBuilder {
@@ -173,6 +199,7 @@ impl Default for VerifierConfigBuilder {
173199 max_recv_data : 16384 ,
174200 max_sent_records : None ,
175201 max_recv_records_online : None ,
202+ root_certs : None ,
176203 }
177204 }
178205}
@@ -202,13 +229,22 @@ impl VerifierConfigBuilder {
202229 self
203230 }
204231
232+ /// Sets custom root certificates (DER-encoded) for TLS server verification.
233+ ///
234+ /// If not set, the Mozilla root certificates are used.
235+ pub fn root_certs ( mut self , certs : Vec < Vec < u8 > > ) -> Self {
236+ self . root_certs = Some ( certs) ;
237+ self
238+ }
239+
205240 /// Builds the VerifierConfig.
206241 pub fn build ( self ) -> VerifierConfig {
207242 VerifierConfig {
208243 max_sent_data : self . max_sent_data ,
209244 max_recv_data : self . max_recv_data ,
210245 max_sent_records : self . max_sent_records ,
211246 max_recv_records_online : self . max_recv_records_online ,
247+ root_certs : self . root_certs ,
212248 }
213249 }
214250}
@@ -240,3 +276,31 @@ pub struct ClientAuth {
240276 /// Client private key (DER encoded).
241277 pub key : Vec < u8 > ,
242278}
279+
280+ /// Builds a [`RootCertStore`] from optional DER-encoded root certificates.
281+ ///
282+ /// If `root_certs` is `Some`, builds a store from the provided certificates.
283+ /// If `None`, falls back to Mozilla root certificates (requires `mozilla-certs`
284+ /// feature).
285+ pub ( crate ) fn build_root_store ( root_certs : & Option < Vec < Vec < u8 > > > ) -> Result < RootCertStore > {
286+ match root_certs {
287+ Some ( certs) => Ok ( RootCertStore {
288+ roots : certs
289+ . iter ( )
290+ . map ( |cert| CertificateDer ( cert. clone ( ) ) )
291+ . collect ( ) ,
292+ } ) ,
293+ None => {
294+ #[ cfg( feature = "mozilla-certs" ) ]
295+ {
296+ Ok ( RootCertStore :: mozilla ( ) )
297+ }
298+ #[ cfg( not( feature = "mozilla-certs" ) ) ]
299+ {
300+ Err ( SdkError :: config (
301+ "no root certificates provided and mozilla-certs feature is not enabled" ,
302+ ) )
303+ }
304+ }
305+ }
306+ }
0 commit comments