blob: 61bd674fef6ca030ca246d51312418859adf590d [file] [log] [blame]
Jens Geyerb18964e2022-06-28 22:54:38 +02001#!/bin/bash
Jens Geyer7a5f29d2022-07-01 21:15:57 +02002#
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 Geyerb18964e2022-06-28 22:54:38 +020020
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
26echo init folder
27rm *.p12 2> /dev/null
28rm *.pem 2> /dev/null
29rm *.crt 2> /dev/null
30rm *.key 2> /dev/null
31rm *.cfg 2> /dev/null
32rm *.csr 2> /dev/null
33
34#cp ../*.key .
35
36echo writing config
37echo '[ req ]' > my.cfg
38echo 'default_bits= 4096' >> my.cfg
39echo 'distinguished_name=req' >> my.cfg
40echo 'x509_extensions = v3_ca' >> my.cfg
41echo 'req_extensions = v3_req' >> my.cfg
42echo '' >> my.cfg
43echo '[ v3_req ]' >> my.cfg
44echo 'basicConstraints = CA:FALSE' >> my.cfg
45echo 'keyUsage = nonRepudiation, digitalSignature, keyEncipherment' >> my.cfg
46echo 'subjectAltName=@alternate_names' >> my.cfg
47echo '' >> my.cfg
48echo '[ alternate_names ]' >> my.cfg
49echo 'IP.1=127.0.0.1' >> my.cfg
50echo 'IP.2=::1' >> my.cfg
51echo 'IP.3=::ffff:127.0.0.1' >> my.cfg
52echo 'DNS.1=localhost' >> my.cfg
53echo '' >> my.cfg
54echo '[ v3_ca ]' >> my.cfg
55echo 'subjectKeyIdentifier=hash' >> my.cfg
56echo 'authorityKeyIdentifier=keyid:always,issuer' >> my.cfg
57echo 'basicConstraints = critical, CA:TRUE, pathlen:0' >> my.cfg
58echo 'keyUsage = critical, cRLSign, keyCertSign, nonRepudiation, digitalSignature, keyEncipherment' >> my.cfg
59echo 'extendedKeyUsage = serverAuth, clientAuth' >> my.cfg
60echo 'subjectAltName=@alternate_names' >> my.cfg
61echo '' >> my.cfg
62
63echo
64echo step 1a
65winpty 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
76echo
77echo step 1b
78openssl x509 -in server.crt -text > CA.pem
79
80echo
81echo step 1c
82cat server.crt server.key > server.pem
83
84echo
85echo step 2
86echo 'Use "thrift" as password (without the quotes)'
87winpty openssl pkcs12 -export -clcerts -in server.crt -inkey server.key -out server.p12
88
89echo
90echo step 3
91winpty openssl genrsa -out client.key
92
93
94echo
95echo step 4
96winpty 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
102echo
103echo step 5
104winpty openssl x509 -req -days 3000 -in client.csr -CA CA.pem -CAkey server.key -set_serial 01 -out client.crt
105
106
107echo
108echo step 6
109winpty openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
110
111
112echo
113echo step 7
114winpty openssl pkcs12 -in client.p12 -out client.pem -clcerts
115
116
117echo
118echo step 8a
119openssl genrsa -out client_v3.key
120
121echo
122echo step 8b
123winpty 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
132echo
133echo step 9
134winpty 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
136echo
137echo cleanup
138rm *.cfg 2> /dev/null
139rm *.csr 2> /dev/null
140
141echo
142echo test
143openssl s_client -connect localhost:9090 &
144openssl s_server -accept 9090 -www
145
146echo
147echo done
148
149