summaryrefslogtreecommitdiffstats
path: root/tests/manual/network/ssl/client-auth/certs/generate.sh
blob: 5dbe3b3712acadb6517857b9bc07cb22d1a4f970 (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
#!/bin/bash
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

# Requires mkcert and openssl

warn () { echo "$@" >&2; }
die () { warn "$@"; exit 1; }


command -v mkcert 1>/dev/null 2>&1 || die "Failed to find mkcert"
command -v openssl 1>/dev/null 2>&1 || die "Failed to find openssl"

SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

pushd "$SCRIPTPATH" || die "Unable to pushd to $SCRIPTPATH"
mkcert 127.0.0.1
mkcert -client 127.0.0.1
warn "Remember to run mkcert -install if you haven't already"

# Generate CA
openssl genrsa -out ca-key.pem 2048
openssl req -new -x509 -noenc -days 365 -key ca-key.pem -out rootCA.pem

# Generate accepted client certificate
openssl genrsa -out accepted-client-key.pem 2048
openssl req -new -sha512 -nodes -key accepted-client-key.pem -out accepted-client.csr -config accepted-client.conf
openssl x509 -req -sha512 -days 45 -in accepted-client.csr -CA rootCA.pem -CAkey ca-key.pem -CAcreateserial -out accepted-client.pem
rm accepted-client.csr
rm rootCA.srl

popd || die "Unable to popd"