-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
encrypt-keys.sh
executable file
·49 lines (36 loc) · 1.33 KB
/
encrypt-keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
set -o errexit -o nounset -o pipefail
source "$(dirname ${BASH_SOURCE[0]})/common.sh"
[[ $# -ne 1 ]] && user_error "expected 1 argument (key directory)"
cd $1
read -rp "Enter old key passphrase (empty if none): " -s password
echo
read -rp "Enter new key passphrase: " -s new_password
echo
read -rp "Confirm new key passphrase: " -s confirm_new_password
echo
if [[ "$new_password" != "$confirm_new_password" ]]; then
echo new password does not match
exit 1
fi
tmp="$(mktemp -d /dev/shm/encrypt-keys.XXXXXXXXXX)"
trap "rm -rf \"$tmp\"" EXIT
export password
export new_password
for key in releasekey platform shared media networkstack bluetooth sdk_sandbox; do
if [[ -n $password ]]; then
openssl pkcs8 -inform DER -in $key.pk8 -passin env:password | openssl pkcs8 -topk8 -outform DER -out "$tmp/$key.pk8" -passout env:new_password -scrypt
else
openssl pkcs8 -topk8 -inform DER -in $key.pk8 -outform DER -out "$tmp/$key.pk8" -passout env:new_password -scrypt
fi
done
if [[ -f avb.pem ]]; then
if [[ -n $password ]]; then
openssl pkcs8 -topk8 -in avb.pem -passin env:password -out "$tmp/avb.pem" -passout env:new_password -scrypt
else
openssl pkcs8 -topk8 -in avb.pem -out "$tmp/avb.pem" -passout env:new_password -scrypt
fi
fi
unset password
unset new_password
mv "$tmp"/* .