Created
June 9, 2025 12:34
-
-
Save meenakshi-koushik/41c7a0f97f5f2987a6d54d2c8195b674 to your computer and use it in GitHub Desktop.
Generate certificates with arbitrary validity
This file contains hidden or 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
#!/usr/bin/bash | |
# Usage: | |
# gen.sh <STARTDATE> <ENDDATE> | |
# the dates are in YYYYMMDDhhmmssZ format and are UTC timestamps | |
# Example: | |
# gen.sh 20250609000000Z 20250630000000Z | |
STARTDATE="${1:-20250101000000Z}" | |
ENDDATE="${2:-20250101000000Z}" | |
# Generate private key | |
openssl genrsa -out server.key 2048 | |
# Generate CSR with specific hostname | |
openssl req -new -key server.key -out server.csr -subj "/CN=your-hostname.example.com" | |
# Generate self-signed certificate with specific expiry | |
openssl x509 -req \ | |
-not_before "${STARTDATE}" \ | |
-not_after "${ENDDATE}" \ | |
-in server.csr \ | |
-signkey server.key \ | |
-out server.crt \ | |
-extensions v3_req \ | |
-extfile <(printf "[v3_req]\nsubjectAltName=DNS:your-hostname.example.com") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment