Page History
...
Users have a choice to use CA-signed certificates and self-signed certificates:
- CA-signed certificates are issued by a know known and trusted Certificate Authority (CA) that validates the domain owner.
- Self-signed certificates are created by the user and are not related to a known CA.
...
The article explains how to create self-signed certificates by use of OpenSSL. This utility ships with Linux and most Unix environments and is available for Windows environments. The below examples are focused on Unix.
...
Anchor | ||||
---|---|---|---|---|
|
The first step includes to create the root-ca.key
private key file and the root-ca.crt
self-signed certificate file for the Root CA both in PEM format. This step is performed just once.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# stepGenerate 1 GenerateRoot Certificate Authority (CA) Private Key openssl ecparam -name prime256v1 -genkey -noout -out root-ca.key # step 2: Generate CertificateRoot AuthorityCA Certificate openssl req -new -x509 -sha256 -days 5475 -key root-ca.key -out root-ca.crt |
...
# You are about to be asked to enter information that will be incorporated
# into your certificate request.
# What you are about to enter is what is called a Distinguished Name or a DN.
# There are quite a few fields but you can leave some blank
# For some fields there will be a default value,
# If you enter '.', the field will be left blank.
# -----
# Country Name (2 letter code) [XX]:DE
# State or Province Name (full name) []:Berlin
# Locality Name (eg, city) [Default City]:Berlin
# Organization Name (eg, company) [Default Company Ltd]:SOS
# Organizational Unit Name (eg, section) []:JS7
# Common Name (eg, your name or your server's hostname) []:JS7 Deployment CA
# Email Address []: |
Explanation:
As a response to the second command the OpenSSL utility prompts for a number of specifications for the Distinguished Name, i.e. the unique name of the Root CA Certificate:
Country Name
: a 2 letter country code is expected as stated for example with https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2State or Province Name
: the name of a state is expectedLocality Name
: the name of a city is expectedOrganization Name
: arbitrary input is allowedOrganizational Unit Name
: arbitrary input is allowedCommon Name
: an arbitrary name can be chosen as the name of the Root CAEmail Address
: empty input is allowed
Anchor | ||||
---|---|---|---|---|
|
For a given server the second step next steps includes to create a private key and Certificate Signing Request (CSR). The resulting server certificate will be signed.
...
Run the following commands from a bash shell and replace the value of the SERVER
server variable with the hostname or FQDN for which the certificate should be created:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# Specify server for which the certificate should be created SERVERserver=somehost # Step 1 - Generate Private Key and Certificate Signing Request openssl req -new -config openssl-cert.config -extensions 'standard exts' -nodes \ -days 73005475 -newkey rsa:4096 -keyout ${SERVERserver}.key -out ${SERVERserver}.csr # Step 2 - Generate and Signsign the Server Certificate openssl x509 -req \ -in ${SERVERserver}.csr \ -CA root-ca.crt \ -CAkey root-ca.key \ -CAcreateserial \ -out ${SERVERserver}.crt -days 7300 \ -extfile <(printf "'subjectAltName=DNS:${SERVER}%s\nnsCertType = client, server\nkeyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment\nextendedKeyUsage = serverAuth, clientAuth\n' "${server}") |
Explanation:
- The following files will be created for the given server:
<SERVER>
<server>
.key
: the Private Key<SERVER>
<server>
.csr
: the Certificate Signing Request<SERVER>
<server>
.crt
: the Server Certificate
- For operation with JS7 JOC Cockpit, Controller and Agents users can add
- the Private Key and Server Certificate to a keystore.
- the Root CA Certificate to a truststore.
- For details see JS7 - How to add SSL TLS Certificates to Keystore and Truststore
In order to run the script successfully the following openssl-cert.config
file has to be present. To create a server certificate Server Certificate the CommonName
attribute has to be adjusted.
- Download: openssl-cert.config
- Replace the value of the
commonName
attribute with the hostname of the server for which the certificate should be created
...
- .
- Adjust other attributes in the
[ standard_dn ]
section to your needs.
Code Block | ||||
---|---|---|---|---|
| ||||
[ req ] prompt = no distinguished_name = standard dn [ standard dn ] commonName = somehost 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 a few scripts are provided that perform this task.
...
The sub-directories certs
, csr
and private
will be created from the below scripts should they not exist.
...
Creating the Root CA Certificate
Download: create_root_ca.sh
The following files will be created:
...
This step is performed just once. In case of repeated execution a new of renewal of the Root CA Certificate will be created and server certificates will any Server Certificates will have to be renewed.
...
.
Code Block | ||||
---|---|---|---|---|
| ||||
# Description
# create_root_ca.sh --days=<number-of-days>
# Example
./create_root_ca.sh |
...
--days=5475 |
The shell script is executed with an optional single argument:
--days
- The lifetime of the certificate is specified by the number of days (default: 5475, matching approx. 15 years).
- Consider that server certificates have to be renewed if the Root CA Certificate expires.
Creating a Server Certificate
Download: create_certificate.sh
The following files will be created with <server>
being a placeholder for the hostname of the indicated serverfor which a certificate should be created.
<ca>/certs/<server>.crt
<ca>/certs/<server>.csr
<ca>/private/<server>.key
This step is performed for each server certificate Server Certificate that should be created.
...
Code Block | ||||
---|---|---|---|---|
| ||||
# Description # create_certificate.sh --dns=<server-hostname>[,<server-hostname>] --days=<number-of-days> # Example ./create_certificate.sh --dns=apmaccs,apmaccs.sos --days=365 |
The shell script is executed with two arguments:
--dns
- The DNS hostname of the server that should receive be assigned the certificate. A server can be assigned more than one DNS hostname, for example the FQDN can extend the hostname. Only DNS hostnames that are added to the certificate can be used later on to establish secure HTTPS connections.
--days
- The lifetime of the certificate is specified by the number of days .
- The lifetime of the certificate is specified by the number of days .
...
title | Run .create_certificate.sh shell script |
---|---|
linenumbers | true |
- (default: 5475, matching approx. 15 years).
Links
...