Skip to main content

Tutorial: Configure External PKI with OpenSSL

Abstract

How to set up the Access Server External PKI (Public Key Infrastructure) feature using the OpenSSL tool.

Overview

The Access Server external public key infrastructure (PKI) feature integrates Access Server with third-party tools for X509 PKI management instead of using the built-in certificate management capabilities.

When configured for external PKI usage, Access Server doesn't manage client certificates directly; instead, the customer's third-party PKI software generates and distributes client certificate/key pairs to client machines and a server certificate/key pair to the OpenVPN server.

This tutorial shows you how to set up external PKI using OpenSSL.

At a high level, these are the steps for your configuration:

  1. Modify as.conf to set Access Server in external PKI mode.

  2. Create the server CA using OpenSSL commands.

  3. Generate the server certificate and key via OpenSSL commands.

  4. Generate the client certificate and key via OpenSSL commands.

  5. Create the TLS_auth key.

  6. Generate Diffie Hellman parameters.

  7. Import the necessary certificate and key files to Access Server.

  8. Provide certificate/key pairs in a P12/PFX file to the VPN client.

  9. Generate and download a server-locked profile for the client.

  • An installed Access Server.

  • A machine with OpenSSL installed. This could be the same Linux where Access Server is installed or an external machine.

  • Console access and the ability to get root access.

  • An OpenVPN client that supports the macOS Keychain and Windows certificate store.

  1. Connect to the Access Server console and get root privileges.

  2. Edit as.conf for external PKI usage:

    nano /usr/local/openvpn_as/etc/as.conf
  3. Comment out certs_db:

    # certificates database
    # certs_db=sqlite:///~/db/certs.db
  4. Save and exit the file — ctrl+x, y, then enter.

    • Access Server no longer uses the certificate database. Instead, an external system must handle this.

  1. Run the below command to generate the CA key:

    openssl genpkey -algorithm RSA -out ca.key -pkeyopt rsa_keygen_bits:2048
  2. Run the below command to generate the CA certificate:

    openssl req -new -x509 -key ca.key -out ca.crt -days 3650 -subj "/CN=OpenVPN CA"
    • From the above commands, you get two files:

      1. CA key (ca.key)

      2. CA certificate (ca.crt)

  1. Open the openssl.cnf file to edit (we use nano):

    nano /etc/ssl/openssl.cnf
  2. Look for the section [ req ] and add the below line in that section:

    req_extensions = v3_req
  3. Look for the section [ v3_req ], remove/mask the content of this section, and add the below lines in that section:

    basicConstraints = critical, CA:FALSE
    keyUsage = critical, digitalSignature, keyEncipherment
    extendedKeyUsage = serverAuth
  4. Save and exit the file — ctrl + x, y, save with a new name (e.g., openssl-server.cnf), then enter.

  1. Open the openssl.cnf file to edit (we use nano):

    nano /etc/ssl/openssl.cnf
  2. Look for the section [ req ] and add the below line in that section:

    req_extensions = v3_req
  3. Look for the section [ v3_req ], remove/mask the content of this section, and add the below lines in that section:

    basicConstraints = critical, CA:FALSE
    keyUsage = critical, digitalSignature
    extendedKeyUsage = clientAuth
    nsCertType = client
  4. Save and exit the file — ctrl + x, y, save with a new name (e.g., openssl-client.cnf), then enter.

  1. Run the below command to generate the server key:

    openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048
  2. Run the below command to generate the server CSR with the server key and the custom OpenSSL file created in Step 3:

    openssl req -new -key server.key -out server.csr -subj "/CN=OpenVPN Server" -config /etc/ssl/openssl-server.cnf
  3. Run the below command to generate the server certificate with the custom OpenSSL file created in Step 3:

    openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -extfile /etc/ssl/openssl-server.cnf -extensions v3_req
    • From the above commands, you get three files:

      1. Server key (server.key)

      2. Server certificate (server.crt)

      3. Server CSR (server.csr)

  1. Run the below command to generate the client key:

    openssl genpkey -algorithm RSA -out client.key -pkeyopt rsa_keygen_bits:2048
  2. Run the below command to generate the client CSR with the client key and the custom OpenSSL file created in Step 4:

    openssl req -new -key client.key -out client.csr -subj "/CN=etest" -config /etc/ssl/openssl-client.cnf
  3. Run the below command to generate the client certificate with the custom OpenSSL file created in Step 4:

    openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 -extfile /etc/ssl/openssl-client.cnf -extensions v3_req
  4. Generate a P12 file with the client certificate and key:

    openssl pkcs12 -export -inkey client.key -in client.crt -out etest.p12 -name "etest"

    You will be prompted to insert a password for the P12 file. Type it twice.

    • From the above commands, you get three files:

      1. Client key (client.key)

      2. Client certificate (client.crt)

      3. Client CSR (client.csr)

      4. Client P12 file (etest.p12)

  1. Connect to the console and get root privileges.

  2. Create a directory:

    mkdir epki && cd epki
  3. Place the CA certificate, server certificate, and key generated from the OpenSSL commands in the new epki directory:

    cp ../ca.crt ./
    cp ../server.crt ./
    cp ../server.key ./
  4. Create a tls_auth key for the OpenVPN server:

    /usr/local/openvpn_as/scripts/certool --tls_auth
  5. Generate Diffie Hellman parameters for the OpenVPN server:

    openssl dhparam -out epki/dh.pem 2048
  6. For Access Server 2.7 and newer, you must also generate your auth token and add the generated file:

    /usr/local/openvpn_as/scripts/certool --auth_token 
  7. Configure X509 explicit/extended key usage based on RFC3280 TLS rules:

    /usr/local/openvpn_as/scripts/sacli --key "external_pki.remote_cert_usage" --value eku ConfigPut
  8. Configure the use of the X509 “role” attribute for the declaration of auto-login permission:

    /usr/local/openvpn_as/scripts/sacli --key "external_pki.autologin_x509_spec" --value "role,,AUTOLOGIN" ConfigPut
  9. Generate the tls-crypt-v2 key (for Access Server 2.9.0 and higher only):

    /usr/local/openvpn_as/scripts/certool --tls_crypt2_server 
  10. Load the newly generated files into the Access Server config database:

    /usr/local/openvpn_as/scripts/sacli --key "external_pki.ta_key" --value_file ta.key ConfigPut
    /usr/local/openvpn_as/scripts/sacli --key "external_pki.ca_crt" --value_file ca.crt ConfigPut
    /usr/local/openvpn_as/scripts/sacli --key "external_pki.server_crt" --value_file server.crt ConfigPut
    /usr/local/openvpn_as/scripts/sacli --key "external_pki.server_key" --value_file server.key ConfigPut
    /usr/local/openvpn_as/scripts/sacli --key "external_pki.dh_pem" --value_file dh.pem ConfigPut
    /usr/local/openvpn_as/scripts/sacli --key "external_pki.auth_token_key" --value_file auth_token.key ConfigPut
    /usr/local/openvpn_as/scripts/sacli --key "external_pki.tls_cryptv2_server" --value_file tls_crypt2.key ConfigPut
  11. Start Access Server:

    service openvpnas restart

To test our example, we generate a test client, etest.

  1. Sign in to the Admin Web UI.

  2. Click User Management > User Permissions.

  3. Create the new user, etest, and click More Settings to enter a password.

  4. Finally, generate a server-locked profile. The profile will be stored in etest.ovpn:

    /usr/local/openvpn_as/scripts/sacli GetGeneric >etest.ovpn
  5. Copy these two files to the client machine:

    • Client P12 file (etest.p12)

    • Client profile (etest.ovpn)

  6. Install the profile and P12 file in OpenVPN Connect v3:

    1. Launch OpenVPN Connect v3.

    2. Import the connection profile, etest.ovpn.

    3. Click Certificate & Tokens.

    4. Under PKCS#12, click ADD CERTIFICATE.

    5. Select your client P12 file etest.p12.

    6. Enter the password for this file that you configured in Step 6 and click OK.

    7. Go back to the Profiles anc click or tap the Edit icon for the profile.

    8. Under Certificate and Key, click or tap Assign.

    9. Select the hardware token and click CONFIRM.

    10. Save the changes.

    11. Click or tap the profile toggle to connect.