From 9ab4d5efeed3430931e6f0d5fac039462beaf60c Mon Sep 17 00:00:00 2001 From: idk Date: Tue, 18 Sep 2018 00:14:45 -0400 Subject: [PATCH] fixed some names --- README.md.asc | 16 ++++---- common.go | 17 ++++---- etc/init.d/samcatd | 91 +++++++++++++++++++++++++++++++++++++++++ etc/samcatd/tunnels.ini | 61 +++++++++++++++++++++++++++ udp/common.go | 17 ++++---- 5 files changed, 180 insertions(+), 22 deletions(-) create mode 100644 etc/init.d/samcatd create mode 100644 etc/samcatd/tunnels.ini diff --git a/README.md.asc b/README.md.asc index a7deb86..92c7746 100644 --- a/README.md.asc +++ b/README.md.asc @@ -80,12 +80,12 @@ I'm eventually going to make the manager implement net.Conn. This won't be exposed in the default application probably though, but rather as a library. -----BEGIN PGP SIGNATURE----- -iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAlugdTMACgkQ11wDs5te -FOGGTggAqP7jEXjl0dhdxo8ANB2IliJtPRSLvWNk3n+f2XsHYl80cvwjAJ+fZ7d9 -x7rZ30vFwzvGLEt0RB+GU4vbVbuOe4iJL+KbfQJ64MT31U/A53bUSOG2+rOB7asp -DTcEsLWNUCzohMokem2tvVprldk/IfyHPp7t+PyfzQRNcewPunTJE2Jx1ymzhMhZ -IUcC/xSAGf5VsT/0ADLDFiR/mq4VpMpnky6Ch3W22RZFGO8dfnQy+v1RbZVmukd/ -WHf6Q5hhxfrFXZHEVtqKN9t0W//VRzBqPPybjx+QD3WZqVxM5lf0EA8qKNZ3FA21 -I1BoQGph7VgpZbEI8VhlAK4tba8bdg== -=T7Xt +iQEzBAEBCAAdFiEEcNIGBzi++AUjrK/311wDs5teFOEFAluge7AACgkQ11wDs5te +FOGe4Af/Ulw4pnDfb+vTkevH0dqwqnFO5QEzug6Eb0GfCTykz774KIFWtoAuYoSW +UvmPaUr0/Kl+Csnl2p2hrnwgReFZvfGSthV1UmfnFuya4d6XyrvRBpsnkdQreKEF +krc72VJLhPwhaAGYTVqi3dBAIX3gdm7FGQSSz4NWoWlKAELMrLAf5a0uRlyqPzQI +/fq3LNML+KLwq7/VcEaq7vhyRROOUiV8tQAEnGAqszJghXWGhlfR91EsQMlg11SZ +CyN2OMkltdAQN1GcmncoALETyJkGKkGc1gUyxumsZvHv7O5RfYU/4Dd3UtGmTlbm +hmnkj0sVdrAsnT82JcErXWdMrlzwDQ== +=NXVQ -----END PGP SIGNATURE----- diff --git a/common.go b/common.go index affe96f..58ac75d 100644 --- a/common.go +++ b/common.go @@ -27,18 +27,21 @@ func Encrypt(i2pkeypath, aeskeypath string) error { if r, e := ioutil.ReadFile(i2pkeypath); e != nil { return e } else { - var key *[32]byte if _, err := os.Stat(aeskeypath); os.IsNotExist(err) { - key = cryptopasta.NewEncryptionKey() + key := cryptopasta.NewEncryptionKey() ioutil.WriteFile(aeskeypath, bytes(*key), 644) } else if err != nil { return err } - crypted, err := cryptopasta.Encrypt(r, key) - if err != nil { - return err - } - ioutil.WriteFile(i2pkeypath, crypted, 644) + if ra, re := ioutil.ReadFile(aeskeypath); re != nil { + return e + } else { + crypted, err := cryptopasta.Encrypt(r, key(ra)) + if err != nil { + return err + } + ioutil.WriteFile(i2pkeypath, crypted, 644) + } } } return nil diff --git a/etc/init.d/samcatd b/etc/init.d/samcatd new file mode 100644 index 0000000..b8d1405 --- /dev/null +++ b/etc/init.d/samcatd @@ -0,0 +1,91 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: samcatd +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: +### END INIT INFO + +SCRIPT='/usr/local/bin/samcatd -f /etc/samcatd/tunnels.ini' +RUNAS=samcatd + +PIDFILE=/var/run/samcatd/samcatd.pid +RUNFOLDER=/var/run/samcatd +LOGFILE=/var/log/samcatd/samcatd.log + +start() { + if [ -f "$PIDFILE" ]; then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting destination-isolating proxy service…' >&2 + start-stop-daemon -S -b -q -d "$RUNFOLDER" -g "$RUNAS" -c "$RUNAS" -p "$PIDFILE" \ + --startas /bin/bash -- -c "exec $SCRIPT > $LOGFILE 2>&1" + echo $! > "$PIDFILE" + echo "Service started: $SCRIPT" >&2 + cat "$PIDFILE" >&2 +} + +stop() { + if [ ! -f "$PIDFILE" ]; then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping destination-isolating proxy service…' >&2 + start-stop-daemon -K -q -d "$RUNFOLDER" -g "$RUNAS" -c "$RUNAS" -p "$PIDFILE" \ + --startas /bin/bash -- -c "exec $SCRIPT > $LOGFILE 2>&1" + echo "Service stopped: $SCRIPT" >&2 + rm -f "$PIDFILE" +} + +status() { + if [ -f "$PIDFILE" ]; then + start-stop-daemon -T -q -d "$RUNFOLDER" -g "$RUNAS" -c "$RUNAS" -p "$PIDFILE" \ + --startas /bin/bash -- -c "exec $SCRIPT > $LOGFILE 2>&1" + echo 'Currently open pipes:' >&2 + ls /var/run/samcatd/* >&2 + tail $LOGFILE >&2 + return 1 + else + echo 'Service not running' >&2 + ls /var/run/samcatd >&2 + return 1 + fi + echo 'Starting destination-isolating proxy service…' >&2 +} + +uninstall() { + echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " + local SURE + read SURE + if [ "$SURE" = "yes" ]; then + stop + rm -f "$PIDFILE" + echo "Notice: log file is not be removed: '$LOGFILE'" >&2 + update-rc.d -f samcatd remove + rm -fv "$0" + fi +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + uninstall) + uninstall + ;; + restart) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|restart|uninstall}" +esac diff --git a/etc/samcatd/tunnels.ini b/etc/samcatd/tunnels.ini new file mode 100644 index 0000000..8ebd631 --- /dev/null +++ b/etc/samcatd/tunnels.ini @@ -0,0 +1,61 @@ + +## Defaults, these are only invoked with the -start option or if labeled tunnels +## are not present(samcatd instructions) + +inbound.length = 3 +outbound.length = 6 +inbound.lengthVariance = 0 +outbound.lengthVariance = 0 +inbound.backupQuantity = 3 +outbound.backupQuantity = 3 +inbound.quantity = 5 +outbound.quantity = 5 +inbound.allowZeroHop = false +outbound.allowZeroHop = false +i2cp.encryptLeaseSet = false +gzip = true +i2cp.reduceOnIdle = true +i2cp.reduceIdleTime = 3000000 +i2cp.reduceQuantity = 2 +i2cp.enableWhiteList = false +i2cp.enableBlackList = false + +[sam-forwarder] +type = server +host = 127.0.0.1 +port = 8081 +inbound.length = 3 +outbound.length = 6 +keys = forwarder + +[sam-forwarder-two] +type = client +host = 127.0.0.1 +port = 8082 +inbound.length = 6 +outbound.length = 3 +keys = forwarder-two + +[sam-forwarder-three] +type = udpclient +host = 127.0.0.1 +port = 8083 +inbound.length = 3 +outbound.length = 6 +keys = forwarder-three + +[sam-forwarder-four] +type = udpserver +host = 127.0.0.1 +port = 8084 +inbound.length = 6 +outbound.length = 3 +keys = forwarder-four + +[sam-forwarder-five] +type = http +host = 127.0.0.1 +port = 8085 +inbound.length = 3 +outbound.length = 6 +keys = forwarder-five diff --git a/udp/common.go b/udp/common.go index 7d72add..5132e7e 100644 --- a/udp/common.go +++ b/udp/common.go @@ -27,18 +27,21 @@ func Encrypt(i2pkeypath, aeskeypath string) error { if r, e := ioutil.ReadFile(i2pkeypath); e != nil { return e } else { - var key *[32]byte if _, err := os.Stat(aeskeypath); os.IsNotExist(err) { - key = cryptopasta.NewEncryptionKey() + key := cryptopasta.NewEncryptionKey() ioutil.WriteFile(aeskeypath, bytes(*key), 644) } else if err != nil { return err } - crypted, err := cryptopasta.Encrypt(r, key) - if err != nil { - return err - } - ioutil.WriteFile(i2pkeypath, crypted, 644) + if ra, re := ioutil.ReadFile(aeskeypath); re != nil { + return e + } else { + crypted, err := cryptopasta.Encrypt(r, key(ra)) + if err != nil { + return err + } + ioutil.WriteFile(i2pkeypath, crypted, 644) + } } } return nil