Web - Being your own CA and SSL Certs for Apache


2002-11-20
I - Being your own CA

If you installed sources you can find CA.sh in /usr/src/crypto/openssl/apps. Otherwise you can install the port.

# cd /usr/ports/security/openssl
# make install

# cd /usr/local/openssl/misc
# ./CA.sh -newca

The CA.sh script will ask you a series of questions. The answers I used are in bold:
Country: US
State: California
Locality: Highland
Organizational Name: Plumbing Co
Organizational Unit Name: Daemon Hunters
Common Name: PLUMBING CA

This will generate cacert.pem which you will want to put someplace where users can download and import into their browsers.

I copied cacert.pem to /home/webmail/squirrelmail-1.2.9/csci.cacert and I added the following line to the end of “/usr/local/apache2/conf/mime.types”:

“application/x-x509-ca-cert cacert”

II - Creating an SSL Certificate for Apache

# cd /usr/local/openssl/misc
# openssl req -new -nodes -keyout key.pem -out req.pem -days 365

Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:California
Locality Name (eg, city) []:Highland
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Plumbing Co
Organizational Unit Name (eg, section) []:Web Folks
Common Name (eg, YOUR name) []:mail.akxnet.org
Email Address []:admin@akxnet.org

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:[enter]
An optional company name []:[enter]

Run this command to sign your certificate:

# openssl ca -policy policy_anything -out cert.pem -infiles req.pem

III - Configure Apache

# cp cert.pem /usr/local/etc/apache2/
# cp key.pem /usr/local/etc/apache2/

Edit the following lines in /usr/local/etc/apache2/ …

# vi /usr/local/etc/apache2/ssl.conf

SSLCertificateFile /usr/local/etc/apache2/cert.pem
SSLCertificateKeyFile /usr/local/etc/apache2/key.pem

To Start Apache with SSL type…

# apachetcl stop
# apachectl startssl

Note: To restart Apache DO NOT USE “apachectl restart”. You must completely stop Apache then start it back up with “startssl”

If you don’t want the Warning to popup each time someone visits your site just point them to a url that will install your CA Certificate (cacert.pem).

To output a cacert you can distrubute to users… openssl x509 -in cacert.pem -inform pem -out cacert.der -outform der