iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⛳

Using certificates stored in Azure Key Vault by Acmebot with Apache2

に公開
2023/10/05

TL;DR

  • Create a certificate in Azure Key Vault using Shibayan's acmebot
  • Process the created certificate so it can be used with apache2
  • Create and use a config using the Mozilla SSL Configuration Generator

Introduction

Based on Yotan-san's Using Let's Encrypt for Azure Application Gateway SSL Certificates, I am running Shibayan's Acmebot and saving the certificates in Azure Key Vault.

Created certificates can be downloaded as CER or PFX

In Azure, or rather the Microsoft ecosystem, the PFX (PKCS#12) format is frequently used, but it cannot be used by apache2 as is.
Therefore, it needs to be converted.

Downloading the Certificate

Downloading the certificate is not difficult; simply download it in CER format from the Azure Portal. However, for some reason, the header and footer are missing, so you need to add -----BEGIN CERTIFICATE----- to the beginning of the file and -----END CERTIFICATE----- to the end.

You can verify whether the decoded certificate is correct using the following command. Check the "Subject" field to confirm it matches the relevant domain.

openssl x509 -text -noout -in certificate.crt

Extracting the Private Key

Next, to extract the private key, download it in PFX format from the Azure Portal. Since this cannot be used by apache2 as is, you'll need to extract the private key.

openssl pkcs12 -in cert.pfx -nocerts -nodes -out key.pem

You can verify the private key with the following command:

openssl rsa -text -noout -in key.pem

Verifying the Combination of Certificate and Private Key

You can check if the combination of the certificate and private key is correct using the following command. If these two match, there should be no issues.

openssl x509 -noout -modulus -in certificate.crt | openssl md5
openssl rsa -noout -modulus -in key.pem | openssl md5

Creating a Configuration with the Mozilla SSL Configuration Generator

As a bonus, it's easy to create settings using the SSL Configuration Generator provided by Mozilla.

https://ssl-config.mozilla.org/

For the SSLCertificateFile part, specify the certificate.crt created earlier, and for the SSLCertificateKeyFile part, specify the key.pem created earlier.
You can set the path to something like /etc/apache2/ssl.

References

  • Using Let's Encrypt for Azure Application Gateway SSL Certificates

https://zenn.dev/yotan/articles/abfd178caae809

  • OpenSSL Essentials: Working with SSL Certificates, Private Keys and CSRs

https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs

  • Mozilla SSL Configuration Generator

https://ssl-config.mozilla.org/

Discussion