Package org.microproxy.tls
Class SslContexts
java.lang.Object
org.microproxy.tls.SslContexts
Small factory methods for
SSLContexts. The contexts made here remember how they validate
servers (trustManagerOf(javax.net.ssl.SSLContext)), so that TLS stacks other than the JDK's, such as QUIC's to
HTTP/3 servers, can validate servers the same way.-
Method Summary
Modifier and TypeMethodDescriptionstatic SSLContextReturns a context using the JDK's default trust store and no client certificate.static SSLContextsystemDefaultPlus(X509Certificate... extraAnchors) A context that trusts the JDK's default trust store and, in addition,extraAnchors(e.g. a corporate or test CA).static SSLContexttrustAll()A context that trusts every server.static SSLContexttrusting(X509Certificate... anchors) A context that trusts only the given certificates.static X509TrustManagertrustManagerOf(SSLContext context) How a context made by this class validates servers: its trust manager, which trusts every server fortrustAll().static booleantrustsAll(X509TrustManager trustManager) WhethertrustManagertrusts every server without checking, astrustAll()'s does.static SSLContextwithKey(PrivateKey key, X509Certificate[] chain, TrustManager[] trustManagers) A context presentingchain(leaf first) withkey, trustingtrustAnchors(or the system default when none are given).
-
Method Details
-
trustManagerOf
How a context made by this class validates servers: its trust manager, which trusts every server fortrustAll(). Contexts made elsewhere are unknown, except the JDK's default context (SSLContext.getDefault()), whose trust is the JDK's default trust store.- Parameters:
context- the context- Returns:
- its trust manager, or null if it is unknown
-
trustsAll
WhethertrustManagertrusts every server without checking, astrustAll()'s does.- Parameters:
trustManager- the trust manager- Returns:
- whether it accepts any server certificate
-
systemDefault
Returns a context using the JDK's default trust store and no client certificate.- Returns:
- a context using the JDK's default trust store and no client certificate
-
trustAll
A context that trusts every server. Insecure; for tests and debugging.- Returns:
- a context that trusts every server
-
trusting
A context that trusts only the given certificates.- Parameters:
anchors- the trusted CA certificates- Returns:
- a context that trusts only the given certificates
-
systemDefaultPlus
A context that trusts the JDK's default trust store and, in addition,extraAnchors(e.g. a corporate or test CA). Host names are still verified where endpoint identification is enabled.- Parameters:
extraAnchors- the CA certificates trusted in addition to the system defaults- Returns:
- a context that trusts the JDK's default trust store and, in addition,
extraAnchors(e.g. a corporate or test CA)
-
withKey
public static SSLContext withKey(PrivateKey key, X509Certificate[] chain, TrustManager[] trustManagers) A context presentingchain(leaf first) withkey, trustingtrustAnchors(or the system default when none are given).- Parameters:
key- the private key matching the leaf certificatechain- the certificate chain, leaf firsttrustManagers- the peer certificate validators, ornullfor system defaults- Returns:
- a TLS context using the supplied private key, chain and peer validators
-