tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

40 lignes · 1475 octetsBrut · Historique
1#!/usr/bin/env bash
2# Certificates for the example's two nodes, into DIR (README.md):
3#
4# examples/cluster/make-certs.sh DIR
5#
6# - ca.pem / ca.key: the cluster's authority;
7# - a.pem / a.key: node a.cluster.example;
8# - b.pem / b.key: node b.cluster.example.
9# A node is both a TLS server and a TLS client (mutual TLS), so each
10# certificate is for both, and names its node in its subjectAltName: the
11# name the other nodes check. FOR TRYING THE EXAMPLE ONLY: a real cluster's
12# keys come from its own authority, and stay secret.
13set -euo pipefail
14dir=${1:?usage: make-certs.sh DIR}
15mkdir -p "$dir"
16cd "$dir"
17
18key() { openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out "$1" 2>/dev/null; }
19
20key ca.key
21openssl req -x509 -new -key ca.key -subj "/CN=cluster example CA" -days 30 -out ca.pem \
22 -addext "basicConstraints=critical,CA:TRUE" \
23 -addext "keyUsage=critical,keyCertSign,cRLSign"
24
25for n in a b; do
26 key "$n.key"
27 openssl req -new -key "$n.key" -subj "/CN=$n.cluster.example" -out "$n.csr"
28 cat > "$n.ext" <<EXT
29basicConstraints=critical,CA:FALSE
30keyUsage=critical,digitalSignature,keyEncipherment
31extendedKeyUsage=serverAuth,clientAuth
32subjectAltName=DNS:$n.cluster.example
33EXT
34 openssl x509 -req -in "$n.csr" -CA ca.pem -CAkey ca.key -CAcreateserial \
35 -extfile "$n.ext" -days 30 -out "$n.pem" 2>/dev/null
36 rm -f "$n.csr" "$n.ext"
37done
38rm -f ca.srl
39chmod 600 ./*.key
40echo "certificates for a.cluster.example and b.cluster.example in $PWD"