Skip to content

Instantly share code, notes, and snippets.

@pablomujica
Last active October 6, 2020 18:26
Show Gist options
  • Save pablomujica/b80d4285f1049bea742cb24e62770f9e to your computer and use it in GitHub Desktop.
Save pablomujica/b80d4285f1049bea742cb24e62770f9e to your computer and use it in GitHub Desktop.
How to generate a CSR with SubjectAltName in Linux and sign it in a Windows Certificate Authority.

How to generate a CSR with SubjectAltName in Linux and sign it in a Windows Certificate Authority.

  1. Create a file in the folder with the following content(changing the values for your required ones):
[req]
distinguished_name = req_distinguished_name
req_extensions = SAN
prompt = no

[req_distinguished_name]
C = US
ST = VA
L = SomeCity
O = MyCompany
OU = MyDivision
CN = csrexample.local
emailAddress = [email protected]

[SAN]
subjectAltName = @alt_names

[alt_names]
DNS.1 = csrexample.local
DNS.2 = csrexample
  1. Generating the Certificate Signing Request:

    • Execute the following command to generate the csr if you already have a keyfile:
$ openssl req -out <signingrequest.csr> -key <keyile> -nodes -config custom.cnf
  • Execute the following command to generate the csr and a keyfile:
$ openssl req -out <signingrequest.csr> -newkey rsa:2048 -nodes -keyout <keyile> -config custom.cnf
  1. Verify the data in the CSR:
$ openssl req -noout -text -in <signingrequest.csr>
Certificate Request:
    Data:
        Version: 1 (0x0)
        Subject: C = US, ST = VA, L = SomeCity, O = MyCompany, OU = MyDivision, CN = csrexample.local, emailAddress = [email protected]
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                RSA Public-Key: (2048 bit)
                Modulus:
                    (REDACTED)
                Exponent: (REDACTED) ((REDACTED))
        Attributes:
        Requested Extensions:
            X509v3 Subject Alternative Name:
                DNS:csrexample.local, DNS:csrexample
    Signature Algorithm: sha256WithRSAEncryption
         (REDACTED)
  1. Move the CSR to a srver with access to de the CA.

  2. Execute the powershell command to get the list of available templates:

Get-CATemplate
  1. Generate the certificate(example with the WebServer template):
certreq -attrib "CertificateTemplate:WebServer" <signingrequest.csr> <outputcertificate.cer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment