34
34
35
35
import javax .net .ssl .HostnameVerifier ;
36
36
import java .io .File ;
37
+ import java .net .MalformedURLException ;
37
38
import java .net .Socket ;
39
+ import java .net .URL ;
38
40
import java .time .Duration ;
39
41
import java .util .ArrayList ;
40
42
import java .util .Collections ;
@@ -331,20 +333,20 @@ public static final class Builder {
331
333
private String socket ;
332
334
333
335
@ Nullable
334
- private String sslCert = null ;
336
+ private URL sslCert = null ;
335
337
336
338
private HostnameVerifier sslHostnameVerifier = DefaultHostnameVerifier .INSTANCE ;
337
339
338
340
@ Nullable
339
- private String sslKey = null ;
341
+ private URL sslKey = null ;
340
342
341
343
private SSLMode sslMode = SSLMode .DISABLE ;
342
344
343
345
@ Nullable
344
346
private CharSequence sslPassword = null ;
345
347
346
348
@ Nullable
347
- private String sslRootCert = null ;
349
+ private URL sslRootCert = null ;
348
350
349
351
private Function <SslContextBuilder , SslContextBuilder > sslContextBuilderCustomizer = Function .identity ();
350
352
@@ -637,8 +639,8 @@ public Builder sslContextBuilderCustomizer(Function<SslContextBuilder, SslContex
637
639
* @param sslCert an X.509 certificate chain file in PEM format
638
640
* @return this {@link Builder}
639
641
*/
640
- public Builder sslCert (String sslCert ) {
641
- this .sslCert = Assert .requireFileExistsOrNull (sslCert , "sslCert must not be null and must exist" );
642
+ public Builder sslCert (URL sslCert ) {
643
+ this .sslCert = Assert .requireUrlExistsOrNull (sslCert , "sslCert must not be null and must exist" );
642
644
return this ;
643
645
}
644
646
@@ -659,8 +661,8 @@ public Builder sslHostnameVerifier(HostnameVerifier sslHostnameVerifier) {
659
661
* @param sslKey a PKCS#8 private key file in PEM format
660
662
* @return this {@link Builder}
661
663
*/
662
- public Builder sslKey (String sslKey ) {
663
- this .sslKey = Assert .requireFileExistsOrNull (sslKey , "sslKey must not be null and must exist" );
664
+ public Builder sslKey (URL sslKey ) {
665
+ this .sslKey = Assert .requireUrlExistsOrNull (sslKey , "sslKey must not be null and must exist" );
664
666
return this ;
665
667
}
666
668
@@ -692,8 +694,8 @@ public Builder sslPassword(@Nullable CharSequence sslPassword) {
692
694
* @param sslRootCert an X.509 certificate chain file in PEM format
693
695
* @return this {@link Builder}
694
696
*/
695
- public Builder sslRootCert (String sslRootCert ) {
696
- this .sslRootCert = Assert .requireFileExistsOrNull (sslRootCert , "sslRootCert must not be null and must exist" );
697
+ public Builder sslRootCert (URL sslRootCert ) {
698
+ this .sslRootCert = Assert .requireUrlExistsOrNull (sslRootCert , "sslRootCert must not be null and must exist" );
697
699
return this ;
698
700
}
699
701
@@ -779,14 +781,14 @@ private Supplier<SslProvider> createSslProvider() {
779
781
SslContextBuilder sslContextBuilder = SslContextBuilder .forClient ();
780
782
if (this .sslMode .verifyCertificate ()) {
781
783
if (this .sslRootCert != null ) {
782
- sslContextBuilder .trustManager (new File (this .sslRootCert ));
784
+ sslContextBuilder .trustManager (new File (this .sslRootCert . getFile () ));
783
785
}
784
786
} else {
785
787
sslContextBuilder .trustManager (InsecureTrustManagerFactory .INSTANCE );
786
788
}
787
789
788
- String sslKey = this .sslKey ;
789
- String sslCert = this .sslCert ;
790
+ URL sslKey = this .sslKey ;
791
+ URL sslCert = this .sslCert ;
790
792
791
793
// Emulate Libpq behavior
792
794
// Determining the default file location
@@ -801,20 +803,28 @@ private Supplier<SslProvider> createSslProvider() {
801
803
if (sslCert == null ) {
802
804
String pathname = defaultDir + "postgresql.crt" ;
803
805
if (new File (pathname ).exists ()) {
804
- sslCert = pathname ;
806
+ try {
807
+ sslCert = new URL (pathname );
808
+ } catch (MalformedURLException e ) {
809
+ throw new RuntimeException (e );
810
+ }
805
811
}
806
812
}
807
813
808
814
if (sslKey == null ) {
809
815
String pathname = defaultDir + "postgresql.pk8" ;
810
816
if (new File (pathname ).exists ()) {
811
- sslKey = pathname ;
817
+ try {
818
+ sslKey = new URL (pathname );
819
+ } catch (MalformedURLException e ) {
820
+ throw new RuntimeException (e );
821
+ }
812
822
}
813
823
}
814
824
815
825
if (sslKey != null && sslCert != null ) {
816
826
String sslPassword = this .sslPassword == null ? null : this .sslPassword .toString ();
817
- sslContextBuilder .keyManager (new File (sslCert ) , new File (sslKey ), sslPassword );
827
+ sslContextBuilder .keyManager (new File (sslCert . getFile ()) , new File (sslKey . getFile () ), sslPassword );
818
828
}
819
829
820
830
return () -> SslProvider .builder ()
0 commit comments