As seen in https://github.com/square/okhttp/issues/5845 and a metric shedload of stackoverflow posts
private final static X509TrustManager TRUST_MANAGER = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
};
As it is it's creating work for users and for us.
Is pretty much the 2nd most typed code in history after Hello World. We should either make an Intellij plugin to create it, or find a nicer and safer pattern to support dev servers?
Thoughts
cc @swankjesse
I was thinking similarly, but I also really don't want to make this too easy. Bad unsafe code should look bad and unsafe.
Maybe the right API makes it safe. E.g. checks it's a Dev build on Android and uses a strict allowlist of patterns.
This is absolutely part of the normal developer workflow if your devserver has self signed or corp signed certs.
Yep. I just don't want this accidentally shipping to production.
Potential ways to do that:
/.well-known/CLIENT_SABOTAGED_TLS/☠️Are there other examples of mitigations against debug-only settings?
A very early draft PR for discussion
Yep. I just don't want this accidentally shipping to production.
Agree 100%, but I think by not making this easier, we have effectively made it more likely that apps are out there in the Play Store with security turned off. But at least it isn't our fault currently.
The PR attempts to make it safe, correct and optimal.
For information in some cases we have no choices than disable those security when connecting to badly configured servers with self signed certificates. From apps that connect to some devices and not public secure web servers.
We do this with tons of warning to user and a few confirmation clicks, but currently it's fully disabled for that connection and as such is probably leaking that security removal when the server redirect to other things. Would be nice to have this debug thing allowed in prod and runtime configurable under a tons of opt in warning / lint checks whatever, so that we can lift those checks properly only for 1 IP and prevent bad implementation that goes out of that IP, because by lack of knowledge on how to do this right, I do use the OP code snippet for this. Or some better recipe about this use case.
Yep. I might move the PR code relevant to this to a sample.