Jens Geyer | b18964e | 2022-06-28 22:54:38 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # tested with git bash on Windows |
| 4 | # probably needs a bit of tweaking for other environments |
| 5 | |
| 6 | # re the "//SKIP=this" in sub see at https://stackoverflow.com/a/54924640/499466 |
| 7 | |
| 8 | echo init folder |
| 9 | rm *.p12 2> /dev/null |
| 10 | rm *.pem 2> /dev/null |
| 11 | rm *.crt 2> /dev/null |
| 12 | rm *.key 2> /dev/null |
| 13 | rm *.cfg 2> /dev/null |
| 14 | rm *.csr 2> /dev/null |
| 15 | |
| 16 | #cp ../*.key . |
| 17 | |
| 18 | echo writing config |
| 19 | echo '[ req ]' > my.cfg |
| 20 | echo 'default_bits= 4096' >> my.cfg |
| 21 | echo 'distinguished_name=req' >> my.cfg |
| 22 | echo 'x509_extensions = v3_ca' >> my.cfg |
| 23 | echo 'req_extensions = v3_req' >> my.cfg |
| 24 | echo '' >> my.cfg |
| 25 | echo '[ v3_req ]' >> my.cfg |
| 26 | echo 'basicConstraints = CA:FALSE' >> my.cfg |
| 27 | echo 'keyUsage = nonRepudiation, digitalSignature, keyEncipherment' >> my.cfg |
| 28 | echo 'subjectAltName=@alternate_names' >> my.cfg |
| 29 | echo '' >> my.cfg |
| 30 | echo '[ alternate_names ]' >> my.cfg |
| 31 | echo 'IP.1=127.0.0.1' >> my.cfg |
| 32 | echo 'IP.2=::1' >> my.cfg |
| 33 | echo 'IP.3=::ffff:127.0.0.1' >> my.cfg |
| 34 | echo 'DNS.1=localhost' >> my.cfg |
| 35 | echo '' >> my.cfg |
| 36 | echo '[ v3_ca ]' >> my.cfg |
| 37 | echo 'subjectKeyIdentifier=hash' >> my.cfg |
| 38 | echo 'authorityKeyIdentifier=keyid:always,issuer' >> my.cfg |
| 39 | echo 'basicConstraints = critical, CA:TRUE, pathlen:0' >> my.cfg |
| 40 | echo 'keyUsage = critical, cRLSign, keyCertSign, nonRepudiation, digitalSignature, keyEncipherment' >> my.cfg |
| 41 | echo 'extendedKeyUsage = serverAuth, clientAuth' >> my.cfg |
| 42 | echo 'subjectAltName=@alternate_names' >> my.cfg |
| 43 | echo '' >> my.cfg |
| 44 | |
| 45 | echo |
| 46 | echo step 1a |
| 47 | winpty openssl req \ |
| 48 | -new \ |
| 49 | -x509 \ |
| 50 | -nodes \ |
| 51 | -days 3000 \ |
| 52 | -out server.crt \ |
| 53 | -keyout server.key \ |
| 54 | -subj '//SKIP=this/CN=localhost/emailAddress=dev@thrift.apache.org/OU=Apache Thrift/O=The Apache Software Foundation/L=Forest Hill/ST=Maryland/C=US' \ |
| 55 | -extensions v3_ca \ |
| 56 | -config my.cfg |
| 57 | |
| 58 | echo |
| 59 | echo step 1b |
| 60 | openssl x509 -in server.crt -text > CA.pem |
| 61 | |
| 62 | echo |
| 63 | echo step 1c |
| 64 | cat server.crt server.key > server.pem |
| 65 | |
| 66 | echo |
| 67 | echo step 2 |
| 68 | echo 'Use "thrift" as password (without the quotes)' |
| 69 | winpty openssl pkcs12 -export -clcerts -in server.crt -inkey server.key -out server.p12 |
| 70 | |
| 71 | echo |
| 72 | echo step 3 |
| 73 | winpty openssl genrsa -out client.key |
| 74 | |
| 75 | |
| 76 | echo |
| 77 | echo step 4 |
| 78 | winpty openssl req \ |
| 79 | -new \ |
| 80 | -subj '//SKIP=this/CN=localhost/emailAddress=dev@thrift.apache.org/OU=Apache Thrift/O=The Apache Software Foundation/L=Forest Hill/ST=Maryland/C=US' \ |
| 81 | -key client.key \ |
| 82 | -out client.csr |
| 83 | |
| 84 | echo |
| 85 | echo step 5 |
| 86 | winpty openssl x509 -req -days 3000 -in client.csr -CA CA.pem -CAkey server.key -set_serial 01 -out client.crt |
| 87 | |
| 88 | |
| 89 | echo |
| 90 | echo step 6 |
| 91 | winpty openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12 |
| 92 | |
| 93 | |
| 94 | echo |
| 95 | echo step 7 |
| 96 | winpty openssl pkcs12 -in client.p12 -out client.pem -clcerts |
| 97 | |
| 98 | |
| 99 | echo |
| 100 | echo step 8a |
| 101 | openssl genrsa -out client_v3.key |
| 102 | |
| 103 | echo |
| 104 | echo step 8b |
| 105 | winpty openssl req \ |
| 106 | -new \ |
| 107 | -subj '//SKIP=this/CN=localhost/emailAddress=dev@thrift.apache.org/OU=Apache Thrift/O=The Apache Software Foundation/L=Forest Hill/ST=Maryland/C=US' \ |
| 108 | -key client_v3.key \ |
| 109 | -out client_v3.csr \ |
| 110 | -extensions v3_req \ |
| 111 | -config my.cfg |
| 112 | |
| 113 | |
| 114 | echo |
| 115 | echo step 9 |
| 116 | winpty openssl x509 -req -days 3000 -in client_v3.csr -CA CA.pem -CAkey server.key -set_serial 01 -out client_v3.crt -extensions v3_req -extfile my.cfg |
| 117 | |
| 118 | echo |
| 119 | echo cleanup |
| 120 | rm *.cfg 2> /dev/null |
| 121 | rm *.csr 2> /dev/null |
| 122 | |
| 123 | echo |
| 124 | echo test |
| 125 | openssl s_client -connect localhost:9090 & |
| 126 | openssl s_server -accept 9090 -www |
| 127 | |
| 128 | echo |
| 129 | echo done |
| 130 | |
| 131 | |