| 1 | Linux System Administration |
|---|
| 2 | |
|---|
| 3 | Apache SSL Certificate Generation and Use |
|---|
| 4 | |
|---|
| 5 | 1. Create a local SSL Certificate repository |
|---|
| 6 | -------------------------------------------- |
|---|
| 7 | |
|---|
| 8 | Log in to your machine either as the root user, or once logged in become the root |
|---|
| 9 | user, then do: |
|---|
| 10 | |
|---|
| 11 | # mkdir /etc/ssl/localcerts |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | 2. Generate a locally signed Digital Certficate for Apache |
|---|
| 15 | ---------------------------------------------------------- |
|---|
| 16 | |
|---|
| 17 | We'll use openssl to generate a local server key, local server certificate, a CSR |
|---|
| 18 | (Certificate Signing Request) and a server key that is unencrypted (no passphrase) |
|---|
| 19 | to allow Apache to start without prompting for a passphrase. |
|---|
| 20 | |
|---|
| 21 | Create our own self signed certificate: |
|---|
| 22 | |
|---|
| 23 | # cd /etc/ssl/localcerts |
|---|
| 24 | # mkdir apache |
|---|
| 25 | # cd apache |
|---|
| 26 | |
|---|
| 27 | Ubuntu uses a special wrapper program to create a self-signed certificate. You can |
|---|
| 28 | create your own, manually generated certificates, but this method works fine for what |
|---|
| 29 | we are doing. To generate your local certificate for apache do: |
|---|
| 30 | |
|---|
| 31 | # make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/ssl/localcerts/apache/server.pem |
|---|
| 32 | |
|---|
| 33 | When you are prompted to enter the host name to use in the SSL certificate enter: |
|---|
| 34 | |
|---|
| 35 | pcX.ws.nsrc.org |
|---|
| 36 | |
|---|
| 37 | and tab to "<OK>" and press ENTER to continue. |
|---|
| 38 | |
|---|
| 39 | Now you have a local certificate named server.pem in the directory /etc/ssl/localcerts/apache. |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | 3. Enable Apache SSL configuration for your default domain |
|---|
| 43 | ---------------------------------------------------------- |
|---|
| 44 | |
|---|
| 45 | We need to update the /etc/apache2/sites-available/default-ssl configuration file and enable |
|---|
| 46 | the site for our server. First we edit the file: |
|---|
| 47 | |
|---|
| 48 | # cd /etc/apache2/sites-available |
|---|
| 49 | # vi default-ssl |
|---|
| 50 | |
|---|
| 51 | Find the line that says: |
|---|
| 52 | |
|---|
| 53 | DocumentRoot /var/www |
|---|
| 54 | |
|---|
| 55 | and change this to: |
|---|
| 56 | |
|---|
| 57 | DocumentRoot /var/www/pcX.ws.nsrc.org |
|---|
| 58 | |
|---|
| 59 | Now find the line that says: |
|---|
| 60 | |
|---|
| 61 | #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem |
|---|
| 62 | |
|---|
| 63 | And create a line just below that says: |
|---|
| 64 | |
|---|
| 65 | SSLCertificateFile /etc/ssl/localcerts/apache/server.pem |
|---|
| 66 | |
|---|
| 67 | Now save the file and exit, then we'll enable the Apache SSL configuration. |
|---|
| 68 | |
|---|
| 69 | # a2ensite default-ssl |
|---|
| 70 | # service apache2 restart |
|---|
| 71 | |
|---|
| 72 | To verify that Apache will provide an encrypted connection to pcX.ws.nsrc.org open a web browser |
|---|
| 73 | and go to: |
|---|
| 74 | |
|---|
| 75 | https://pcX.ws.nsrc.org/ |
|---|
| 76 | |
|---|
| 77 | You should receive a warning that the certificate is not trusted. Click "Continue" (this is different |
|---|
| 78 | in each web browser) to view your home page. |
|---|
| 79 | |
|---|
| 80 | 4. Manually verify SSL certificate use on your web server |
|---|
| 81 | --------------------------------------------------------- |
|---|
| 82 | |
|---|
| 83 | You can use the built-in OpenSSL command line tool to connect to your web server and see information about |
|---|
| 84 | the SSL certificate in use. To do this do (as root or a regular user): |
|---|
| 85 | |
|---|
| 86 | # openssl s_client -connect pcX.ws.nsrc.org:443 |
|---|
| 87 | |
|---|
| 88 | And you will see information about the SSL Digital Certificate for the site pcX.ws.nsrc.org. You should see |
|---|
| 89 | something like: |
|---|
| 90 | |
|---|
| 91 | subject=/CN=pcX.ws.nsrc.org |
|---|
| 92 | issuer=/CN=pcX.ws.nsrc.org |
|---|
| 93 | --- |
|---|
| 94 | No client certificate CA names sent |
|---|
| 95 | --- |
|---|
| 96 | SSL handshake has read 1004 bytes and written 319 bytes |
|---|
| 97 | --- |
|---|
| 98 | New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA |
|---|
| 99 | Server public key is 1024 bit |
|---|
| 100 | Secure Renegotiation IS supported |
|---|
| 101 | Compression: NONE |
|---|
| 102 | Expansion: NONE |
|---|
| 103 | SSL-Session: |
|---|
| 104 | Protocol : TLSv1 |
|---|
| 105 | Cipher : DHE-RSA-AES256-SHA |
|---|
| 106 | Session-ID: 18541F63DDD15E050A3C72ED9415CC9A00B7DCD0DC472919AE4E4B67E4D88837 |
|---|
| 107 | Session-ID-ctx: |
|---|
| 108 | Master-Key: 20BC655CCF5BC3D3BECD1D04333F928CB1A756871E5ACBD94455DD324E7E62BE29D11664AFDD61257DB71CBE1B4A7FEE |
|---|
| 109 | Key-Arg : None |
|---|
| 110 | Start Time: 1334826634 |
|---|
| 111 | Timeout : 300 (sec) |
|---|
| 112 | Verify return code: 18 (self signed certificate) |
|---|
| 113 | --- |
|---|
| 114 | closed |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | Press CTRL-C to exit from the program. |
|---|
| 118 | |
|---|
| 119 | As you can see reasonable ciphers are available to ensure encrypted communication between the server and |
|---|
| 120 | a client connecting via https (SSL). |
|---|