Hands On Labs+: Apache and Self Signed SSL Certificates
Hands On Labs+: Apache and Self Signed SSL Certificates
Hands On Labs+
Apache and Self Signed SSL
Certificates
Table of Contents
Introduction .................................................................................................................................................. 2
Goals ............................................................................................................................................................. 2
Packages, Resources and Prerequisites ........................................................................................................ 2
Document Conventions ................................................................................................................................ 3
General Process ............................................................................................................................................ 3
Linux Academy Lab Server – Server Installation and Configuration ............................................................. 6
Apache Installation ................................................................................................................................... 6
Create a Self-Signed Certificated .............................................................................................................. 6
Enable the Apache SSL Module ................................................................................................................ 7
Edit the Default SSL VHOST File ................................................................................................................ 8
Test the Connection .................................................................................................................................. 9
Appendix A: /etc/apache2/sites-available/default-ssl.conf Example......................................................... 10
1
Hands On Labs+ – Apache and Self Signed SSL Certificates
Introduction
Security is a commonly overlooked topic of conversation when discussing Linux servers. Although
it is not uncommon to talk about hardening the server itself, client access to the server can
sometimes be an afterthought. Securing your Apache web server’s content can be accomplished
simply by using an encrypted web session. This is accomplished by installed an SSL Certificate in
Apache.
We will talk about the security around generating SSL keys and then how to install a Self Signed
Certificate can be a means to that end (and keep in mind, a certificate from a Third Party issuer is
accomplished the same way).
Goals
This Hands On Lab will show you how to generate a valid Self Signed Certificate and Key for
Apache that can be installed on the local server.
Although we will be using Ubuntu 14.04 LTS during the course of this document, the process is
exactly the same for all Linux distributions with the exception of the location of the VHOST files
on the web server. In Red Hat (RPM distributions), by default, all vhost entries are in the httpd.conf
file itself and not in the ‘sites-available and sites-enabled’ directories as indicated here.
2
Hands On Labs+ – Apache and Self Signed SSL Certificates
Document Conventions
Just a couple of housekeeping items to go over so you can get the most out of this Hands On Lab
without worrying about how to interpret the contents of the document.
When we are demonstrating a command that you are going to type in your shell while connected
to a server, you will see a box with a dark blue background and some text, like this:
linuxacademy@ip-10-0-0-0:~$ sudo apt-get install package
[sudo] password for linuxacademy: <PASSWORD PROVIDED>
General Process
When you are ready to begin the Hands On Lab, log into your Linux Academy Lab+ subscription
and navigate to the “Live Labs” section on the Dashboard. Once you choose the “Secure VNC”
Lab from the list, you will see the screen below:
3
Hands On Labs+ – Apache and Self Signed SSL Certificates
4
Hands On Labs+ – Apache and Self Signed SSL Certificates
You will see all the information you need to access your servers from another system. Specifically,
you need:
The server public IP addresse
Access credentials
One thing to note is that, in addition to the IP that you see above, the server will have another IP
assigned to it in the 10.0.0.x subnet. This is a private IP address and will not route outside of your
private server pool. Your server will have a static private address of 10.0.0.100. We will be using
the external IP address to connect over SSH as well as when configuring VNC.
5
Hands On Labs+ – Apache and Self Signed SSL Certificates
Apache Installation
Once we are logged into our Linux Academy Lab Server, we need to install a couple of things in
order to generate, install and test our secure server. Open a command prompt and type in the
following:
sudo apt-get install apache2 apache2-doc apache2-utils openssl
This will install all the necessary packages and services to run Apache as well as the plugins,
modules and libraries necessary to support SSL traffic. You can now test whether your system is
running Apache by navigating to the external IP address of your server in a browser. You should
get the default Apache “It Works” web page. If you do, we are ready to move on to the certificate
installation.
After we have a directory for our certificates, let’s go ahead and create what we need:
sudo openssl req –x509 –nodes –days 365 –newkey rsa:2048 ~
-keyout /etc/apache2/ssl/apache.key –out ~
/etc/apache2/ssl/apache.crt
After you execute this command, you will be asked to enter a bunch of information that will be
incorporated into your key and your certificate. Since this is a self-signed certificate that will show
a browser warning in any event (since you are not considered a trusted certificate issuing
authority), what you enter is largely unimportant. If we were generating just the key file to send to
a valid issuer, it would. You will see something like the following:
6
Hands On Labs+ – Apache and Self Signed SSL Certificates
......................+++
........................................................................
..............................................................+++
writing new private key to '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]:US
State or Province Name (full name) [Some-State]:WY
Locality Name (eg, city) []:Lourdes
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Name
Company
Organizational Unit Name (eg, section) []:Information Technology
Common Name (e.g. server FQDN or YOUR name) []:ip-10-0-0-
100.linuxacademy.com
Email Address []:[email protected]
At this point, our certificate key and the certificate have been written to the previously created
‘/etc/apache2/ssl’ directory.
Keep in mind that some of the output may differ slightly for your installation depending on whether
you are using the Linux Academy Servers or your own distribution. As long as you don’t receive
an error message that the SSL Module doesn’t exist, you are ready to enable our certificates from
within the system vhost files for our web server.
7
Hands On Labs+ – Apache and Self Signed SSL Certificates
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
... Leave the rest of the file alone, defaults are fine
</VirtualHost>
Now we just have to activate the vhost file for our new SSL configured site. We can do this the
same way we activated the SSL module:
sudo a2ensite default-ssl.conf
Enabling site default-ssl.
To activate the new configuration, you need to run:
service apache2 reload
Finally, we have to restart Apache so that the new configuration file is read in by Apache and it
knows to answer for that IP address over HTTPS (SSL). We do that as directed by:
sudo service apache2 restart
A quick test can be performed locally to be sure we are now listening on port 443 (SSL) by doing
the following:
telnet localhost 443
Trying ::1...
Connected to localhost.
Escape character is '^]'.
We have successfully enabled HTTPS traffic requests on our system and Apache is now listening
on port 443 to incoming requests.
8
Hands On Labs+ – Apache and Self Signed SSL Certificates
However, you will then know that your system is indeed answering on port 443 externally, using
your certificate. You can view the certificate details to confirm. You have now set up SSL and
tested your configuration!
9
Hands On Labs+ – Apache and Self Signed SSL Certificates
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
10
Hands On Labs+ – Apache and Self Signed SSL Certificates
# Access Control:
# With SSLRequire you can do per-directory access control based
# on arbitrary complex boolean expressions containing server
# variable checks and other lookup directives. The syntax is a
# mixture between C and Perl. See the mod_ssl documentation
# for more details.
#<Location />
#SSLRequire ( %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
# and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
# and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
# and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
# and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20 ) \
# or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>
11
Hands On Labs+ – Apache and Self Signed SSL Certificates
</Directory>
</VirtualHost>
</IfModule>
12