@@ -98,9 +98,12 @@ pub enum Host {
98
98
/// * `dbname` - The name of the database to connect to. Defaults to the username.
99
99
/// * `options` - Command line options used to configure the server.
100
100
/// * `application_name` - Sets the `application_name` parameter on the server.
101
+ /// * `sslcert` - Location of the client SSL certificate file.
102
+ /// * `sslkey` - Location for the secret key file used for the client certificate.
101
103
/// * `sslmode` - Controls usage of TLS. If set to `disable`, TLS will not be used. If set to `prefer`, TLS will be used
102
104
/// if available, but not used otherwise. If set to `require`, `verify-ca`, or `verify-full`, TLS will be forced to
103
105
/// be used. Defaults to `prefer`.
106
+ /// * `sslrootcert` - Location of SSL certificate authority (CA) certificate.
104
107
/// * `host` - The host to connect to. On Unix platforms, if the host starts with a `/` character it is treated as the
105
108
/// path to the directory containing Unix domain sockets. Otherwise, it is treated as a hostname. Multiple hosts
106
109
/// can be specified, separated by commas. Each host will be tried in turn when connecting. Required if connecting
@@ -166,7 +169,10 @@ pub struct Config {
166
169
pub ( crate ) dbname : Option < String > ,
167
170
pub ( crate ) options : Option < String > ,
168
171
pub ( crate ) application_name : Option < String > ,
172
+ pub ( crate ) ssl_cert : Option < PathBuf > ,
173
+ pub ( crate ) ssl_key : Option < PathBuf > ,
169
174
pub ( crate ) ssl_mode : SslMode ,
175
+ pub ( crate ) ssl_root_cert : Option < PathBuf > ,
170
176
pub ( crate ) host : Vec < Host > ,
171
177
pub ( crate ) port : Vec < u16 > ,
172
178
pub ( crate ) connect_timeout : Option < Duration > ,
@@ -192,7 +198,10 @@ impl Config {
192
198
dbname : None ,
193
199
options : None ,
194
200
application_name : None ,
201
+ ssl_cert : None ,
202
+ ssl_key : None ,
195
203
ssl_mode : SslMode :: Prefer ,
204
+ ssl_root_cert : None ,
196
205
host : vec ! [ ] ,
197
206
port : vec ! [ ] ,
198
207
connect_timeout : None ,
@@ -271,6 +280,32 @@ impl Config {
271
280
self . application_name . as_deref ( )
272
281
}
273
282
283
+ /// Sets the location of the client SSL certificate file.
284
+ ///
285
+ /// Defaults to `None`.
286
+ pub fn ssl_cert ( & mut self , ssl_cert : & str ) -> & mut Config {
287
+ self . ssl_cert = Some ( PathBuf :: from ( ssl_cert) ) ;
288
+ self
289
+ }
290
+
291
+ /// Gets the location of the client SSL certificate file.
292
+ pub fn get_ssl_cert ( & self ) -> Option < PathBuf > {
293
+ self . ssl_cert . clone ( )
294
+ }
295
+
296
+ /// Sets the location of the secret key file used for the client certificate.
297
+ ///
298
+ /// Defaults to `None`.
299
+ pub fn ssl_key ( & mut self , ssl_key : & str ) -> & mut Config {
300
+ self . ssl_key = Some ( PathBuf :: from ( ssl_key) ) ;
301
+ self
302
+ }
303
+
304
+ /// Gets the location of the secret key file used for the client certificate.
305
+ pub fn get_ssl_key ( & self ) -> Option < PathBuf > {
306
+ self . ssl_key . clone ( )
307
+ }
308
+
274
309
/// Sets the SSL configuration.
275
310
///
276
311
/// Defaults to `prefer`.
@@ -284,6 +319,19 @@ impl Config {
284
319
self . ssl_mode
285
320
}
286
321
322
+ /// Sets the location of SSL certificate authority (CA) certificate.
323
+ ///
324
+ /// Defaults to `None`.
325
+ pub fn ssl_root_cert ( & mut self , ssl_root_cert : & str ) -> & mut Config {
326
+ self . ssl_root_cert = Some ( PathBuf :: from ( ssl_root_cert) ) ;
327
+ self
328
+ }
329
+
330
+ /// Gets the location of SSL certificate authority (CA) certificate.
331
+ pub fn get_ssl_root_cert ( & self ) -> Option < PathBuf > {
332
+ self . ssl_root_cert . clone ( )
333
+ }
334
+
287
335
/// Adds a host to the configuration.
288
336
///
289
337
/// Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix
@@ -432,6 +480,18 @@ impl Config {
432
480
"application_name" => {
433
481
self . application_name ( & value) ;
434
482
}
483
+ "sslcert" => {
484
+ if std:: fs:: metadata ( & value) . is_err ( ) {
485
+ return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslcert" ) ) ) ) ;
486
+ }
487
+ self . ssl_cert ( & value) ;
488
+ }
489
+ "sslkey" => {
490
+ if std:: fs:: metadata ( & value) . is_err ( ) {
491
+ return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslkey" ) ) ) ) ;
492
+ }
493
+ self . ssl_key ( & value) ;
494
+ }
435
495
"sslmode" => {
436
496
let mode = match value {
437
497
"disable" => SslMode :: Disable ,
@@ -443,6 +503,12 @@ impl Config {
443
503
} ;
444
504
self . ssl_mode ( mode) ;
445
505
}
506
+ "sslrootcert" => {
507
+ if std:: fs:: metadata ( & value) . is_err ( ) {
508
+ return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslrootcert" ) ) ) ) ;
509
+ }
510
+ self . ssl_root_cert ( & value) ;
511
+ }
446
512
"host" => {
447
513
for host in value. split ( ',' ) {
448
514
self . host ( host) ;
@@ -581,7 +647,10 @@ impl fmt::Debug for Config {
581
647
. field ( "dbname" , & self . dbname )
582
648
. field ( "options" , & self . options )
583
649
. field ( "application_name" , & self . application_name )
650
+ . field ( "ssl_cert" , & self . ssl_cert )
651
+ . field ( "ssl_key" , & self . ssl_key )
584
652
. field ( "ssl_mode" , & self . ssl_mode )
653
+ . field ( "ssl_root_cert" , & self . ssl_root_cert )
585
654
. field ( "host" , & self . host )
586
655
. field ( "port" , & self . port )
587
656
. field ( "connect_timeout" , & self . connect_timeout )
0 commit comments