Scott Baker | 1fe7273 | 2019-10-21 10:58:51 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | cd "$(dirname $0)" |
| 6 | |
| 7 | # Run this script to generate files used by tests. |
| 8 | |
| 9 | echo "Creating protosets..." |
| 10 | protoc testing/test.proto \ |
| 11 | --include_imports \ |
| 12 | --descriptor_set_out=testing/test.protoset |
| 13 | |
| 14 | protoc testing/example.proto \ |
| 15 | --include_imports \ |
| 16 | --descriptor_set_out=testing/example.protoset |
| 17 | |
| 18 | echo "Creating certs for TLS testing..." |
| 19 | if ! hash certstrap 2>/dev/null; then |
| 20 | # certstrap not found: try to install it |
| 21 | go get github.com/square/certstrap |
| 22 | go install github.com/square/certstrap |
| 23 | fi |
| 24 | |
| 25 | function cs() { |
| 26 | certstrap --depot-path testing/tls "$@" --passphrase "" |
| 27 | } |
| 28 | |
| 29 | rm -rf testing/tls |
| 30 | |
| 31 | # Create CA |
| 32 | cs init --years 10 --common-name ca |
| 33 | |
| 34 | # Create client cert |
| 35 | cs request-cert --common-name client |
| 36 | cs sign client --years 10 --CA ca |
| 37 | |
| 38 | # Create server cert |
| 39 | cs request-cert --common-name server --ip 127.0.0.1 --domain localhost |
| 40 | cs sign server --years 10 --CA ca |
| 41 | |
| 42 | # Create another server cert for error testing |
| 43 | cs request-cert --common-name other --ip 1.2.3.4 --domain foobar.com |
| 44 | cs sign other --years 10 --CA ca |
| 45 | |
| 46 | # Create another CA and client cert for more |
| 47 | # error testing |
| 48 | cs init --years 10 --common-name wrong-ca |
| 49 | cs request-cert --common-name wrong-client |
| 50 | cs sign wrong-client --years 10 --CA wrong-ca |
| 51 | |
| 52 | # Create expired cert |
| 53 | cs request-cert --common-name expired --ip 127.0.0.1 --domain localhost |
| 54 | cs sign expired --years 0 --CA ca |