mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
fix(release): repair Apple and Android builds
This commit is contained in:
@@ -53,18 +53,6 @@ verify_archive_entries() {
|
||||
done
|
||||
}
|
||||
|
||||
find_apksigner() {
|
||||
if command -v apksigner >/dev/null 2>&1; then
|
||||
command -v apksigner
|
||||
return
|
||||
fi
|
||||
local sdk_root=${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}
|
||||
[[ -n $sdk_root ]] || return 1
|
||||
find "$sdk_root/build-tools" -type f -name apksigner -perm -111 2>/dev/null |
|
||||
sort -r |
|
||||
head -1
|
||||
}
|
||||
|
||||
for name in \
|
||||
VNIDROP_ANDROID_KEYSTORE_PATH \
|
||||
VNIDROP_ANDROID_KEYSTORE_PASSWORD \
|
||||
@@ -119,26 +107,12 @@ grep -F 'jar verified.' <<< "$jarsigner_report" >/dev/null || {
|
||||
}
|
||||
verify_archive_entries "$source_apk" "${required_apk_libraries[@]}"
|
||||
verify_archive_entries "$source_aab" "${required_aab_libraries[@]}"
|
||||
apksigner_path="$(find_apksigner)" || {
|
||||
printf 'apksigner was not found in PATH or the Android SDK\n' >&2
|
||||
exit 1
|
||||
}
|
||||
signature_report="$("$apksigner_path" verify --verbose --print-certs "$source_apk")"
|
||||
actual_fingerprint="$(
|
||||
printf '%s\n' "$signature_report" |
|
||||
awk -F': ' '/Signer #1 certificate SHA-256 digest:/ {print $2; exit}'
|
||||
"$script_dir/verify-apk-signature.sh" \
|
||||
"$source_apk" \
|
||||
"$VNIDROP_ANDROID_UPLOAD_CERT_SHA256"
|
||||
)"
|
||||
[[ -n $actual_fingerprint ]] || {
|
||||
printf 'Could not read the APK signing certificate fingerprint\n' >&2
|
||||
exit 1
|
||||
}
|
||||
actual_fingerprint="$(normalize_fingerprint "$actual_fingerprint")"
|
||||
expected_fingerprint="$(normalize_fingerprint "$VNIDROP_ANDROID_UPLOAD_CERT_SHA256")"
|
||||
[[ $actual_fingerprint == "$expected_fingerprint" ]] || {
|
||||
printf 'APK signing certificate mismatch: expected %s, got %s\n' \
|
||||
"$expected_fingerprint" "$actual_fingerprint" >&2
|
||||
exit 1
|
||||
}
|
||||
aab_fingerprint="$(
|
||||
keytool -printcert -jarfile "$source_aab" |
|
||||
awk -F': ' '/SHA256:/ {print $2; exit}'
|
||||
|
||||
57
packaging/android/tests/test_verify_apk_signature.sh
Executable file
57
packaging/android/tests/test_verify_apk_signature.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
verifier="$script_dir/../verify-apk-signature.sh"
|
||||
scratch="$(mktemp -d "${TMPDIR:-/tmp}/vnidrop-apksigner-test.XXXXXX")"
|
||||
trap 'rm -rf "$scratch"' EXIT
|
||||
|
||||
apk="$scratch/app.apk"
|
||||
fake_apksigner="$scratch/apksigner"
|
||||
printf 'apk\n' > "$apk"
|
||||
|
||||
cat > "$fake_apksigner" <<'SCRIPT'
|
||||
#!/usr/bin/env bash
|
||||
case "${FAKE_APKSIGNER_MODE:-success}" in
|
||||
success)
|
||||
printf '%s\n' \
|
||||
'Verifies' \
|
||||
'Signer #1 certificate SHA-256 digest: AA:BB:CC:DD' >&2
|
||||
;;
|
||||
missing)
|
||||
printf '%s\n' 'Verifies' >&2
|
||||
;;
|
||||
failure)
|
||||
printf '%s\n' 'invalid APK signature' >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
SCRIPT
|
||||
chmod +x "$fake_apksigner"
|
||||
|
||||
actual="$(
|
||||
APKSIGNER="$fake_apksigner" \
|
||||
"$verifier" "$apk" "aa bb cc dd"
|
||||
)"
|
||||
[[ $actual == aabbccdd ]]
|
||||
|
||||
if APKSIGNER="$fake_apksigner" \
|
||||
"$verifier" "$apk" deadbeef >/dev/null 2>&1; then
|
||||
printf 'Expected a certificate mismatch to fail\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if FAKE_APKSIGNER_MODE=missing APKSIGNER="$fake_apksigner" \
|
||||
"$verifier" "$apk" aabbccdd >/dev/null 2>&1; then
|
||||
printf 'Expected missing certificate output to fail\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if FAKE_APKSIGNER_MODE=failure APKSIGNER="$fake_apksigner" \
|
||||
"$verifier" "$apk" aabbccdd >/dev/null 2>&1; then
|
||||
printf 'Expected signature verification failure to propagate\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'APK signature verifier tests passed.\n'
|
||||
86
packaging/android/verify-apk-signature.sh
Executable file
86
packaging/android/verify-apk-signature.sh
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 2 ]]; then
|
||||
printf 'Usage: %s <apk> <expected-certificate-sha256>\n' "$0" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
apk=$1
|
||||
expected_fingerprint=$2
|
||||
build_tools_version=${ANDROID_BUILD_TOOLS_VERSION:-36.0.0}
|
||||
|
||||
normalize_fingerprint() {
|
||||
printf '%s' "$1" |
|
||||
tr -d '[:space:]:' |
|
||||
tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
find_apksigner() {
|
||||
if [[ -n ${APKSIGNER:-} ]]; then
|
||||
[[ -x $APKSIGNER ]] || {
|
||||
printf 'Configured apksigner is not executable: %s\n' "$APKSIGNER" >&2
|
||||
return 1
|
||||
}
|
||||
printf '%s\n' "$APKSIGNER"
|
||||
return
|
||||
fi
|
||||
|
||||
local sdk_root=${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}
|
||||
if [[ -n $sdk_root ]]; then
|
||||
local pinned="$sdk_root/build-tools/$build_tools_version/apksigner"
|
||||
if [[ -x $pinned ]]; then
|
||||
printf '%s\n' "$pinned"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if command -v apksigner >/dev/null 2>&1; then
|
||||
command -v apksigner
|
||||
return
|
||||
fi
|
||||
|
||||
printf 'apksigner %s was not found in the Android SDK or PATH\n' \
|
||||
"$build_tools_version" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
[[ -s $apk ]] || {
|
||||
printf 'APK is missing or empty: %s\n' "$apk" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
apksigner_path="$(find_apksigner)" || exit 1
|
||||
if ! signature_report="$(
|
||||
"$apksigner_path" verify --verbose --print-certs "$apk" 2>&1
|
||||
)"; then
|
||||
printf 'APK signature verification failed:\n%s\n' "$signature_report" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
actual_fingerprint="$(
|
||||
printf '%s\n' "$signature_report" |
|
||||
awk '
|
||||
tolower($0) ~ /^signer #1 certificate sha-256 digest:[[:space:]]*/ {
|
||||
line = $0
|
||||
sub(/^[^:]*:[[:space:]]*/, "", line)
|
||||
print line
|
||||
exit
|
||||
}
|
||||
'
|
||||
)"
|
||||
[[ -n $actual_fingerprint ]] || {
|
||||
printf 'Could not read the APK signing certificate fingerprint\n' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
actual_fingerprint="$(normalize_fingerprint "$actual_fingerprint")"
|
||||
expected_fingerprint="$(normalize_fingerprint "$expected_fingerprint")"
|
||||
[[ $actual_fingerprint == "$expected_fingerprint" ]] || {
|
||||
printf 'APK signing certificate mismatch: expected %s, got %s\n' \
|
||||
"$expected_fingerprint" "$actual_fingerprint" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
printf '%s\n' "$actual_fingerprint"
|
||||
Reference in New Issue
Block a user