Skip to content

Instantly share code, notes, and snippets.

@blackrobot
Forked from koop/ensure-cert-macos.sh
Created December 7, 2017 00:25

Revisions

  1. @koop koop created this gist Nov 28, 2017.
    15 changes: 15 additions & 0 deletions ensure-cert-macos.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/bin/bash
    # Usage
    # $ ./install-cert-macos.sh "/path/to/cert"
    CERT_PATH="$1"

    # First, grab the SHA-1 from the provided SSL cert.
    CERT_SHA1=$(openssl x509 -in "$CERT_PATH" -sha1 -noout -fingerprint | cut -d "=" -f2 | sed "s/://g")

    # Next, grab the SHA-1s of any standard.dev certs in the keychain.
    # Don't return an error code if nothing is found.
    EXISTING_CERT_SHAS=$(security find-certificate -a -c "standard.dev" -Z /Library/Keychains/System.keychain | grep "SHA-1") || true

    echo "$EXISTING_CERT_SHAS" | grep -q "$CERT_SHA1" || {
    sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$CERT_PATH"
    }