OpenSSL Certificate Authority notes

Alexander Wintermans

I have yet to decide under which license this document can be redistributed.


Table of Contents

1. Introduction
2. Creating a Certificate Authority
3. Creating a server certificate
3.1. Creating a server certificate request
3.2. Signing a certificate request
4. Inspecting objects
4.1. Examining a key
4.2. Examining a certificate
4.3. Examining a certificate request

1. Introduction

This document is intended as an instruction for creating your own certificate authority for signing certificates for use with all sorts of SSL connections (e.g. HTTPS, LDAPS). It is intended for small-scale work. It does not consider CRLs. The certificate authority may be used to sign any kind of certificate.

This document was made using the following (debian) packages.

PackageVersion
openssl0.9.7c-5

2. Creating a Certificate Authority

  1. Create directory structure:

      # mkdir /etc/certificateAuthority
      # cd /etc/certificateAuthority
    
      # mkdir certs
      # mkdir private
      # chmod 700 private
    
      # echo '01' > serial
      # touch index.txt

  2. Edit /etc/ssl/openssl.cnf:

    1. Change the following properties in the [CA_default] section:

         dir             = /etc/certificateAuthority
         new_certs_dir   = $dir/certs
         copy_extensions = copy                        # Only copy requested
                                                       #  extensions that are not
                                                       #  defined in [usr_cert]
         default_days    = 1825                        # certification lasts 5 years
         policy          = policy_anything
         # Set display options
         nameopt         = ca_default
         certopt         = ca_default

    2. Delete the following properties in the [CA_default] section:

         certs =
         crl_dir =
         crl =

    3. Change the following properties in the [req_distinguished_name] section as appropriate:

         countryName_default         = NL
         stateOrProvinceName_default = Noord Holland
         localityName_default        = Amsterdam
         0.organizationName_default  = joe.org
         commonName_default          = J. Bloggs
         emailAddress_default        = ca.admin@joe.org

    4. Change the following properties in the [v3_ca] section:

         keyUsage = cRLSign, keyCertSign
         nsCertType = sslCA, emailCA, objCA

  3. Create the certificate authority key:

      # openssl genrsa -des3 -out private/cakey.pem 2048
    Remember the pass phrase! Better yet, since you won't be needing it often (key signing is probably not an every-day activity for you), write it down somewhere safe.

  4. Create the certificate authority's (self-signed) certificate:

      # openssl req -new -x509 -key private/cakey.pem -days 1825 -out cacert.pem -outform PEM
      # cp cacert.pem /etc/ssl/certs

  5. Create a certificate request configuration template:

    1.   # cp /etc/ssl/openssl.cnf /etc/ssl/openssl_server_req.template
    2. Remove the following sections:

      • [ca]

      • [CA_default]

      • [policy_match]

      • [policy_anything]

      • [usr_cert]

      • [v3_ca]

      • [crl_ext]

    3. Change the following properties in the [v3_req] section:

        nsCertType     = server
        subjectAltName = @altdns

    4. Change the following properties in the [req] section:

        default_bits       = 2048
        default_keyfile    = /etc/ssl/private/SERVER_ID_key.pem
        encrypt_key        = no
        prompt             = no
        #  x509_extensions = v3_ca
        req_extensions     = v3_req

    5. Change the following properties in the [req_distinguished_name] section:

        countryName         = NL
        stateOrProvinceName = Noord Holland
        localityName        = Amsterdam
        organizationName    = joe.org
        commonName          = SERVER_NAME
        emailAddress        = SERVER_ID.admin@joe.org

    6. Comment out the following properties in the [req_attributes] section:

        # challengePassword = Not needed
        # unstructuredName  =

    7. Add a section [altdns] with the following properties:

        DNS.1 = ALT_SERVER_NAME_1
        DNS.2 = ALT_SERVER_NAME_2
        DNS.3 = ALT_SERVER_NAME_3

3. Creating a server certificate

This section demonstrates how to create a certificate for an SSL-enabled LDAP server.

3.1. Creating a server certificate request

  1. Create a request configuration file:

      # cp /etc/ssl/openssl_server_req.template /etc/ssl/ldap_req.cnf

  2. Change the following property in the [req] section:

      default_keyfile = /etc/ssl/private/ldap_key.pem

  3. Change the following properties in the [req_distinguished_name] section:

      commonName = ldap.intra.net
      emailAddress = ldap.admin@joe.org

  4. Change the [altdns] section to add alternative names for the server (in case it has them):

      DNS.1 = joesmachine.hisisp.net
      DNS.2 = server1.intra.net
      DNS.3 = ldap.joe.org
      DNS.4 = localhost
      IP.1  = 192.168.120.30
      IP.2  = 163.61.64.62
      IP.3  = 127.0.0.1

  5. Generate the certificate request:

      # cd
      # openssl req -config /etc/ssl/ldap_req.cnf -newkey rsa:2048 -out ldapreq.pem -outform PEM
      # chmod 400 /etc/ssl/private/ldap_key.pem

3.2. Signing a certificate request

  # openssl ca -in ldapreq.pem -out /etc/ssl/certs/ldap.pem

4. Inspecting objects

4.1. Examining a key

  # openssl rsa -in /etc/ssl/private/ldap_key.pem -text

4.2. Examining a certificate

  # openssl x509 -in /etc/certificateAuthority/cacert.pem -text

4.3. Examining a certificate request

  # openssl req -in ldapreq.pem -text