Skip to content

Instantly share code, notes, and snippets.

@typelogic
Last active June 13, 2023 15:46
Show Gist options
  • Save typelogic/2a1dcc4f873d3d06c9251641724acecf to your computer and use it in GitHub Desktop.
Save typelogic/2a1dcc4f873d3d06c9251641724acecf to your computer and use it in GitHub Desktop.
SSL server/client in socat
#!/bin/sh
#
if [ $# -eq 0 ];then
echo "Supply client|server"
exit 1
fi
FILENAME=$1
openssl genrsa -out $FILENAME.key 1024
# During certificate creation when prompted for
# `Common Name (eg, your name or your server's hostname) []` you should enter localhost
openssl req -new -key $FILENAME.key -x509 -days 3653 -out $FILENAME.crt
cat $FILENAME.key $FILENAME.crt >$FILENAME.pem
chmod 600 $FILENAME.key $FILENAME.pem
# Server
# socat openssl-listen:14344,reuseaddr,cert=./server.pem,cafile=./client.crt echo
# Client
# socat stdio openssl-connect:localhost:14344,cert=./client.pem,cafile=./server.crt
# Verification
# You should see ESTABLISHED connection
# netstat -ant | grep 14344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment