Saturday, 2 May 2015

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

Apache HTTP Server

Apache HTTP server is a web server. A Web server serves static pages to the browser. It receives the request from browser and serves the response. You can enhance the Apaches abilities by installing other modules, so that it can serve dynamic webpages using various technologies such as PHP, CGI, Servlets etc., but the core of Apache is just a plain old HTTP server.

a. Web browser sends a request to the server for a web page.
         Ex: http://mydomain/pages/home.html

b. Web server looks for the document on the file system and retrieves documents from file system

c. Once the document is received, web server sends the data of the document to the browser.

A simple web server accepts connections from web browser, read the request from browser, Retrieve the static (or) dynamic content and return it to the browser. Close the connection with browser.

I hope with this you got some basic idea of web server. Follow the link, to know how to install Apache HTTP server on Ubuntu.

Prevoius                                                 Next                                                 Home

Ubuntu : Install SSL cerificate on Apache


Following post, explains, how to generate self-signed certificate for Apache. Before proceeding, install Apache using the link.

Step 1: Open shell Run the following commands, to enable SSL.
#a2enmod ssl

Step 2: Create a directory “/etc/apache2/ssl ”.
mkdir /etc/apache2/ssl 

Step 3: Run the following command to generate SSL certificate.
openssl req -newkey rsa:2048 -x509 -sha256 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.key
Once you entered above command, it prompts for number of inputs to generate a certificate. This example will create a certificate valid for 365 days.
# openssl req -newkey rsa:2048 -x509 -sha256 -days 365 -nodes -out /etc/apache2/ssl/apache.pem -keyout /etc/apache2/ssl/apache.key
Generating a 2048 bit RSA private key
........+++
...................+++
writing new private key to '/etc/apache2/ssl/apache.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Karnataka
Locality Name (eg, city) []:Bangalore
Organization Name (eg, company) [Internet Widgits Pty Ltd]:JavaTuorial
Organizational Unit Name (eg, section) []:SSl
Common Name (e.g. server FQDN or YOUR name) []:hariJavaTutorial
Email Address []:


Step 4: Configure Apache to use the Self-Signed Certificate.
Open file “/etc/apache2/sites-available/default-ssl.conf”. Edit the virtual host configuration files for sites which you would like to enable SSL on. For each virtual host, you must add the following stanza.

<IfModule mod_ssl.c>
        <VirtualHost 127.0.0.1:443>
                ServerAdmin webmaster@localhost
                DocumentRoot /var/www/html
                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined
                SSLEngine on
                SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
                SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

                BrowserMatch "MSIE [2-6]" \
                                nokeepalive ssl-unclean-shutdown \
                                downgrade-1.0 force-response-1.0
                BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

        </VirtualHost>
</IfModule>


Step 5: Enable SSL site entries with following command.
a2ensite default-ssl

Step 6: Restart web server using following command.
#service apache2 restart

Step 7: Now you can open localhost using https.
Open browser, and type “https://localhost” in your browser’s URL text box. You will get “Apache2 Ubuntu Default Page”.


Note:
If you want to disable https, open “/etc/apache2/sites-enabled/default-ssl.conf” and update the variable SSLEngine as off.

Prevoius                                                 Next                                                 Home

Install Apche HTTP Server on Ubuntu


Step 1: Open terminal and enter the following command.
sudo apt-get install apache2

Step 2: Start web server.
/etc/init.d/apache2 start

Step 3: Open browser, and type “http://localhost” in your browser’s URL text box. You will get “Apache2 Ubuntu Default Page”.

Note:
Restart Apache 2 Server
# /etc/init.d/apache2 restart 

Stop Apache 2 Server
# /etc/init.d/apache2 stop


Prevoius                                                 Next                                                 Home