Skip to content

Commit 60d61fb

Browse files
committed
ci(ios): say which secret is wrong instead of failing inside base64
The first run of this step died on base64: stdin: (null): error decoding base64 input stream Error: Process completed with exit code 1 which names neither the secret nor the mistake, in a step whose whole job is to stop a signing problem from being cryptic. The value was a *path* rather than the file's contents. I could not find any other input that produces that message: empty, wrapped lines, stray spaces and even a PEM header all decode without complaint on macOS, so the one thing it does say is the one thing it says badly. So the decode is guarded and its result is checked. Whitespace is stripped first, because a value that travelled through a browser text field arrives with whatever that field did to it, and `base64 --decode` is not uniformly forgiving about it across runner images. Then the bytes have to start 0x30, the DER SEQUENCE tag — a .cer, a PEM or a truncated paste all reach `security import` otherwise, and it answers "Unknown format in import", which is the same problem one layer further down.
1 parent c667f37 commit 60d61fb

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

tool/release/ios_keychain.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,35 @@ keychain="$RUNNER_TEMP/dpip-signing.keychain-db"
7575
keychain_password="$(uuidgen)"
7676
p12="$RUNNER_TEMP/dpip-ios-dev.p12"
7777

78-
printf '%s\n' "$APPLE_DEV_CERT_BASE64" | base64 --decode > "$p12"
78+
# Whitespace out first. A value that travelled through a browser text field
79+
# can arrive with a trailing newline or a wrapped line, and neither is part of
80+
# the payload — but `base64 --decode` on macOS is not uniformly forgiving about
81+
# them across versions, and this is not a thing to leave to the runner image.
82+
#
83+
# The failure being caught here is not exotic; it is the one that happened. The
84+
# secret held a *path* rather than the file's contents, and all `base64` said
85+
# was "stdin: (null): error decoding base64 input stream" — a message that
86+
# names neither the secret nor the mistake, in a step whose entire job is to
87+
# stop a signing problem from being cryptic.
88+
if ! printf '%s' "$APPLE_DEV_CERT_BASE64" | tr -d '[:space:]' |
89+
base64 --decode > "$p12" 2>/dev/null; then
90+
printf '::error::APPLE_DEV_CERT_BASE64 is not base64.\n'
91+
printf 'It usually means the path was pasted instead of the contents. '
92+
printf 'Rebuild it with: base64 -i <the .p12> | pbcopy\n'
93+
exit 1
94+
fi
95+
96+
# And check it is a PKCS#12 rather than merely *some* bytes. DER starts with a
97+
# SEQUENCE tag, 0x30 — a .cer, a PEM, or a truncated paste all fail here, and
98+
# all of them would otherwise reach `security import` and be reported as
99+
# "Unknown format in import", which says nothing about which secret is wrong.
100+
if [[ ! -s $p12 ]] || [[ $(head -c 1 "$p12" | od -An -tx1 | tr -d ' ') != 30 ]]; then
101+
printf '::error::APPLE_DEV_CERT_BASE64 decoded to %s bytes that are not a ' \
102+
"$(wc -c < "$p12" | tr -d ' ')"
103+
printf 'PKCS#12 file. Export the identity from Keychain Access -> '
104+
printf 'My Certificates -> Export as .p12, then base64 that file.\n'
105+
exit 1
106+
fi
79107

80108
security create-keychain -p "$keychain_password" "$keychain"
81109
# `-t 21600` is the inactivity timeout. `-l` locks on sleep as well — it is a

0 commit comments

Comments
 (0)