summaryrefslogtreecommitdiff
path: root/chromium/net/data/ssl/scripts/generate-aia-certs.sh
blob: 98b858e139aa497bb74f8d7fef62f30280d3fa7a (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh

# Copyright 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 generates a set of test (end-entity, intermediate, root)
# certificates that can be used to test fetching of an intermediate via AIA.

try() {
  echo "$@"
  $@ || exit 1
}

try rm -rf out
try mkdir out

# Create the serial number files.
try echo 1 > out/aia-test-root-serial
try echo 1 > out/aia-test-intermediate-serial

# Create the signers' DB files.
touch out/aia-test-root-index.txt
touch out/aia-test-intermediate-index.txt

# Generate the keys
try openssl genrsa -out out/aia-test-root.key 2048
try openssl genrsa -out out/aia-test-intermediate.key 2048
try openssl genrsa -out out/aia-test-cert.key 2048

# Generate the root certificate
CA_COMMON_NAME="AIA Test Root CA" \
  CA_DIR=out \
  CA_NAME=aia-test-root \
  try openssl req \
    -new \
    -key out/aia-test-root.key \
    -out out/aia-test-root.csr \
    -config aia-test.cnf

CA_COMMON_NAME="AIA Test Root CA" \
  CA_DIR=out \
  CA_NAME=aia-test-root \
  try openssl x509 \
    -req -days 3650 \
    -in out/aia-test-root.csr \
    -out out/aia-test-root.pem \
    -signkey out/aia-test-root.key \
    -extfile aia-test.cnf \
    -extensions ca_cert

# Generate the intermediate
CA_COMMON_NAME="AIA Test Intermediate CA" \
  CA_DIR=out \
  CA_NAME=aia-test-root \
  try openssl req \
    -new \
    -key out/aia-test-intermediate.key \
    -out out/aia-test-intermediate.csr \
    -config aia-test.cnf

CA_COMMON_NAME="AIA Test Intermediate CA" \
  CA_DIR=out \
  CA_NAME=aia-test-root \
  try openssl ca \
    -batch \
    -in out/aia-test-intermediate.csr \
    -out out/aia-test-intermediate.pem \
    -config aia-test.cnf \
    -extensions ca_cert

# Generate the leaf
CA_COMMON_NAME="aia-host.invalid" \
CA_DIR=out \
CA_NAME=aia-test-intermediate \
try openssl req \
  -new \
  -key out/aia-test-cert.key \
  -out out/aia-test-cert.csr \
  -config aia-test.cnf

CA_COMMON_NAME="AIA Test Intermediate CA" \
  CA_DIR=out \
  CA_NAME=aia-test-intermediate \
  AIA_URL=http://aia-test.invalid \
  try openssl ca \
    -batch \
    -in out/aia-test-cert.csr \
    -out out/aia-test-cert.pem \
    -config aia-test.cnf \
    -extensions user_cert