Secure Websites Using SSL And Certificates
|
Submitted by punk0mi (Contact Author) (Forums) on Wed, 2007-05-16 16:14. :: Fedora | Apache | Security
Secure Websites Using SSL And CertificatesThis how-to will guide you through the entire process of setting up a secure website using SSL and digital certificates. This guide assumes that you have already a fully functional (and configured) server running Apache, BIND, and OpenSSL. Just as a side note, this guide was written based on a Fedora Core 6 distribution, but should be the same for most other distros out there.
IntroductionToday it is possible to create a secure website with relative ease by requiring a client to present a digitally signed certificate. A digitally signed certificate is simply a piece of information that contains data about the subject, public key, dates of validity, identification of the Certificate Authority (CA), and the digital signature. There are typically two ways to go about creating a secure website. First is by the use of a self-signed certificate. The second way is by using a Trusted Certificate signed by a CA. The choice is up to you, and this tutorial will show you how to do both. Go ahead and su into root and let's begin!
Step 1: Preconfigure OpenSSLWe can preconfigure OpenSSL to fill in the fields of the certificate by modifying its configuration file. Doing this will save us a few steps during the certificate creation process. First, navigate to the SSL directory and do a listing of files # cd /etc/pki/tls In the listing you should see the file openssl.cnf. Go ahead and open up this file in your favorite editor and find the beginning of the [ req_distinguished_name ] section. Modify the countryName_default, stateOrProvinceName_default, 0.organizationName_default, 1.organizationName_default values with the values that suit your needs. The section of the file you are looking for looks like this [ req_distinguished_name ] countryName = Country Name (2 letter code) countryName_default = US countryName_min = 2 countryName_max = 2 stateOrProvinceName = State or Province Name (full name) stateOrProvinceName_default = Berkshire localityName = Locality Name (eg, city) localityName_default = Berkshire Hills 0.organizationName = Organization Name (eg, company) 0.organizationName_default = My Secure Website Company # we can do this but it is not needed normally :-) #1.organizationName = Second Organization Name (eg, company) #1.organizationName_default = MSWC organizationalUnitName = Organizational Unit Name (eg, section) #organizationalUnitName_default = Your IT Department commonName = Common Name (eg, your name or your server\'s hostname) commonName_max = 64 emailAddress = Email Address emailAddress_max = 64 Once you have made the changes, save and quit the editor.
Step 2: Creating The Server CANow we must create the server's CA. You should still be in the /etc/pki/tls directory, if you are not sure just run a quick pwd to find out. We now need to make sure that we have no other certificates in the system: # rm -rf ../../CA Once that is done, we will use the shell scripts OpenSSL comes with to create a new CA: # misc/CA -newca A dialog will appear saying: CA certificate filename (or enter to create) Go ahead and press enter. At this point the program will begin generating the CA. During this process you will be asked to enter a PEM pass phrase, create one and write it down! Once you have entered the PEM and verified it you will be asked some questions about the Distinguished Name (DN). A lot of the questions will have the correct values in them by default since we edited the openssl.cnf file. So press enter until it asks for the Common Name. When asked for the common name you should put down the server's hostname. It should look like this: #misc/CA -newca The CA for the server has been created and placed in the /etc/CA/private/cakey.pem file.
Step 3: Creating A Server Certificate RequestNow that we have the CA established, we need to make a request to create the certificate. Once again, using the shell scripts included with OpenSSL we want to run this command: # misc/CA -newreq Once the command has been entered, the program will being generating the request. When asked for the PEM, go ahead and enter it and press enter. Once again you will be asked the same questions about the Distinguished Name (DN). Everything should be the same, except this time when asked for the common name you should enter the complete address of the site you wish to secure (not just the hostname as this will cause internet browsers to see a conflict!). Once you have entered the Common Name you will be asked to create a Challenge Password, create one and write it down. This process should look like this: #misc/CA -newreq The certificate request has now been created and placed in the file /etc/pki/tls/newreq.pem and the private key is in /etc/pki/tls/newkey.pem.
Step 4: Signing The CertificateBefore you move on to the next step you need to consider which of the two routes you are going to take - the self-signed certificate or trusted third-party signed certificate. The choice is entirely up to you. If your website is not for commercial use, you can probably get away with using a self-signed certificate, however, most web browsers will not recognize it as a "trusted website" right away since it does not have the signature of a trusted CA. Alternatively to both the self-signed or purchased methods, I recommend looking into using CACert.org. CACert.org is a completely public, community driven, and FREE CA that is growing. If you want to create a Self-Signed certificate go to Step 4A. If you want to create a Trusted certificate thru a third party go to Step 4B.
Step 4A - The Self Signed CertificateThis is a fairly simple process. Using the shell scripts we can sign our own certificate with ease by running the following command # misc/CA -sign Once executed the program loads the configuration file from the openssl.cnf file. Once it opens the CA key information you will be prompted for the PEM pass phrase, go ahead and enter it. Once the pass phrase is entered the program then verifies the integrity and validity of the data. Once it is done checking, it will ask if you want to sign the certificate, enter "y" and continue. The whole result should look something like this: # misc/CA -sign The certificate has now been self-signed and placed in the /etc/pki/tls directory. Both the private key and the certificate need to be renamed to better identify what server they represent so do the following: # mv newcert.pem hostnameCert.prm That is it! Continue on to step 5 to configure Apache to use the newly created information.
Step 4B - The Trusted CertificateTo get a server certificate created by some third-party company like Thawte, VeriSign, GeoTrust, or CACert.org, look for the certification request file that was created in step 3 (This file can be found in /etc/pki/tls/newreq.pem). Since each CA operates differently, you will have to research which way they want you to submit the data (also called the CSR by some websites)held within this file; however, most places have a simple on-line copy-and-paste procedure, or a file upload system. Once you have submitted the data held in the newreq.pem file you will be given back another batch of code similar to what you submitted. This snippet of code is your new signed/trusted certificate. Once you have that code you will need to save it back to the /etc/pki/tls directory with a filename which makes it easily identifiable such as hostnameCert.pem Once you have completed this step you are ready to move on to Step 5.
Step 5: Configuring Apache To Use Your CertificatesWe must now configure the Apache server to utilize SSL. The first thing we will want to do is copy our newly made certificates to the proper location. Do the following: # cd /etc/httpd/conf In the listing, look for directories called ssl.key and ssl.crt. If they do not exist go ahead and make them: # mkdir ssl.key ssl.crt Once you have found or created the directories, it is time to copy our certificates over: # cp /etc/pki/tls/hostnameCert.pem ssl.crt/server.crt Once you have copied over the files, it is time to configure the Apache server to use them. Do this: # cd /etc/httpd/conf.d You should see a file called ssl.conf. Go ahead and open this file with your favorite editor. There are two thing that need to be changed in this file. They are around lines 112 and 119, it looks like this: # Server Certificate: # Point SSLCertificateFile at a PEM encoded certificate. If # the certificate is encrypted, then you will be prompted for a # pass phrase. Note that a kill -HUP will prompt again. A new # certificate can be generated using the genkey(1) command. SSLCertificateFile /etc/httpd/conf/ssl.crt/localhost.crt Change the SSLCertificateFile path to the new path of /etc/httpd/conf/ssl.crt/server.crt. Then, we need to change the SSLCertificateKeyFile to the new path of /etc/httpd/conf/ssl.key/server.key. Once these changes are made save and quit the editor. If we leave the configuration just as it is now, the SSL will work with a restart of the apache server. However, there is bit of a bump - each time we restart the httpd server it will ask us for the PEM passphrase. This is ok if you are constantly able to monitor the system, but for the sake of saving you that headache let's fix that problem. To fix this issue do the following: # cd /etc/httpd/conf/ssl.key You will be asked to enter the PEM pass phrase, so go ahead and input it and press enter. The program will finish and will have created the key file that will not require you to enter the PEM pass phrase on starting Apache. For security, we need to put security permissions on this file and restart the Apache server: # chmod 700 server.key If everything was done correctly, Apache will start with no problems. Now it is time to try out your new secure website. Open your browser and navigate to https://hostname.yourdomain.com. If you decided to do a self-signed certificate, or one through CACert.org you may get a message about the certificate not being trusted. This is normal and you should just tell the browser to accept the certificate. Once your on the website you should be able to view your certificate and the details on it. Congratulations - you have just set up up an SSL secure website!
|
Join the discussion.
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com







Recent comments
13 hours 24 min ago
14 hours 53 min ago
18 hours 27 min ago
21 hours 20 min ago
1 day 18 min ago
1 day 59 min ago
1 day 1 hour ago
1 day 2 hours ago
1 day 3 hours ago
1 day 3 hours ago