|
| 1 | +#! /usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +export COMPOSE_FILE="../docker-compose.yml:./custom-ca-roots/docker-compose.test.yml" |
| 5 | + |
| 6 | +TEST_NGINX_CONF_PATH="./custom-ca-roots/nginx" |
| 7 | +CUSTOM_CERTS_PATH="../certificates" |
| 8 | + |
| 9 | +# generate tightly constrained CA |
| 10 | +# NB: `-addext` requires LibreSSL 3.1.0+, or OpenSSL (brew install openssl) |
| 11 | +openssl req -x509 -new -nodes -newkey rsa:2048 -keyout $TEST_NGINX_CONF_PATH/ca.key \ |
| 12 | +-sha256 -days 1 -out $TEST_NGINX_CONF_PATH/ca.crt -batch \ |
| 13 | +-subj "/CN=TEST CA *DO NOT TRUST*" \ |
| 14 | +-addext "keyUsage = critical, keyCertSign, cRLSign" \ |
| 15 | +-addext "nameConstraints = critical, permitted;DNS:self.test" |
| 16 | + |
| 17 | +## Lines like the following are debug helpers ... |
| 18 | +# openssl x509 -in nginx/ca.crt -text -noout |
| 19 | + |
| 20 | +mkdir -p $CUSTOM_CERTS_PATH |
| 21 | +cp $TEST_NGINX_CONF_PATH/ca.crt $CUSTOM_CERTS_PATH/test-custom-ca-roots.crt |
| 22 | + |
| 23 | +# generate server certificate |
| 24 | +openssl req -new -nodes -newkey rsa:2048 -keyout $TEST_NGINX_CONF_PATH/self.test.key \ |
| 25 | +-addext "subjectAltName=DNS:self.test" \ |
| 26 | +-out $TEST_NGINX_CONF_PATH/self.test.req -batch -subj "/CN=Self Signed with CA Test Server" |
| 27 | + |
| 28 | +# openssl req -in nginx/self.test.req -text -noout |
| 29 | + |
| 30 | +openssl x509 -req -in $TEST_NGINX_CONF_PATH/self.test.req -CA $TEST_NGINX_CONF_PATH/ca.crt -CAkey $TEST_NGINX_CONF_PATH/ca.key \ |
| 31 | +-extfile <(printf "subjectAltName=DNS:self.test") \ |
| 32 | +-CAcreateserial -out $TEST_NGINX_CONF_PATH/self.test.crt -days 1 -sha256 |
| 33 | + |
| 34 | +# openssl x509 -in nginx/self.test.crt -text -noout |
| 35 | + |
| 36 | +# sanity check that signed certificate passes OpenSSL's validation |
| 37 | +openssl verify -CAfile $TEST_NGINX_CONF_PATH/ca.crt $TEST_NGINX_CONF_PATH/self.test.crt |
| 38 | + |
| 39 | +# self signed certificate, for sanity check of not just accepting all certs |
| 40 | +openssl req -x509 -newkey rsa:2048 -nodes -days 1 -keyout $TEST_NGINX_CONF_PATH/fake.test.key \ |
| 41 | +-out $TEST_NGINX_CONF_PATH/fake.test.crt -addext "subjectAltName=DNS:fake.test" -subj "/CN=Self Signed Test Server" |
| 42 | + |
| 43 | +# openssl x509 -in nginx/fake.test.crt -text -noout |
| 44 | + |
| 45 | +cp ./custom-ca-roots/test.py ../sentry/test-custom-ca-roots.py |
| 46 | + |
| 47 | +$dc up -d fixture-custom-ca-roots |
0 commit comments