Skip to content

Instantly share code, notes, and snippets.

@xmpf
Created December 18, 2021 21:18
Show Gist options
  • Save xmpf/2fc6322d1380e0b46a99bc675ffc9f57 to your computer and use it in GitHub Desktop.
Save xmpf/2fc6322d1380e0b46a99bc675ffc9f57 to your computer and use it in GitHub Desktop.
Generate keys and start a TLS listener using socat
#!/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