3 # Copyright (C) 2009 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Generates a public/private key pair suitable for use in signing
18 # android .apks and OTA update packages.
20 if [ "$#" -ne 2 ]; then
22 Usage: $0 <name> <subject>
24 Creates <name>.pk8 key and <name>.x509.pem cert. Cert contains the
30 if [[ -e $1.pk8 || -e $1.x509.pem ]]; then
31 echo "$1.pk8 and/or $1.x509.pem already exist; please delete them first"
32 echo "if you want to replace them."
36 # Use named pipes to connect get the raw RSA private key to the cert-
37 # and .pk8-creating programs, to avoid having the private key ever
41 trap 'rm -rf ${tmpdir}; echo; exit 1' EXIT INT QUIT
47 chmod 0600 ${one} ${two}
49 read -p "Enter password for '$1' (blank for none; password will be visible): " \
52 ( openssl genrsa -3 2048 | tee ${one} > ${two} ) &
54 openssl req -new -x509 -sha1 -key ${two} -out $1.x509.pem \
55 -days 10000 -subj "$2" &
57 if [ "${password}" == "" ]; then
58 echo "creating ${1}.pk8 with no password"
59 openssl pkcs8 -in ${one} -topk8 -outform DER -out $1.pk8 -nocrypt
61 echo "creating ${1}.pk8 with password [${password}]"
62 echo $password | openssl pkcs8 -in ${one} -topk8 -outform DER -out $1.pk8 \