Saturday, 2 May 2015

SSL in detail

In SSL, Web Browser is the SSL client and Web server is the SSL Server. First Client initiates the SSL connection. In brief the process looks like following.

Step 1: Client sends Hello message. As I said, client initiates the connection with server by sending Hello message. Client Hello message contains following information.

Field
Description
Version
Client sends the highest version of SSL it supports.
RandomNumber
It is 32byte random number. 4-byte number that consists of the client’s date and time plus a 28-byte randomly generated number that will be used with the server random value to generate a seed from which the encryption keys will be derived.
SessionID(If any)
SessionId is included to enable the client to resume the previous session.
CipherSuites
List of cipher suites available on the client.

Example
TLS_RSA_WITH_DES_CBC_SHA, where TLS is the protocol version, RSA is the algorithm that will be used for the key exchange, DES_CBC is the encryption algorithm (using a 56-bit key in CBC mode), and SHA is the hash function.
CompressionMethods
Specifies the compression algoithms that client support

Following is the example of Client Hell message.

ClientVersion 3.0
ClientRandom[32]
SessionID: None (new session)
Suggested Cipher Suites:
   TLS_RSA_WITH_DES_CBC_SHA
   TLS_RSA_WITH_3DES_EDE_CBC_SHA
Suggested Compression Algorithm: NONE

Note: TLS used version number as 3.1

Step 2:  Once server receives ClientHello message, Server respond with ServerHello message. ServerHello message includes following information.

Field
Description
Version
Server sends the highest number of the version that both client and server supportd.
RandomNumber
It is 32byte random number. 4-byte number that consists of the server date and time plus a 28-byte randomly generated number that will be used with the client random value to generate a seed from which the encryption keys will be derived.
SessionId
Identifies specific SSL session. It can have three valid values.
1.   New Session Id: When for a new request (or) when client don’t want to resume the session, then a new Id is generated.
2.   Resumed Session Id : Client sends already existing session id, if it wants to resume the session.
3.   Null: this is a new session, but the server is not willing to resume it at a later time so no ID is returned.
CipherSuite
Server selects the cipher suite that supported by both client and server.
CompressionMethod
Specifies the compression algorithm to use.

Following is the example of ServerHello message

Version 3.1
ServerRandom[32]
SessionID:c629767869f0e3ebfe6b0c044acb67a63bdcffb0ef58b1b941820a77 ea7bd608
Use Cipher Suite:
TLS_RSA_WITH_3DES_EDE_CBC_SHA
Compression Algorithm: NONE

Step 3: Server sends the certificate
Server sends its certificate to client. This certificate is used to authenticate client, that the server is trusted one. The server certificate contains server public key. By using this public key client encrypts the secret key and send it to the server.

If you want see a certificate, open https connection in your browser. On address bar you used to see padlock symbol, click on that.

Step 4: Server hello done, and waiting for the response from client.

Step 5: Client generates a secret key, by using the random values generated by both client and server. Once key is generated, client encrypts this secret key with server public key, send it to the server.

Step 6: Client Change Cipher Spec. This message notifies the server that all messages that follow the Client Finished message will be encrypted using the keys and algorithms just negotiated.

Step 7: Server Change Cipher Spec Message. This message notifies the client that the server will begin encrypting messages with the keys just negotiated.

Step 8: After sending “change Cipher Spec” messages, both the systems send finished messages. Once both client and server able to receive finished messages successfully, then the negotiation process is finished. Both client and server are ready for secure communication.

Optional Cases
1. In some cases, server decides, client authentication is required. In those scenarios, Server asks CertificateRequest for the client. Sever sends this request only after sending servers certificate to the client.

How to resume previous session
If client wants to resume previous session, then it sends ClientHello message to server, by specifying the previous sessionId. Server responds with ServerHello message agreeing to this sessionID (If server don’t want to resume the session, then it creates new sessionId and send it in ServerHello message). After this both client and server exchange ChangeCipherSpec and Finished messages.

X509 Certificates
In cryptography, X.509 is an ITU Telecommunication Standardization Sector (ITU-T) standard for a public key infrastructure (PKI) and Privilege Management Infrastructure (PMI). X.509 specifies, amongst other things, standard formats for public key certificates, certificate revocation lists, attribute certificates, and a certification path validation algorithm.

The structure of an X.509 v3 digital certificate is as follows:

Certificate
Version
Serial Number
Algorithm ID
Issuer
Validity
Not Before
Not After
Subject
Subject Public Key Info
Public Key Algorithm
Subject Public Key
Issuer Unique Identifier (optional)
Subject Unique Identifier (optional)
Extensions (optional)
...
Certificate Signature Algorithm
Certificate Signature

If you want see a certificate, open https connection in your browser. On address bar you used to see padlock symbol, click on that.



References


Prevoius                                                 Next                                                 Home

Public key certificates

In previous post, I explained two basic strategies in encryption. We almost solve the problems in secret key and public key algorithms by combining both of these.

Suppose ‘A’ and ‘B’ wants to communicate.

a.   ‘A’ generates his public-private key pair
b.   ‘A’ sends his public key to ‘B’
c.    ‘B’ generate a random number, and encrypt the random number with ‘A’ public key and send the encrypted message to ‘A’.
d.   ‘A’ receives the encrypted message and decrypts the message with his private key.
e.   At this point of time, both ‘A’ and ‘B’ knows the random number, they use this random number as secret key and perform secret key encryption with this key.

There is one problem here, Closely observe for a minute…

'A' sends his public key to 'B'. But how 'B' confirms that A is authentic (or) trusted one. Here public key certificates and certificate authorities came into picture.

A trusted third party usually issues the certificate. You can assume a certificate like your voter ID, Driving license, Marks memo etc., For example, marks memo is given by universities, voter ID is given by Government.

Popular certificate authorities for web include, verisign, GoDaddy, AT&T certificate services, Microsoft etc., A typical certificate contains following fields.

Issuer: It is the organization that issues the certificate.
Period Of validity: How long this certificate is valid.
Subjet details : Include details about the subject, Suppose for a company like amazon.com, the subject can be

Company Name : Amazon.com
Country : US
Common Name : Amazon.com

Public Key information : It includes the algorithm used, public key, key size etc.,

Certificate Authorities
Certificate Authority is the organization, who issues the certificate.
Popular certificate authorities include, verisign, GoDaddy, AT&T certificate services, Microsoft etc.,

There are two kinds of Certificate Authorities.
a.   Private certificate Authorities
b.   Public Certificate Authorities

Private certificate authorities are completely for internal purpose. For example company like Symantec, issues a certificate to every computer/laptop in their organization for secure communication.

Public certificate authorities for Internet purpose. These are global authorities. They verify the identity of both individuals and organizations and issue the certificate.

Prevoius                                                 Next                                                 Home

Types Of Cryptography

There are two types of Cryptographies.
   a.   Secret key cryptography
   b.   Public key cryptography

Secret key cryptography
It is also known as symmetric key encryption. Let’s say ‘A’ wants to send message to ‘B’, then ‘A’ shares a key with ‘B’ (Assuming that key is not disclosed to any one). Once the key shared between ‘A’ and ‘B’, ‘A’ encrypts the data and send to ‘B’.  Once ‘B’ receives encrypted data, it uses same key to decrypt. Since same key is used for both encryption and decryption, it is called Symmetric Encryption. The larger the key, the more difficult to break the encrypted message.

Public Key Cryptography
The problem with secret key cryptography is in, transferring the key securely between the parties involved in communication. This problem solved by using public key cryptography, also called Asymmetric cryptography. In public key cryptography, encryption is done with public key and decryption is done with private key. Steps are like following.

a.   Person ‘A’, creates public-private key pair.
b.   ‘A’ distribute (publish) his public key, to all the parties involved in communication.
c.    ‘B’ who wants to send information to ‘A’, encrypt the message with ‘A’ ‘s public key and send.
d.   ‘A’ receives the encrypted message, decrypt it with his private key.

Since private key is known to ‘A’ only, it is nearly impossible for any other person to decrypt the message. This seems to be some what magic to, who are new to cryptography.  For complete understanding, go through following wiki article.


By using public key encryption, we can provide authentication service also. Let’s say ‘A’ encrypt some info ‘x’ with his private key and send it to ‘B’. Once ‘B’ receives the encrypted message, he decrypts the message with ‘A’ public key and make sure that it is ‘x”. If is there any mismatch in decrypted information, then ‘B’ confirm that it is not ‘A’. Only the problem with public key cryptography is, it is costly, complex mathematical operations performed while encrypting.

So better solution is to combine both Symmetric and Asymmetric algorithms. The main problem with symmetric encryption is, how can key exchange happen securely between ‘A’ and ‘B’.

a.   ‘A’ generates his public-private key pair
b.   ‘A’ sends his public key to ‘B’
c.    ‘B’ generate a random number, and encrypt the random number with ‘A’ public key and send the encrypted message to ‘A’.
d.   ‘A’ receives the encrypted message and decrypts the message with his private key.
e.   At this point of time, both ‘A’ and ‘B’ knows the random number, they use this random number as secret key and perform secret key encryption with this key.

In summary, public key encryption is used for key exchange, secret key encryption is used for data exchange.


Prevoius                                                 Next                                                 Home

SSL


This tutorial series is all about security protocol SSL. SSL stands for Secure Sockets Layer protocol. SSL encrypts the communication between web browser and web server.

Why SSL is needed (Why we need encryption)
Suppose I want to purchase a product from flipkart.com.

a.   First I go to the site flipkart.com
b.   Select the product and checkout for payment
c.    At the time of online payment, I need to provide all my credit card information to the web site. In case of HTTP, data is transmitted from browser to server as simple text. Once you submit your credit card details, it travels through number of systems before reaching flipkart server. Since HTTP transfers data as simple text, there is a security threat.  Neither the user, nor the server has control on the information that is travelling across the network. Here SSL came into picture, it solves the problem by making the communications between client and server encrypted.

Now a days, almost all web browsers and web servers support SSL. You can see https prefix for ssl secured URLs.


As shown in the above figure, above sequence is the basic communication flow. The Network Interface layer is responsible for transmitting/receiving TCP/IP packets across network. The Internet layer is responsible for addressing, packaging, and routing functions. TCP is responsible for the establishment of a TCP connection, the sequencing and acknowledgment of packets sent, and the recovery of packets lost during transmission. Application layer defines the protocols like HTTP, FTP that applications use to exchange data.


As shown in the figure, SSL comes in between HTTP and TCP.



Prevoius                                                 Next                                                 Home