Page History
Table of Contents |
---|
Introduction
Prerequisites
The below scripts assume the following directory layout:
<ca>
The directory<ca>
is a placeholder. Any directory can be used.create_root_ca.sh
create_certificate.sh
certs
csr
private
The sub-directories certs
, csr
and private
will be created from the below scripts should they not exist.
Create Root CA Certificate
The first step includes to create a private key (root-ca.key
) and self-signed certificate (root-ca.crt
) both in PEM format. As a result the following files will be created:
<ca>/certs/root-ca.crt
<ca>/private/root-ca.key
This step is performed just once. In case of repeated execution a new Root CA Certificate will be created and server certificates will have to be renewed.
...
title | Run create_root_ca.sh shell script |
---|---|
linenumbers | true |
...
Run OpenSSL commands
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
#!/bin/bash # Create Root CA private key and certificate set -e CA_HOME=$(dirname "$0") CA_HOME=$(cd "${CA_HOME}" >/dev/null && pwd) CA_CERTS=${CA_HOME}/certs CA_PRIVATE=${CA_HOME}/private # step 1 Generate Certificate Authority (CA) Private Key openssl ecparam -name prime256v1 -genkey -noout -out ${CA_PRIVATE}/root-ca.key # step 2: Generate Certificate Authority Certificate openssl req -new -x509 -sha256 -key ${CA_PRIVATE}/root-ca.key -out ${CA_CERTS}/root-ca.crt |
Create Server Certificate
...
This step is performed for each server certificate that should be created:
...
.
...
Replace the value of the SERVER
variable with the hostname or FQDN for which the certificate should be created:
Code Block |
---|
Code Block | ||||
---|---|---|---|---|
| ||||
./create_certificate.sh <server-hostname> |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#!/bin/bash # Create certificate for Server Authentication and Client Authentication set -e CA_HOME=$(dirname "$0") CA_HOME=$(cd "${CA_HOME}" >/dev/null && pwd) CA_CERTS=${CA_HOME}/certs CA_CSR=${CA_HOME}/csr CA_PRIVATE=${CA_HOME}/private # Specify server for which the certificate should be created SERVER=$1somehost # Create required sub-directories mkdir -p ${CA_CERTS} ${CA_CSR} ${CA_PRIVATE} # Step 1 - Generate Private Key and Certificate Signing Request openssl req -new -config ${CA_HOME}/openssl-cert.config -extensions 'standard exts' -nodes \ -days 7300 -newkey rsa:4096 -keyout ${CA_PRIVATE}/${SERVER}.key -out ${CA_CSR}/${SERVER}.csr # Step 2 - Generate and Sign the Server Certificate openssl x509 -req \ -in ${CA_CSR}/${SERVER}.csr \ -CA ${CA_CERTS}/root-ca.crt \ -CAkey ${CA_PRIVATE}/root-ca.key \ -CAcreateserial \ -out ${CA_CERTS}/${SERVER}.crt -days 7300 \ -extfile <(printf "subjectAltName=DNS:apmaccs,DNS:apmaccs.sos${SERVER}\nnsCertType = client, server\nkeyUsage = digitalSignature, keyEncipherment\nextendedKeyUsage = serverAuth, clientAuth\n") |
...
Code Block | ||||
---|---|---|---|---|
| ||||
[ req ] prompt = no distinguished_name = standard dn [ standard dn ] commonName = apmaccs countryName = DE localityName = Berlin organizationName = SOS organizationalUnitName = JS7 stateOrProvinceName = Berlin [ standard exts ] extendedKeyUsage = serverAuth,clientAuth |
Resources
Shell Scripts
As an alternative to running OpenSSL commands in an interactive shell scripts are provided that perform this task.
The below scripts assume the following directory layout:
<ca>
The directory<ca>
is a placeholder. Any directory can be used.create_root_ca.sh
create_certificate.sh
certs
csr
private
The sub-directories certs
, csr
and private
will be created from the below scripts should they not exist.
Create Root CA Certificate
The following files will be created:
<ca>/certs/root-ca.crt
<ca>/private/root-ca.key
This step is performed just once. In case of repeated execution a new Root CA Certificate will be created and server certificates will have to be renewed.
- Download: create_root_ca.sh
- The shell script is executed without arguments.
Code Block | ||||
---|---|---|---|---|
| ||||
./create_root_ca.sh |
Create Certificate from Shell Script
The following files will be created with <server>
being a placeholder for the hostname of the indicated server.
<ca>/certs/<server>.crt
<ca>/certs/<server>.csr
<ca>/private/<server>.key
This step is performed for each server certificate that should be created.
- Download: create_certificate.sh
- The shell script is executed with two arguments:
- The DNS hostname of the server that should receive the certificate. A server can be assigned more than one DNS hostname, for example its FQDN can be different. All DNS hostnames have to be added to the certificate in order to secure connections.
- The lifetime of the certificate specified by the number of days.
Code Block | ||||
---|---|---|---|---|
| ||||
./create_certificate.sh --dns=<server-hostname>[,<server-hostname>]> --days=<number-of-days> |
Links
...