2019-09-12 07:56:54 +00:00
|
|
|
#!/bin/bash
|
2020-12-11 16:31:40 +00:00
|
|
|
|
|
|
|
# Generate some test certificates which are used by the regression test suite:
|
|
|
|
#
|
|
|
|
# tests/tls/ca.{crt,key} Self signed CA certificate.
|
2024-04-03 21:04:52 +00:00
|
|
|
# tests/tls/valkey.{crt,key} A certificate with no key usage/policy restrictions.
|
2020-12-11 16:31:40 +00:00
|
|
|
# tests/tls/client.{crt,key} A certificate restricted for SSL client usage.
|
2021-04-25 07:11:16 +00:00
|
|
|
# tests/tls/server.{crt,key} A certificate restricted for SSL server usage.
|
2024-04-03 21:04:52 +00:00
|
|
|
# tests/tls/valkey.dh DH Params file.
|
2020-12-11 16:31:40 +00:00
|
|
|
|
|
|
|
generate_cert() {
|
|
|
|
local name=$1
|
|
|
|
local cn="$2"
|
|
|
|
local opts="$3"
|
|
|
|
|
|
|
|
local keyfile=tests/tls/${name}.key
|
|
|
|
local certfile=tests/tls/${name}.crt
|
|
|
|
|
|
|
|
[ -f $keyfile ] || openssl genrsa -out $keyfile 2048
|
|
|
|
openssl req \
|
|
|
|
-new -sha256 \
|
2024-05-30 17:09:29 +00:00
|
|
|
-subj "/O=Valkey Test/CN=$cn" \
|
2020-12-11 16:31:40 +00:00
|
|
|
-key $keyfile | \
|
|
|
|
openssl x509 \
|
|
|
|
-req -sha256 \
|
|
|
|
-CA tests/tls/ca.crt \
|
|
|
|
-CAkey tests/tls/ca.key \
|
|
|
|
-CAserial tests/tls/ca.txt \
|
|
|
|
-CAcreateserial \
|
|
|
|
-days 365 \
|
|
|
|
$opts \
|
|
|
|
-out $certfile
|
|
|
|
}
|
|
|
|
|
2019-09-12 07:56:54 +00:00
|
|
|
mkdir -p tests/tls
|
2020-12-11 16:31:40 +00:00
|
|
|
[ -f tests/tls/ca.key ] || openssl genrsa -out tests/tls/ca.key 4096
|
2019-09-12 07:56:54 +00:00
|
|
|
openssl req \
|
|
|
|
-x509 -new -nodes -sha256 \
|
|
|
|
-key tests/tls/ca.key \
|
|
|
|
-days 3650 \
|
2024-05-30 17:09:29 +00:00
|
|
|
-subj '/O=Valkey Test/CN=Certificate Authority' \
|
2019-09-12 07:56:54 +00:00
|
|
|
-out tests/tls/ca.crt
|
2020-12-11 16:31:40 +00:00
|
|
|
|
|
|
|
cat > tests/tls/openssl.cnf <<_END_
|
|
|
|
[ server_cert ]
|
|
|
|
keyUsage = digitalSignature, keyEncipherment
|
|
|
|
nsCertType = server
|
|
|
|
|
|
|
|
[ client_cert ]
|
|
|
|
keyUsage = digitalSignature, keyEncipherment
|
|
|
|
nsCertType = client
|
|
|
|
_END_
|
|
|
|
|
|
|
|
generate_cert server "Server-only" "-extfile tests/tls/openssl.cnf -extensions server_cert"
|
|
|
|
generate_cert client "Client-only" "-extfile tests/tls/openssl.cnf -extensions client_cert"
|
2024-04-03 21:04:52 +00:00
|
|
|
generate_cert valkey "Generic-cert"
|
2020-12-11 16:31:40 +00:00
|
|
|
|
2024-04-03 21:04:52 +00:00
|
|
|
[ -f tests/tls/valkey.dh ] || openssl dhparam -out tests/tls/valkey.dh 2048
|