Modern Apps git

MAOS.git

Public
git clone https://git.maproj.org/MAOS.git
main ▾

MAOS.git / keys / generate-keys.sh

generate-keys.sh81 lines · 3.3 KiBRaw
1#!/usr/bin/env bash
2#
3# generate-keys.sh — create the MAOS signing key set on the (offline) build host.
4#
5# These are the OS keys, entirely separate from the app signing keys: the 28 Modern
6# Apps ship `presigned` and keep their own com.vayunmathur certificate, so app updates
7# via the app store keep working. Do NOT reuse an app key here, and do NOT reuse these
8# for apps (a platform-signed app would be massively over-privileged).
9#
10# >>> The generated files are PRIVATE KEYS. Keep them OFFLINE, back them up, and NEVER
11# >>> commit them. This repo's .gitignore excludes keys/*, but be careful anyway.
12#
13# Usage:
14# source build/envsetup.sh # sets ANDROID_BUILD_TOP, adds avbtool to PATH
15# vendor/modern-apps/keys/generate-keys.sh ~/.android-certs ["/C=US/ST=.../CN=MAOS/..."]
16#
17set -euo pipefail
18
19OUT="${1:?usage: generate-keys.sh <output-dir> [x509-subject]}"
20SUBJECT="${2:-/C=US/ST=California/L=Burlingame/O=MAOS/OU=MAOS/CN=MAOS/[email protected]}"
21
22: "${ANDROID_BUILD_TOP:?run 'source build/envsetup.sh' in the AOSP tree first}"
23MAKE_KEY="$ANDROID_BUILD_TOP/development/tools/make_key"
24[[ -x "$MAKE_KEY" ]] || { echo "make_key not found at $MAKE_KEY" >&2; exit 1; }
25command -v avbtool >/dev/null || { echo "avbtool not on PATH (source envsetup.sh / lunch)" >&2; exit 1; }
26
27mkdir -p "$OUT"
28cd "$OUT"
29
30# The AOSP APK-signing key set. releasekey also signs the OTA payloads.
31# platform/shared/media are classic; networkstack (A10+), sdk_sandbox (A14+) and
32# bluetooth (A13+) are required by newer platforms — generating extras is harmless.
33# Keep this list in sync with the key set generated by build-maos.sh phase_keys.
34KEYS=(releasekey platform shared media networkstack bluetooth sdk_sandbox gmscompat_lib nfc)
35
36for k in "${KEYS[@]}"; do
37 if [[ -f "$k.pk8" ]]; then
38 echo "skip $k (already exists)"
39 continue
40 fi
41 echo "generating $k ..."
42 # Empty passphrase (piped) => unencrypted keys suitable for automated signing.
43 # For encrypted keys, run make_key interactively and keep the passphrases in a
44 # secrets manager the release job can read.
45 echo | "$MAKE_KEY" "$k" "$SUBJECT"
46done
47
48# Verified Boot (AVB) key: RSA-4096 private key + its public-key metadata blob that
49# gets embedded in vbmeta. Wired into the build via BOARD_AVB_* / the signing step
50# (see docs/BUILD_RUNBOOK.md).
51if [[ ! -f avb.pem ]]; then
52 echo "generating avb.pem (RSA-4096) ..."
53 openssl genrsa -out avb.pem 4096
54 avbtool extract_public_key --key avb.pem --output avb_pkmd.bin
55else
56 echo "skip avb.pem (already exists)"
57fi
58
59# SSH keypair included in the encrypted key blob by build-maos.sh phase_keys.
60if [[ ! -f id_ed25519 ]]; then
61 echo "generating id_ed25519 ..."
62 ssh-keygen -t ed25519 -N "" -f id_ed25519 >/dev/null
63else
64 echo "skip id_ed25519 (already exists)"
65fi
66
67chmod 600 ./*.pk8 ./*.pem id_ed25519 2>/dev/null || true
68
69cat <<EOF
70
71Done. Key set written to: $OUT
72 APK/OTA keys : ${KEYS[*]} (.pk8 + .x509.pem each)
73 AVB : avb.pem (private) + avb_pkmd.bin (public metadata)
74 SSH : id_ed25519 (+ .pub)
75
76Next:
77 * Keep this directory OFFLINE and backed up. Losing releasekey/avb bricks OTA updates
78 for every installed device (they can only accept updates signed by the same keys).
79 * Never commit these files.
80 * See docs/BUILD_RUNBOOK.md for wiring them into the build + signing + OTA steps.
81EOF