Easily buildable client `TrustManager`
See original GitHub issueIn some cases, a user has to relax the verification of server certificates, e.g.
- Accept a certificate regardless if it’s valid or not.
- Accept a certificate even if the certificate’s CN does not match the server’s host name as long as the certificate chain’s signatures are valid.
- Accept a certificate when its SHA-256 (or any digest algorithm) checksum matches.
- Accept a certificate only when its CN matches the server’s host name AND the certificate chain’s signatures are valid.
… for all servers or a certain set of servers.
For now, we do (4) by default and a user can do (1) for all or specific hosts.
We could provide a simple way to build a client-side TrustManager that allows a user to implement all 4 actions for all or a certain set of servers.
The following is a hypothetical API I designed for it:
public final class ClientTrustManagers {
// Does (1) for all hosts.
public static TrustManager noVerify() { ... }
// Does (2) for all hosts.
public static TrustManager verifySignaturesOnly() { ... }
// Does (3) for all hosts.
public static TrustManager verifyFingerprintOnly(String algorithm, String... fingerprints) { ... }
// Does (4) for all hosts. (default)
public static TrustManager verifyAll() { ... }
public static ClientTrustManagerBuilder builder() { ... }
}
// Examples
ClientTrustManagers
.builder()
.noVerify("a.com") // Do (1) if a.com.
.reject("*.b.com") // Always reject if *.b.com.
.verifySignaturesOnly("c.com") // (2) if c.com.
.verifyFingerprintOnly("d.com", "SHA-256", "00:00:....", "01:01:...", ...) // (3) if d.com.
.verifyAll("e.com") // (4) if "e.com"
.action("f.com", (chain, authType, engine) -> { ... }) // Custom action if f.com.
//.noVerifyByDefault()
//.rejectByDefault()
//.verifyFingerprintByDefault("SHA-256", "00:00:...", ...)
//.verifySignaturesOnlyByDefault()
//.verifyAllByDefault()
.build()
public interface ClientTrustManagerAction {
static ClientTrustManagerAction noVerify() { ... }
static ClientTrustManagerAction reject() { ... }
static ClientTrustManagerAction verifySignaturesOnly() { ... }
static ClientTrustManagerAction verifyFingerprintsOnly(String algo, String fingerprint...) { ... }
static ClientTrustManagerAction verifyAll() { ... }
void checkServerTrusted(X509Certificate[] chain,
String authType, SSLEngine engine) throws CertificateException;
}
Once this is implemented, we could:
- Deprecate some methods like
tlsNoVerifyHosts(). - Add
ClientFactory.tlsTrustManager(TrustManager)for convenience, because otherwise a user has to do:clientFactory.tlsCustomizer(sslCtxBuilder -> { sslCtxBuilder.trustManager(...); });
Some examples:
// Do not check endpoint identification.
ClientFactory
.builder()
.tlsTrustManager(ClientTrustManagers.verifySignaturesOnly())
.build();
// Disable endpoint identification only for *.foo.com.
ClientFactory
.builder()
.tlsTrustManager(
ClientTrustManagers
.builder()
.verifySignaturesOnly("*.foo.com")
.build()
)
.build();
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:12 (7 by maintainers)
Top Results From Across the Web
X509TrustManager (Java Platform SE 7 ) - Oracle Help Center
Instance of this interface manage which X509 certificates may be used to authenticate the remote side of a secure socket. Decisions may be...
Read more >android - Trusting all certificates with okHttp - Stack Overflow
Just in case anyone falls here, the (only) solution that worked for me is creating the OkHttpClient like explained here. Here is the...
Read more >Apache HttpClient with SSL - Baeldung
Let's now configure the HTTP client to trust all certificate chains regardless ... and RegistryBuilder, it's easy to build SSLSocketFactory.
Read more >Security with network protocols - Android Developers
Client apps need a mechanism to verify the server because the CA offers certificates for numerous servers. The CA's certificate identifies the server...
Read more >HTTPS in Java with a self-signed certificate - Brice Dutheil
sslSocketFactory( sslContext(null, new TrustManager[]{trustManager}).getSocketFactory(), trustManager) .build(); try (Response r = client.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@trustin @ikhoon Working on this starting Feb 07.
Working on implementing a trie data structure in order to search ClientTrustManagerAction based on the hostname url pattern. We will support the following patterns