Building A Secure RedHat Apache Server HOWTO
Building A Secure RedHat Apache Server HOWTO
Table of Contents
Building a Secure RedHat Apache Server HOWTO.......................................................................................1 Richard Sigle, Richard.sigle@equifax.com.............................................................................................1 1. Purpose/Scope of this Guide................................................................................................................1 2. Introduction to Secure Sockets Layer/Private Key Infrastructure.......................................................1 3. Working with Certificates....................................................................................................................1 4. Configuring your Apache Server ........................................................................................................1 5. Troubleshooting...................................................................................................................................1 6. Glossary...............................................................................................................................................2 1. Purpose/Scope of this Guide................................................................................................................2 1.1 About Secure Sockets Layer (SSL)...................................................................................................2 1.2 FeedBack ............................................................................................................................................2 1.3 Copyrights and Trademarks...............................................................................................................3 1.4 Acknowledgements and Thanks........................................................................................................3 2. Introduction to Secure Sockets Layer/Private Key Infrastructure.......................................................3 2.1 Responsibilities of SSL/PKI..............................................................................................................3 2.2 How SSL Works................................................................................................................................4 SSL Handshake Protocol............................................................................................................4 Session Key(Symmetric Code)...................................................................................................5 Public/Private Key Pair(Asymmetric Code)...............................................................................5 2.3 How PKI Works .................................................................................................................................5 2.4 Certificates(x509 Standard)...............................................................................................................6 2.5 Digital Certificate Private Key ...........................................................................................................6 2.6 Digital Certificate Public Key ............................................................................................................7 2.7 Certificate Signing Request(CSR).....................................................................................................7 3. Working with Certificates....................................................................................................................7 3.1 Create a Private Key..........................................................................................................................7 3.2 Create a Certificate Signing Request.................................................................................................8 3.3 Creating a SelfSigned Certificate....................................................................................................8 3.4 Installing your Web Server Certificate..............................................................................................9 4. Configuring your Apache Server .......................................................................................................9 4.1 Define a Secure Virtual Host.............................................................................................................9 SSL Engine...............................................................................................................................10 SSLCertificateFile....................................................................................................................10 SSLCertificateKeyFile..............................................................................................................10 SSLCACertificateFile...............................................................................................................11 4.2 Certificate Examples........................................................................................................................11 Server Certificate File...............................................................................................................11 Contents of the Certificate File.................................................................................................11 Private Key File........................................................................................................................12 Contents of the Private Key......................................................................................................12 4.3 Restart the Web Server....................................................................................................................13 5. Troubleshooting.................................................................................................................................14 5.1 Server Appears to start, but you cannot access the secure site........................................................14 5.2 Certificate Name Check Warning is issued by the client's browser................................................15 5.3 Certificate was Signed by an Untrusted Certificate Authority Warning is issued by the client's browser ...................................................................................................................................................15 5.4 SSLEngine on is an unrecognized command (when starting Apache)..........................................15 5.5 You have forgotten your "PEM Passphrase" and you would like to know how to reset it.............15 i
Table of Contents
6. Glossary.............................................................................................................................................15
ii
The guide is designed to explain how PKI and SSL work together. It is essential to understand how the SSL protocol works to successfully deploy a secure server.
5. Troubleshooting
5.1 Server Appears to start, but you cannot access the secure site 5.2 Certificate Name Check Warning is issued by the client's browser Building a Secure RedHat Apache Server HOWTO 1
Building a Secure RedHat Apache Server HOWTO 5.3 Certificate was Signed by an Untrusted Certificate Authority Warning 5.4 SSLEngine on is an unrecognized command (when starting Apache) 5.5 You have forgotten your "PEM Passphrase" and you would like to know
1.2 FeedBack
Comments on this guide may be directed to the author ([email protected]).
6. Glossary
Building a Secure RedHat Apache Server HOWTO with A's private key and then with B's public key. B now has to decrypt it first with his private key and then with A's public key. Now B can be sure that A is who he claims to be as nobody else could create a message encrypted with his private key. SSL achieves this with the use of certificates (PKI). A certificate is issued by a neutral third party such as a certificate authority (CA) and includes a digital signature and/or a time stamp in addition to the public key of the certified party. A selfsigned digital certificate can be created by anyone with the correct SSL tools, but selfsigned certificates lack the weight of validation performed by a mutually respected neutral third party. integrity In SSL, integrity is guaranteed by using a MAC (Message Authentication Code) with the necessary hash table functions. Upon generation of a message, the MAC is obtained by applying a hash function and the result is then added to the message. After the message has been received, validity is then checked by comparing the message's embedded MAC with a new MAC computed from the received message. This would immediately reveal messages that have been altered by a third party. NonRepudiation Nonrepudiation protects both parties from each other during online transactions. It prevents one or the other from saying that they did not send a particular piece of information. Nonrepudiation does not allow either party to alter the transaction after it has been made. Digital nonrepudiation is the equivalent of signing a contract, in the traditional sense.
Building a Secure RedHat Apache Server HOWTO The client then generates a random key (symmetric key). These will be used for encryption and for calculating MACs. They are encrypted using the server's public key and sent to the server. Only the server has the ability to decrypt the new random key. The new symmetric key is used for encrypting the data that is sent between client and server. Note: The use of a symmetric key after serverbrowser authentication greatly enhances subsequent throughput performance. A message encryption algorithm and a hash function for integrity are negotiated. This negotiation process could be carried out such that the client presents a list of supported algorithms to the server, which, in turn, selects the strongest cipher available to both of them. Identifiers for the chosen encryption algorithm and hash function are stored in the cipher spec field of the current state for use by the record protocol. All of the following fields are set during handshaking: Protocol Version, Session ID, Cipher Suite, Compression Method and two random values ClientHello.random and ServerHello.random. Note: An IP address is required for each SSL connection. Name based virtual hosts are resolved during the application layer. Remember Secure Sockets Layer resides below the application layer.
Building a Secure RedHat Apache Server HOWTO as the fingerprint) to the message. The digest (which is now known as the signature) is attached or appended to the message. The signature's length is constant (no matter how large the file is) and depends on what type of message digest the private key contains (md5 128 bit, sha1 160 bit, etc). Changing even one bit in the message will change the length of the signature and thus prove that the message has been tampered with.
You will be prompted to enter and reenter a pass phrase. If you choose to use triple des encryption, you will be prompted for the password each time you start the SSL server from a cold start. (When using the restart command, you will not be prompted for the password). Some of you may find this password prompt to be a nuisance, especially if you need to boot the system during offhours. Or, you may believe that your system is already sufficiently secure. So, if you choose not to have a password prompt (hence no triple des encryption), use the command below. If you would rather create just a 512bit key, then omit the 1024 at the end of the command and OpenSSL will default to 512 bits. Using the smaller key is slightly faster, but it is also less secure. To create a private key without triple des encryption, use the following command:
openssl genrsa out filename.key 1024
To remove a password from an existing private key, use the following command: 2.6 Digital Certificate Public Key 7
Note: Your private key will be created in the current directory unless otherwise specified. There are 3 easy ways to deal with this. If OpenSSL is in your path, you can run it from the directory that you have designated to store your key files in (default is /etc/httpd/conf/ssl.key if you installed Apache using the RPM or /usr/local/apache/conf/ssl.key if you installed Apache using the source files). Another solution is to copy the files from the directory where they were created to the correct directory. And, last but not least, you can specify the path when running the command (eg. openssl genrsa out /etc/httpd/conf/ssl.key/filename.key 1024). Doesn't matter how you do it as long as it gets done before you proceed. For more information on the OpenSSL toolkit check out: OpenSSL Website.
You will be prompted for Locality information, common name (domain name), organizational information, etc. Check with the CA that you are applying to for information on required fields and invalid entries. Send the CSR to the CA per their instructions. Wait for your new certificate and/or create a selfsigned certificate. A selfsigned certificate can be used until you receive your certificate from the certificate authority. Note: Use the following command to create a private key and request at the same time.
openssl genrsa des3 out filename.key 1024
Building a Secure RedHat Apache Server HOWTO In these examples, I use the .crt and .key file extensions. That is my personal way of avoiding confusion with the various files. With Apache, you can use any extension you choose or no extension at all. All of your secure virtual hosts should be contained within <IfDefine SSL> and </IfDefine SSL>, usually located towards the end of the httpd.conf file. An example of a secure virtual host:
<VirtualHost 172.18.116.42:443> DocumentRoot /etc/httpd/htdocs ServerName www.somewhere.com ServerAdmin [email protected] ErrorLog /etc/httpd/logs/error_log TransferLog /etc/httpd/logs/access_log SSLEngine on SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key SSLCACertificateFile /etc/httpd/conf/ssl.crt/cabundle.crt <Files ~ "\.(cgi|shtml)$"> SSLOptions +StdEnvVars </Files> <Directory "/etc/httpd/cgibin"> SSLOptions +StdEnvVars </Directory> SetEnvIf UserAgent ".*MSIE.*" nokeepalive ssluncleanshutdown CustomLog /etc/httpd/logs/ssl_request_log \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost>
The directives that are the most important for SSL are the SSLEngine on, SSLCertificateFile, SSLCertificateKeyFile, and in many cases SSLCACertificateFile directives.
SSL Engine
"SSLEngine on" this is ModSSL's command to start SSL.
SSLCertificateFile
SSLCertificateFile Tells Apache where to find the certificate file and what it is named. The example above shows "server.crt" as the certificate file name. This is the default that is added when you configure ModSSL with Apache. I personally don't recommend using the default names. Save yourself some frustration and name your certificates as servername.crt (domainname.crt). You may also decide to use an alternative directory than the default /etc/httpd/conf/ssl.crt or /usr/local/apache/conf/ssl.crt. Just remember to make the necessary changes to the path.
SSLCertificateKeyFile
SSLCertificateKeyFile tells Apache the name of the private key and where to find it. The directory defined here should have read/write permissions for root only. No one else should have access to this directory.
SSL Engine
10
SSLCACertificateFile
The SSLCACertificateFile directive tells Apache where to find the Intermediate (root) certificate. This directive may or may not be necessary depending on the CA that you are using. This certificate is essentially a ring of trust. Intermediate Certificate A Certificate Authority obtains a certificate in much the same way as you. This is known as an intermediate certificate. It basically says that the holder of the intermediate certificate is whom they say they are and is authorized to issue certificates to customers. Web browsers have a list of "trusted" certificate authorities that is updated with each release. If a Certificate authority is fairly new, its intermediate certificate may not be in the browser's list of trusted CA's. Combine this with the fact that most people don't update their browsers very often; it could take years before a CA is recognized as trusted automatically. The solution is to install the intermediate certificate on the server using the SSLCACertificateFile directive. Usually, a "trusted" CA issues the intermediate certificate. If it is not, then you may need to use the SSLCertificateChainFile directive, although this is unlikely.
Certificate: Data: Version: 3 (0x2) Serial Number: 1516 (0x5ec) Signature Algorithm: md5WithRSAEncryption Issuer: C=US, O=Equifax Secure Inc, CN=Equifax Secure EBusiness CA Validity Not Before: Jul 12 15:21:01 2000 GMT Not After : Jun 2 22:42:34 2001 GMT Subject: C=us, ST=ga, L=atlanta, O=Equifax, OU=Rick, CN=172.18.116.44/Email=richard.si Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public Key: (1024 bit) Modulus (1024 bit):
SSLCACertificateFile
11
12
13
or
apachectl stop apachectl startssl apachectl restart
5. Troubleshooting
Here are some common problems that may arise.
5.1 Server Appears to start, but you cannot access the secure site
Check the error_log file. If you did not set your virtual host to write to an error log, you may want to reconsider. The example SSL virtual host writes to an error log file. Most likely you will have a few warnings and an error at the end of the log that basically say that the private key does not match the certificate. Example:
[Tue Nov 21 09:09:02 2000] [notice] Apache/1.3.14 (Unix) mod_ssl/2.7.1 OpenSSL/0.9.6 configured resuming normal operations [Tue Nov 21 09:09:16 2000] [notice] caught SIGTERM, shutting down [Tue Nov 21 14:39:54 2000] [notice] Apache/1.3.14 (Unix) mod_ssl/2.7.1 OpenSSL/0.9.6 configured resuming normal operations [Tue Nov 21 14:40:31 2000] [notice] caught SIGTERM, shutting down [Tue Nov 21 14:43:53 2000] [error] mod_ssl: Init: (esi.fin.equifax.com:443) Unable to configure RSA server private key (OpenSSL library error follows) [Tue Nov 21 14:43:53 2000] [error] OpenSSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch
If you get the error messages above, chances are the key and certificate do not match. Make sure you aren't using the default server.key file. You should also check the httpd.conf file to make sure that the directives are pointing to the correct private key and certificate. You can check to make sure that you your private key and certificate are in the correct format and match each other. To do this, give the commands below to decrypt the private key in one terminal window and decrypt the certificate in the other. What you will be comparing are the Modulus and the Exponent of each key. If the modulus and exponent from the key matches the set from the certificate, you have just confirmed that your certificate and key are correctly paired. If all else fails, create a new private key, CSR or selfsigned certificate. Before you do this, check your CA's reissue policy. You may be charged for a reissue. To view the contents of the certificate:
openssl x509 noout text in filename.crt
5. Troubleshooting
14
5.3 Certificate was Signed by an Untrusted Certificate Authority Warning is issued by the client's browser
If you are using a selfsigned certificate, you will get this warning. Your clients will be given the option to trust your certificate or not. If you have a CA signed certificate and are getting the untrusted warning, you probably need to install their intermediate (root) certificate.
5.5 You have forgotten your "PEM Passphrase" and you would like to know how to reset it
There is no way to reset this passphrase. The only solution is to remember the passphrase or create a new private key. You will then need to obtain a new certificate or create a new selfsigned certificate.
6. Glossary
Authentication The positive identification of a network entity such as a server, a client, or a user. In SSL context, authentication represents the server and client Certificate verification process. Access Control The restriction of access to network realms. In Apache context usually the restriction of access to certain URLs. Algorithm 5.2 Certificate Name Check Warning is issued by the client's browser 15
Building a Secure RedHat Apache Server HOWTO An unambiguous formula or set of rules for solving a problem in a finite number of steps. Algorithms for encryption are usually called Ciphers. Certificate A data record used for authenticating network entities such as a server or a client. A certificate contains X.509 information pieces about its owner (called the subject) and the signing Certificate Authority (called the issuer), plus the owner's public key and the signature made by the CA. Network entities verify these signatures using CA certificates. Certificate Authority (CA) A trusted third party whose purpose is to sign certificates for network entities that it has authenticated using secure means. Other network entities can check the signature to verify that a CA has authenticated the bearer of a certificate. Certificate Signing Request (CSR) An unsigned certificate for submission to a Certification Authority, which signs it with the Private Key of their CA Certificate. Once the CSR is signed, it becomes a real certificate. Cipher An algorithm or system for data encryption. Examples are DES, IDEA, RC4, etc. Ciphertext The result after a Plaintext passed a Cipher. Configuration Directive A configuration command that controls one or more aspects of a program's behavior. In Apache context these are all the command names in the first column of the configuration files. Cryptography Symmetric The client and server use the same key to encrypt and to decrypt data. Cryptography Asymmetric Consists of a key pair (public and private). PKI is Asymmetric Cryptography Digital Signatures A piece of data that is sent with an encrypted message that identifies the originator and verifies that it has not been altered. HTTPS The HyperText Transport Protocol (Secure), the standard encrypted communication mechanism on the World Wide Web. This is actually just HTTP over SSL. Message Digest
16
Building a Secure RedHat Apache Server HOWTO A hash of a message, which can be used to verify that the contents of the message have not been altered in transit. Nonrepudiation A service that provides proof of the integrity and origin of data, both in an nonforgeable relationship, which can be verified by any third party at any time, or, an authentication that with high assurance can be asserted to be genuine. A property achieved through cryptographic methods which prevents an individual or entity from denying having performed a particular action related to data (such as mechanisms for nonrejection or authority (origin); for proof of obligation, intent, or commitment, or for proof of ownership). OpenSSL The Open Source toolkit for SSL/TLS; see http://www.openssl.org/ Pass Phrase The word or phrase that protects private key files. It prevents unauthorized users from encrypting them. Usually it's just the secret encryption/decryption key used for Ciphers. Plaintext The unencrypted text. Private Key The secret key in a Public Key Cryptography system, used to decrypt incoming messages and sign outgoing ones. Public Key The publicly available key in a Public Key Cryptography system, used to encrypt messages bound for its owner and to decrypt signatures made by its owner. Public Key Cryptography The study and application of asymmetric encryption systems, which use one key for encryption and another for decryption. A corresponding pair of such keys constitutes a key pair. Also called Asymmetric Cryptography. Secure Sockets Layer (SSL) A protocol created by Netscape Communications Corporation for general communication authentication and encryption over TCP/IP networks. The most popular usage is HTTPS, i.e. the HyperText Transfer Protocol (HTTP) over SSL. Session The context information of an SSL communication. 5.2 Certificate Name Check Warning is issued by the client's browser 17
Building a Secure RedHat Apache Server HOWTO SSLeay The original SSL/TLS implementation library developed by Eric A. Young <[email protected]>; see http://www.ssleay.org/ Symmetric Cryptography The study and application of Ciphers that use a single secret key for both encryption and decryption operations. Transport Layer Security (TLS) The successor protocol to SSL, created by the Internet Engineering Task Force (IETF) for general communication authentication and encryption over TCP/IP networks. TLS version 1 and is nearly identical with SSL version 3. Uniform Resource Locator (URL) The formal identifier to locate various resources on the World Wide Web. The most popular URL scheme is http. SSL uses the scheme https X.509 An authentication certificate scheme recommended by the International Telecommunication Union (ITUT) and used for SSL/TLS authentication. ITUT Recommendation X.509 [CCI88c] specifies the authentication service for X.500 directories, as well as the X.509 certificate syntax. Directory authentication in X.509 can be carried out using either secretkey techniques or publickey techniques; the latter is based on publickey certificates. The standard does not specify a particular cryptographic algorithm, although an informative annex of the standard describes the RSA algorithm.
18