There are two things you need to do.
First, you need to generate certificates for the browsers that you are going to have connected.
Then, you need to set Apache to require these certs for some folder.
The apache portion is simple - just add this to your /etc/apache2/sites-enabled/your_apache_file.conf:
<Location /path/to/folder>
SSLVerifyClient require
SSLVerifyDepth 1
</Location>
Now assuming you've set up your apache SSL like this:
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
SSLCACertificateFile /etc/apache2/ssl/ca.crt
SSLVerifyClient optional
SSLOptions +StdEnvVars +ExportCertData
You also need to set yourself up as a CA.
Here is a chunk of Python code we use for generating client certs - this should give you a good idea of what you need to do from here:
commonname = "name_of_client_machine"
serial_file = open('/usr/local/my/web/certs/ca.srl','r')
serial = serial_file.read().strip()
cert_folder = '/usr/local/my/web/certs/clients/%s_%s' % (serial,commonname)
try:
os.makedirs(cert_folder, 0755)
except OSError:
pass
commands.getstatusoutput("sed s/hostname/%s/ /usr/local/my/web/certs/client.tpl > %s/client.tpl" % (commonname,cert_folder))
commands.getstatusoutput("openssl genrsa -des3 -passout pass:mypassword -out %s/web_client.key 4096" % cert_folder)
commands.getstatusoutput("openssl req -new -key %(cert_folder)s/web_client.key -out %(cert_folder)s/web_client.csr -config %(cert_folder)s/client.tpl -passin pass:mypassword" % ({'cert_folder':cert_folder}))
commands.getstatusoutput("openssl x509 -req -days 3650 -in %(cert_folder)s/web_client.csr -CA /usr/local/my/web/certs/ca.crt -CAkey /usr/local/my/web/certs/ca.key -out %(cert_folder)s/web_client.crt -passin pass:mypassword" % ({'cert_folder':cert_folder}))
commands.getstatusoutput("openssl pkcs12 -export -clcerts -in %(cert_folder)s/web_client.crt -inkey %(cert_folder)s/web_client.key -out %(cert_folder)s/web_client.P12 -passin pass:mypassword -passout pass:mypassword" % ({'cert_folder':cert_folder}))
Now you take the .p12 file and you import it into the client browser. You will be asked for the password (which above was just 'mypassword'), and then it will be installed and ready to go.