software:openssl:createcert
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
software:openssl:createcert [2025/10/19 16:09] – rodolico | software:openssl:createcert [2025/10/19 23:31] (current) – rodolico | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Create Service Certificate ====== | ====== Create Service Certificate ====== | ||
- | <code conf> | + | I use the term //" |
- | [ ca ] | + | |
- | default_ca = CA_default | + | |
- | [ CA_default ] | + | On our workstations, |
- | dir = ./ | + | |
- | database | + | |
- | new_certs_dir | + | |
- | certificate | + | |
- | private_key | + | |
- | default_md | + | |
- | preserve | + | |
- | policy | + | |
- | [ policy_any | + | Doing this requires building a certificate, |
- | countryName | + | |
- | stateOrProvinceName | + | ===== Creating the Certificate ===== |
- | organizationName | + | |
- | organizationalUnitName | + | Creating the certificate is similar to creating a CA: We create a key file, then turn it into a certificate. The difference is, as an intermediate step, we create a CSR (Certificate Request) which uses the key, then we use that to create and sign the certificate with the CA. The basic functionality is shown in the following four steps. |
- | commonName | + | |
- | emailAddress | + | - Create an EXT (extension) file containing the names which the service will be called by. |
+ | - Generate a private key | ||
+ | - Create a signing request | ||
+ | - Generate the certificate and sign them with the CA | ||
+ | |||
+ | |||
+ | We'll take each one in turn, then I'll show you a simple script that can automate the process. | ||
+ | ==== Create EXT file ==== | ||
+ | |||
+ | The EXT file defines how to create the cert and what services it is valid for. You can have one or more names which the certificate is valid for. For example, if a web server can be called as web.example.local, | ||
+ | |||
+ | An EXT file is a lot like a openssl.cnf file, but with some additional stanzas. To simplify things, I tend to copy the openssl.cnf file to a new file name, then add the additional stanzas, then use the same file for both. | ||
+ | |||
+ | Here is an example of an ext file which has been merged with an openssl.cnf file to allow it to be used for both functions. | ||
+ | |||
+ | <code conf www.example.local.ext> | ||
+ | [ req ] | ||
+ | default_bits | ||
+ | default_md | ||
+ | distinguished_name = req_distinguished_name # definition used for DN | ||
+ | req_extensions | ||
+ | prompt | ||
+ | |||
+ | [ req_distinguished_name ] | ||
+ | # Required fields | ||
+ | CN = www.example.com | ||
+ | # not required | ||
+ | C | ||
+ | ST = Texas | ||
+ | O = Example Corp | ||
+ | L = Dallas | ||
+ | OU = Headquarters | ||
+ | emailAddress = info@example.com | ||
+ | |||
+ | [ v3_req ] | ||
+ | keyUsage | ||
+ | extendedKeyUsage | ||
+ | subjectAltName | ||
+ | basicConstraints | ||
+ | |||
+ | [ alt_names ] | ||
+ | DNS.1 = www.example.local | ||
+ | DNS.2 = example.local | ||
+ | DNS.3 = mail.example.local | ||
+ | DNS.4 = 192.168.1.1 | ||
</ | </ | ||
+ | |||
+ | Here, we've added //prompt = no// to tell openssl to not prompt us for values, but instead use what is in the ext file if possible. We have also added // | ||
+ | |||
+ | In the // | ||
+ | |||
+ | Finally, we give it // | ||
+ | |||
+ | In the alt_names, we list multiple DN (alternate names). The format is | ||
+ | DNS=URL | ||
+ | But, since openssl configuration files can not list the same key more than once, we modify it slightly by adding arbitrary text after a period. openssl will ignore anything between the period and the equals sign, so we just list them as | ||
+ | DNS.1=name | ||
+ | DNS.2=alias | ||
+ | DNS.3=another alias | ||
+ | |||
+ | This is used when we build a Certificate Request and then integrated as alternate names in the subject for the DN. | ||
+ | |||
+ | I save this file as name (the primary name of the service) with an extension of .ext | ||
+ | |||
+ | ==== Generate Private Key ==== | ||
+ | |||
+ | Private key generation is the same as it was for the CA, except we do not want a password in most cases. If we have a password, it would require you to enter the password every time a service was restarted. | ||
+ | |||
+ | Here, we're creating a private key named www.example.internal.key. This allows us to know which key this is for. Also note we did not include the -des3. Leaving off the encryption algorithm tells genpkey that we don't want to encrypt the key. | ||
+ | |||
+ | <code bash> | ||
+ | openssl \ | ||
+ | | ||
+ | | ||
+ | | ||
+ | --out www.example.local.key \ | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ==== Create CSR (Request) ==== | ||
+ | Creating a Certificate Signing Request is simpler since we have the configuration file created earlier. Basically, we call openssl with the req flag and tell it what to do. | ||
+ | |||
+ | <code bash> | ||
+ | openssl \ | ||
+ | req \ | ||
+ | -new \ | ||
+ | -key www.example.local.key \ | ||
+ | -out www.example.local.csr \ | ||
+ | | ||
+ | </ | ||
+ | |||
+ | You can almost read this in english. Create a new (-new) signing request (req) using the key www.example.local.key, | ||
+ | |||
+ | ==== Generate Certificate and sign ==== | ||
+ | |||
+ | The certificate file is what all of this is about. We generate it using the Signing Request (csr), signing with the key. | ||
+ | |||
+ | <code bash> | ||
+ | openssl \ | ||
+ | x509 \ | ||
+ | -req \ | ||
+ | -in www.example.local.csr \ | ||
+ | -CA vanduzen_CA.pem \ | ||
+ | | ||
+ | | ||
+ | -out www.example.local.crt \ | ||
+ | -days 365 \ | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ===== Automation ===== | ||
+ | |||
+ | ===== openssl ca function ===== | ||
<code cnf> | <code cnf> |
software/openssl/createcert.1760908176.txt.gz · Last modified: 2025/10/19 16:09 by rodolico