Advertisement
devinteske

stalk -- encrypted chat using openssl

Aug 30th, 2015
2,990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.70 KB | None | 0 0
  1. #!/bin/sh
  2. pgm="${0##*/}" PORT=4242 KEYFILE="/tmp/stalk.$$" DELETE_KEYFILE=1 SERVER=
  3. usage() { exec >&2
  4.     printf "Usage (SERVER): %s [-p PORT] [-k keyfile] -s\n" "$pgm"
  5.     printf "Usage (CLIENT): %s [-p PORT] host\n" "$pgm"
  6.     exit 1
  7. }
  8. while getopts hk:p:s flag; do
  9.     case "$flag" in
  10.     k) KEYFILE="$OPTARG" DELETE_KEYFILE= ;;
  11.     p) PORT="$OPTARG" ;;
  12.     s) SERVER=1 ;;
  13.     *) usage
  14.     esac
  15. done
  16. shift $(( $OPTIND - 1 ))
  17. [ $# -gt 0 ] && { openssl s_client -host "$1" -port "$PORT"; exit; }
  18. [ "$SERVER" ] || usage
  19. [ -e "$KEYFILE" ] || openssl req -nodes -new -x509 -batch \
  20.     -subj / -out "$KEYFILE" -keyout "$KEYFILE" || exit
  21. [ "$DELETE_KEYFILE" ] && trap "rm -f $KEYFILE" EXIT
  22. openssl s_server -cert "$KEYFILE" -accept "$PORT"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement