Skip to content

Instantly share code, notes, and snippets.

@itsmunim
Created August 6, 2021 18:58
Show Gist options
  • Save itsmunim/9fb76fffb6d56001945aa4f8ac060114 to your computer and use it in GitHub Desktop.
Save itsmunim/9fb76fffb6d56001945aa4f8ac060114 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Creates a certificate authority cert & key; this you can use as CA for your self-signed certs
function create_ca() {
openssl req -new -x509 -nodes -days "${1}" -keyout ca.key -out ca.crt
}
# Creates a private key and a respective csr
function create_csr() {
openssl req -new -newkey rsa:2048 -nodes -keyout "${1}".key -out "${1}".csr
}
# Generates a self-signed cert; expects a csr to be present with the name given, as well as a ca.crt and ca.key
# to be present in current dir.
# Expects number of days as second param
function create_cert() {
openssl x509 -req -in "${1}".csr -CA ca.crt -CAkey ca.key -CAcreateserial -days "${2}" -out "${1}".crt
}
# Helps to check cert content
function check_cert() {
openssl x509 -in "${1}".crt -text -noout
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment