Last active
May 20, 2020 09:54
-
-
Save marc-hanheide/672cb004894c52ac60480411b45549a0 to your computer and use it in GitHub Desktop.
Generate certificates for mongodb
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
KEY_BITS=4096 | |
CA_PRIVATE_KEY_NAME="certificate_authority_private_key.key" | |
CA_CERT_NAME="certificate_authority_root_certificate.cert" | |
DAYS_VALID=365 | |
ENTITY_PRIVATE_KEY_NAME="entity_private_key.key" | |
ENTITY_CERTIFICATE_SIGN_REQUEST_NAME="entity_certificate_sign_request.csr" | |
ENTITY_CERT_NAME="entity_private_certificate.cert" | |
# these are subject variables to be added into the certificate | |
ENTITY_COUNTRY_CODE="GB" | |
ENTITY_PROVINCE="Lincolnshire" | |
ENTITY_LOCATION="Lincoln" | |
ENTITY_ORGANISATION="University of lincoln" | |
ENTITY_ORGANISATION_UNIT="LCAS" | |
ENTITY_NAME="lcas.lincoln.ac.uk" | |
ENTITY_EMAIL="[email protected]" | |
# user information: | |
echo "Generating private key and using it will require a password, all following passwords should be the same:" | |
# generate an entity private key which is encrypted (using -aes-256-cbc flag) | |
openssl genpkey -algorithm RSA -aes-256-cbc -pkeyopt rsa_keygen_bits:$KEY_BITS -out $ENTITY_PRIVATE_KEY_NAME | |
# generate a certificate signing request file for the certificate authority to sign next | |
openssl req -new -sha256 -key $ENTITY_PRIVATE_KEY_NAME -out $ENTITY_CERTIFICATE_SIGN_REQUEST_NAME -subj \ | |
"/C=${ENTITY_COUNTRY_CODE}/ST=${ENTITY_PROVINCE}/L=${ENTITY_LOCATION}/O=${ENTITY_ORGANISATION}/OU=${ENTITY_ORGANISATION_UNIT}/CN=${ENTITY_NAME}/emailAddress=${ENTITY_EMAIL}" | |
# generate entity certificate | |
openssl x509 -req -in $ENTITY_CERTIFICATE_SIGN_REQUEST_NAME -CA $CA_CERT_NAME -CAkey $CA_PRIVATE_KEY_NAME -CAcreateserial -out $ENTITY_CERT_NAME -days $DAYS_VALID | |
# display the certificate | |
openssl x509 -text -noout -in $ENTITY_CERT_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment