The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
Client Authentication with SSL
12 July 2001
|
Most of you will be aware that I'm in the process of setting up a new box for the website. As part of that process, I'm strengthening some of the administration functions. Specifically, I'm adding client authentication to make that that only my browser can access these features. In short, only specific people will be able to access certain areas of my website. These people will be authenticated using client authentication. If you're actually looking for how to set up an https server, please try Apache with SSL. Or if you're looking for something more simple than certificates, you could just use passwords. But first, let me introduce a few terms and explain a few things in order to give you a bit of background.
|
Other resources
|
Introducing SSL and Certificates using SSLeay by Frederick J. Hirsch. We're going to be using X.509 certificates so perhaps this document might be useful: http://java.sun.com/products/jdk/1.2/docs/guide/security/cert3.html |
Certificates
|
Certificates tell us who is who. A certificate ensures that the website you are talking to is indeed the website you think it is and who it says it is. But how can you trust that a certificate hasn't been forged. Because it's been signed by someone you trust. Well, not necessarily someone that you personally trust, but someone that is widely regarded as a Trusted Authority. For example, Baltimore, RSA, VeriSign and, Thawte each issue certificates. If I look at my MS IE browser, I can find a long list of trusted root certicate authorities. Your broswer probably contains a similar list. https and SSL is all about trust. This trust has to start somewhere. Usually it starts with a signing authority which is trusted implicitly. From there, anything signed by that authority can be trusted. And so on... My description is a rather simplistic approach to what can be a very complex matter. But it should suffice for what we're trying to accomplish here. The whole idea of SSL is to get the data securely between a web server and a client. That is accomplished by encryption. The first time a client accesses a web server that uses SSL, the client is presented with an the certificate. This information allows the client to determine three important things:
If any of these three conditions are not met, the client browser will display a popup that explain the violations and requests premission to continue browsing. When you install an SSL-capable browser, it should include a list of certificates of widely known trusted parties. Part of the reason why you don't see any popup certificate window when you enter Amazon's secure area is that their certificate was signed by an authority known to your broswer. For our purposes, we're going to fake it. We're going to create our own certificate authority. For our own personal use. We'll call it a personal CA. And we'll use it to create personal certificates. We could ask a real certificate authority to give us a certificate signed by them. But we don't need that. Plus, that signing process normally costs money. In this instance, I'm the only person that's going to be using this certificate. I trust myself. So I don't need someone else to create the certificate when I can do it myself. I won't be able to use this certificate for "real" purposes. It can be used only for my own use. Nobody else will trust it. So it's useful for commercial purposes (i.e. I won't be able to put it on my webserver and expect people to give me their credit card details). If you are going to need a real certificate, pay your money and get one. |
Certificate Authority
|
For this step, I found HOWTO: Creating your own CA with OpenSSL by Pheng Siong Ng to be very useful. With this information, I was able to create my own certification authority (CA) with OpenSSL (note that VeriSign is also a CA, albeit a much better known CA than the one you just created). Then I used that CA to sign a certificate request. This is what VeriSign would do if you ask them for a certificate. If you have more than one web server in your organisation, it is a good idea to have the same CA sign all of the certificates. The HOWTO document referenced above actually does more than just create a CA. It also shows you how to create a server certificate and then sign it. I think it's important to distinguish between the two processes, so I will break up the HOWTO steps into two sections:
|
Certificate Authority - creation
|
I'll outline the steps I took but please refer to the primary document for full information on what I'm doing here.
|
Server Certificate - creation
|
In this section we'll create a server certificate request and then sign that request using the CA we created in the previous section.
|
File names should reflect file contents
|
For ease of use, I moved things around so the file names reflected the file contents. mv newcert.pem server_cert.pem mv newkey.pem server_key.pem mv newreq.pem server_req.pem |
OK. What did I just do?
|
In summary, you now have the following items:
|
Create the secure area of your website
|
The creation of an https server is beyond the scope of this article. Perhaps Apache with SSL will help you with that. What I'm going to show you is how to allow clients to visit most of the website but require authentication to visit a particular URL. I found exactly what I wanted at the How To section of the mod_ssl website. I'm using the mod_ssl port on my web server. In this example, we want to control access to the SSLEngine on SSLProtocol all SSLCipherSuite HIGH:MEDIUM SSLCertificateFile /usr/local/etc/apache/ssl.crt/server_cert.pem SSLCertificateKeyFile /usr/local/etc/apache/ssl.key/server_key.pem SSLVerifyClient none SSLCACertificatePath configuration/certificates SSLCACertificateFile configuration/certificates/cacert.pem <Location /stuff> SSLVerifyClient require SSLVerifyDepth 1 </Location> I'll explain some of the above with the following:
After setting up the above directives, you should verify the settings: and make any changes as necessary. Then I would stop and start the server. This is necessary because you are changing certificate information./usr/local/sbin/apachectl configtest You should then check for any error messages:/usr/local/etc/rc.d/apache.sh stop /usr/local/etc/rc.d/apache.sh start $ tail /var/log/httpd-error.log [notice] caught SIGTERM, shutting down [notice] Apache/1.3.20 (Unix) PHP/4.0.6 mod_ssl/2.8.4 OpenSSL/0.9.6 configured -- resuming normal operations |
Converting the certificate to pkcs12 format
|
The signed server certificate to be converted into the format used by programs such as Netscape, MSIE and MS Outlook. Fortunately, I've been pointed at the right place by my friend Eric Rosenquist. To do the conversion I used this command: Make up a password, use it, and remember it. This password will be required when you go to import the certificate into your browser. Remember it.$ openssl pkcs12 -export -in server_cert.pem -inkey server_key.pem -out iestuff.p12 Enter Export Password: Verifying password - Enter Export Password: |
Security considerations
|
Be careful with your certificates and keys. If someone steals your certificate, they can't be authenticated over SSL as you unless they also have your private RSA key. Your private key is included in the .p12 file. Thus, if someone gains access to your .p12 file, they can impersonate you. Simply being aware of this is a good start. |
Import the certificate
|
If you were to browse to your secure area now, you would be warned about the site certificate. Since we know we created our own certificate, we could view the certificate to verify that it's the one we expect, and then click on Yes to proceed. Then you will be presented with a message asking which certificate you wish to use. You would also be given a list of certificates to select from. This step allows you to import a certificate into your browser. Instructions are supplied only for MSIE.
You'll need the
|
Revoking a certificate
|
A CA can revoke a certificate it has issued. This may be for a number of reasons but a prime reason would be a certificate compromise: someone has accessed the private key associated with a certificate and it needs to be revoked for security reasons. Each CA should publish a list of revoked certificates. This list is known as a Certificate Revocation List (CRL). Normally these lists are publically availble so that a server can check it before accepting a given certificate. That said, in my instance, I'm not doing a CRL yet, because I'm the only person using these certificates. These resources might help: |
Browsing again
|
I found that I had to stop and restart my broswer in order for the certificate to "take". I think it caches old results from the previous attempts. After a restart, I broswed again to the secure area of my website. I was presented, again, with the security alert message. But if you created a certificate which matches the name of your website, you should see this picture instead. After accepting that server certificate, I was presented with the list from before, only this time, it contained my imported certificate. I selected that certificate. Had I had more than one certificates installed on my browser, I would have choosen the right one for the site I'm browsing. After the certificate was selected, the server authenticated me, and I was allowed into the secure area of my website. |
Thanks
|
I thank the following people, who appear in no particular order, for their help in composing this article.
It's very useful to have technical reviewers. My understanding was greatly enhanced by their feedback. It is appreciated. |
Summary
|
SSL is a protocol for ensuring that your communications are encrypted and secure. OpenSSL is an implementation of SSL. Certificates are used to ensure people and/or websites are who they say they are. You can use SSL client certificates to restrict access to various areas of your websites. Or indeed the whole website (I didn't cover that part, but that is easily extended; read the modSSL how to). The above should get you started. If you had to do something different, please add your comments. |