Skip to content

Instantly share code, notes, and snippets.

@PVi1
Last active October 19, 2021 07:39
Show Gist options
  • Save PVi1/583a6b393db013b0bb108496ed79c4b4 to your computer and use it in GitHub Desktop.
Save PVi1/583a6b393db013b0bb108496ed79c4b4 to your computer and use it in GitHub Desktop.
How to user Openssl to generate CSR and PKCS12 for Microsoft Azure Stack Hub platform

How to generate CSR and PKCS12

Azure certs have to follow requirements published here

Generate private key

openssl genrsa -out key/domain.tld.key 4096

Generate CSR

  1. Prepare CNF file as follows:
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req

[req_distinguished_name]
countryName = Country Name (2 letter code)
countryName_default = SK
stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = Slovakia
localityName = Locality Name (eg, city)
localityName_default = Bratislava
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = IT
commonName = Common Name (eg, YOUR name)
commonName_default = *.domain.tld
commonName_max = 64
emailAddress = Email Address
emailAddress_default = your@email.tld
emailAddress_max = 40

[v3_req] 
keyUsage = keyEncipherment, digitalSignature
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = @alt_names

[alt_names]
DNS.1   = *.domain.tld
  1. Generate CSR openssl req -new -key key/domain.tld.key -out csr/domain.tld.csr -config cnf/domain.tld.cnf

Get your cert from CA

After you get your cert from CA (eg. DigiCert & RapidSSL+RapidSSL Wildcards works fine) save CA, Intermediate and certificate pem files into separate files. You will reuse CA & Intermediate crt for all certs.

Create Microsoft compatible certificate chain

The Microsoft required certificate chain order is as follows: Start with CA, then continue with intermediate certs and after that insert you cert as a last part.

Eg. for Digicert & RapidSSL use: cat crt/intermediate/TrustedRoot.pem crt/intermediate/DigiCertCA.pem crt/certonly/domain.tld.pem > crt/fullchain/domain.tld.pem

Create PKCS12 file AKA .PFX

openssl pkcs12 -export -in crt/fullchain/domain.tld.pem -inkey key/domain.tld.key -out pkcs12/domain.tld.pfx -descert -LMK

Enter PKCS12 passphrase twice and you are good to go.

Validate PKCS12 files via Microsoft PowerShell

Validate Azure Stack Hub PKI certificates If needed, fix PowerShell warning Unable to resolve package source

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment