ssl:generate-certificates-self-signed
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ssl:generate-certificates-self-signed [2020/08/08 12:43] – odefta | ssl:generate-certificates-self-signed [2023/07/04 16:36] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Generate Root CA certificate ====== | ====== Generate Root CA certificate ====== | ||
| - | ===== Generate private key and CSR (certificate signing request) | + | ===== Generate private key ===== |
| - | Run the command and fill the required | + | You should enter a password when required. |
| - | It will generate 2 files: **ca.key** and **ca.csr**. | + | |
| - | Let the challenge password empty. | + | |
| < | < | ||
| - | openssl | + | openssl |
| </ | </ | ||
| Line 15: | Line 13: | ||
| ............+++++ | ............+++++ | ||
| e is 65537 (0x010001) | e is 65537 (0x010001) | ||
| - | Enter pass phrase for ca1.key: | + | Enter pass phrase for ca.key: |
| - | Verifying - Enter pass phrase for ca1.key: | + | Verifying - Enter pass phrase for ca.key: |
| - | + | ||
| - | C: | + | |
| - | Generating a RSA private key | + | |
| - | ...............................+++++ | + | |
| - | .................................................................+++++ | + | |
| - | writing new private key to ' | + | |
| - | ----- | + | |
| - | 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 ' | + | |
| - | ----- | + | |
| - | Country Name (2 letter code) [AU]:RO | + | |
| - | State or Province Name (full name) [Some-State]: | + | |
| - | Locality Name (eg, city) []: | + | |
| - | Organization Name (eg, company) [Internet Widgits Pty Ltd]:AX | + | |
| - | Organizational Unit Name (eg, section) []:AX Software | + | |
| - | Common Name (e.g. server FQDN or YOUR name) []:AX Root CA | + | |
| - | Email Address []: | + | |
| - | + | ||
| - | Please enter the following ' | + | |
| - | to be sent with your certificate request | + | |
| - | A challenge password []: | + | |
| - | An optional company name []: | + | |
| </ | </ | ||
| Line 81: | Line 53: | ||
| </ | </ | ||
| - | ===== Level 2 Headline | + | ===== Generate the final Root CA certificate ===== |
| + | |||
| + | < | ||
| + | openssl req -new -x509 -days 3650 -config root-ca.conf -key ca.key -out ca.crt | ||
| + | </ | ||
| + | |||
| + | Output: | ||
| + | < | ||
| + | Enter pass phrase for ca.key: | ||
| + | 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 ' | ||
| + | ----- | ||
| + | RO [RO]: | ||
| + | Romania [Romania]: | ||
| + | Bucharest [Bucharest]: | ||
| + | AX [AX]: | ||
| + | AX Software [AX Software]: | ||
| + | AX Root CA []: | ||
| + | admin@ax.com []: | ||
| + | </ | ||
| + | |||
| + | ca.crt images: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ====== Generate a certificate signed by the previously created Root CA ====== | ||
| + | |||
| + | ===== Generate private key and certificate request ===== | ||
| + | |||
| + | This will generate the private key - int1.key and the certificate request - int1.csr. | ||
| + | Leave empty the challenge password. | ||
| + | < | ||
| + | openssl req -new -newkey rsa:2048 -nodes -keyout int1.key -out int1.csr | ||
| + | </ | ||
| + | |||
| + | Output: | ||
| + | < | ||
| + | Generating a RSA private key | ||
| + | ..........+++++ | ||
| + | .........+++++ | ||
| + | writing new private key to ' | ||
| + | ----- | ||
| + | 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 ' | ||
| + | ----- | ||
| + | Country Name (2 letter code) [AU]:RO | ||
| + | State or Province Name (full name) [Some-State]: | ||
| + | Locality Name (eg, city) []: | ||
| + | Organization Name (eg, company) [Internet Widgits Pty Ltd]:AX | ||
| + | Organizational Unit Name (eg, section) []:AX Software | ||
| + | Common Name (e.g. server FQDN or YOUR name) []: | ||
| + | Email Address []: | ||
| + | |||
| + | Please enter the following ' | ||
| + | to be sent with your certificate request | ||
| + | A challenge password []: | ||
| + | An optional company name []: | ||
| + | </ | ||
| + | |||
| + | ===== Create extension file (ssl.conf) ===== | ||
| + | |||
| + | <file ini ssl.conf> | ||
| + | [ req ] | ||
| + | default_bits | ||
| + | distinguished_name = req_distinguished_name | ||
| + | req_extensions | ||
| + | |||
| + | [ req_distinguished_name ] | ||
| + | countryName | ||
| + | countryName_default | ||
| + | stateOrProvinceName | ||
| + | stateOrProvinceName_default = Romania | ||
| + | localityName | ||
| + | localityName_default | ||
| + | organizationName | ||
| + | organizationName_default | ||
| + | commonName | ||
| + | commonName_max | ||
| + | commonName_default | ||
| + | |||
| + | [ req_ext ] | ||
| + | subjectAltName = @alt_names | ||
| + | |||
| + | [alt_names] | ||
| + | DNS.1 = item-ax | ||
| + | DNS.2 = item-ax.com | ||
| + | </ | ||
| + | |||
| + | ===== Generate the actual certificate (int1.crt) singed by the Root CA (ca.crt) ===== | ||
| + | |||
| + | < | ||
| + | openssl x509 -req -in int1.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out int1.crt -days 1000 -sha256 -extensions req_ext -extfile ssl.conf | ||
| + | </ | ||
| + | |||
| + | Output: | ||
| + | < | ||
| + | Signature ok | ||
| + | subject=C = RO, ST = Romania, L = Bucharest, O = AX, OU = AX Software, CN = item-ax, emailAddress = item@ax.com | ||
| + | Getting CA Private Key | ||
| + | Enter pass phrase for ca.key: | ||
| + | </ | ||
| + | |||
| + | int1.crt images: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ====== Generate an intermediate CA ====== | ||
| + | |||
| + | Edit the following configuration lines (if needed.) | ||
| + | |||
| + | <file ini int1.conf> | ||
| + | [ ca ] | ||
| + | default_ca = default_CA | ||
| + | [ default_CA ] | ||
| + | dir = . | ||
| + | certs = . | ||
| + | new_certs_dir = ca.db.certs | ||
| + | database = ca.db.index | ||
| + | serial = ca.db.serial | ||
| + | RANDFILE = random-bits | ||
| + | certificate = ca.crt | ||
| + | private_key = ca.key | ||
| + | default_days = 1000 | ||
| + | default_crl_days = 30 | ||
| + | default_md = sha256 | ||
| + | preserve = no | ||
| + | x509_extensions = server_cert | ||
| + | policy = policy_anything | ||
| + | [ policy_anything ] | ||
| + | countryName = optional | ||
| + | stateOrProvinceName = optional | ||
| + | localityName = optional | ||
| + | organizationName = optional | ||
| + | organizationalUnitName = optional | ||
| + | commonName = supplied | ||
| + | emailAddress = optional | ||
| + | [ server_cert ] | ||
| + | # | ||
| + | authorityKeyIdentifier = keyid: | ||
| + | extendedKeyUsage = serverAuth, | ||
| + | basicConstraints = critical, | ||
| + | </ | ||
| + | |||
| + | In the same folder create the directory ca.db.certs, | ||
| + | |||
| + | < | ||
| + | mkdir ca.db.certs | ||
| + | echo 01 > ca.db.serial | ||
| + | type NUL > ca.db.index | ||
| + | </ | ||
| + | |||
| + | Generate the private key and csr: | ||
| + | < | ||
| + | openssl req -new -newkey rsa:2048 -nodes -keyout int1.key -out int1.csr | ||
| + | </ | ||
| + | |||
| + | Output: | ||
| + | < | ||
| + | Generating a RSA private key | ||
| + | .............................+++++ | ||
| + | ............................................+++++ | ||
| + | writing new private key to ' | ||
| + | ----- | ||
| + | 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 ' | ||
| + | ----- | ||
| + | Country Name (2 letter code) [AU]:RO | ||
| + | State or Province Name (full name) [Some-State]: | ||
| + | Locality Name (eg, city) []: | ||
| + | Organization Name (eg, company) [Internet Widgits Pty Ltd]:AX | ||
| + | Organizational Unit Name (eg, section) []:AX INT1 CA | ||
| + | Common Name (e.g. server FQDN or YOUR name) []: | ||
| + | Email Address []: | ||
| + | |||
| + | Please enter the following ' | ||
| + | to be sent with your certificate request | ||
| + | A challenge password []: | ||
| + | An optional company name []: | ||
| + | </ | ||
| + | |||
| + | Generate the actual intermediate CA: | ||
| + | < | ||
| + | openssl ca -config int1.conf -out int1.crt -infiles int1.csr | ||
| + | </ | ||
| + | |||
| + | Output: | ||
| + | |||
| + | < | ||
| + | Using configuration from int1.conf | ||
| + | Enter pass phrase for ca.key: | ||
| + | Check that the request matches the signature | ||
| + | Signature ok | ||
| + | The Subject' | ||
| + | countryName | ||
| + | stateOrProvinceName | ||
| + | localityName | ||
| + | organizationName | ||
| + | organizationalUnitName: | ||
| + | commonName | ||
| + | emailAddress | ||
| + | Certificate is to be certified until May 5 14:59:03 2023 GMT (1000 days) | ||
| + | Sign the certificate? | ||
| + | |||
| + | |||
| + | 1 out of 1 certificate requests certified, commit? [y/n]y | ||
| + | Write out database with 1 new entries | ||
| + | Data Base Updated | ||
| + | </ | ||
| + | |||
| + | int1.crt images: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ====== Generate another intermediate CA ====== | ||
| + | |||
| + | Repeat the steps for the above configuration, | ||
| + | |||
| + | <file ini int2.conf> | ||
| + | [ ca ] | ||
| + | default_ca = default_CA | ||
| + | [ default_CA ] | ||
| + | dir = . | ||
| + | certs = . | ||
| + | new_certs_dir = ca.db.certs | ||
| + | database = ca.db.index | ||
| + | serial = ca.db.serial | ||
| + | RANDFILE = random-bits | ||
| + | certificate = int1.crt | ||
| + | private_key = int1.key | ||
| + | default_days = 500 | ||
| + | default_crl_days = 30 | ||
| + | default_md = sha256 | ||
| + | preserve = no | ||
| + | x509_extensions = server_cert | ||
| + | policy = policy_anything | ||
| + | [ policy_anything ] | ||
| + | countryName = optional | ||
| + | stateOrProvinceName = optional | ||
| + | localityName = optional | ||
| + | organizationName = optional | ||
| + | organizationalUnitName = optional | ||
| + | commonName = supplied | ||
| + | emailAddress = optional | ||
| + | [ server_cert ] | ||
| + | # | ||
| + | authorityKeyIdentifier = keyid | ||
| + | extendedKeyUsage = serverAuth, | ||
| + | basicConstraints = critical, | ||
| + | </ | ||
| + | |||
| + | Then generate the private key and csr: | ||
| + | |||
| + | < | ||
| + | openssl req -new -newkey rsa:2048 -nodes -keyout int2.key -out int2.csr | ||
| + | </ | ||
| + | |||
| + | Finally generate the certificate: | ||
| + | |||
| + | < | ||
| + | openssl ca -config int2.conf -out int2.crt -infiles int2.csr | ||
| + | </ | ||
| + | |||
| + | Output: | ||
| + | |||
| + | < | ||
| + | Using configuration from int2.conf | ||
| + | Check that the request matches the signature | ||
| + | Signature ok | ||
| + | The Subject' | ||
| + | countryName | ||
| + | stateOrProvinceName | ||
| + | localityName | ||
| + | organizationName | ||
| + | organizationalUnitName: | ||
| + | commonName | ||
| + | emailAddress | ||
| + | Certificate is to be certified until Dec 21 15:39:26 2021 GMT (500 days) | ||
| + | Sign the certificate? | ||
| + | |||
| + | |||
| + | 1 out of 1 certificate requests certified, commit? [y/n]y | ||
| + | Write out database with 1 new entries | ||
| + | Data Base Updated | ||
| + | </ | ||
| + | |||
| + | Final CA certificate with 2 intermediate CA - int2.crt images: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| + | |||
ssl/generate-certificates-self-signed.1596890586.txt.gz · Last modified: (external edit)
