2017-04-25 22:55:27 +02:00
#!/bin/sh
set -xe
2015-01-29 14:34:31 +01:00
# simply run me from mysql-test/
cd std_data/
# boilerplace for "openssl ca" and /etc/ssl/openssl.cnf
rm -rf demoCA
2017-04-25 22:55:27 +02:00
mkdir demoCA demoCA/newcerts
2015-01-29 14:34:31 +01:00
touch demoCA/index.txt
2020-04-14 20:38:44 +03:00
touch demoCA/index.txt.attr
2015-01-29 14:34:31 +01:00
echo 01 > demoCA/serial
2019-02-20 15:15:34 +01:00
echo 01 > demoCA/crlnumber
2015-01-29 14:34:31 +01:00
2020-04-14 20:38:44 +03:00
# Use rsa:3072 at minimum for all keys to be future compatible with next OpenSSL releases
# See level 3 in https://www.openssl.org/docs/man1.1.0/man3/SSL_CTX_set_security_level.html
# Following industry practice, jump directly to rsa:4096 instead of just rsa:3072.
2015-01-29 14:34:31 +01:00
# CA certificate, self-signed
2020-04-14 20:38:44 +03:00
openssl req -x509 -newkey rsa:4096 -keyout cakey.pem -out cacert.pem -days 7300 -nodes -subj '/CN=cacert/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB' -text
2015-01-29 14:34:31 +01:00
2015-04-25 17:22:46 +02:00
# server certificate signing request and private key. Note the very long subject (for MDEV-7859)
2020-04-14 20:38:44 +03:00
openssl req -newkey rsa:4096 -keyout server-key.pem -out demoCA/server-req.pem -days 7300 -nodes -subj '/CN=localhost/C=FI/ST=state or province within country, in other certificates in this file it is the same as L/L=location, usually an address but often ambiguously used/OU=organizational unit name, a division name within an organization/O=organization name, typically a company name'
2015-01-29 14:34:31 +01:00
# convert the key to yassl compatible format
openssl rsa -in server-key.pem -out server-key.pem
# sign the server certificate with CA certificate
2019-02-20 15:15:34 +01:00
openssl ca -keyfile cakey.pem -days 7300 -batch -cert cacert.pem -policy policy_anything -out server-cert.pem -in demoCA/server-req.pem
2015-01-29 14:34:31 +01:00
2023-08-21 16:25:56 +02:00
# server certificate with different validity period (MDEV-16266)
2020-04-14 20:38:44 +03:00
openssl req -newkey rsa:4096 -keyout server-new-key.pem -out demoCA/server-new-req.pem -days 7301 -nodes -subj '/CN=server-new/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
2019-02-20 15:15:34 +01:00
openssl rsa -in server-new-key.pem -out server-new-key.pem
openssl ca -keyfile cakey.pem -days 7301 -batch -cert cacert.pem -policy policy_anything -out server-new-cert.pem -in demoCA/server-new-req.pem
# 8K cert
2015-04-25 17:22:46 +02:00
openssl req -newkey rsa:8192 -keyout server8k-key.pem -out demoCA/server8k-req.pem -days 7300 -nodes -subj '/CN=server8k/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
2015-01-29 14:34:31 +01:00
openssl rsa -in server8k-key.pem -out server8k-key.pem
2019-02-20 15:15:34 +01:00
openssl ca -keyfile cakey.pem -days 7300 -batch -cert cacert.pem -policy policy_anything -out server8k-cert.pem -in demoCA/server8k-req.pem
2015-01-29 14:34:31 +01:00
2017-04-25 23:00:58 +02:00
# with SubjectAltName, only for OpenSSL 1.0.2+
cat > demoCA/sanext.conf <<EOF
2019-04-24 11:15:08 +02:00
subjectAltName = IP:127.0.0.1, DNS:localhost
2017-04-25 23:00:58 +02:00
EOF
2020-04-14 20:38:44 +03:00
openssl req -newkey rsa:4096 -keyout serversan-key.pem -out demoCA/serversan-req.pem -days 7300 -nodes -subj '/CN=server/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
2019-02-20 15:15:34 +01:00
openssl ca -keyfile cakey.pem -extfile demoCA/sanext.conf -days 7300 -batch -cert cacert.pem -policy policy_anything -out serversan-cert.pem -in demoCA/serversan-req.pem
# client cert
2020-04-14 20:38:44 +03:00
openssl req -newkey rsa:4096 -keyout client-key.pem -out demoCA/client-req.pem -days 7300 -nodes -subj '/CN=client/C=FI/ST=Helsinki/L=Helsinki/O=MariaDB'
2019-02-20 15:15:34 +01:00
openssl rsa -in client-key.pem -out client-key.pem
openssl ca -keyfile cakey.pem -days 7300 -batch -cert cacert.pem -policy policy_anything -out client-cert.pem -in demoCA/client-req.pem
2019-06-02 13:12:39 +02:00
# generate combined client cert and key file
cat client-cert.pem client-key.pem > client-certkey.pem
2019-02-20 15:15:34 +01:00
# generate crls
openssl ca -revoke server-cert.pem -keyfile cakey.pem -batch -cert cacert.pem
openssl ca -gencrl -keyfile cakey.pem -crldays 7300 -batch -cert cacert.pem -out server-cert.crl
# we only want to have one certificate per CRL. Un-revoke server-cert.crl
cp demoCA/index.txt.old demoCA/index.txt
openssl ca -revoke client-cert.pem -keyfile cakey.pem -batch -cert cacert.pem
openssl ca -gencrl -keyfile cakey.pem -crldays 7300 -batch -cert cacert.pem -out client-cert.crl
rm -fv crldir/*
cp -v client-cert.crl crldir/` openssl x509 -in client-cert.pem -noout -issuer_hash` .r0
2017-04-25 23:00:58 +02:00
2015-01-29 14:34:31 +01:00
rm -rf demoCA