Reputation: 1239
I'm trying to understand the merge API of Azure Key vault. What is the use case of it? https://learn.microsoft.com/en-us/rest/api/keyvault/mergecertificate/mergecertificate
The doc says
The MergeCertificate operation performs the merging of a certificate or certificate chain with a key pair currently available in the service.
One use case I understand here is to create CSR in key vault, get it signed by your CA and then merge it to the CSR in key vault to complete the certificate creation.
But what do we mean by merging a certificate chain? Does it mean the certificate chain that was used to sign the CSR?
Upvotes: 2
Views: 5439
Reputation: 4571
Yes, merging the chain means that the whole chain, which starts with the certificate that is generated for CSR.
So, to have a local test using OpenSSL 1.1.1
openssl req -new -newkey rsa:2048 -nodes -out ca.csr -keyout ca.key -extensions v3_ca
openssl x509 -signkey ca.key -days 365 -req -in ca.csr -set_serial 01 -out ca.crt
openssl req -new -newkey rsa:2048 -nodes -out inter.csr -keyout inter.key -addext basicConstraints=CA:TRUE
openssl x509 -CA ca.crt -CAkey ca.key -days 365 -req -in inter.csr -set_serial 02 -out inter.crt
Generate request using Azure KeyVault and download CSR to test.csr file. Assuming using keyvault test-kv and certificate with name test.
Sign the request using intermediate CA
openssl x509 -CA inter.crt -CAkey inter.key -days 365 -req -in test.csr -set_serial 03 -out test.crt
cat test.crt inter.crt ca.crt > test-chain.pem
az keyvault certificate pending merge --vault-name test-kv --name test --file test-chain.pem
Additional note about formats:
The certificate content type can be set to either PKCS12 or PEM upon creation in Azure KeyVault. As result merged certificate is exported/downloaded
The format of the chain bundle for merging, however, does not depend on that content type. It only depends on the method that is used to perform the merge:
The following command can be used to create a P7B file containing the chain:
openssl crl2pkcs7 -nocrl -certfile test.crt -out test.p7b -certfile inter.crt -certfile ca.crt
When certificate that was merged together with the chain is downloaded in PEM, it contains the whole chain already. When certificate is downloaded in PFX, to extract individual certificates the following command can be used to convert to PEM, containing only certificates (omitting the private key):
openssl pkcs12 -in downloaded-cert.pfx -nokeys -nodes -out chain.pem
Then chain.pem can be opened with text editor and individual certificates can be extracted to separate crt files
Upvotes: 4