Skip to content

Commit a03f857

Browse files
scottfrederickphilwebb
authored andcommitted
Document update SSL support
Add a new SSL section to the reference documentation to describe SSL bundles. See gh-34814
1 parent 66db13b commit a03f857

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ include::features/developing-auto-configuration.adoc[]
3030

3131
include::features/kotlin.adoc[]
3232

33+
include::features/ssl.adoc[]
34+
3335
include::features/whats-next.adoc[]
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[[features.ssl]]
2+
== SSL
3+
Spring Boot provides the ability to configure SSL trust material that can be applied to several types of connections in order to support secure communications.
4+
Configuration properties with the prefix `spring.ssl.bundle` can be used to specify named sets of trust material and associated information.
5+
6+
7+
8+
[[features.ssl.jks]]
9+
=== Configuring SSL With Java KeyStore Files
10+
Configuration properties with the prefix `spring.ssl.bundle.jks` can be used to configure bundles of trust material created with the Java `keytool` utility and stored in Java KeyStore files in the JKS or PKCS12 format.
11+
Each bundle has a user-provided name that can be used to reference the bundle.
12+
13+
When used to secure an embedded web server, a `keystore` is typically configured with a Java KeyStore containing a certificate and private key as shown in this example:
14+
15+
[source,yaml,indent=0,subs="verbatim",configblocks]
16+
----
17+
spring:
18+
ssl:
19+
bundle:
20+
jks:
21+
mybundle:
22+
key:
23+
alias: "application"
24+
keystore:
25+
location: "classpath:application.p12"
26+
password: "secret"
27+
type: "PKCS12"
28+
----
29+
30+
When used to secure a client-side connection, a `truststore` is typically configured with a Java KeyStore containing the server certificate as shown in this example:
31+
32+
[source,yaml,indent=0,subs="verbatim",configblocks]
33+
----
34+
spring:
35+
ssl:
36+
bundle:
37+
jks:
38+
mybundle:
39+
truststore:
40+
location: "classpath:server.p12"
41+
password: "secret"
42+
----
43+
44+
See {spring-boot-autoconfigure-module-code}/ssl/JksSslBundleProperties.java[JksSslBundleProperties] for the full set of supported properties.
45+
46+
47+
48+
[[features.ssl.pem]]
49+
=== Configuring SSL With PEM-encoded Certificates
50+
Configuration properties with the prefix `spring.ssl.bundle.pem` can be used to configure bundles of trust material in the form of PEM-encoded text.
51+
Each bundle has a user-provided name that can be used to reference the bundle.
52+
53+
When used to secure an embedded web server, a `keystore` is typically configured with a certificate and private key as shown in this example:
54+
55+
[source,yaml,indent=0,subs="verbatim",configblocks]
56+
----
57+
spring:
58+
ssl:
59+
bundle:
60+
pem:
61+
mybundle:
62+
keystore:
63+
certificate: "classpath:application.crt"
64+
private-key: "classpath:application.key"
65+
----
66+
67+
When used to secure an embedded web server, a `truststore` is typically configured with the server certificate as shown in this example:
68+
69+
[source,yaml,indent=0,subs="verbatim",configblocks]
70+
----
71+
spring:
72+
ssl:
73+
bundle:
74+
pem:
75+
mybundle:
76+
truststore:
77+
certificate: "classpath:server.crt"
78+
----
79+
80+
See {spring-boot-autoconfigure-module-code}/ssl/PemSslBundleProperties.java[PemSslBundleProperties] for the full set of supported properties.
81+
82+
83+
84+
[[features.ssl.applying]]
85+
=== Applying SSL Bundles
86+
Once configured using properties, SSL bundles can be referred to by name in configuration properties for various types of connections that are auto-configured by Spring Boot.
87+
See the sections on <<howto#howto.webserver.configure-ssl,embedded web servers>> and <<data#data,data technologies>> for further information.
88+
89+
90+
91+
[[features.ssl.bundles]]
92+
=== Using SSL Bundles
93+
Spring Boot auto-configures a bean of type `SslBundles` that provides access to each of the named bundles configured using the `spring.ssl.bundle` properties.
94+
An `SslBundle` can be retrieved from the auto-configured `SslBundles` bean and used to create a `javax.net.ssl.SSLContext` or objects of other types from the `java.net.ssl` package that are typically used to configure SSL connectivity in other APIs.
95+
96+
The following example shows retrieving an `SslBundle` and using it to create an `SSLContext`:
97+
98+
include::code:MyComponent[]
99+

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/webserver.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ The following example shows setting SSL properties using PEM-encoded certificate
207207
trust-certificate: "classpath:ca-cert.crt"
208208
----
209209

210+
Alternatively, the SSL trust material can be configured in an <<features#features.ssl,SSL bundle>> and applied to the web server as shown in this example:
211+
212+
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
213+
----
214+
server:
215+
port: 8443
216+
ssl:
217+
bundle: "example"
218+
----
219+
210220
See {spring-boot-module-code}/web/server/Ssl.java[`Ssl`] for details of all of the supported properties.
211221

212222
Using configuration such as the preceding example means the application no longer supports a plain HTTP connector at port 8080.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.features.ssl.bundles;
18+
19+
import javax.net.ssl.SSLContext;
20+
21+
import org.springframework.boot.ssl.SslBundle;
22+
import org.springframework.boot.ssl.SslBundles;
23+
import org.springframework.stereotype.Component;
24+
25+
@Component
26+
public class MyComponent {
27+
28+
@SuppressWarnings("unused")
29+
public MyComponent(SslBundles sslBundles) {
30+
SslBundle sslBundle = sslBundles.getBundle("mybundle");
31+
SSLContext sslContext = sslBundle.createSslContext();
32+
// do something with the created sslContext
33+
}
34+
35+
}

0 commit comments

Comments
 (0)