verify-signed-darwin.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bash
  2. # Post-sign: fail if quill embedded the broken designated requirement
  3. # certificate root[field.1.2.840.113635.100.6.2.6] (missing Apple Root in P12).
  4. set -euo pipefail
  5. if [[ -z "${MACOS_SIGN_P12:-}" ]]; then
  6. echo "MACOS_SIGN_P12 unset; skipping darwin signature check."
  7. exit 0
  8. fi
  9. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  10. REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
  11. DIST_DIR="${REPO_ROOT}/dist"
  12. BAD_REQ='certificate root\[field\.1\.2\.840\.113635\.100\.6\.2\.6\]'
  13. GOOD_REQ='certificate 1\[field\.1\.2\.840\.113635\.100\.6\.2\.6\]'
  14. if ! command -v quill >/dev/null 2>&1; then
  15. echo "Installing quill..."
  16. go install github.com/anchore/quill/cmd/quill@latest
  17. export PATH="$(go env GOPATH)/bin:${PATH}"
  18. fi
  19. shopt -s nullglob
  20. archives=("${DIST_DIR}"/OliveTin-darwin-*.tar.gz)
  21. if [[ "${#archives[@]}" -eq 0 ]]; then
  22. echo "No OliveTin-darwin-*.tar.gz archives found under ${DIST_DIR}." >&2
  23. exit 1
  24. fi
  25. tmpdir="$(mktemp -d)"
  26. trap 'rm -rf "${tmpdir}"' EXIT
  27. checked=0
  28. for archive in "${archives[@]}"; do
  29. name="$(basename "${archive}" .tar.gz)"
  30. extract_dir="${tmpdir}/${name}"
  31. mkdir -p "${extract_dir}"
  32. tar -xzf "${archive}" -C "${extract_dir}"
  33. # Prefer the top-level binary; archives also ship helper scripts named OliveTin.
  34. binary="${extract_dir}/${name}/OliveTin"
  35. if [[ ! -f "${binary}" ]]; then
  36. binary="$(find "${extract_dir}" -type f -path "*/OliveTin" ! -path "*/var/*" | head -n 1)"
  37. fi
  38. if [[ -z "${binary}" || ! -f "${binary}" ]]; then
  39. echo "OliveTin binary not found inside ${archive}." >&2
  40. exit 1
  41. fi
  42. if ! file "${binary}" | grep -qi 'Mach-O'; then
  43. echo "Expected a Mach-O binary at ${binary}, got: $(file "${binary}")" >&2
  44. exit 1
  45. fi
  46. echo "Checking designated requirement in ${archive}..."
  47. describe_out="$(quill describe "${binary}")"
  48. if echo "${describe_out}" | grep -qE "${BAD_REQ}"; then
  49. echo "Broken designated requirement in ${archive}:" >&2
  50. echo " found certificate root[field.1.2.840.113635.100.6.2.6]" >&2
  51. echo "MACOS_SIGN_P12 is missing Apple Root CA. Rebuild per docs/modules/dev/pages/signing.adoc." >&2
  52. exit 1
  53. fi
  54. if ! echo "${describe_out}" | grep -qE "${GOOD_REQ}"; then
  55. echo "Expected designated requirement with certificate 1[...] not found in ${archive}." >&2
  56. echo "${describe_out}" >&2
  57. exit 1
  58. fi
  59. checked=$((checked + 1))
  60. done
  61. echo "Darwin signature check OK (${checked} archive(s); designated requirement uses certificate 1[...])."