Openssl PDF
Openssl PDF
HTTPS Configuration:
The mod_ssl module is available in apache2-common package. To enable the mod_ssl module:
$ sudo a2enmod ssl
Module ssl installed; run /etc/init.d/apache2 force-reload to enable.
$ sudo /etc/init.d/apache2 force-reload
* Reloading web server config apache2
Certificates:
To set up your secure server, use public key cryptography to create a public and private key pair. You need a
key and a certificate to operate your secure server, which means that you can either generate a self-signed
certificate or purchase a CA-signed certificate.
1. You can create your own self-signed certificate. Note, however, that self-signed certificates should not be
used in most production environments. Self-signed certificates are not automatically accepted by a user's
browser. Users are prompted by the browser to accept the certificate and create the secure connection.
2. You can send your certificate request (including your public key), proof of your company's identity, and
payment to a Certificate Authority (CA). The CA verifies the certificate request and your identity, and then
sends back a certificate for your secure server.
Once you have a self-signed certificate or a signed certificate from the CA of your choice, you need to install
it on your secure server.
If you don't have a fully qualified domain name, you should use the IP that you'll be using to access your
SSL site for Common Name (CN).
1B.5 Sign the certificate signing request (csr) with the self-created (CA)
Note that 365 days is used here. After a year you'll need to do this again. Note also that I set the serial
number of the signed server certificate to "01". Each time you do this, especially if you do this before a
previously-signed certificate expires, you'll need to change the serial key to something else -- otherwise
everyone who's visited your site with a cached version of your certificate will get a browser warning
message to the effect that your certificate signing authority has screwed up -- they've signed a new
key/request, but kept the old serial number. There are a couple ways to rectify that. crl's (certificate
revocation list) is one method, but beyond the scope of the document. Another method is for all clients which
have stored the CA certificate to go into their settings and delete the old one manually. But for the purposes
of this document, we'll just avoid the problem. (If you're a sysadmin of a production system and your
server.key is compromised, you'll certainly need to worry.)
The command below does a number of things. It takes your signing request (csr) and makes a one-year valid
signed server certificate (crt) out of it. In doing so, we need to tell it which Certificate Authority (CA) to use,
which CA key to use, and which Server key to sign. We set the serial number to 01, and output the signed
key in the file named server.crt. If you do this again after people have visited your site and trusted your CA
(storing it in their browser), you might want to use 02 for the next serial number, and so on. You might create
some scheme to make the serial number more "official" in appearance or makeup but keep in mind that it is
fully exposed to the public in their web browsers, so it offers no additional security in itself.
$ sudo openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial
01 -out server.crt
Signature ok
subject=/C=it/ST=italy/L=rende/O=mycomp/OU=myunit/CN=localhost/emailAddress=mymail
Getting CA Private Key
Enter pass phrase for ca.key:
(Note: Use your assigned IP or DNS name followed with ":80" if you have one for ServerName).
Similar procedure for HTTPS over port 443 (edit /etc/apache2/sites-available/ssl):
NameVirtualHost *:443
<VirtualHost *:443>
ServerName localhost
DocumentRoot /var/www-ssl/html/
(Note: Again, use your assigned IP or a DNS name followed with ":443" if you have one for ServerName.)
Instruct Apache to listen to 443
Go to /etc/apache2/ports.conf and check whether it looks like (starting with Ubuntu 7.10) the ports.conf may
already have an IfModule clause in it for the SSL portion. If you see this, you can just leave it as-is:
<IfModule mod_ssl.c>
Listen 443
</IfModule>
When starting and stopping Apache there may be a complaint such as "Could not determine the server's fully
qualified domain name, using 127.0.1.1 for ServerName". You may encounter this if you don't have a DNS
name for your server, and are just using an IP. If this applies to you, go into your /etc/hosts file and make the
following changes.
127.0.0.1 localhost localhost.localdomain {your system name}
127.0.1.1 {your system name}
{static IP if you you have one} {fully qualified DNS host name if you have one}
If you don't have a fully qualified domain name (FQDN) for your box, you may need to make an additional
tweak. In your /etc/apache2/apache2.conf file, you may want to add the following line at the very end of the
file if Apache is still complaining about lacking a fully qualified domain name at startup: ServerName
localhost.
You can also export the certificate (via the Export button).
When accepting the certificate you are allowed to connect to https://localhost (you see the lock icon on the