plainblack.com
Username Password
search
Bookmark and Share

Secure Socket Layer (SSL)

At some point, you’ll likely want to enable SSL (Secure Socket Layer) on your web site. You may want to just encrypt logins to protect your user’s passwords, or you might want to protect site data and commerce functions. No matter your reasons, setting up SSL is very easy, and we recommend that you do it sooner rather than later.

What Is SSL?

Normal web traffic is sent unencrypted over the Internet. That is, anyone with access to the right tools can snoop all of that traffic. Obviously, this can lead to problems, especially where security and privacy is necessary, such as in credit card data and bank transactions. The Secure Socket Layer is used to encrypt the data stream between the web server and the web client (the browser).

SSL makes use of what is known as asymmetric cryptography, commonly referred to as public key cryptography (PKI). With public key cryptography, two keys are created, one public, one private. Anything encrypted with either key can only be decrypted with its corresponding key. Thus if a message or data stream were encrypted with the server's private key, it can be decrypted only using its corresponding public key, ensuring that the data only could have come from the server.

If SSL utilizes public key cryptography to encrypt the data stream traveling over the Internet, why is a certificate necessary? The technical answer to that question is that a certificate is not really necessary - the data is secure and cannot easily be decrypted by a third party. However, certificates do serve a crucial role in the communication process. The certificate, signed by a trusted Certificate Authority (CA), ensures that the certificate holder is really who he claims to be. Without a trusted signed certificate, your data may be encrypted, however, the party you are communicating with may not be whom you think. Without certificates, impersonation attacks would be much more common.

 

Enabling SSL

Follow these easy steps to enable SSL on your web server.

Step 1: Generate a Private Key

The openssl toolkit is used to generate an RSA Private Key and CSR (Certificate Signing Request). It can also be used to generate self-signed certificates which can be used for testing purposes or internal usage.

The first step is to create your RSA Private Key. This key is a 1024 bit RSA key which is encrypted using Triple-DES and stored in a PEM format so that it is readable as ASCII text.

 

mkdir -p /data/domains/www.example.com/certs

cd /data/domains/www.example.com/certs

. /data/wre/sbin/setenvironment.sh
openssl genrsa -des3 -out server.key 1024

 

The output will look something like this:

 

Generating RSA private key, 1024 bit long modulus

.........................................................++++++

........++++++

e is 65537 (0x10001)

Enter PEM pass phrase:

Verifying password - Enter PEM pass phrase:

 

Step 2: Generate a Certificate Signing Request

Once the private key is generated a Certificate Signing Request can be generated. The CSR is then used in one of two ways. Ideally, the CSR will be sent to a Certificate Authority, such as Thawte or Verisign who will verify the identity of the requester and issue a signed certificate. The second option is to self-sign the CSR, which will be demonstrated in Step 4: Generating a Self-Signed Certificate.

During the generation of the CSR, you will be prompted for several pieces of information. These are the X.509 attributes of the certificate. One of the prompts will be for "Common Name". It is important that this field be filled in with the fully qualified domain name of the server to be protected by SSL. If the website to be protected will be http://www.example.com, then enter www.example.com at this prompt. The command to generate the CSR is as follows:

 

openssl req -new -key server.key -out server.csr

 

The output will look something like this:

 

Country Name (2 letter code) [GB]:US

State or Province Name (full name) [Berkshire]:WI

Locality Name (eg, city) [Newbury]:Madison

Organization Name (eg, company) [My Company Ltd]:Example Co.

Organizational Unit Name (eg, section) []:

Common Name (eg, your name or your server's hostname) []:www.example.com

Email Address []:info@example.com

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

Plain Black offers discounted SSL Certificates. Visit their online shop to learn more.

 

Step 3: Remove Passphrase from Key

One unfortunate side-effect of the pass-phrased private key is that Apache will ask for the pass-phrase each time the web server is started. Obviously this is not necessarily convenient as someone will not always be around to type in the pass-phrase, such as after a reboot or crash. mod_ssl includes the ability to use an external program in place of the built-in pass-phrase dialog, however, this is not necessarily the most secure option either. It is possible to remove the Triple-DES encryption from the key, thereby no longer needing to type in a pass-phrase. If the private key is no longer encrypted, it is critical that this file only be readable by the root user! If your system is ever compromised and a third party obtains your unencrypted private key, the corresponding certificate will need to be revoked. With that being said, use the following command to remove the pass-phrase from the key:

 

cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

chmod 600 server.key

 

The newly created server.key file has no more passphrase in it. Your certs folder should have three files in it similar to this, with these permissions:

 

-rw-r--r-- 1 root root 745 Jun 29 12:19 server.csr

-rw------- 1 root root 891 Jun 29 13:22 server.key

-rw-r--r-- 1 root root 963 Jun 29 13:22 server.key.org

 

Step 4: Generating a Self-Signed Certificate

If you don’t plan on having your certificate signed by a CA, or you wish to test your new SSL implementation while waiting for your CA to sign your certificate, you should generate a self signed certificate. If you are having a CA sign your certificate, and you don’t need to test SSL right now you can skip this step, and just wait for your certificate to come back from your CA. When you get it, put it in a file called server.crt.

The self-signed certificate will generate an error in the client browser to the effect that the signing certificate authority is unknown and not trusted.

To generate a self-signed certificate which is good for 365 days, issue the following command:

 

openssl x509 -req -days 365 -in server.csr \
 -signkey server.key -out server.crt

Signature ok

subject=/C=US/ST=WI/L=Madison/O=Example Co./OU=Information Technology/CN=www.example.com/Email=info@example.com

Getting Private key

 

Though you can technicallygenerate a certificate that will last longer than 365 days, it's not recommended. The shorter the interval between generating certificates, the less likely you are to be the victim of crack attacks.

 

Step 5: Configuring SSL Enabled Virtual Hosts

Now that you’ve got a signed certificate, all you need to do is tell Apache that you want to use it. Let’s create an SSL virtual host in your site’s mod_proxy config file. Edit www.example.com.modproxy and add this to the bottom of the file:

 <VirtualHost *:443>
DocumentRoot /data/domains/www.example.com/public
ServerName www.example.com
ServerAlias example.com
SSLEngine on
SSLCertificateFile /data/domains/www.example.com/certs/server.crt
SSLCertificateKeyFile /data/domains/www.example.com/certs/server.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog /data/domains/www.example.com/logs/access.log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>


You also need to enable name based virtual hosting on the proxy by adding the following lines to modproxy.conf:

Listen *:443
NameVirtualHost *:443

Note: Before version 2.2.12 of Apache mod_ssl lacked SNI support needed for name based virtual hosting. This meant that one needed different IP-addresses for each website served over SSL. This restriction no longer applies. However, some old browsers and operating systems, most notably IE8 on XP do not support name based virtual hosting. If you need to support those, then IP based virtual hosting is your only choice. In that case leave out the Listen and NameVirtualHost directives above and instead precede the VirtualHost directive in www.example.com.modproxy with

Listen 10.0.0.1:443

and change the VirtualHost directive itself to

<VirtualHost 10.0.0.1:443>

replacing 10.0.0.1 with the unique IP address of your website.

Step 6: Restart Apache and Test

Now all you need to do is restart your web server and test.

 

rc.webgui restartmodproxy

 

Now visit your web site and test it at https://www.example.com

Keywords: encrypt encryption public key cryptography security ssl ssl certificate

Search | Most Popular | Recent Changes | Wiki Home
© 2018 Plain Black Corporation | All Rights Reserved