Welcome to part two of this series. First, let’s recap what we learnt in Part One:
Now that we have learned about SSL Pinning and how one can acquire a certificate, let us dig deep into what a certificate is and what forms its composition.
A certificate is a file that encapsulates information about the server that owns the certificate. The structure of the certificate uses X.509 standards. X.509 is defined by the International Telecommunication Unions’ Standardization Sector.
A Digital Certificate consists of a variety of information, such as –
For more information, please visit the thread here1.
The choice of certificate impacts the level of security achieved. It decreases as we move down towards the Root Certificate. Hence, the developers need to choose carefully.
SSL/Leaf Certificate: This is the most secure option. If you pin the leaf certificate, then you can be sure that the presented certificate is yours. But as mentioned earlier, this creates a problem anytime you want to rotate your certificate. When the certificate is changed, everyone’s application needs to be updated.
Intermediate Certificate: When you pin the intermediate certificate, you are placing your trust in intermediate CA that it will not issue an unauthorised certificate for your server. The advantage of this approach is that you can rotate your leaf certificate as often as you want, as long as you use the same intermediate CA.
Root Certificate: If you pin the root certificate, you are trusting a collection of certificate authorities — the root CA itself as well as any intermediaries it trusts – not to issue unauthorised certificates. This is the least secure option and hence the attack surface is larger.
It is generally recommended to pin multiple certificates to decrease the chances of bricking your application. Pinning intermediate and leaf-level certificates together is the popular approach.
Now let’s find the best approach to pin a certificate
In Certificate Pinning, the developer hardcodes the SSL certificate (X.509 certificates) into an application code. When the application communicates with the server, it checks whether the same certificate is present or not. If it is present, the application proceeds with the communication. Otherwise, it will throw an error. The downside to this type of pinning is if the certificates are rotated regularly, then the application needs to be updated regularly too.
Here, the underlying public keys are pinned to check the integrity of the connection. This is more flexible but a little trickier due to the extra steps are taken to extract the public key from a certificate.
As with a certificate, the program checks the extracted public key with its embedded copy of the public key. The underlying public keys in certificates can remain static. Hence, it is immune to the certificate rotation problem.
That is all folks. Hope you enjoyed reading about certificates and how they can make your Android experiences more secure.
If you are interested in identifying and solving problems like these and working with the Android team, connect with Piyush Maheswari on LinkedIn. We are always on the lookout for amazing Android engineers like you, at Zomato.
All images are designed in-house.
-x-
Sources: