@@ -58,7 +58,7 @@ public static SSLContext createSslContext(boolean allowInsecureConnection, Certi
58
58
}
59
59
60
60
public static SslContext createNettySslContextForClient (boolean allowInsecureConnection , String trustCertsFilePath )
61
- throws GeneralSecurityException , SSLException , FileNotFoundException {
61
+ throws IOException , GeneralSecurityException , SSLException , FileNotFoundException {
62
62
return createNettySslContextForClient (allowInsecureConnection , trustCertsFilePath , (Certificate []) null ,
63
63
(PrivateKey ) null );
64
64
}
@@ -73,21 +73,23 @@ public static SSLContext createSslContext(boolean allowInsecureConnection, Strin
73
73
74
74
public static SslContext createNettySslContextForClient (boolean allowInsecureConnection , String trustCertsFilePath ,
75
75
String certFilePath , String keyFilePath )
76
- throws GeneralSecurityException , SSLException , FileNotFoundException {
76
+ throws IOException , GeneralSecurityException , SSLException , FileNotFoundException {
77
77
X509Certificate [] certificates = loadCertificatesFromPemFile (certFilePath );
78
78
PrivateKey privateKey = loadPrivateKeyFromPemFile (keyFilePath );
79
79
return createNettySslContextForClient (allowInsecureConnection , trustCertsFilePath , certificates , privateKey );
80
80
}
81
81
82
82
public static SslContext createNettySslContextForClient (boolean allowInsecureConnection , String trustCertsFilePath ,
83
83
Certificate [] certificates , PrivateKey privateKey )
84
- throws GeneralSecurityException , SSLException , FileNotFoundException {
84
+ throws GeneralSecurityException , IOException , FileNotFoundException {
85
85
SslContextBuilder builder = SslContextBuilder .forClient ();
86
86
if (allowInsecureConnection ) {
87
87
builder .trustManager (InsecureTrustManagerFactory .INSTANCE );
88
88
} else {
89
89
if (trustCertsFilePath != null && trustCertsFilePath .length () != 0 ) {
90
- builder .trustManager (new FileInputStream (trustCertsFilePath ));
90
+ try (FileInputStream input = new FileInputStream (trustCertsFilePath )) {
91
+ builder .trustManager (input );
92
+ }
91
93
}
92
94
}
93
95
builder .keyManager (privateKey , (X509Certificate []) certificates );
@@ -96,7 +98,7 @@ public static SslContext createNettySslContextForClient(boolean allowInsecureCon
96
98
97
99
public static SslContext createNettySslContextForServer (boolean allowInsecureConnection , String trustCertsFilePath ,
98
100
String certFilePath , String keyFilePath )
99
- throws GeneralSecurityException , SSLException , FileNotFoundException {
101
+ throws IOException , GeneralSecurityException , SSLException , FileNotFoundException {
100
102
X509Certificate [] certificates = loadCertificatesFromPemFile (certFilePath );
101
103
PrivateKey privateKey = loadPrivateKeyFromPemFile (keyFilePath );
102
104
@@ -105,7 +107,9 @@ public static SslContext createNettySslContextForServer(boolean allowInsecureCon
105
107
builder .trustManager (InsecureTrustManagerFactory .INSTANCE );
106
108
} else {
107
109
if (trustCertsFilePath != null && trustCertsFilePath .length () != 0 ) {
108
- builder .trustManager (new FileInputStream (trustCertsFilePath ));
110
+ try (FileInputStream input = new FileInputStream (trustCertsFilePath )) {
111
+ builder .trustManager (input );
112
+ }
109
113
} else {
110
114
builder .trustManager ((File ) null );
111
115
}
0 commit comments