Last active
October 21, 2019 12:42
-
-
Save timja/00ff10fc1c34b243e67c5c731090bfba to your computer and use it in GitHub Desktop.
copy cert between keyvault
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC_SECRET_NAME=${1} | |
SRC_VAULT=${2} | |
DEST_VAULT=${3} | |
DEST_SECRET_NAME=${4} | |
CERTIFICATE_NAME=${1} | |
function usage() { | |
echo "usage: ./key-vault-copy-cert-to-different-vault <src-secret-name> <src-vault> <dest-vault> <dest-secret-name>" | |
} | |
if [ -z "${SRC_SECRET_NAME}" ] || [ -z "${SRC_VAULT}" ] || [ -z "${DEST_VAULT}" ] || [ -z "${DEST_SECRET_NAME}" ] | |
then | |
usage | |
exit 1 | |
fi | |
TMP_DIR=$(mktemp -d) | |
cd ${TMP_DIR} | |
az keyvault secret show --vault-name ${SRC_VAULT} --name ${SRC_SECRET_NAME} --query value -o tsv | \ | |
base64 -D > ${CERTIFICATE_NAME}.pfx | |
openssl pkcs12 -in ${CERTIFICATE_NAME}.pfx -out ${CERTIFICATE_NAME}.pem -nodes -passin pass:"" | |
openssl pkey -in ${CERTIFICATE_NAME}.pem -out ${CERTIFICATE_NAME}.key | |
openssl pkcs12 -export -out ${CERTIFICATE_NAME}.new.pfx -inkey ${CERTIFICATE_NAME}.key -in ${CERTIFICATE_NAME}.pem -passout pass:Password12 | |
az keyvault certificate import --vault-name ${DEST_VAULT} --name ${DEST_SECRET_NAME} --password Password12 --file ${CERTIFICATE_NAME}.new.pfx | |
echo ${TMP_DIR} | |
rm -rf ${TMP_DIR} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment