Jens Geyer | b18964e | 2022-06-28 22:54:38 +0200 | [diff] [blame] | 1 | #!/bin/bash |
Jens Geyer | 7a5f29d | 2022-07-01 21:15:57 +0200 | [diff] [blame] | 2 | # |
| 3 | # Licensed to the Apache Software Foundation (ASF) under one |
| 4 | # or more contributor license agreements. See the NOTICE file |
| 5 | # distributed with this work for additional information |
| 6 | # regarding copyright ownership. The ASF licenses this file |
| 7 | # to you under the Apache License, Version 2.0 (the |
| 8 | # "License"); you may not use this file except in compliance |
| 9 | # with the License. You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, |
| 14 | # software distributed under the License is distributed on an |
| 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | # KIND, either express or implied. See the License for the |
| 17 | # specific language governing permissions and limitations |
| 18 | # under the License. |
| 19 | # |
Jens Geyer | b18964e | 2022-06-28 22:54:38 +0200 | [diff] [blame] | 20 | |
| 21 | # tested with git bash on Windows |
| 22 | # probably needs a bit of tweaking for other environments |
| 23 | |
| 24 | # re the "//SKIP=this" in sub see at https://stackoverflow.com/a/54924640/499466 |
| 25 | |
| 26 | echo init folder |
| 27 | rm *.p12 2> /dev/null |
| 28 | rm *.pem 2> /dev/null |
| 29 | rm *.crt 2> /dev/null |
| 30 | rm *.key 2> /dev/null |
| 31 | rm *.cfg 2> /dev/null |
| 32 | rm *.csr 2> /dev/null |
| 33 | |
| 34 | #cp ../*.key . |
| 35 | |
| 36 | echo writing config |
| 37 | echo '[ req ]' > my.cfg |
| 38 | echo 'default_bits= 4096' >> my.cfg |
| 39 | echo 'distinguished_name=req' >> my.cfg |
| 40 | echo 'x509_extensions = v3_ca' >> my.cfg |
| 41 | echo 'req_extensions = v3_req' >> my.cfg |
| 42 | echo '' >> my.cfg |
| 43 | echo '[ v3_req ]' >> my.cfg |
| 44 | echo 'basicConstraints = CA:FALSE' >> my.cfg |
| 45 | echo 'keyUsage = nonRepudiation, digitalSignature, keyEncipherment' >> my.cfg |
| 46 | echo 'subjectAltName=@alternate_names' >> my.cfg |
| 47 | echo '' >> my.cfg |
| 48 | echo '[ alternate_names ]' >> my.cfg |
| 49 | echo 'IP.1=127.0.0.1' >> my.cfg |
| 50 | echo 'IP.2=::1' >> my.cfg |
| 51 | echo 'IP.3=::ffff:127.0.0.1' >> my.cfg |
| 52 | echo 'DNS.1=localhost' >> my.cfg |
| 53 | echo '' >> my.cfg |
| 54 | echo '[ v3_ca ]' >> my.cfg |
| 55 | echo 'subjectKeyIdentifier=hash' >> my.cfg |
| 56 | echo 'authorityKeyIdentifier=keyid:always,issuer' >> my.cfg |
| 57 | echo 'basicConstraints = critical, CA:TRUE, pathlen:0' >> my.cfg |
| 58 | echo 'keyUsage = critical, cRLSign, keyCertSign, nonRepudiation, digitalSignature, keyEncipherment' >> my.cfg |
| 59 | echo 'extendedKeyUsage = serverAuth, clientAuth' >> my.cfg |
| 60 | echo 'subjectAltName=@alternate_names' >> my.cfg |
| 61 | echo '' >> my.cfg |
| 62 | |
| 63 | echo |
| 64 | echo step 1a |
| 65 | winpty openssl req \ |
| 66 | -new \ |
| 67 | -x509 \ |
| 68 | -nodes \ |
| 69 | -days 3000 \ |
| 70 | -out server.crt \ |
| 71 | -keyout server.key \ |
| 72 | -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' \ |
| 73 | -extensions v3_ca \ |
| 74 | -config my.cfg |
| 75 | |
| 76 | echo |
| 77 | echo step 1b |
| 78 | openssl x509 -in server.crt -text > CA.pem |
| 79 | |
| 80 | echo |
| 81 | echo step 1c |
| 82 | cat server.crt server.key > server.pem |
| 83 | |
| 84 | echo |
| 85 | echo step 2 |
| 86 | echo 'Use "thrift" as password (without the quotes)' |
| 87 | winpty openssl pkcs12 -export -clcerts -in server.crt -inkey server.key -out server.p12 |
| 88 | |
| 89 | echo |
| 90 | echo step 3 |
| 91 | winpty openssl genrsa -out client.key |
| 92 | |
| 93 | |
| 94 | echo |
| 95 | echo step 4 |
| 96 | winpty openssl req \ |
| 97 | -new \ |
| 98 | -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' \ |
| 99 | -key client.key \ |
| 100 | -out client.csr |
| 101 | |
| 102 | echo |
| 103 | echo step 5 |
| 104 | winpty openssl x509 -req -days 3000 -in client.csr -CA CA.pem -CAkey server.key -set_serial 01 -out client.crt |
| 105 | |
| 106 | |
| 107 | echo |
| 108 | echo step 6 |
| 109 | winpty openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12 |
| 110 | |
| 111 | |
| 112 | echo |
| 113 | echo step 7 |
| 114 | winpty openssl pkcs12 -in client.p12 -out client.pem -clcerts |
| 115 | |
| 116 | |
| 117 | echo |
| 118 | echo step 8a |
| 119 | openssl genrsa -out client_v3.key |
| 120 | |
| 121 | echo |
| 122 | echo step 8b |
| 123 | winpty openssl req \ |
| 124 | -new \ |
| 125 | -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' \ |
| 126 | -key client_v3.key \ |
| 127 | -out client_v3.csr \ |
| 128 | -extensions v3_req \ |
| 129 | -config my.cfg |
| 130 | |
| 131 | |
| 132 | echo |
| 133 | echo step 9 |
| 134 | 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 |
| 135 | |
| 136 | echo |
| 137 | echo cleanup |
| 138 | rm *.cfg 2> /dev/null |
| 139 | rm *.csr 2> /dev/null |
| 140 | |
| 141 | echo |
| 142 | echo test |
| 143 | openssl s_client -connect localhost:9090 & |
| 144 | openssl s_server -accept 9090 -www |
| 145 | |
| 146 | echo |
| 147 | echo done |
| 148 | |
| 149 | |