Skip to content

Commit a163fa9

Browse files
krutonAndroid Git Automerger
authored andcommitted
am 7e0d5c2: am c9421a7: Merge "make_key: add EC key generation support"
* commit '7e0d5c29b33f3056aedcb44cb8cbae808c11c35d': make_key: add EC key generation support
2 parents b40c157 + 7e0d5c2 commit a163fa9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tools/make_key

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
# Generates a public/private key pair suitable for use in signing
1818
# android .apks and OTA update packages.
1919

20-
if [ "$#" -ne 2 ]; then
20+
if [ "$#" -lt 2 -o "$#" -gt 3 ]; then
2121
cat <<EOF
22-
Usage: $0 <name> <subject>
22+
Usage: $0 <name> <subject> [<keytype>]
2323
2424
Creates <name>.pk8 key and <name>.x509.pem cert. Cert contains the
25-
given <subject>.
25+
given <subject>. A keytype of "rsa" or "ec" is accepted.
2626
EOF
2727
exit 2
2828
fi
@@ -49,9 +49,18 @@ chmod 0600 ${one} ${two}
4949
read -p "Enter password for '$1' (blank for none; password will be visible): " \
5050
password
5151

52-
( openssl genrsa -f4 2048 | tee ${one} > ${two} ) &
52+
if [ "${3}" = "rsa" -o "$#" -eq 2 ]; then
53+
( openssl genrsa -f4 2048 | tee ${one} > ${two} ) &
54+
hash="-sha1"
55+
elif [ "${3}" = "ec" ]; then
56+
( openssl ecparam -name prime256v1 -genkey -noout | tee ${one} > ${two} ) &
57+
hash="-sha256"
58+
else
59+
echo "Only accepts RSA or EC keytypes."
60+
exit 1
61+
fi
5362

54-
openssl req -new -x509 -sha1 -key ${two} -out $1.x509.pem \
63+
openssl req -new -x509 ${hash} -key ${two} -out $1.x509.pem \
5564
-days 10000 -subj "$2" &
5665

5766
if [ "${password}" == "" ]; then

0 commit comments

Comments
 (0)