Lab 9b - Apache SSL

Aims

To configure the Apache web server to support SSL connections.

Task 1: Configuring SSL

The Apache installation on CentOS already comes with SSL enabled. So for this lab exercise, we will remove some of the existing configuration so you understand the processing of configuring SSL from the beginning.

The first step is to set up the public and private encryption keys that will be used for SSL. The public key will be contained inside a certificate, so we need to create a private key for the web server, as well as public certificate that the web server will send out to clients.

First begin by removing the existing SSL server key and certificate:

cd /etc/pki/tls/certs

rm ../private/localhost.key (The server’s private key, used to sign the certificate)

rm localhost.crt (The web server’s certificate)


Now generate new ones. Enter the command below and make sure you are in /etc/pki/tls/certs. Make sure you enter the command ALL ON ONE LINE:

# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ../private/localhost.key -out localhost.crt






Be sure to answer the questions as best you can. In particular, when it asks for the Common Name, you should enter your web server’s DNS name (e.g. www.it.netserv.edu.au), or you can use a wildcard entry (e.g.

*.it.netserv.edu.au).

This process should have generated two new files – ../private/localhost.key (the new private key for the web server) and localhost.crt (the new certificate).

These filenames are configurable in the SSL configuration file /etc/httpd/conf.d/ssl.conf, but it is easiest for us now to use the defaults.

Now we are finished with generating the keys/certificates. For the next step, we will specify a new DocumentRoot for the SSL web server, so that SSL web pages come from a different location. SSL in Apache is configured as a module, and the configuration files for Apache modules are in /etc/httpd/conf.d. Change to that directory and edit the ssl.conf file.

Search the ssl.conf file for a DocumentRoot directive. It should initially be commented out, meaning that the SSL web server by default will serve documents from the same directory as the normal (non-SSL) web server. For testing, uncomment the DocumentRoot directive in ssl.conf, and change it to point to a new directory, e.g.

/var/www/secure. Create this new directory and put a simple index.html file inside.

Now start/restart httpd using systemctl.

Test your web server by accessing a “https” URL, e.g.

https://www.it.netserv.edu.au/

You will get a warning about the certificate, because it is self-signed. Choose “Advanced”. Note the warning about a self-signed certificate. View the certificate (you should see the details you entered earlier). Then “Accept the risk and continue”. If you’ve done the configuration correctly, you should see your “secure” web page show up.


Steps:

On Linux

# cd /etc/pki/tls/certs/

# rm -f ../private/localhost.key

//remove the server’s private key, that used to sign the certificate//

# rm -f localhost.crt

// remove the web server’s certificate//

Now generate new ones. Enter the command below and make sure you are in /etc/pki/tls/certs. Make sure you enter the command ALL ON ONE LINE:

# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ../private/localhost.key -out localhost.crt

Country Name: AU

State: NSW

Lacality Name: Sydney

Organisation: UTS

Organisation Unit: FEIT

Common Name: www.it.netserv.edu.au

Email Address:

Next let’s check what’s inside the certificate

# cat ../private/localhost.key

# cat localhost.crt

To test SSL setting it is recommended to create a new web page for https. Go to configuration file

# vim /etc/httpd/conf.d/ssl.conf

Find DocumentRoot and update to the following:

DocumentRoot “/var/www/secure”
:wq

Create a new web page

# mkdri /var/www/secure

# cd /var/www/secure/

# touch index.html

# vim index.html

Ø Add: SSL Test page

Ø :wq

Restart the service httpd for the changes to take effect.

# systemctl restart httpd

Verify SSL

Go to a browser (Firefox) and type the following on the search bar:

https://www.it.netserv.edu.au

View page

Accept the risk and continue