summaryrefslogtreecommitdiff
path: root/chromium/net/data/ssl/scripts/generate-android-test-keys.sh
blob: 1c297e3a86fc3ff6064e40e58c3ef5704efb1e09 (plain)
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
50
51
52
53
54
55
56
#!/bin/sh

# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# This script is used to generate the test keys for the unit test in
# android/keystore_unittest.c.
#
# These are test RSA / DSA / ECDSA private keys in PKCS#8 format, as well
# as the corresponding DSA / ECDSA public keys.
#

# Exit script as soon a something fails.
set -e

mkdir -p out
rm -rf out/*

# Generate a single 2048-bits RSA private key in PKCS#8 format.
KEY=android-test-key-rsa
openssl genrsa \
    -out out/$KEY.pem \
    2048

# Generate a 2048-bits DSA private key in PKCS#8 format,
# as well as its public key in X.509 DER format.
KEY=android-test-key-dsa
openssl dsaparam \
    -out out/$KEY.param.pem \
    2048

openssl gendsa \
    -out out/$KEY.pem \
    out/$KEY.param.pem

openssl dsa \
    -in out/$KEY.pem \
    -outform PEM \
    -out out/$KEY-public.pem \
    -pubout

rm out/$KEY.param.pem

# Generate an ECDSA private key, in PKCS#8 format,
# as well as its public key in X.509 DER format.
KEY=android-test-key-ecdsa
openssl ecparam -genkey -name prime256v1 -out out/$KEY.pem

openssl ec \
    -in out/$KEY.pem \
    -outform PEM \
    -out out/$KEY-public.pem \
    -pubout

# We're done here.