Repository navigation
Pluggable SSLContextProvider for in-memory key and trust stores - #1344
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1344 +/- ##
============================================
+ Coverage 70.78% 71.75% +0.97%
- Complexity 2272 2306 +34
============================================
Files 162 162
Lines 9087 9104 +17
Branches 1192 1192
============================================
+ Hits 6432 6533 +101
+ Misses 2201 2119 -82
+ Partials 454 452 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
d4dd222 to
93736f6
Compare
the-thing
left a comment
There was a problem hiding this comment.
Useful feature. Can we just make the field final and if specific provider logic is required can we make it in the builder?
|
Hello @the-thing , thank you for your comments, moved everything to builders and made the field final. Could you please review again when you have a chance? |
|
Will do. It might take a few days, but I will. Stay tuned. |
the-thing
left a comment
There was a problem hiding this comment.
LGTM.
SSLContextProviderTest start / stop could have been wrapped in separate try / finally blocks.
Not for this PR, but I have a feeling that these overloaded super constructors are too large and probably every one of them should have a single parameter builder and take whatever they need from there.
|
Thank you @the-thing , addressed this comment:
Also will take a look whether we can replace the ctors' parameters with builders, will create an issue for that if this is feasible. |
Allow applications to supply the SSLContext for SSL-enabled sessions instead of having SSLContextFactory load stores from files, e.g. when key material is delivered by a secrets manager as environment variables. - Add SSLContextProvider, keyed by SSLConfig; the default is SSLContextFactory::getInstance, so existing behaviour is unchanged. - Add setSSLContextProvider on SessionConnector and withSSLContextProvider on the connector builders. - Report provider failures and null contexts as initialization errors, honouring ContinueInitializationOnError; no fallback to file stores. - Document usage in the secure communications user manual. Relates to quickfix-j#1343, quickfix-j#678
Address review: remove SessionConnector.setSSLContextProvider and the wrapping getter, keep the provider in a final, never-null field of the socket acceptor and initiator, and pass it through their constructors. The builder defaults the provider to SSLContextFactory::getInstance in build(), like the log and message factories.
Give each connector in SSLContextProviderTest its own try/finally, so a failing stop cannot leave the other connector running. Load the trust store in the user manual example with its password: PKCS12 trust stores created by current JDKs encrypt their certificates, so loading them without a password yields an empty trust store.
6ec69c7 to
03fcd09
Compare
SSLContextProvider for in-memory key and trust stores
Yes, please do create a separate issue and/or PR. Thank you. And thank you for this PR and @the-thing for the thorough review. 👍 |
A null context used to reach MINA's SslFilter and fail start() with an NPE that bypassed ContinueInitializationOnError. Report it as a GeneralSecurityException naming the session or acceptor address, so it goes through the existing initialization error handling.
Summary
Adds a pluggable
SSLContextProviderso applications can supply theSSLContextfor SSL-enabled sessions instead of havingSSLContextFactoryload key and trust stores from files. This lets key material held in memory, e.g. delivered by a secrets manager as environment variables, be used without writing it to disk.Closes #1343. Follows the approach suggested in #678 / discussion #679.
Changes
SSLContextProvider(quickfix.mina.ssl): a functional interface,SSLContext getSSLContext(SSLConfig). The default isSSLContextFactory::getInstance, so existing behaviour is unchanged.withSSLContextProvider(...)on the builders ofSocketInitiator,SocketAcceptorand their threaded variants. Without it (or withnull), the builder usesSSLContextFactory::getInstance.final, never-null field ofAbstractSocketAcceptor/AbstractSocketInitiator, set through new constructor overloads; the existing constructors use the default.GeneralSecurityException, the session (initiator) or listening address (acceptor) fails to initialize, honouringContinueInitializationOnError. The provider must not returnnull. There is no silent fallback to file stores.SSLContextcomes from the provider; protocols, cipher suites,NeedClientAuth, SNI and endpoint identification are still applied from the settings.secure_communications.html.Usage
The provider receives the
SSLConfigof each session or acceptor address, so it can also return different contexts per session, or delegate toSSLContextFactory.getInstance(sslConfig)for stores that should still be loaded from files.Compatibility
SSLContextFactoryandSessionConnectorare unchanged, and connectors created with the existing constructors keep loading stores from files.IoSessionInitiatorconstructor is kept and delegates to the new one.Testing
New
SSLContextProviderTest:GeneralSecurityException;ContinueInitializationOnError=Y, a failing provider skips the acceptor address and the initiator session.Existing
SSLCertificateTest,SecureSocketTest,IoSessionInitiatorTest,SocketInitiatorTestandSocketAcceptorTestpass unchanged.