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
ac91f14f
Commit
ac91f14f
authored
Feb 12, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Verify ssl key alias on server startup"
See gh-19202
parent
e3516059
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
31 additions
and
32 deletions
+31
-32
SslServerCustomizer.java
...ramework/boot/web/embedded/jetty/SslServerCustomizer.java
+4
-3
SslServerCustomizer.java
...ramework/boot/web/embedded/netty/SslServerCustomizer.java
+3
-4
SslBuilderCustomizer.java
...work/boot/web/embedded/undertow/SslBuilderCustomizer.java
+3
-4
SslConfigurationValidator.java
...gframework/boot/web/server/SslConfigurationValidator.java
+5
-5
NettyReactiveWebServerFactoryTests.java
...eb/embedded/netty/NettyReactiveWebServerFactoryTests.java
+1
-1
TomcatServletWebServerFactoryTests.java
...b/embedded/tomcat/TomcatServletWebServerFactoryTests.java
+1
-1
AbstractReactiveWebServerFactoryTests.java
...eactive/server/AbstractReactiveWebServerFactoryTests.java
+1
-1
SslConfigurationValidatorTest.java
...mework/boot/web/server/SslConfigurationValidatorTest.java
+12
-12
AbstractServletWebServerFactoryTests.java
.../servlet/server/AbstractServletWebServerFactoryTests.java
+1
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -37,8 +37,8 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
...
@@ -37,8 +37,8 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
import
org.springframework.boot.web.server.Http2
;
import
org.springframework.boot.web.server.Http2
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.SslConfigurationValidator
;
import
org.springframework.boot.web.server.SslStoreProvider
;
import
org.springframework.boot.web.server.SslStoreProvider
;
import
org.springframework.boot.web.server.SslUtils
;
import
org.springframework.boot.web.server.WebServerException
;
import
org.springframework.boot.web.server.WebServerException
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ClassUtils
;
...
@@ -50,6 +50,7 @@ import org.springframework.util.ResourceUtils;
...
@@ -50,6 +50,7 @@ import org.springframework.util.ResourceUtils;
*
*
* @author Brian Clozel
* @author Brian Clozel
* @author Olivier Lamy
* @author Olivier Lamy
* @author Chris Bono
*/
*/
class
SslServerCustomizer
implements
JettyServerCustomizer
{
class
SslServerCustomizer
implements
JettyServerCustomizer
{
...
@@ -245,7 +246,7 @@ class SslServerCustomizer implements JettyServerCustomizer {
...
@@ -245,7 +246,7 @@ class SslServerCustomizer implements JettyServerCustomizer {
@Override
@Override
protected
void
doStart
()
throws
Exception
{
protected
void
doStart
()
throws
Exception
{
super
.
doStart
();
super
.
doStart
();
Ssl
Utils
.
assertStoreContains
Alias
(
this
.
sslContextFactory
.
getKeyStore
(),
this
.
keyAlias
);
Ssl
ConfigurationValidator
.
validateKey
Alias
(
this
.
sslContextFactory
.
getKeyStore
(),
this
.
keyAlias
);
}
}
}
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/SslServerCustomizer.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -43,8 +43,8 @@ import reactor.netty.tcp.SslProvider;
...
@@ -43,8 +43,8 @@ import reactor.netty.tcp.SslProvider;
import
org.springframework.boot.web.server.Http2
;
import
org.springframework.boot.web.server.Http2
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.SslConfigurationValidator
;
import
org.springframework.boot.web.server.SslStoreProvider
;
import
org.springframework.boot.web.server.SslStoreProvider
;
import
org.springframework.boot.web.server.SslUtils
;
import
org.springframework.boot.web.server.WebServerException
;
import
org.springframework.boot.web.server.WebServerException
;
import
org.springframework.util.ResourceUtils
;
import
org.springframework.util.ResourceUtils
;
...
@@ -107,8 +107,7 @@ public class SslServerCustomizer implements NettyServerCustomizer {
...
@@ -107,8 +107,7 @@ public class SslServerCustomizer implements NettyServerCustomizer {
protected
KeyManagerFactory
getKeyManagerFactory
(
Ssl
ssl
,
SslStoreProvider
sslStoreProvider
)
{
protected
KeyManagerFactory
getKeyManagerFactory
(
Ssl
ssl
,
SslStoreProvider
sslStoreProvider
)
{
try
{
try
{
KeyStore
keyStore
=
getKeyStore
(
ssl
,
sslStoreProvider
);
KeyStore
keyStore
=
getKeyStore
(
ssl
,
sslStoreProvider
);
SslUtils
.
assertStoreContainsAlias
(
keyStore
,
ssl
.
getKeyAlias
());
SslConfigurationValidator
.
validateKeyAlias
(
keyStore
,
ssl
.
getKeyAlias
());
KeyManagerFactory
keyManagerFactory
=
(
ssl
.
getKeyAlias
()
==
null
)
KeyManagerFactory
keyManagerFactory
=
(
ssl
.
getKeyAlias
()
==
null
)
?
KeyManagerFactory
.
getInstance
(
KeyManagerFactory
.
getDefaultAlgorithm
())
?
KeyManagerFactory
.
getInstance
(
KeyManagerFactory
.
getDefaultAlgorithm
())
:
new
ConfigurableAliasKeyManagerFactory
(
ssl
.
getKeyAlias
(),
:
new
ConfigurableAliasKeyManagerFactory
(
ssl
.
getKeyAlias
(),
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/SslBuilderCustomizer.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -40,8 +40,8 @@ import org.xnio.Sequence;
...
@@ -40,8 +40,8 @@ import org.xnio.Sequence;
import
org.xnio.SslClientAuthMode
;
import
org.xnio.SslClientAuthMode
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.Ssl
;
import
org.springframework.boot.web.server.SslConfigurationValidator
;
import
org.springframework.boot.web.server.SslStoreProvider
;
import
org.springframework.boot.web.server.SslStoreProvider
;
import
org.springframework.boot.web.server.SslUtils
;
import
org.springframework.boot.web.server.WebServerException
;
import
org.springframework.boot.web.server.WebServerException
;
import
org.springframework.util.ResourceUtils
;
import
org.springframework.util.ResourceUtils
;
...
@@ -108,8 +108,7 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
...
@@ -108,8 +108,7 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
private
KeyManager
[]
getKeyManagers
(
Ssl
ssl
,
SslStoreProvider
sslStoreProvider
)
{
private
KeyManager
[]
getKeyManagers
(
Ssl
ssl
,
SslStoreProvider
sslStoreProvider
)
{
try
{
try
{
KeyStore
keyStore
=
getKeyStore
(
ssl
,
sslStoreProvider
);
KeyStore
keyStore
=
getKeyStore
(
ssl
,
sslStoreProvider
);
SslUtils
.
assertStoreContainsAlias
(
keyStore
,
ssl
.
getKeyAlias
());
SslConfigurationValidator
.
validateKeyAlias
(
keyStore
,
ssl
.
getKeyAlias
());
KeyManagerFactory
keyManagerFactory
=
KeyManagerFactory
KeyManagerFactory
keyManagerFactory
=
KeyManagerFactory
.
getInstance
(
KeyManagerFactory
.
getDefaultAlgorithm
());
.
getInstance
(
KeyManagerFactory
.
getDefaultAlgorithm
());
char
[]
keyPassword
=
(
ssl
.
getKeyPassword
()
!=
null
)
?
ssl
.
getKeyPassword
().
toCharArray
()
:
null
;
char
[]
keyPassword
=
(
ssl
.
getKeyPassword
()
!=
null
)
?
ssl
.
getKeyPassword
().
toCharArray
()
:
null
;
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/Ssl
Utils
.java
→
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/Ssl
ConfigurationValidator
.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -26,14 +26,14 @@ import org.springframework.util.StringUtils;
...
@@ -26,14 +26,14 @@ import org.springframework.util.StringUtils;
* Provides utilities around SSL.
* Provides utilities around SSL.
*
*
* @author Chris Bono
* @author Chris Bono
* @since 2.1.
x
* @since 2.1.
13
*/
*/
public
final
class
Ssl
Utils
{
public
final
class
Ssl
ConfigurationValidator
{
private
Ssl
Utils
()
{
private
Ssl
ConfigurationValidator
()
{
}
}
public
static
void
assertStoreContains
Alias
(
KeyStore
keyStore
,
String
keyAlias
)
{
public
static
void
validateKey
Alias
(
KeyStore
keyStore
,
String
keyAlias
)
{
if
(!
StringUtils
.
isEmpty
(
keyAlias
))
{
if
(!
StringUtils
.
isEmpty
(
keyAlias
))
{
try
{
try
{
Assert
.
state
(
keyStore
.
containsAlias
(
keyAlias
),
Assert
.
state
(
keyStore
.
containsAlias
(
keyAlias
),
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/Ssl
Utils
Test.java
→
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/Ssl
ConfigurationValidator
Test.java
View file @
ac91f14f
...
@@ -27,12 +27,12 @@ import org.junit.Test;
...
@@ -27,12 +27,12 @@ import org.junit.Test;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatThrownBy
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatThrownBy
;
/**
/**
* Tests for {@link Ssl
Utils
}.
* Tests for {@link Ssl
ConfigurationValidator
}.
*
*
* @author Chris Bono
* @author Chris Bono
*/
*/
public
class
Ssl
Utils
Test
{
public
class
Ssl
ConfigurationValidator
Test
{
private
static
final
String
VALID_ALIAS
=
"test-alias"
;
private
static
final
String
VALID_ALIAS
=
"test-alias"
;
...
@@ -47,31 +47,31 @@ public class SslUtilsTest {
...
@@ -47,31 +47,31 @@ public class SslUtilsTest {
}
}
@Test
@Test
public
void
assertStoreContainsAliasPassesWhenAliasFound
()
throws
KeyStoreException
{
public
void
validateKeyAliasWhenAliasFoundShouldNotFail
()
{
Ssl
Utils
.
assertStoreContains
Alias
(
this
.
keyStore
,
VALID_ALIAS
);
Ssl
ConfigurationValidator
.
validateKey
Alias
(
this
.
keyStore
,
VALID_ALIAS
);
}
}
@Test
@Test
public
void
assertStoreContainsAliasPassesWhenNullAlias
()
throws
KeyStoreException
{
public
void
validateKeyAliasWhenNullAliasShouldNotFail
()
{
Ssl
Utils
.
assertStoreContains
Alias
(
this
.
keyStore
,
null
);
Ssl
ConfigurationValidator
.
validateKey
Alias
(
this
.
keyStore
,
null
);
}
}
@Test
@Test
public
void
assertStoreContainsAliasPassesWhenEmptyAlias
()
throws
KeyStoreException
{
public
void
validateKeyAliasWhenEmptyAliasShouldNotFail
()
{
Ssl
Utils
.
assertStoreContains
Alias
(
this
.
keyStore
,
""
);
Ssl
ConfigurationValidator
.
validateKey
Alias
(
this
.
keyStore
,
""
);
}
}
@Test
@Test
public
void
assertStoreContainsAliasFailsWhenAliasNotFound
()
throws
KeyStoreException
{
public
void
validateKeyAliasWhenAliasNotFoundShouldThrowException
()
{
assertThatThrownBy
(()
->
Ssl
Utils
.
assertStoreContains
Alias
(
this
.
keyStore
,
INVALID_ALIAS
))
assertThatThrownBy
(()
->
Ssl
ConfigurationValidator
.
validateKey
Alias
(
this
.
keyStore
,
INVALID_ALIAS
))
.
isInstanceOf
(
IllegalStateException
.
class
)
.
isInstanceOf
(
IllegalStateException
.
class
)
.
hasMessage
(
"Keystore does not contain specified alias '"
+
INVALID_ALIAS
+
"'"
);
.
hasMessage
(
"Keystore does not contain specified alias '"
+
INVALID_ALIAS
+
"'"
);
}
}
@Test
@Test
public
void
assertStoreContainsAliasFail
sWhenKeyStoreThrowsExceptionOnContains
()
throws
KeyStoreException
{
public
void
validateKeyAlia
sWhenKeyStoreThrowsExceptionOnContains
()
throws
KeyStoreException
{
KeyStore
uninitializedKeyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
KeyStore
uninitializedKeyStore
=
KeyStore
.
getInstance
(
KeyStore
.
getDefaultType
());
assertThatThrownBy
(()
->
Ssl
Utils
.
assertStoreContains
Alias
(
uninitializedKeyStore
,
"alias"
))
assertThatThrownBy
(()
->
Ssl
ConfigurationValidator
.
validateKey
Alias
(
uninitializedKeyStore
,
"alias"
))
.
isInstanceOf
(
IllegalStateException
.
class
)
.
isInstanceOf
(
IllegalStateException
.
class
)
.
hasMessage
(
"Could not determine if keystore contains alias 'alias'"
);
.
hasMessage
(
"Could not determine if keystore contains alias 'alias'"
);
}
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java
View file @
ac91f14f
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
...
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