@@ -119,9 +119,12 @@ pub enum Host {
119
119
/// * `dbname` - The name of the database to connect to. Defaults to the username.
120
120
/// * `options` - Command line options used to configure the server.
121
121
/// * `application_name` - Sets the `application_name` parameter on the server.
122
+ /// * `sslcert` - Location of the client SSL certificate file.
123
+ /// * `sslkey` - Location for the secret key file used for the client certificate.
122
124
/// * `sslmode` - Controls usage of TLS. If set to `disable`, TLS will not be used. If set to `prefer`, TLS will be used
123
125
/// if available, but not used otherwise. If set to `require`, `verify-ca`, or `verify-full`, TLS will be forced to
124
126
/// be used. Defaults to `prefer`.
127
+ /// * `sslrootcert` - Location of SSL certificate authority (CA) certificate.
125
128
/// * `host` - The host to connect to. On Unix platforms, if the host starts with a `/` character it is treated as the
126
129
/// path to the directory containing Unix domain sockets. Otherwise, it is treated as a hostname. Multiple hosts
127
130
/// can be specified, separated by commas. Each host will be tried in turn when connecting. Required if connecting
@@ -217,7 +220,10 @@ pub struct Config {
217
220
pub ( crate ) dbname : Option < String > ,
218
221
pub ( crate ) options : Option < String > ,
219
222
pub ( crate ) application_name : Option < String > ,
223
+ pub ( crate ) ssl_cert : Option < PathBuf > ,
224
+ pub ( crate ) ssl_key : Option < PathBuf > ,
220
225
pub ( crate ) ssl_mode : SslMode ,
226
+ pub ( crate ) ssl_root_cert : Option < PathBuf > ,
221
227
pub ( crate ) host : Vec < Host > ,
222
228
pub ( crate ) hostaddr : Vec < IpAddr > ,
223
229
pub ( crate ) port : Vec < u16 > ,
@@ -247,7 +253,10 @@ impl Config {
247
253
dbname : None ,
248
254
options : None ,
249
255
application_name : None ,
256
+ ssl_cert : None ,
257
+ ssl_key : None ,
250
258
ssl_mode : SslMode :: Prefer ,
259
+ ssl_root_cert : None ,
251
260
host : vec ! [ ] ,
252
261
hostaddr : vec ! [ ] ,
253
262
port : vec ! [ ] ,
@@ -334,6 +343,32 @@ impl Config {
334
343
self . application_name . as_deref ( )
335
344
}
336
345
346
+ /// Sets the location of the client SSL certificate file.
347
+ ///
348
+ /// Defaults to `None`.
349
+ pub fn ssl_cert ( & mut self , ssl_cert : & str ) -> & mut Config {
350
+ self . ssl_cert = Some ( PathBuf :: from ( ssl_cert) ) ;
351
+ self
352
+ }
353
+
354
+ /// Gets the location of the client SSL certificate file.
355
+ pub fn get_ssl_cert ( & self ) -> Option < PathBuf > {
356
+ self . ssl_cert . clone ( )
357
+ }
358
+
359
+ /// Sets the location of the secret key file used for the client certificate.
360
+ ///
361
+ /// Defaults to `None`.
362
+ pub fn ssl_key ( & mut self , ssl_key : & str ) -> & mut Config {
363
+ self . ssl_key = Some ( PathBuf :: from ( ssl_key) ) ;
364
+ self
365
+ }
366
+
367
+ /// Gets the location of the secret key file used for the client certificate.
368
+ pub fn get_ssl_key ( & self ) -> Option < PathBuf > {
369
+ self . ssl_key . clone ( )
370
+ }
371
+
337
372
/// Sets the SSL configuration.
338
373
///
339
374
/// Defaults to `prefer`.
@@ -347,6 +382,19 @@ impl Config {
347
382
self . ssl_mode
348
383
}
349
384
385
+ /// Sets the location of SSL certificate authority (CA) certificate.
386
+ ///
387
+ /// Defaults to `None`.
388
+ pub fn ssl_root_cert ( & mut self , ssl_root_cert : & str ) -> & mut Config {
389
+ self . ssl_root_cert = Some ( PathBuf :: from ( ssl_root_cert) ) ;
390
+ self
391
+ }
392
+
393
+ /// Gets the location of SSL certificate authority (CA) certificate.
394
+ pub fn get_ssl_root_cert ( & self ) -> Option < PathBuf > {
395
+ self . ssl_root_cert . clone ( )
396
+ }
397
+
350
398
/// Adds a host to the configuration.
351
399
///
352
400
/// Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix
@@ -579,6 +627,18 @@ impl Config {
579
627
"application_name" => {
580
628
self . application_name ( value) ;
581
629
}
630
+ "sslcert" => {
631
+ if std:: fs:: metadata ( value) . is_err ( ) {
632
+ return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslcert" ) ) ) ) ;
633
+ }
634
+ self . ssl_cert ( value) ;
635
+ }
636
+ "sslkey" => {
637
+ if std:: fs:: metadata ( value) . is_err ( ) {
638
+ return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslkey" ) ) ) ) ;
639
+ }
640
+ self . ssl_key ( value) ;
641
+ }
582
642
"sslmode" => {
583
643
let mode = match value {
584
644
"disable" => SslMode :: Disable ,
@@ -590,6 +650,12 @@ impl Config {
590
650
} ;
591
651
self . ssl_mode ( mode) ;
592
652
}
653
+ "sslrootcert" => {
654
+ if std:: fs:: metadata ( value) . is_err ( ) {
655
+ return Err ( Error :: config_parse ( Box :: new ( InvalidValue ( "sslrootcert" ) ) ) ) ;
656
+ }
657
+ self . ssl_root_cert ( value) ;
658
+ }
593
659
"host" => {
594
660
for host in value. split ( ',' ) {
595
661
self . host ( host) ;
@@ -776,7 +842,10 @@ impl fmt::Debug for Config {
776
842
. field ( "dbname" , & self . dbname )
777
843
. field ( "options" , & self . options )
778
844
. field ( "application_name" , & self . application_name )
845
+ . field ( "ssl_cert" , & self . ssl_cert )
846
+ . field ( "ssl_key" , & self . ssl_key )
779
847
. field ( "ssl_mode" , & self . ssl_mode )
848
+ . field ( "ssl_root_cert" , & self . ssl_root_cert )
780
849
. field ( "host" , & self . host )
781
850
. field ( "hostaddr" , & self . hostaddr )
782
851
. field ( "port" , & self . port )
0 commit comments