HTTPS is designed to secure communication between parties by establishing encrypted connection. It allows to encrypt the messages so even if they’re intercepted nobody would be able to read them or modify unless they have a pair of Public/Private keys.
This is achieved by utilizing asymetric encryption keys.
ClientHello
message when it wants to initiate the communication. The message contains metadata with preffered SSL version, cipher suites etc. Server choses preffered settings and sends ServerHello
message in response. It contains similar set of data.The important part in the above algorithm is played by Certification Authority (CA). Without CA it wouldn’t be possible to negotiate symetric key as parties wouldn’t know if they could trust to certificates they receive. Anybody could intercept the requests and edit the certificates. But having CA in place allows to verify if Certificate is legit. The browser itself is coming with predefined list of CAs that can be used to verify legitimacy of the certificates. On top of that the browser also has a list of trusted certificates controlled by secure centralized group. If needed you can extend this list on your own.
Certificate is a file that contains information about server owning it. It cosists of the following blocks:
There are different types of certificates:
.pem
. Contains base64 encoded certificate between — — - BEGIN CERTIFICATE — — —
and — — - END CERTIFICATE — — -
.p12
, .p8
, .p7b
etc. They contain public and private keys in the same file..cer
, .crt
, .der
. Contains binary encoded certificate.This is the process of associating a host with its certificate or public key. It’s used to verify that communication with host stays secure. By using SSL pinning you make your application to trust predefined certificates and public keys.
So if you distribute the application you need to embed certificate into the application bundle. Then at the runtime application would rely on this certificate to compare it with what comes from server.
In practical terms it means you’re retrieving public key from the certificate as a string. Then this string is passed into your application as configuration parameter. Then at runtime application would rely on this string to compare it with public key coming from server in Certificate.
The benefit of pinning public key over pinning certificate is that you don’t need to re-distribute application every time certificate changes. As certificate rotation happens public key doesn’t change so applications using it wouldn’t need to be re-distributed. The downside though is that you need to extract public key from certificate coming from server every time the connection is established.