Created
December 18, 2021 21:18
-
-
Save xmpf/2fc6322d1380e0b46a99bc675ffc9f57 to your computer and use it in GitHub Desktop.
Generate keys and start a TLS listener using socat
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 | |
FILENAME=server | |
# Generate a public/private key pair: | |
if [ ! -f "$FILENAME.key" ]; then | |
openssl genrsa -out "$FILENAME.key" 1024 | |
fi | |
# Generate a self signed certificate: | |
if [ ! -f "$FILENAME.crt" ]; then | |
openssl req -new -key "$FILENAME.key" -x509 -sha256 -days 3653 -out "$FILENAME.crt" | |
fi | |
# Generate the PEM file by just appending the key and certificate files: | |
if [ ! -f "$FILENAME.pem" ]; then | |
cat "$FILENAME.key" "$FILENAME.crt" > "$FILENAME.pem" | |
fi | |
# Run listener over TLS | |
echo '[+] Starting TLS listener...' | |
sudo socat -v -v openssl-listen:443,reuseaddr,fork,cert="$FILENAME.pem",cafile="$FILENAME.crt",verify=0 - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment