Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web server fails to start due to "Resource location must not be null" when attempting to use a PKCS 11 KeyStore #32179

Closed
wants to merge 5 commits into from

Conversation

cdanger
Copy link
Contributor

@cdanger cdanger commented Aug 27, 2022

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 and others added 2 commits August 27, 2022 19:02
…xception: Could not load key store 'null'" / "IllegalArgumentException: Resource location must not be null" when using PKCS11 keystore type ('server.ssl.key-store-type') with undefined/null 'server.ssl.key-store' property (as there is no keystore file to be specified for a PKCS#11 HSM) on a Spring Boot Reactor Netty configuration.

- Added unit tests in spring-boot-project/spring-boot SslServerCustomizerTests class with a mock PKCS#11 keystore provider implementation to validate the fix
- Added TestContainers integration test loading a Spring Boot Webflux (Netty SSL server) app with an actual PKCS#11 HSM (SoftHSM) for the keystore: to make sure it works with real implementation: see project spring-boot-tests/spring-boot-smoke-tests/spring-boot-test-webflux-ssl
@pivotal-cla
Copy link

@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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 27, 2022
@pivotal-cla
Copy link

@cdanger Thank you for signing the Contributor License Agreement!

@cdanger cdanger marked this pull request as ready for review August 27, 2022 17:48
@wilkinsona wilkinsona changed the title Fixes PKCS#11 support in Spring Boot Reactor Netty SSL server Web server fails to start due to "Resource location must not be null" when attempting to use a PKCS 11 KeyStore Sep 1, 2022
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 1, 2022
@wilkinsona wilkinsona added this to the 2.6.x milestone Sep 1, 2022
@wilkinsona wilkinsona added the for: merge-with-amendments Needs some changes when we merge label Sep 1, 2022
@wilkinsona
Copy link
Member

Thanks very much for the PR, @cdanger.

@wilkinsona
Copy link
Member

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.

@cdanger
Copy link
Contributor Author

cdanger commented Sep 11, 2022

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?

@cdanger
Copy link
Contributor Author

cdanger commented Oct 2, 2022

Could any maintainer approve this? or tell me whether anything else is needed. Thanks.

@wilkinsona
Copy link
Member

Thanks for your patience, @cdanger. We'll approve and merge the changes as soon as we can.

@mhalbritter
Copy link
Contributor

Thank you!

philwebb added a commit that referenced this pull request Dec 21, 2022
Remove `spring-boot-smoke-test-webflux-ssl` since it's more of
an integration test than a smoke test. We could consider
relocating it to `spring-boot-integration-tests` but since we
have unit tests with a mock PCKCS11 security it's probably
best to see if we can get away without it.

See gh-32179
krenson pushed a commit to krenson/test-push that referenced this pull request Mar 15, 2023
…ot-starter-parent from 2.3.5.RELEASE to 2.7.7 (minor)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | minor | `2.3.5.RELEASE` -> `2.7.7` |

---

### Release Notes

<details>
<summary>spring-projects/spring-boot</summary>

### [`v2.7.7`](https://github.com/spring-projects/spring-boot/releases/tag/v2.7.7)

[Compare Source](spring-projects/spring-boot@v2.7.6...v2.7.7)

#### 🐞 Bug Fixes

-   Fix typo in LocalDevToolsAutoConfiguration logging [#&#8203;33569](spring-projects/spring-boot#33569)
-   Web server fails to start due to "Resource location must not be null" when attempting to use a PKCS 11 KeyStore [#&#8203;32179](spring-projects/spring-boot#32179)

#### 📔 Documentation

-   Improve gradle plugin tags documentation [#&#8203;33614](spring-projects/spring-boot#33614)
-   Improve maven plugin tags documentation [#&#8203;33609](spring-projects/spring-boot#33609)
-   Fix typo in tomcat accesslog checkExists doc [#&#8203;33460](spring-projects/spring-boot#33460)
-   Document that the shutdown endpoint is not intended for use when deploying a war to a servlet container [#&#8203;17398](spring-projects/spring-boot#17398)

#### 🔨 Dependency Upgrades

-   Upgrade to Byte Buddy 1.12.20 [#&#8203;33570](spring-projects/spring-boot#33570)
-   Upgrade to Dropwizard Metrics 4.2.14 [#&#8203;33571](spring-projects/spring-boot#33571)
-   Upgrade to Elasticsearch 7.17.8 [#&#8203;33572](spring-projects/spring-boot#33572)
-   Upgrade to HttpClient 4.5.14 [#&#8203;33573](spring-projects/spring-boot#33573)
-   Upgrade to HttpCore 4.4.16 [#&#8203;33574](spring-projects/spring-boot#33574)
-   Upgrade to Infinispan 13.0.14.Final [#&#8203;33575](spring-projects/spring-boot#33575)
-   Upgrade to Jaybird 4.0.8.java8 [#&#8203;33576](spring-projects/spring-boot#33576)
-   Upgrade to Jetty 9.4.50.v20221201 [#&#8203;33577](spring-projects/spring-boot#33577)
-   Upgrade to MSSQL JDBC 10.2.2.jre8 [#&#8203;33578](spring-projects/spring-boot#33578)
-   Upgrade to Neo4j Java Driver 4.4.11 [#&#8203;33579](spring-projects/spring-boot#33579)
-   Upgrade to Netty 4.1.86.Final [#&#8203;33580](spring-projects/spring-boot#33580)
-   Upgrade to Reactor 2020.0.26 [#&#8203;33543](spring-projects/spring-boot#33543)
-   Upgrade to Spring Integration 5.5.16 [#&#8203;33581](https://github.com/spring-projects/spring...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants