-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use separate certificates for client,server
Use same script to generate as core Fixes #3334 Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
- Loading branch information
1 parent
97a56ab
commit dfb77b2
Showing
26 changed files
with
533 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script is used to create the CA, server and client's certificates and keys required by unit tests. | ||
# These certificates use the Subject Alternative Name extension rather than the Common Name, which will be unsupported from Go 1.15. | ||
|
||
usage() { | ||
echo "Usage: $0 [-d]" | ||
echo | ||
echo "-d Dry-run mode. No project files will not be modified. Default: 'false'" | ||
echo "-m Domain name to use in the certificate. Default: 'localhost'" | ||
echo "-o Output directory where certificates will be written to. Default: '.'; the current directory" | ||
exit 1 | ||
} | ||
|
||
dry_run=false | ||
domain="localhost" | ||
output_dir="." | ||
|
||
while getopts "dm:o:" o; do | ||
case "${o}" in | ||
d) | ||
dry_run=true | ||
;; | ||
m) | ||
domain=$OPTARG | ||
;; | ||
o) | ||
output_dir=$OPTARG | ||
;; | ||
*) | ||
usage | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
||
set -ex | ||
|
||
# Create temp dir for generated files. | ||
tmp_dir=$(mktemp -d -t certificates) | ||
clean_up() { | ||
ARG=$? | ||
if [ $dry_run = true ]; then | ||
echo "Dry-run complete. Generated files can be found in $tmp_dir" | ||
else | ||
rm -rf "$tmp_dir" | ||
fi | ||
exit $ARG | ||
} | ||
trap clean_up EXIT | ||
|
||
gen_ssl_conf() { | ||
domain_name=$1 | ||
output_file=$2 | ||
|
||
cat << EOF > "$output_file" | ||
[ req ] | ||
prompt = no | ||
default_bits = 2048 | ||
distinguished_name = req_distinguished_name | ||
req_extensions = req_ext | ||
[ req_distinguished_name ] | ||
countryName = AU | ||
stateOrProvinceName = Australia | ||
localityName = Sydney | ||
organizationName = MyOrgName | ||
commonName = MyCommonName | ||
[ req_ext ] | ||
subjectAltName = @alt_names | ||
[alt_names] | ||
DNS.1 = $domain_name | ||
EOF | ||
} | ||
|
||
# Generate config files. | ||
gen_ssl_conf "$domain" "$tmp_dir/ssl.conf" | ||
|
||
# Create CA (accept defaults from prompts). | ||
openssl genrsa -out "$tmp_dir/ca.key" 2048 | ||
openssl req -new -key "$tmp_dir/ca.key" -x509 -days 3650 -out "$tmp_dir/ca.crt" -config "$tmp_dir/ssl.conf" | ||
|
||
# Create client and server keys. | ||
openssl genrsa -out "$tmp_dir/server.key" 2048 | ||
openssl genrsa -out "$tmp_dir/client.key" 2048 | ||
|
||
# Create certificate sign request using the above created keys. | ||
openssl req -new -nodes -key "$tmp_dir/server.key" -out "$tmp_dir/server.csr" -config "$tmp_dir/ssl.conf" | ||
openssl req -new -nodes -key "$tmp_dir/client.key" -out "$tmp_dir/client.csr" -config "$tmp_dir/ssl.conf" | ||
|
||
# Creating the client and server certificates. | ||
openssl x509 -req \ | ||
-sha256 \ | ||
-days 3650 \ | ||
-in "$tmp_dir/server.csr" \ | ||
-signkey "$tmp_dir/server.key" \ | ||
-out "$tmp_dir/server.crt" \ | ||
-extensions req_ext \ | ||
-CA "$tmp_dir/ca.crt" \ | ||
-CAkey "$tmp_dir/ca.key" \ | ||
-CAcreateserial \ | ||
-extfile "$tmp_dir/ssl.conf" | ||
openssl x509 -req \ | ||
-sha256 \ | ||
-days 3650 \ | ||
-in "$tmp_dir/client.csr" \ | ||
-signkey "$tmp_dir/client.key" \ | ||
-out "$tmp_dir/client.crt" \ | ||
-extensions req_ext \ | ||
-CA "$tmp_dir/ca.crt" \ | ||
-CAkey "$tmp_dir/ca.key" \ | ||
-CAcreateserial \ | ||
-extfile "$tmp_dir/ssl.conf" | ||
|
||
# Copy files if not in dry-run mode. | ||
if [ $dry_run = false ]; then | ||
cp "$tmp_dir/ca.crt" \ | ||
"$tmp_dir/client.crt" \ | ||
"$tmp_dir/client.key" \ | ||
"$tmp_dir/server.crt" \ | ||
"$tmp_dir/server.key" \ | ||
"$output_dir" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDNjCCAh4CCQDAtHQ9svPM4TANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJB | ||
VTESMBAGA1UECAwJQXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoM | ||
CU15T3JnTmFtZTEVMBMGA1UEAwwMTXlDb21tb25OYW1lMB4XDTIxMDUwNjAzMTYz | ||
MFoXDTMxMDUwNDAzMTYzMFowXTELMAkGA1UEBhMCQVUxEjAQBgNVBAgMCUF1c3Ry | ||
YWxpYTEPMA0GA1UEBwwGU3lkbmV5MRIwEAYDVQQKDAlNeU9yZ05hbWUxFTATBgNV | ||
BAMMDE15Q29tbW9uTmFtZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB | ||
AMqR3+6s+Iirta769tDlA0N0OAF9hyY6Y3OHshtBFCUiDgZSrTEcNlyHQLJN9J+L | ||
W5lPJm5nIAUZZphc1fPLEsF3pH8tNM21X0wrefjfb3FV/0V6ZXpxkZMCREx9B+Qo | ||
HKOwax6jsxXM03o1bRAxTFGVwDjPop1VZKmQT/z3qo4D1xpgpvkSGWW5zqeaZXje | ||
lEJ71TKF2diMshUooHADkDpTFznFwBGPQJvm0Kpkir08VDdIOxbkPIb+SLsM3zlN | ||
NUjOW9xN25RR1rSfWIpEJqUIpXrN+0PES9lU9k09YbP24QE2V1dnrRl9mE8AW5jn | ||
f1Ye4Dj/aFDaA9ByXD5F+g8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEArIi+Vu8q | ||
dKcPT74kbBGBsw9G6No17plPrQ3fVky8/B+HhOLGU2pHjyMyYd3G3DWjCV1JA4PO | ||
B15raWWsWqTV3+zutQ6zgbSCo8c/KiN6CKJdptiDV242Sx64gvswjDm5YIRaIoZr | ||
Y8hiy64DrqN5eG1g/VO7w4xnskgEyQW67qX7ccrxBFaq3nUbgfBoMvFaaEMVAiz6 | ||
9Rmc+p4qA2hfdfY29n5iA9m6cTQ91WKXXN5qLIqfKzsRlb7neHCk/z1BhF/dEJi1 | ||
T+BpwaMhGFCcTl2E7fIJmzEMeQkaAUpGyOgrJ+Of7Srmw4uRwC1QOsgaxdEfj/Am | ||
wS/wXW0j+fNzfQ== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDazCCAlOgAwIBAgIJAJ04Tjxr61SEMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV | ||
BAYTAkFVMRIwEAYDVQQIDAlBdXN0cmFsaWExDzANBgNVBAcMBlN5ZG5leTESMBAG | ||
A1UECgwJTXlPcmdOYW1lMRUwEwYDVQQDDAxNeUNvbW1vbk5hbWUwHhcNMjEwNTA2 | ||
MDMxNjMxWhcNMzEwNTA0MDMxNjMxWjBdMQswCQYDVQQGEwJBVTESMBAGA1UECAwJ | ||
QXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoMCU15T3JnTmFtZTEV | ||
MBMGA1UEAwwMTXlDb21tb25OYW1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB | ||
CgKCAQEA9YS6A2aFmaGVSbe4c5XAFR+7A2pzS+pD8fs+J6AxafkONhCN3/mW5cxp | ||
vucDTQBnq/gxz2nLaUAEL7YrW5C0k0Wt8XKu6cM0WbtMEv3im87N8jOVWxHEBlAe | ||
0uaR+CKNdJaxg1OH03XHfuM1FW1fALEPJVmIKHvJRMPyx0d2H9ACJ7wx0X490IeS | ||
NtFmGLyawXNkV0EnVkCa1S+bdAUHUWoE1OlIfYZ9haRygEwlkK5wiQ/ngTZaS27b | ||
96P01KnnMg3GSHxExk86PkoYizrE8MN3luheFKGkgtJBEUR9iC1NZT9WPkl/dLw3 | ||
0FsZBMqipwNmFpeXfK0MiM+Ii4p/qQIDAQABoy4wLDAUBgNVHREEDTALgglsb2Nh | ||
bGhvc3QwFAYDVR0RBA0wC4IJbG9jYWxob3N0MA0GCSqGSIb3DQEBCwUAA4IBAQB8 | ||
83osKF1Up3jdR7gV9XkdhYWigA8G1hum6W10mMyphOMnPtcER0VKJFdVxVS80VlX | ||
H0CqPJ2DOczeuxNdgAot1X3vFGD+20+EDMVwL6G5pED1Cl5Pz5qj+aO96jOeLT35 | ||
OEQCTDLSSm75wsf16J501tOF2z99U1cFXv9j6cX/LJc0NdeqaG2TE8o7PvkpbKXV | ||
QjUmYv9VfvAJoUa4Tr0I5I3bi/K0xaiVPugyv5oCHW/I3B9QqC/mv7lDa4LPTK4Y | ||
jujWZW+Fbk31JX2yq81QQ89vhSJXo/pnut8JPNJW295gkFAjFCUtjqBuW9QdMJlG | ||
z+buUqr8lpMCK8570aRE | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpQIBAAKCAQEA9YS6A2aFmaGVSbe4c5XAFR+7A2pzS+pD8fs+J6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oGBAMGUnYYKxq1fU1UOU+80 | ||
7QImKrSxZ71Ht4gFluoXegoJe6wooxoan6HPdjIa/0xiaGFYZ6YQjrIol48B8nMp | ||
UiPpFjiYJhou8ShtMqjGeovEAkLs4wtwD1cMdIu1EPSkS3+nCZmQvW1R6LHWvDQV | ||
KGhGKNMRMIdLlajNnkP6VTwBAoGBAJBoZvPlLDw6m8hheo6XfhdWDZDzTQfBuUgs | ||
IG2QCCAtjzXpE5oSrJbr2aPxIvyvKhpwssINfT2uEjwBFxYP0QylBGDrY0h/FOhz | ||
ab5+aBhH77oaJ7ljG0EpVjh8oGGTEcc8gj+PfrXzMmw3elNEbTvLl5sBb7jYH9S2 | ||
IrQUw7WJAoGAJneoFPKRrPYxV5mjjfaz2bMJYTgGE8WepgJiFBLpZCXQK5wIlnuN | ||
9W43dC0+9GrCdhVoYm5UmkN8xuBRMzDdm0Of5fJqdsxIvzOsaUt34tPoH7LOgikj | ||
ENL4WCXHgtNqFH1XCL/0/Ftb5fVGMw9jhXtT4hsqN4xXnkGPrgYMglA= | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDazCCAlOgAwIBAgIJAJ04Tjxr61SDMA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV | ||
BAYTAkFVMRIwEAYDVQQIDAlBdXN0cmFsaWExDzANBgNVBAcMBlN5ZG5leTESMBAG | ||
A1UECgwJTXlPcmdOYW1lMRUwEwYDVQQDDAxNeUNvbW1vbk5hbWUwHhcNMjEwNTA2 | ||
MDMxNjMxWhcNMzEwNTA0MDMxNjMxWjBdMQswCQYDVQQGEwJBVTESMBAGA1UECAwJ | ||
QXVzdHJhbGlhMQ8wDQYDVQQHDAZTeWRuZXkxEjAQBgNVBAoMCU15T3JnTmFtZTEV | ||
MBMGA1UEAwwMTXlDb21tb25OYW1lMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB | ||
CgKCAQEA4JRQCdODFJCucb3WAq6ojysyl/6GpYy0YaaBgpby57agtnt8E7NGlfrP | ||
UhCnT0tKStagkh+yNbHFP63D/YD2Yys23BuDHZb5gbG5GwHF+qpIO6klweErDfgy | ||
p+z8q/t6oLTS6FQzIiIN1vzIutGTiuixU+hz8P6Eo7dXWEBdrf9h+Vpe76OaLGp9 | ||
36jYDKjkY8ZR9SV3WwqGcMw/Hj3nJ/99PUQxiaSSrULrEaj+6PDKAKyEyQ/y0nX9 | ||
mrx758LyFfhEOYrbmKW5vz5NLKpHpDF7BiIqTiqNkunGbKVMh9VMwkR25z5G+Aya | ||
xLK9961f7tW0nBNkANGrEl70Xii96QIDAQABoy4wLDAUBgNVHREEDTALgglsb2Nh | ||
bGhvc3QwFAYDVR0RBA0wC4IJbG9jYWxob3N0MA0GCSqGSIb3DQEBCwUAA4IBAQAX | ||
rgDGCNj4ypE+sTVUDEYuyRU9U1CeFNThDtirSWp5sLkcxi9sKZibfq1gtYvOZqEu | ||
a6FmW3NENV+9fxjx2SqOCMmRbyRylRnOKOrciw0TCqnsO2HVHLgnIOFkBxsRbPK5 | ||
K348T0OAcpp+4S5JfAHWyVHDkr+ME8F+X/iJt44Gl3LMLsmfUXIfjsn4isjNuuDu | ||
YTuUIudAc8QXn8nqUUkCgaaLMdI0Jv8vos52InXLdZQN3BZEQvh9IV/rlq6u+sDN | ||
SdQySnhCRfDxHtFNF1fWSzsH+W3EDj6773EDRnbtJ5khnS4bjcf1xIBHrq2KG+ZB | ||
IuvI1IjQR7mOOcBOAv++ | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----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yXxliHX2m7yMP1IyhWTw4TDyYhWITxQN9U6vwuu+Xo9S4D | ||
yx2Fj7RB3JskOivO8G6HUr7agJ+VhPEqSB6a88sCgYEAlKC6Nk9N6SSR1rG+5ND0 | ||
C0DUYDGs1N5NC92Hoy9xnkiHH9aYEYQfRh2GZuU+wL6r+nOszGzd3md9DXwZJi2d | ||
ByNr5j99f+1/YbaY9tCeaKiGJxQT02W2/Lg61gtw8nvbMgh1tXMAtVzaxo3QkJMm | ||
1iCMz31MxECufjzK/qT2JwkCgYEAjIQR1xq27OqeURQmys4X+e1eLfqtNr1TRHCF | ||
Xeqw4VUhdQ1qZUqAnNO/nJq5L3Ym83QnVl4lOfgkgCPTz17TRtknBPmrlE46d6JB | ||
85/70+S+rLyoGLb3jOV4I/M0ePNFSadBjIxANTpSbhaA02+tNrWZMJsHU4KVKUsM | ||
tdKRHqECgYBsqvFtcI2A3zogJP6X22ZuGBtolkt0toU1pXV4zDO4Gn5RujgDqS4U | ||
7o9ET1meCXZ9olGqWUrgqxfN0cUbNu38nUqzfnjZH0LeA3yTbvbMLnkpTXSJ6/J1 | ||
Mt2mxIA5eiarcvAc83g0eIcCji3d4aZgqS8XqBBUSk22mO3Q3IZ9xw== | ||
-----END RSA PRIVATE KEY----- |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.