|
52 | 52 | bundler: latest |
53 | 53 |
|
54 | 54 | steps: |
| 55 | + - name: Remove eMudhra roots from the macOS CA bundle |
| 56 | + if: runner.os == 'macOS' |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + #!/bin/sh |
| 60 | + # Remove the eMudhra-related roots from the macOS system CA bundle. |
| 61 | + # |
| 62 | + # Apple's /etc/ssl/cert.pem still carries roots from the eMudhra incident, and the |
| 63 | + # developer tools Apple ships (git, curl, python3) read that file, so a network |
| 64 | + # attacker could tamper with downloads made during a release build. GitHub's macOS |
| 65 | + # runners are ephemeral, so removing the roots at job start needs no re-application |
| 66 | + # after OS updates. Reference: https://github.com/galadran/we-have-a-problem.com/issues/157 |
| 67 | + # |
| 68 | + # It must run BEFORE the first step that downloads anything (actions/checkout runs |
| 69 | + # git), so the workflows inline this exact file. A contract test keeps them identical. |
| 70 | + # |
| 71 | + # Matching is by certificate subject so no fingerprints need to be guessed; every |
| 72 | + # removed certificate is printed with its SHA-256 fingerprint for the audit log, and |
| 73 | + # the script fails if any matching certificate is still present afterwards. |
| 74 | + # |
| 75 | + # Environment (for tests): CA_BUNDLE (default /etc/ssl/cert.pem), SUDO (default sudo). |
| 76 | + set -eu |
| 77 | +
|
| 78 | + bundle="${CA_BUNDLE:-/etc/ssl/cert.pem}" |
| 79 | + sudo_cmd="${SUDO-sudo}" |
| 80 | + work="$(mktemp -d)" |
| 81 | + trap 'rm -rf "$work"' EXIT |
| 82 | +
|
| 83 | + matches() { |
| 84 | + case "$1" in |
| 85 | + *"AAA Certificate Services"* | *"emSign ECC Root CA - G3"* | *[eE][mM]udhra*) return 0 ;; |
| 86 | + *) return 1 ;; |
| 87 | + esac |
| 88 | + } |
| 89 | +
|
| 90 | + total="$(grep -c -- '-----BEGIN CERTIFICATE-----' "$bundle")" |
| 91 | + [ "$total" -ge 100 ] || { echo "refusing to edit $bundle: only $total certificates" >&2; exit 1; } |
| 92 | +
|
| 93 | + awk -v dir="$work" ' |
| 94 | + /-----BEGIN CERTIFICATE-----/ { if (out != "") close(out); n++; out = dir "/c" n ".pem" } |
| 95 | + out != "" { print > out } |
| 96 | + ' "$bundle" |
| 97 | +
|
| 98 | + : > "$work/clean.pem" |
| 99 | + removed=0 |
| 100 | + i=1 |
| 101 | + while [ "$i" -le "$total" ]; do |
| 102 | + file="$work/c$i.pem" |
| 103 | + subject="$(openssl x509 -in "$file" -noout -subject 2>/dev/null || true)" |
| 104 | + if [ -n "$subject" ] && matches "$subject"; then |
| 105 | + fingerprint="$(openssl x509 -in "$file" -noout -fingerprint -sha256)" |
| 106 | + echo "removing: $subject ($fingerprint)" |
| 107 | + removed=$((removed + 1)) |
| 108 | + else |
| 109 | + cat "$file" >> "$work/clean.pem" |
| 110 | + fi |
| 111 | + i=$((i + 1)) |
| 112 | + done |
| 113 | +
|
| 114 | + if [ "$removed" -gt 0 ]; then |
| 115 | + $sudo_cmd tee "$bundle" < "$work/clean.pem" > /dev/null |
| 116 | + fi |
| 117 | +
|
| 118 | + # Verify what is on disk now, not what we intended to write. |
| 119 | + after="$(grep -c -- '-----BEGIN CERTIFICATE-----' "$bundle")" |
| 120 | + [ "$after" -eq $((total - removed)) ] || { echo "certificate count mismatch: $after != $total - $removed" >&2; exit 1; } |
| 121 | + rm -f "$work"/c*.pem |
| 122 | + awk -v dir="$work" ' |
| 123 | + /-----BEGIN CERTIFICATE-----/ { if (out != "") close(out); n++; out = dir "/v" n ".pem" } |
| 124 | + out != "" { print > out } |
| 125 | + ' "$bundle" |
| 126 | + for file in "$work"/v*.pem; do |
| 127 | + subject="$(openssl x509 -in "$file" -noout -subject 2>/dev/null || true)" |
| 128 | + if [ -n "$subject" ] && matches "$subject"; then |
| 129 | + echo "still trusted after cleanup: $subject" >&2 |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | + done |
| 133 | + echo "CA bundle $bundle: $total certificates, removed $removed, $after remain." |
| 134 | +
|
55 | 135 | - name: Checkout |
56 | 136 | uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
57 | 137 | with: |
|
0 commit comments