This repository was archived by the owner on Apr 5, 2023. It is now read-only.
Certificate Pinning #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
MOB-828
Implementation Details:
Optimizely’s
Clientclass incom.optimizely.ab.android.sharedpackage is used to make all it's Http connections. This class is primarily used to create a DatafileClient and an EventClient for downloading the datafile and posting client events respectively.To do so, it interacts with the following hosts -
The Client’s constructor before certificate pinning:
The Client’s constructors after certificate pinning:
The reason to take this approach is to avoid a breaking change, this implementation overloads the constructor with an optional SSLSocketFactory to make secure HttpsURLConnection with pinning in place. Now, Whenever the Client is instantiated, we need to pass SSLSocketFactory as the third parameter. In all other cases, it would default to null and work as expected.
Secondly, the approach followed to implement pinning is based off pinning your certificates through a custom TrustManager and SSLSocketFactory. Here is a better explanation for how
PinnedSSLSocketFactoryclass works: https://developer.android.com/training/articles/security-sslOverall, the Key goals achieved here are - certificate validation from the trusted server, hostname verification.
Test plan
Charles -
The goal here is to make sure that the server is our trusted server, and not a third party impersonating our server. To do so, here are the steps to follow:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.In this case, the SSLHandshakeException occurs because we have a CA that isn't trusted by the system. To be more specific, it is because charles certificate isn't yet trusted by our app.
Fortunately, we can teach HttpsURLConnection to trust a specific set of CAs. And that is exactly what the above implementation does - making sure the connection only uses our CAs for certificate validation. And this test should prove that our certificate pinning is working as expected.
If we add the Charles certificate to the list of our trusted CAs, ideally the connection should be established and Charles should be able to view the contents.
Issues