diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:35:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:35:32 +0000 |
commit | 5ea77a75dd2d2158401331879f3c8f47940a732c (patch) | |
tree | d89dc06e9f4850a900f161e25f84e922c4f86cc8 /tests/data/tls/create-crt.sh | |
parent | Initial commit. (diff) | |
download | openldap-5ea77a75dd2d2158401331879f3c8f47940a732c.tar.xz openldap-5ea77a75dd2d2158401331879f3c8f47940a732c.zip |
Adding upstream version 2.5.13+dfsg.upstream/2.5.13+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/data/tls/create-crt.sh')
-rwxr-xr-x | tests/data/tls/create-crt.sh | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/data/tls/create-crt.sh b/tests/data/tls/create-crt.sh new file mode 100755 index 0000000..739f8ea --- /dev/null +++ b/tests/data/tls/create-crt.sh @@ -0,0 +1,81 @@ +#!/bin/sh +openssl=$(which openssl) + +if [ x"$openssl" = "x" ]; then +echo "OpenSSL command line binary not found, skipping..." +fi + +KEY_BITS=4096 +KEY_TYPE=rsa:$KEY_BITS + +USAGE="$0 [-s] [-u <user@domain.com>]" +SERVER=0 +USER=0 +EMAIL= + +while test $# -gt 0 ; do + case "$1" in + -s | -server) + SERVER=1; + shift;; + -u | -user) + if [ x"$2" = "x" ]; then + echo "User cert requires an email address as an argument" + exit; + fi + USER=1; + EMAIL="$2"; + shift; shift;; + -) + shift;; + -*) + echo "$USAGE"; exit 1 + ;; + *) + break;; + esac +done + +if [ $SERVER = 0 -a $USER = 0 ]; then + echo "$USAGE"; + exit 1; +fi + +rm -rf ./openssl.cnf cruft +mkdir -p private certs cruft/private cruft/certs + +echo "00" > cruft/serial +touch cruft/index.txt +touch cruft/index.txt.attr +hn=$(hostname -f) +sed -e "s;@HOSTNAME@;$hn;" -e "s;@KEY_BITS@;$KEY_BITS;" conf/openssl.cnf > ./openssl.cnf + +if [ $SERVER = 1 ]; then + rm -rf private/localhost.key certs/localhost.crt + + $openssl req -new -nodes -out localhost.csr -keyout private/localhost.key \ + -newkey $KEY_TYPE -config ./openssl.cnf \ + -subj "/CN=localhost/OU=OpenLDAP Test Suite/O=OpenLDAP Foundation/ST=CA/C=US" \ + -batch > /dev/null 2>&1 + + $openssl ca -out certs/localhost.crt -notext -config ./openssl.cnf -days 183000 -in localhost.csr \ + -keyfile ca/private/testsuiteCA.key -extensions v3_req -cert ca/certs/testsuiteCA.crt \ + -batch >/dev/null 2>&1 + + rm -rf ./openssl.cnf ./localhost.csr cruft +fi + +if [ $USER = 1 ]; then + rm -f certs/$EMAIL.crt private/$EMAIL.key $EMAIL.csr + + $openssl req -new -nodes -out $EMAIL.csr -keyout private/$EMAIL.key \ + -newkey $KEY_TYPE -config ./openssl.cnf \ + -subj "/emailAddress=$EMAIL/CN=$EMAIL/OU=OpenLDAP/O=OpenLDAP Foundation/ST=CA/C=US" \ + -batch >/dev/null 2>&1 + + $openssl ca -out certs/$EMAIL.crt -notext -config ./openssl.cnf -days 183000 -in $EMAIL.csr \ + -keyfile ca/private/testsuiteCA.key -extensions req_distinguished_name \ + -cert ca/certs/testsuiteCA.crt -batch >/dev/null 2>&1 + + rm -rf ./openssl.cnf ./$EMAIL.csr cruft +fi |