SSL (Secure Sockets Layer) is the standard security technology for
establishing an encrypted link between a web server and a browser. This
link ensures that all data passed between the web server and browsers
remain private and integral.
In layman terms sender encrypts the message with a specific key and receiver decrypts that message using an identical key.
Essentially three keys are being used up public, private and session keys. Since, processing through public and private keys takes a lot of computation it's hard to do it every single time, so once SSL Handshake is over they use session keys to identify the same.
So how the one way function should look like :-
3^x mod 17 = resultant equally likely to be distributed between 0 - 16.
3- Generator (when raised to any exponent solution distributes uniformly), X- exponent or private key and 17 - Prime modulus (Have to be very large prime number say 2048 bits so decryption becomes fairly impossible)
For bob calculation goes like this performing both operations together 3 ^ 13 mod 17 = 12 i.e 3 ^ 13 ^ 25 mod 17 = 5, where for alice the same calculation is 3^25 mod 17 = 14 i.e 3 ^ 25 ^ 13 mod 17 = 5.
Safe and secure but what is the problem here, a sender has to manage 1000 distinct secret keys to communicate with 1000 different parties and send multiple messages just to establish them.
Public Key Cryptography: RSA Encryption Algorithm
In layman terms sender encrypts the message with a specific key and receiver decrypts that message using an identical key.
How does it create a secure connection ?
When browser and client interacts, they establish a connection using SSL Handshake, which is agnostic of user and will automatically takes place.Essentially three keys are being used up public, private and session keys. Since, processing through public and private keys takes a lot of computation it's hard to do it every single time, so once SSL Handshake is over they use session keys to identify the same.
Understanding the flow:
- Browser connects to a web server (website) secured with SSL (https). Browser requests that the server identify itself.
- Server sends a copy of its SSL X509 Certificate, including the server’s public key.
- Browser checks the certificate root against a list of trusted CAs and that the certificate is unexpired, unrevoked, and that its common name is valid for the website that it is connecting to. If the browser trusts the certificate, it creates, encrypts, and sends back a symmetric session key using the server’s public key.
- Server decrypts the symmetric session key using its private key and sends back an acknowledgement encrypted with the session key to start the encrypted session.
- Server and Browser now encrypt all transmitted data with the session key.
Encryption algorithms:
1. Diffie Hellman key exchange: When two parties exchange their data they come up with common one way function; with the help of it they can generate a shared secret to be used along in further communication. The strength of this function is time needed to reverse it and it works based on symmetric keys.So how the one way function should look like :-
3^x mod 17 = resultant equally likely to be distributed between 0 - 16.
3- Generator (when raised to any exponent solution distributes uniformly), X- exponent or private key and 17 - Prime modulus (Have to be very large prime number say 2048 bits so decryption becomes fairly impossible)
- Bob has his own private key say 25 so he calculates his public key as 3^25 mod 17 = 14, and sends 12 to alice and eve.
- Alice has her own set of private key say 13 and calculates her public key as 3^13 mod 17 = 12 and sends to bob and eve.
- Now the complex part comes where bob uses alice's public key (and alice uses bob's public key) with his private number to obtain a shared secret key which is 5. For eg: 12^25 mod 17 = 5 and 14 ^ 13 mod 17 = 5.
- 5 is common shared secret which eve cannot contemplate until unless he has one of their private keys. They can communicate without even worried about MITM attacks given the prime modulus has to be large enough.
For bob calculation goes like this performing both operations together 3 ^ 13 mod 17 = 12 i.e 3 ^ 13 ^ 25 mod 17 = 5, where for alice the same calculation is 3^25 mod 17 = 14 i.e 3 ^ 25 ^ 13 mod 17 = 5.
Safe and secure but what is the problem here, a sender has to manage 1000 distinct secret keys to communicate with 1000 different parties and send multiple messages just to establish them.
Public Key Cryptography: RSA Encryption Algorithm
RSA Encryption:- Non secret encryption. (Encryption keys and Decryption keys)
The idea is based on splitting it in two parts : Encryption and Decryption key.
So they need a special kind of one way function, it's difficult to reverse unless you have the trapdoor function.
- m^e mod N = c which is easy to perform, however reversing c using e and N to find out which m is used is really difficult to perform.
- So we need another function c ^ d mod N = m (to get an original message).
- So both operations together is same as m^(e*d) mod N = m.
We come with e and d as encryption and decryption keys, and now we need a second one way function for generating d. Euclid algorithm for prime factorisation shown us that it's a complicated problem to find out prime factors, which gives its way for one way trapdoor function.
N = (Prime) P1 * (Prime) P2 ( if one prime is 200 digits long it takes multiple years to come to a solution) and the calculation is easier to perform.
Euler's totient function counts the positive integers up to a given integer n that are relatively prime to n ϕ(n), but it has a property with prime numbers.
ϕ(P1) = P1-1. and it has multiplicative properties also. P1 : Prime number
ϕ(N) = ϕ(P1) * ϕ(P2) = (P1 -1 ) * (P2-1);
Euler theorem states that if m and n are coprime positive integers, the m ^ ϕ(N) = 1 mod N. Now we can use the property where 1 ^ K = 1, so now m ^ (K* ϕ(N) )= 1 mod N. Multiply m to both sides results in m * m ^ (K* ϕ(N) )= m * 1 mod N.
So the final equation looks like m (K* ϕ(N) + 1) = m mod N and from above m^(e*d) = m mod N.
- Bob has the server with p1 = 53, p2 = 59, N = 53 * 59 = 3127, ϕ(N) = ϕ(P1) * ϕ(P2) = 3016 and exponent e = 3 (Odd coprime number with ϕ(N)) and d = 2011.
- Now he will hide everything and sends N and e (3127 and 3)to Alice, and she will encrypt her message with. 89 ^ 3 mod 3127 = 1394 (which is encrypted).
- Bob and eve will receive this encrypted message i.e. 1394, but only bob could decipher it with his private key d. 1394 ^ 2011 mod 3127 = 89.
So now we know the concept of encryption and decryption keys and all these information glued together will give you the concept of ssl certificates.
What is an SSL Certificate ??
SSL Certificates are small data files that digitally bind a cryptographic key (namely private and public key) to an organization’s details. When installed on a web server, it activates the padlock and the https protocol and allows secure connections from a web server to a browser.
It can be self signed but browser checks list of trusted ca's before allowing communication. When choosing the right SSL provider, consider the fact that users’ web browsers normally keep a cached list of trusted CAs on file – so if a digital certificate is signed by an entity that’s not on the “approved” list, the browser will send a warning message to the user that the website may not be trustworthy.
Certificate binds these information mainly which we call it as SPKI (subject public key info)
- A domain name, server name or hostname.
- An organizational identity (i.e. company name) and location.
Do I really need an ssl certificate ??
SSL Certificates protect your sensitive information such as credit card information, usernames, passwords etc. It also:
- Keeps data secure between severs
- Increases your Google Rankings
- Builds/Enhances customer trust
- Improves conversion rates
How do I check certificate of my server ??
You can use OpenSSL client for verious ssl realted task:
- to check the Server Cerificate : openssl s_client -showcerts -connect WordPress.com: Create a free website or blog:443(host:sslport)
- to download the Certificate : openssl s_client -showcerts -connect WordPress.com: Create a free website or blog:443 |openssl x509 -outform PEM >wordpress_certfile.pem
By default browser/mobile host check lists of cached trusted ca's if the certificate is issued with them for the associated host it will simply acknowledge the certificate as trusted and starts communicating which involves high risks of MITM attacks.
What is Pinning ??
Pinning is the process of associating a host with their expected X509 certificate or public key. Once a certificate or public key is known or seen for a host, the certificate or public key is associated or 'pinned' to the host. If there are more then one certificate they hold a pinset to identify the communication channel.
So client needs to pin certificates or SPKI once the handshakes happened to verify the session key is similar to one generated during handshakes to avoid the MITM attacks.
More on how browser client or mobile devices does it will be explained in HOW SSL WORKS AND CERTIFICATE/SSL PINNING TO PREVENT MAN-IN-THE-MIDDLE (MITM) ATTACK - PART 2