|
| 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 | + |
0 commit comments