Skip to content

Commit efcba3a

Browse files
garyrussellartembilan
authored andcommitted
GH-1237: RCFB Close key/trust store input streams
Resolves #1237 **cherry-pick to 2.2.x, 2.1.x, 1.7.x** (cherry picked from commit 165b838) # Conflicts: # spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitConnectionFactoryBean.java
1 parent 028b28a commit efcba3a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitConnectionFactoryBean.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.amqp.rabbit.connection;
1818

19+
import java.io.InputStream;
1920
import java.lang.reflect.Method;
2021
import java.net.URI;
2122
import java.net.URISyntaxException;
@@ -72,7 +73,7 @@
7273
*
7374
* @author Gary Russell
7475
* @author Heath Abelson
75-
* @author Arnaud Cogoluègnes
76+
* @author Arnaud Cogoluegnes
7677
* @author Hareendran
7778
* @author Artem Bilan
7879
* @author Zachary DeLuca
@@ -731,7 +732,13 @@ protected void setUpSSL() throws Exception {
731732
Resource keyStoreResource = this.keyStoreResource != null ? this.keyStoreResource
732733
: resolver.getResource(keyStoreName);
733734
KeyStore ks = KeyStore.getInstance(keyStoreType);
734-
ks.load(keyStoreResource.getInputStream(), keyPassphrase);
735+
InputStream inputStream = keyStoreResource.getInputStream();
736+
try {
737+
ks.load(inputStream, keyPassphrase);
738+
}
739+
finally {
740+
inputStream.close();
741+
}
735742
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
736743
kmf.init(ks, keyPassphrase);
737744
keyManagers = kmf.getKeyManagers();
@@ -740,7 +747,13 @@ protected void setUpSSL() throws Exception {
740747
Resource trustStoreResource = this.trustStoreResource != null ? this.trustStoreResource
741748
: resolver.getResource(trustStoreName);
742749
KeyStore tks = KeyStore.getInstance(trustStoreType);
743-
tks.load(trustStoreResource.getInputStream(), trustPassphrase);
750+
InputStream inputStream = trustStoreResource.getInputStream();
751+
try {
752+
tks.load(inputStream, trustPassphrase);
753+
}
754+
finally {
755+
inputStream.close();
756+
}
744757
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
745758
tmf.init(tks);
746759
trustManagers = tmf.getTrustManagers();

0 commit comments

Comments
 (0)