spring-boot
spring-boot copied to clipboard
Web server fails to start due to "Resource location must not be null" when attempting to use a PKCS 11 KeyStore
This fixes the error Unable to start reactive web server / WebServerException: Could not load key store 'null' / IllegalArgumentException: Resource location must not be null (see spring-boot-error.log for the details) when using PKCS11 keystore type (server.ssl.key-store-type
property) with undefined/null server.ssl.key-store
property (as there is no keystore file in the case of a PKCS#11 HSM) on a Spring Boot Reactor Netty configuration; e.g. running with arguments: --server.ssl.enabled=true --server.ssl.key-store-provider=SunPKCS11-SoftHSM --server.ssl.key-store-type=PKCS11
...
This also adds:
- Unit tests in spring-boot-project/spring-boot SslServerCustomizerTests class, using a mock PKCS#11 keystore provider implementation, for basic validation of the fix.
- TestContainers integration test (requires Docker) in new sub-module
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux-ssl
for more extensive validation: loading a Spring Boot Webflux (Netty SSL server) app with an actual PKCS#11 library (SoftHSM) for the keystore, in order to make sure it works with a full PKCS#11 implementation.
@cdanger Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
@cdanger Thank you for signing the Contributor License Agreement!
Thanks very much for the PR, @cdanger.
The problem isn't limited to Netty. For example, Tomcat fails in a similar manner:
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Could not load key store 'null'
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) ~[main/:na]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.22.jar:5.3.22]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[main/:na]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745) [main/:na]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420) [main/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [main/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) [main/:na]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [main/:na]
at smoketest.tomcat.ssl.SampleTomcatSslApplication.main(SampleTomcatSslApplication.java:26) [main/:na]
Caused by: org.springframework.boot.web.server.WebServerException: Could not load key store 'null'
at org.springframework.boot.web.embedded.tomcat.SslConnectorCustomizer.configureSslKeyStore(SslConnectorCustomizer.java:132) ~[main/:na]
at org.springframework.boot.web.embedded.tomcat.SslConnectorCustomizer.configureSsl(SslConnectorCustomizer.java:92) ~[main/:na]
at org.springframework.boot.web.embedded.tomcat.SslConnectorCustomizer.customize(SslConnectorCustomizer.java:57) ~[main/:na]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.customizeSsl(TomcatServletWebServerFactory.java:364) ~[main/:na]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.customizeConnector(TomcatServletWebServerFactory.java:342) ~[main/:na]
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:203) ~[main/:na]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[main/:na]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[main/:na]
... 8 common frames omitted
Caused by: java.lang.IllegalArgumentException: Resource location must not be null
at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:130) ~[spring-core-5.3.22.jar:5.3.22]
at org.springframework.boot.web.embedded.tomcat.SslConnectorCustomizer.configureSslKeyStore(SslConnectorCustomizer.java:129) ~[main/:na]
... 15 common frames omitted
As part of merging this, we should also make similar changes for Jetty, Tomcat, and Undertow.
As part of merging this, we should also make similar changes for Jetty, Tomcat, and Undertow.
OK I made similar changes for Jetty, Tomcat and Undertow in new commits. Is it now OK for approval?
Could any maintainer approve this? or tell me whether anything else is needed. Thanks.
Thanks for your patience, @cdanger. We'll approve and merge the changes as soon as we can.
Thank you!