forked from osbuild/osbuild-composer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen-certs.sh
executable file
·97 lines (81 loc) · 3.22 KB
/
gen-certs.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
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
92
93
94
95
96
97
#!/bin/bash
if (( $# != 3 )); then
echo "Usage: $0 <openssl-config> <certdir> <cadir>"
echo
echo "Positional arguments"
echo " <openssl-config> OpenSSL configuration file"
echo " <certdir> Destination directory for the generated files"
echo " <cadir> Working directory for the generation process"
exit 1
fi
set -euxo pipefail
# Generate all X.509 certificates for the tests
# The whole generation is done in a $CADIR to better represent how osbuild-ca
# it.
OPENSSL_CONFIG="$1"
CERTDIR="$2"
CADIR="$3"
# The $CADIR might exist from a previous test (current Schutzbot's imperfection)
rm -rf "$CADIR" || true
mkdir -p "$CADIR" "$CERTDIR"
# Convert the arguments to real paths so we can safely change working directory
OPENSSL_CONFIG="$(realpath "${OPENSSL_CONFIG}")"
CERTDIR="$(realpath "${CERTDIR}")"
CADIR="$(realpath "${CADIR}")"
pushd "$CADIR"
mkdir certs private
touch index.txt
# Generate a CA.
openssl req -config "$OPENSSL_CONFIG" \
-keyout private/ca.key.pem \
-new -nodes -x509 -extensions osbuild_ca_ext \
-out ca.cert.pem -subj "/CN=osbuild.org"
# Copy the private key to the location expected by the tests
cp ca.cert.pem "$CERTDIR"/ca-crt.pem
# Generate a composer certificate.
openssl req -config "$OPENSSL_CONFIG" \
-keyout "$CERTDIR"/composer-key.pem \
-new -nodes \
-out /tmp/composer-csr.pem \
-subj "/CN=localhost/[email protected]" \
-addext "subjectAltName=DNS:localhost, DNS:composer"
openssl ca -batch -config "$OPENSSL_CONFIG" \
-extensions osbuild_server_ext \
-in /tmp/composer-csr.pem \
-out "$CERTDIR"/composer-crt.pem
# Generate a worker certificate.
openssl req -config "$OPENSSL_CONFIG" \
-keyout "$CERTDIR"/worker-key.pem \
-new -nodes \
-out /tmp/worker-csr.pem \
-subj "/CN=localhost/[email protected]" \
-addext "subjectAltName=DNS:localhost, DNS:worker"
openssl ca -batch -config "$OPENSSL_CONFIG" \
-extensions osbuild_client_ext \
-in /tmp/worker-csr.pem \
-out "$CERTDIR"/worker-crt.pem
# Generate a client certificate.
openssl req -config "$OPENSSL_CONFIG" \
-keyout "$CERTDIR"/client-key.pem \
-new -nodes \
-out /tmp/client-csr.pem \
-subj "/CN=client.osbuild.org/[email protected]" \
-addext "subjectAltName=DNS:client.osbuild.org"
openssl ca -batch -config "$OPENSSL_CONFIG" \
-extensions osbuild_client_ext \
-in /tmp/client-csr.pem \
-out "$CERTDIR"/client-crt.pem
# Client keys are used by tests to access the composer APIs. Allow all users access.
chmod 644 "$CERTDIR"/client-key.pem
# Generate a kojihub certificate.
openssl req -config "$OPENSSL_CONFIG" \
-keyout "$CERTDIR"/kojihub-key.pem \
-new -nodes \
-out /tmp/kojihub-csr.pem \
-subj "/CN=localhost/[email protected]" \
-addext "subjectAltName=DNS:localhost"
openssl ca -batch -config "$OPENSSL_CONFIG" \
-extensions osbuild_server_ext \
-in /tmp/kojihub-csr.pem \
-out "$CERTDIR"/kojihub-crt.pem
popd