mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Properly close input streams when loading key stores
See gh-25884
This commit is contained in:
parent
2ac160a9b8
commit
1e3f5c342b
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.boot.autoconfigure.couchbase;
|
package org.springframework.boot.autoconfigure.couchbase;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
|
|
||||||
@ -107,7 +108,9 @@ public class CouchbaseAutoConfiguration {
|
|||||||
private KeyStore loadKeyStore(String resource, String keyStorePassword) throws Exception {
|
private KeyStore loadKeyStore(String resource, String keyStorePassword) throws Exception {
|
||||||
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
|
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
URL url = ResourceUtils.getURL(resource);
|
URL url = ResourceUtils.getURL(resource);
|
||||||
store.load(url.openStream(), (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
|
try (InputStream inputStream = url.openStream()) {
|
||||||
|
store.load(inputStream, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
|
||||||
|
}
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.boot.web.embedded.netty;
|
package org.springframework.boot.web.embedded.netty;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
@ -170,7 +171,9 @@ public class SslServerCustomizer implements NettyServerCustomizer {
|
|||||||
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
|
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
|
||||||
try {
|
try {
|
||||||
URL url = ResourceUtils.getURL(resource);
|
URL url = ResourceUtils.getURL(resource);
|
||||||
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
|
try (InputStream inputStream = url.openStream()) {
|
||||||
|
store.load(inputStream, (password != null) ? password.toCharArray() : null);
|
||||||
|
}
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.boot.web.embedded.undertow;
|
package org.springframework.boot.web.embedded.undertow;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -181,7 +182,9 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
|
|||||||
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
|
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
|
||||||
try {
|
try {
|
||||||
URL url = ResourceUtils.getURL(resource);
|
URL url = ResourceUtils.getURL(resource);
|
||||||
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
|
try (InputStream inputStream = url.openStream()) {
|
||||||
|
store.load(inputStream, (password != null) ? password.toCharArray() : null);
|
||||||
|
}
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user