Skip to content

Instantly share code, notes, and snippets.

@omarzl
Created May 5, 2022 22:20
Show Gist options
  • Save omarzl/6afb8d0abe72a28526abfd04c5060278 to your computer and use it in GitHub Desktop.
Save omarzl/6afb8d0abe72a28526abfd04c5060278 to your computer and use it in GitHub Desktop.
# Private key import
security import $PRIVATE_KEY_FILE -k $RAPPI_KEYCHAIN -f pkcs12 -P $KEYCHAIN_PWD -A
# Private key to pem
openssl pkcs12 -in $PRIVATE_KEY_FILE -out $PRIVATE_KEY_FILE.pem -nocerts -nodes -passin pass:$PRIVATE_KEY_PWD
# Key modulus
key_modulus=$(openssl rsa -noout -modulus -in $PRIVATE_KEY_FILE.pem | openssl md5)
for cert in $certs_dir/*; do
# Cert verification
security verify-cert -c $cert
# Cert to der
openssl x509 -inform DER -in $cert -out $cert.crt
# Cert modulus
cert_modulus=$(openssl x509 -modulus -noout -in $cert.crt | openssl md5)
# Making sure the cert corresponds to the private key
if [ "$key_modulus" = "$cert_modulus" ]; then
# Cert import
security import $cert -k $RAPPI_KEYCHAIN -A
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment