Created
November 13, 2015 13:42
-
-
Save trajakovic/4db931dd955b9ddebf38 to your computer and use it in GitHub Desktop.
openssl - certificates: create ca, create cert, sign cert, pack cert to p12
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
#!/bin/bash | |
openssl genrsa -des3 -out ca.key 4096 && \ | |
echo "CA key generated, file ca.key. Now retype password to create cert" && \ | |
openssl req -new -x509 -days 730 -key ca.key -out ca.crt && \ | |
echo "CA cert generated, file: ca.crt" |
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
#!/bin/bash | |
if [[ -n $1 ]]; then | |
openssl req -out "$1".csr -new -newkey rsa:4096 -nodes -keyout "$1".key && \ | |
echo "$1.csr and $1.key created" && \ | |
echo "Now sign csr with ca (type [ ./sign-cert.sh $1) ]" | |
else | |
echo "Missing argument 1: name of usage (usually server, or user short name, etc.)" | |
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
#!/bin/bash | |
if [[ -n $1 ]]; then | |
./create-cert.sh $1 && \ | |
./sign-cert.sh $1 && \ | |
./pack-cert.sh $1 | |
else | |
echo "Missing argument 1: name of cert" | |
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
#!/bin/bash | |
if [[ -n $1 ]]; then | |
openssl pkcs12 -export -in "$1".crt -inkey "$1".key -name "$1 MrServis testing cert" -out "$1".p12 && \ | |
echo "Cert packed into $1.p12" | |
else | |
echo "Missing argument 1: name of cert" | |
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
#!/bin/bash | |
if [[ -n $1 ]]; then | |
openssl x509 -req -in "$1".csr -out "$1".crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 365 && \ | |
echo "Cert created, file: $1.crt" | |
else | |
echo "Missing argument 1: name of cert" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bring local by executing:
Make runnable:
Order
./create-ca-cert.sh
./create-cert.sh myCert
./sign-cert.sh myCert
./pack-cert.sh myCert
Thanks
I'm lazy to write any error / repeat / bulletproof bash scripts