brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 6e8ad76 Raw
58 lines · bash
1#!/bin/bash2 3CERT="lldb_codesign"4 5function error() {6    echo error: "$@"7    exit 18}9 10function cleanup {11    # Remove generated files12    rm -f "$TMPDIR/$CERT.tmpl" "$TMPDIR/$CERT.cer" "$TMPDIR/$CERT.key" > /dev/null 2>&113}14 15trap cleanup EXIT16 17# Check if the certificate is already present in the system keychain18security find-certificate -Z -p -c "$CERT" /Library/Keychains/System.keychain > /dev/null 2>&119if [ $? -eq 0 ]; then20    echo Certificate has already been generated and installed21    exit 022fi23 24# Create the certificate template25cat <<EOF >$TMPDIR/$CERT.tmpl26[ req ]27default_bits       = 2048        # RSA key size28encrypt_key        = no          # Protect private key29default_md         = sha512      # MD to use30prompt             = no          # Prompt for DN31distinguished_name = codesign_dn # DN template32[ codesign_dn ]33commonName         = "$CERT"34[ codesign_reqext ]35keyUsage           = critical,digitalSignature36extendedKeyUsage   = critical,codeSigning37EOF38 39echo Generating and installing lldb_codesign certificate40 41# Generate a new certificate42openssl req -new -newkey rsa:2048 -x509 -days 3650 -nodes -config "$TMPDIR/$CERT.tmpl" -extensions codesign_reqext -batch -out "$TMPDIR/$CERT.cer" -keyout "$TMPDIR/$CERT.key" > /dev/null 2>&143[ $? -eq 0 ] || error Something went wrong when generating the certificate44 45# Install the certificate in the system keychain46sudo security add-trusted-cert -d -r trustRoot -p codeSign -k /Library/Keychains/System.keychain "$TMPDIR/$CERT.cer" > /dev/null 2>&147[ $? -eq 0 ] || error Something went wrong when installing the certificate48 49# Install the key for the certificate in the system keychain50sudo security import "$TMPDIR/$CERT.key" -A -k /Library/Keychains/System.keychain > /dev/null 2>&151[ $? -eq 0 ] || error Something went wrong when installing the key52 53# Kill task_for_pid access control daemon54sudo pkill -f /usr/libexec/taskgated > /dev/null 2>&155 56# Exit indicating the certificate is now generated and installed57exit 058