Skip to content

Commit

Permalink
Script to create certs
Browse files Browse the repository at this point in the history
  • Loading branch information
stianst committed Mar 11, 2024
1 parent d1c77d0 commit a7d353a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions certs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.key
*.crt
*.pem
*.csr
*.srl
*-truststore
21 changes: 21 additions & 0 deletions certs/cert-signed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e

rm -f RootCA.crt RootCA.key RootCA.pem localhost-signed.key localhost-signed.csr localhost-signed.crt signed-truststore

openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=US/CN=Example-Root-CA"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt

openssl req -new -nodes -newkey rsa:2048 -keyout localhost-signed.key -out localhost-signed.csr -subj "/C=US/ST=YourState/L=YourCity/O=Example-Certificates/CN=localhost"
openssl x509 -req -sha256 -days 1024 -in localhost-signed.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out localhost-signed.crt

keytool -importcert -file localhost-signed.crt -keystore signed-truststore -noprompt --storepass password

echo ""
echo "Certificates created"
echo "--------------------"
echo "CA cert: " $(readlink -f RootCA.crt)
echo "CA key: " $(readlink -f RootCA.key)
echo "Public cert: " $(readlink -f localhost-unsigned.crt)
echo "Private key: " $(readlink -f localhost-unsigned.key)
echo "Truststore: " $(readlink -f signed-truststore)
echo "Truststore password: password"
15 changes: 15 additions & 0 deletions certs/cert-unsigned.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

rm -f localhost-unsigned.key localhost-unsigned.crt unsigned-truststore

openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout localhost-unsigned.key -out localhost-unsigned.crt -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,DNS:*.localdomain,IP:127.0.0.1"

keytool -importcert -file localhost-unsigned.crt -keystore unsigned-truststore -noprompt --storepass password

echo ""
echo "Certificates created"
echo "--------------------"
echo "Public cert: " $(readlink -f localhost-unsigned.crt)
echo "Private key: " $(readlink -f localhost-unsigned.key)
echo "Truststore: " $(readlink -f unsigned-truststore)
echo "Truststore password: password"
7 changes: 7 additions & 0 deletions certs/domains.ext
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = localhost.localdomain

0 comments on commit a7d353a

Please sign in to comment.