GH-1237: RCFB Close key/trust store input streams

Resolves https://github.com/spring-projects/spring-amqp/issues/1237

**cherry-pick to 2.2.x, 2.1.x, 1.7.x**
This commit is contained in:
Gary Russell
2020-08-05 11:34:54 -04:00
committed by Artem Bilan
parent 5b8b3dc8b5
commit 165b838c3a

View File

@@ -17,6 +17,7 @@
package org.springframework.amqp.rabbit.connection;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.KeyManagementException;
@@ -816,7 +817,9 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
Resource resource = this.keyStoreResource != null ? this.keyStoreResource
: this.resourceLoader.getResource(keyStoreName);
KeyStore ks = KeyStore.getInstance(storeType);
ks.load(resource.getInputStream(), keyPassphrase);
try (InputStream inputStream = resource.getInputStream()) {
ks.load(inputStream, keyPassphrase);
}
KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.keyStoreAlgorithm);
kmf.init(ks, keyPassphrase);
keyManagers = kmf.getKeyManagers();
@@ -839,7 +842,9 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
Resource resource = this.trustStoreResource != null ? this.trustStoreResource
: this.resourceLoader.getResource(trustStoreName);
KeyStore tks = KeyStore.getInstance(storeType);
tks.load(resource.getInputStream(), trustPassphrase);
try (InputStream inputStream = resource.getInputStream()) {
tks.load(inputStream, trustPassphrase);
}
TrustManagerFactory tmf = TrustManagerFactory.getInstance(this.trustStoreAlgorithm);
tmf.init(tks);
trustManagers = tmf.getTrustManagers();