我想从命令行(终端)得到这个,所以我想出了这个 bash 脚本
链接到要点
#!/usr/bin/env bash
#requires openssl@3 from Homebrew
_openssl=$(brew --prefix openssl 2>/dev/null)/bin/openssl
[[ -x $_openssl ]] || { echo "missing openssl, try \`brew install openssl\`"; exit 1; }
#find development cert
id=$(security find-identity -v -p codesigning | head -1)
[[ -n $id ]] || exit 1
cn=$(sed -En 's/^.*Apple Development.*\((.*)\).*$/\1/p' <<<"$id")
sha1=$(sed -En 's/^.*([A-F0-9]{40}).*$/\1/p' <<<"$id")
[[ -n $cn && -n $sha1 ]] || { echo "could not find valid development cert"; exit 1; }
#make temp dir
outdir=$(mktemp -d /private/tmp/teamid.XXXXXX)
[[ -n $outdir ]] || { echo "error creating temp dir"; exit 1; }
#export cert
if ! security find-certificate -c "$cn" -Z -p >"${outdir}/${cn}.pem"; then
echo "error exporting cert from Keychain"
exit 1
fi
#check for hash match
certhash=$(awk -F: '/SHA-1 hash:/{sub(" ","",$2); print $2}' "${outdir}/${cn}.pem")
[[ "$certhash" == "$sha1" ]] || { echo "hash mismatch!"; exit 1; }
#output DEVELOPMENT_TEAM
$_openssl x509 -in "${outdir}/${cn}.pem" -subject -noout |
sed -En 's/.*OU = ([^,]+),.*$/\1/p'
#cleanup
rm -r "${outdir:?}"