Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
25b7495d
Commit
25b7495d
authored
Apr 08, 2021
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Properly close input streams when loading key stores"
See gh-25884
parent
1e3f5c34
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
25 deletions
+34
-25
CouchbaseAutoConfiguration.java
...t/autoconfigure/couchbase/CouchbaseAutoConfiguration.java
+3
-3
SslServerCustomizer.java
...ramework/boot/web/embedded/netty/SslServerCustomizer.java
+3
-3
SslBuilderCustomizer.java
...work/boot/web/embedded/undertow/SslBuilderCustomizer.java
+3
-3
SslConnectorCustomizerTests.java
...boot/web/embedded/tomcat/SslConnectorCustomizerTests.java
+3
-3
AbstractReactiveWebServerFactoryTests.java
...eactive/server/AbstractReactiveWebServerFactoryTests.java
+4
-2
SslConfigurationValidatorTests.java
...ework/boot/web/server/SslConfigurationValidatorTests.java
+5
-3
AbstractServletWebServerFactoryTests.java
.../servlet/server/AbstractServletWebServerFactoryTests.java
+13
-8
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java
View file @
25b7495d
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -108,8 +108,8 @@ public class CouchbaseAutoConfiguration {
private
KeyStore
loadKeyStore
(
String
resource
,
String
keyStorePassword
)
throws
Exception
{
KeyStore
store
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
URL
url
=
ResourceUtils
.
getURL
(
resource
);
try
(
InputStream
inputS
tream
=
url
.
openStream
())
{
store
.
load
(
inputS
tream
,
(
keyStorePassword
!=
null
)
?
keyStorePassword
.
toCharArray
()
:
null
);
try
(
InputStream
s
tream
=
url
.
openStream
())
{
store
.
load
(
s
tream
,
(
keyStorePassword
!=
null
)
?
keyStorePassword
.
toCharArray
()
:
null
);
}
return
store
;
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java
View file @
25b7495d
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -171,8 +171,8 @@ public class SslServerCustomizer implements NettyServerCustomizer {
KeyStore
store
=
(
provider
!=
null
)
?
KeyStore
.
getInstance
(
type
,
provider
)
:
KeyStore
.
getInstance
(
type
);
try
{
URL
url
=
ResourceUtils
.
getURL
(
resource
);
try
(
InputStream
inputS
tream
=
url
.
openStream
())
{
store
.
load
(
inputS
tream
,
(
password
!=
null
)
?
password
.
toCharArray
()
:
null
);
try
(
InputStream
s
tream
=
url
.
openStream
())
{
store
.
load
(
s
tream
,
(
password
!=
null
)
?
password
.
toCharArray
()
:
null
);
}
return
store
;
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/SslBuilderCustomizer.java
View file @
25b7495d
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -182,8 +182,8 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
KeyStore
store
=
(
provider
!=
null
)
?
KeyStore
.
getInstance
(
type
,
provider
)
:
KeyStore
.
getInstance
(
type
);
try
{
URL
url
=
ResourceUtils
.
getURL
(
resource
);
try
(
InputStream
inputS
tream
=
url
.
openStream
())
{
store
.
load
(
inputS
tream
,
(
password
!=
null
)
?
password
.
toCharArray
()
:
null
);
try
(
InputStream
s
tream
=
url
.
openStream
())
{
store
.
load
(
s
tream
,
(
password
!=
null
)
?
password
.
toCharArray
()
:
null
);
}
return
store
;
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/SslConnectorCustomizerTests.java
View file @
25b7495d
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -220,8 +220,8 @@ class SslConnectorCustomizerTests {
private
KeyStore
loadStore
()
throws
KeyStoreException
,
IOException
,
NoSuchAlgorithmException
,
CertificateException
{
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"JKS"
);
Resource
resource
=
new
ClassPathResource
(
"test.jks"
);
try
(
InputStream
inputS
tream
=
resource
.
getInputStream
())
{
keyStore
.
load
(
inputS
tream
,
"secret"
.
toCharArray
());
try
(
InputStream
s
tream
=
resource
.
getInputStream
())
{
keyStore
.
load
(
s
tream
,
"secret"
.
toCharArray
());
return
keyStore
;
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java
View file @
25b7495d
...
...
@@ -16,8 +16,8 @@
package
org
.
springframework
.
boot
.
web
.
reactive
.
server
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.net.InetSocketAddress
;
import
java.nio.charset.StandardCharsets
;
import
java.security.KeyStore
;
...
...
@@ -228,7 +228,9 @@ public abstract class AbstractReactiveWebServerFactoryTests {
protected
ReactorClientHttpConnector
buildTrustAllSslWithClientKeyConnector
()
throws
Exception
{
KeyStore
clientKeyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
clientKeyStore
.
load
(
new
FileInputStream
(
new
File
(
"src/test/resources/test.jks"
)),
"secret"
.
toCharArray
());
try
(
InputStream
stream
=
new
FileInputStream
(
"src/test/resources/test.jks"
))
{
clientKeyStore
.
load
(
stream
,
"secret"
.
toCharArray
());
}
KeyManagerFactory
clientKeyManagerFactory
=
KeyManagerFactory
.
getInstance
(
KeyManagerFactory
.
getDefaultAlgorithm
());
clientKeyManagerFactory
.
init
(
clientKeyStore
,
"password"
.
toCharArray
());
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/SslConfigurationValidatorTests.java
View file @
25b7495d
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,8 +16,8 @@
package
org
.
springframework
.
boot
.
web
.
server
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.security.KeyStore
;
import
java.security.KeyStoreException
;
...
...
@@ -43,7 +43,9 @@ class SslConfigurationValidatorTests {
@BeforeEach
void
loadKeystore
()
throws
Exception
{
this
.
keyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
this
.
keyStore
.
load
(
new
FileInputStream
(
new
File
(
"src/test/resources/test.jks"
)),
"secret"
.
toCharArray
());
try
(
InputStream
stream
=
new
FileInputStream
(
"src/test/resources/test.jks"
))
{
this
.
keyStore
.
load
(
stream
,
"secret"
.
toCharArray
());
}
}
@Test
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java
View file @
25b7495d
...
...
@@ -17,7 +17,6 @@
package
org
.
springframework
.
boot
.
web
.
servlet
.
server
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStream
;
...
...
@@ -126,6 +125,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.boot.web.servlet.server.Session.SessionTrackingMode
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
...
...
@@ -542,7 +542,7 @@ public abstract class AbstractServletWebServerFactoryTests {
this
.
webServer
=
factory
.
getWebServer
();
this
.
webServer
.
start
();
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"pkcs12"
);
keyStore
.
load
(
new
FileInputStream
(
new
File
(
"src/test/resources/test.p12"
)),
"secret"
.
toCharArray
(
));
loadStore
(
keyStore
,
new
FileSystemResource
(
"src/test/resources/test.p12"
));
SSLConnectionSocketFactory
socketFactory
=
new
SSLConnectionSocketFactory
(
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustSelfSignedStrategy
())
.
loadKeyMaterial
(
keyStore
,
"secret"
.
toCharArray
()).
build
());
...
...
@@ -559,7 +559,7 @@ public abstract class AbstractServletWebServerFactoryTests {
this
.
webServer
=
factory
.
getWebServer
();
this
.
webServer
.
start
();
KeyStore
keyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
keyStore
.
load
(
new
FileInputStream
(
new
File
(
"src/test/resources/test.jks"
)),
"secret"
.
toCharArray
(
));
loadStore
(
keyStore
,
new
FileSystemResource
(
"src/test/resources/test.jks"
));
SSLConnectionSocketFactory
socketFactory
=
new
SSLConnectionSocketFactory
(
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustSelfSignedStrategy
())
.
loadKeyMaterial
(
keyStore
,
"password"
.
toCharArray
()).
build
());
...
...
@@ -592,7 +592,7 @@ public abstract class AbstractServletWebServerFactoryTests {
this
.
webServer
=
factory
.
getWebServer
();
this
.
webServer
.
start
();
KeyStore
keyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
keyStore
.
load
(
new
FileInputStream
(
new
File
(
"src/test/resources/test.jks"
)),
"secret"
.
toCharArray
(
));
loadStore
(
keyStore
,
new
FileSystemResource
(
"src/test/resources/test.jks"
));
SSLConnectionSocketFactory
socketFactory
=
new
SSLConnectionSocketFactory
(
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustSelfSignedStrategy
())
.
loadKeyMaterial
(
keyStore
,
"password"
.
toCharArray
()).
build
());
...
...
@@ -630,7 +630,7 @@ public abstract class AbstractServletWebServerFactoryTests {
this
.
webServer
=
factory
.
getWebServer
();
this
.
webServer
.
start
();
KeyStore
keyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
keyStore
.
load
(
new
FileInputStream
(
new
File
(
"src/test/resources/test.jks"
)),
"secret"
.
toCharArray
(
));
loadStore
(
keyStore
,
new
FileSystemResource
(
"src/test/resources/test.jks"
));
SSLConnectionSocketFactory
socketFactory
=
new
SSLConnectionSocketFactory
(
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustSelfSignedStrategy
())
.
loadKeyMaterial
(
keyStore
,
"password"
.
toCharArray
()).
build
());
...
...
@@ -1354,9 +1354,14 @@ public abstract class AbstractServletWebServerFactoryTests {
private
KeyStore
loadStore
()
throws
KeyStoreException
,
IOException
,
NoSuchAlgorithmException
,
CertificateException
{
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"JKS"
);
Resource
resource
=
new
ClassPathResource
(
"test.jks"
);
try
(
InputStream
inputStream
=
resource
.
getInputStream
())
{
keyStore
.
load
(
inputStream
,
"secret"
.
toCharArray
());
return
keyStore
;
loadStore
(
keyStore
,
resource
);
return
keyStore
;
}
private
void
loadStore
(
KeyStore
keyStore
,
Resource
resource
)
throws
IOException
,
NoSuchAlgorithmException
,
CertificateException
{
try
(
InputStream
stream
=
resource
.
getInputStream
())
{
keyStore
.
load
(
stream
,
"secret"
.
toCharArray
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment