2018-04-07 20:04:10 +00:00
|
|
|
// hkexnet.go - net.Conn compatible channel setup with encrypted/HMAC
|
|
|
|
// negotiation
|
|
|
|
|
|
|
|
// Copyright (c) 2017-2018 Russell Magee
|
|
|
|
// Licensed under the terms of the MIT license (see LICENSE.mit in this
|
|
|
|
// distribution)
|
|
|
|
//
|
|
|
|
// golang implementation by Russ Magee (rmagee_at_gmail.com)
|
2018-01-11 21:44:11 +00:00
|
|
|
|
2018-07-05 04:21:23 +00:00
|
|
|
package hkexnet
|
2018-01-09 03:16:55 +00:00
|
|
|
|
2018-09-11 03:22:09 +00:00
|
|
|
// TODO:
|
|
|
|
// If key exchange algs other than the experimental HerraduraKEx are to
|
|
|
|
// be supported, the Dial() and Accept() methods should take a kex param,
|
|
|
|
// specifying which to use; and the client/server negotiation must then
|
|
|
|
// prefix the channel setup with this param over the wire in order to decide
|
|
|
|
// which is in use.
|
|
|
|
//
|
2018-09-11 03:28:41 +00:00
|
|
|
// DESIGN PRINCIPLE: There shall be no protocol features which enable
|
|
|
|
// downgrade attacks. The server shall have final authority to accept or
|
|
|
|
// reject any and all proposed KEx and connection parameters proposed by
|
|
|
|
// clients at setup. Action on denial shall be a simple server disconnect
|
|
|
|
// with possibly a status code sent so client can determine why connection
|
|
|
|
// was denied (compare to how failed auth is communicated to client).
|
2018-09-11 03:22:09 +00:00
|
|
|
|
2018-01-09 07:08:58 +00:00
|
|
|
// Implementation of HKEx-wrapped versions of the golang standard
|
|
|
|
// net package interfaces, allowing clients and servers to simply replace
|
2018-06-30 02:23:11 +00:00
|
|
|
// 'net.Dial' and 'net.Listen' with 'hkex.Dial' and 'hkex.Listen'
|
|
|
|
// (though some extra methods are implemented and must be used
|
|
|
|
// for things outside of the scope of plain sockets).
|
2018-01-09 03:16:55 +00:00
|
|
|
import (
|
2018-01-11 06:50:13 +00:00
|
|
|
"bytes"
|
2018-01-09 07:26:24 +00:00
|
|
|
"crypto/cipher"
|
2018-03-26 02:58:04 +00:00
|
|
|
"encoding/binary"
|
2018-02-17 02:43:37 +00:00
|
|
|
"encoding/hex"
|
2018-04-15 20:29:06 +00:00
|
|
|
"errors"
|
2018-01-09 03:16:55 +00:00
|
|
|
"fmt"
|
2018-02-17 02:43:37 +00:00
|
|
|
"hash"
|
2018-03-26 02:58:04 +00:00
|
|
|
"io"
|
2018-01-18 05:27:00 +00:00
|
|
|
"log"
|
2018-01-09 03:16:55 +00:00
|
|
|
"math/big"
|
2018-05-04 06:53:47 +00:00
|
|
|
"math/rand"
|
2018-01-09 03:16:55 +00:00
|
|
|
"net"
|
2018-02-17 02:46:29 +00:00
|
|
|
"strings"
|
2018-05-02 19:28:56 +00:00
|
|
|
"sync"
|
2018-01-17 02:30:57 +00:00
|
|
|
"time"
|
2018-07-05 04:21:23 +00:00
|
|
|
|
|
|
|
"blitter.com/go/hkexsh/herradurakex"
|
2018-01-09 03:16:55 +00:00
|
|
|
)
|
|
|
|
|
2018-09-11 03:22:09 +00:00
|
|
|
// KEx type - sent from client to server in order to specify which
|
|
|
|
// algo shall be used (eg., HerraduraKEx, [TODO: others...])
|
|
|
|
type KEX uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
KEX_HERRADURA = iota // this MUST be first for default if omitted in ctor
|
2018-09-11 07:04:38 +00:00
|
|
|
KEX_FOO
|
2018-09-11 03:22:09 +00:00
|
|
|
//KEX_DH
|
|
|
|
//KEX_ETC
|
|
|
|
)
|
|
|
|
|
2018-09-06 20:50:56 +00:00
|
|
|
// const CSExtendedCode - extended (>255 UNIX exit status) codes
|
|
|
|
// This indicate channel-related or internal errors
|
|
|
|
const (
|
2018-09-06 23:23:57 +00:00
|
|
|
CSEBadAuth = 1024 // Failed login password
|
2018-09-06 20:50:56 +00:00
|
|
|
CSETruncCSO // No CSOExitStatus in payload
|
|
|
|
CSEStillOpen // Channel closed unexpectedly
|
|
|
|
CSEExecFail // cmd.Start() (exec) failed
|
|
|
|
CSEPtyExecFail // pty.Start() (exec w/pty) failed
|
|
|
|
)
|
|
|
|
|
2018-04-28 23:05:33 +00:00
|
|
|
const (
|
2018-04-29 02:28:37 +00:00
|
|
|
CSONone = iota // No error, normal packet
|
|
|
|
CSOHmacInvalid // HMAC mismatch detected on remote end
|
|
|
|
CSOTermSize // set term size (rows:cols)
|
2018-09-11 07:04:38 +00:00
|
|
|
CSOExitStatus // Remote cmd exit status
|
2018-04-29 02:28:37 +00:00
|
|
|
CSOChaff // Dummy packet, do not pass beyond decryption
|
2018-04-28 23:05:33 +00:00
|
|
|
)
|
|
|
|
|
2018-09-03 02:58:13 +00:00
|
|
|
const MAX_PAYLOAD_LEN = 4*1024*1024*1024 - 1
|
|
|
|
|
2018-01-09 03:16:55 +00:00
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
|
2018-07-20 05:39:06 +00:00
|
|
|
type (
|
|
|
|
WinSize struct {
|
|
|
|
Rows uint16
|
|
|
|
Cols uint16
|
|
|
|
}
|
2018-04-29 02:28:37 +00:00
|
|
|
|
2018-07-20 05:39:06 +00:00
|
|
|
// chaffconfig captures attributes used to send chaff packets betwixt
|
|
|
|
// client and server connections, to obscure true traffic timing and
|
|
|
|
// patterns
|
|
|
|
// see: https://en.wikipedia.org/wiki/chaff_(countermeasure)
|
|
|
|
ChaffConfig struct {
|
|
|
|
shutdown bool //set to inform chaffHelper to shut down
|
|
|
|
enabled bool
|
|
|
|
msecsMin uint //msecs min interval
|
|
|
|
msecsMax uint //msecs max interval
|
|
|
|
szMax uint // max size in bytes
|
|
|
|
}
|
2018-05-07 00:41:09 +00:00
|
|
|
|
2018-07-20 05:39:06 +00:00
|
|
|
// Conn is a HKex connection - a superset of net.Conn
|
|
|
|
Conn struct {
|
2018-09-11 07:04:38 +00:00
|
|
|
kex KEX // KEX alg (typedef uint8)
|
2018-07-20 05:39:06 +00:00
|
|
|
m *sync.Mutex
|
2018-09-11 07:04:38 +00:00
|
|
|
c net.Conn // which also implements io.Reader, io.Writer, ...
|
|
|
|
h *hkex.HerraduraKEx // TODO: make an interface?
|
|
|
|
cipheropts uint32 // post-KEx cipher/hmac options
|
|
|
|
opts uint32 // post-KEx protocol options (caller-defined)
|
2018-07-20 05:39:06 +00:00
|
|
|
WinCh chan WinSize
|
|
|
|
Rows uint16
|
|
|
|
Cols uint16
|
2018-05-04 06:53:47 +00:00
|
|
|
|
2018-07-20 05:39:06 +00:00
|
|
|
chaff ChaffConfig
|
2018-05-04 06:53:47 +00:00
|
|
|
|
2018-09-06 20:50:56 +00:00
|
|
|
closeStat *uint32 // close status (CSOExitStatus)
|
2018-07-20 05:39:06 +00:00
|
|
|
r cipher.Stream //read cipherStream
|
|
|
|
rm hash.Hash
|
|
|
|
w cipher.Stream //write cipherStream
|
|
|
|
wm hash.Hash
|
|
|
|
dBuf *bytes.Buffer //decrypt buffer for Read()
|
|
|
|
}
|
|
|
|
)
|
2018-06-30 02:23:11 +00:00
|
|
|
|
2018-09-06 20:50:56 +00:00
|
|
|
func (hc Conn) GetStatus() uint32 {
|
2018-06-30 02:23:11 +00:00
|
|
|
return *hc.closeStat
|
|
|
|
}
|
|
|
|
|
2018-09-06 20:50:56 +00:00
|
|
|
func (hc *Conn) SetStatus(stat uint32) {
|
2018-06-30 02:23:11 +00:00
|
|
|
*hc.closeStat = stat
|
2018-09-06 03:36:32 +00:00
|
|
|
//fmt.Println("closeStat:", *hc.closeStat)
|
|
|
|
log.Println("closeStat:", *hc.closeStat)
|
2018-02-17 03:25:11 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// ConnOpts returns the cipher/hmac options value, which is sent to the
|
|
|
|
// peer but is not itself part of the KEx.
|
|
|
|
//
|
2018-01-12 03:42:42 +00:00
|
|
|
// (Used for protocol-level negotiations after KEx such as
|
|
|
|
// cipher/HMAC algorithm options etc.)
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc Conn) ConnOpts() uint32 {
|
|
|
|
return hc.cipheropts
|
2018-01-12 03:42:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// SetConnOpts sets the cipher/hmac options value, which is sent to the
|
|
|
|
// peer as part of KEx but not part of the KEx itself.
|
2018-01-12 03:42:42 +00:00
|
|
|
//
|
|
|
|
// opts - bitfields for cipher and hmac alg. to use after KEx
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) SetConnOpts(copts uint32) {
|
|
|
|
hc.cipheropts = copts
|
2018-01-12 03:42:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// Opts returns the protocol options value, which is sent to the peer
|
|
|
|
// but is not itself part of the KEx or connection (cipher/hmac) setup.
|
2018-01-12 03:42:42 +00:00
|
|
|
//
|
|
|
|
// Consumers of this lib may use this for protocol-level options not part
|
|
|
|
// of the KEx or encryption info used by the connection.
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc Conn) Opts() uint32 {
|
|
|
|
return hc.opts
|
2018-01-12 03:42:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// SetOpts sets the protocol options value, which is sent to the peer
|
|
|
|
// but is not itself part of the KEx or connection (cipher/hmac) setup.
|
|
|
|
//
|
2018-01-12 03:42:42 +00:00
|
|
|
// Consumers of this lib may use this for protocol-level options not part
|
|
|
|
// of the KEx of encryption info used by the connection.
|
|
|
|
//
|
|
|
|
// opts - a uint32, caller-defined
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) SetOpts(opts uint32) {
|
|
|
|
hc.opts = opts
|
2018-01-12 03:42:42 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) applyConnExtensions(extensions ...string) {
|
2018-01-12 03:42:42 +00:00
|
|
|
for _, s := range extensions {
|
|
|
|
switch s {
|
2018-09-11 03:22:09 +00:00
|
|
|
case "KEX_HERRADURA":
|
|
|
|
log.Println("[extension arg = KEX_HERRADURA]")
|
|
|
|
hc.kex = KEX_HERRADURA
|
|
|
|
break
|
2018-09-11 07:04:38 +00:00
|
|
|
case "KEX_FOO":
|
|
|
|
log.Println("[extension arg = KEX_FOO]")
|
|
|
|
hc.kex = KEX_FOO
|
|
|
|
break
|
2018-01-12 03:42:42 +00:00
|
|
|
case "C_AES_256":
|
2018-01-18 05:27:00 +00:00
|
|
|
log.Println("[extension arg = C_AES_256]")
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.cipheropts &= (0xFFFFFF00)
|
|
|
|
hc.cipheropts |= CAlgAES256
|
2018-01-12 03:42:42 +00:00
|
|
|
break
|
|
|
|
case "C_TWOFISH_128":
|
2018-01-18 05:27:00 +00:00
|
|
|
log.Println("[extension arg = C_TWOFISH_128]")
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.cipheropts &= (0xFFFFFF00)
|
|
|
|
hc.cipheropts |= CAlgTwofish128
|
2018-01-12 03:42:42 +00:00
|
|
|
break
|
2018-01-12 07:01:39 +00:00
|
|
|
case "C_BLOWFISH_64":
|
2018-01-18 05:27:00 +00:00
|
|
|
log.Println("[extension arg = C_BLOWFISH_64]")
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.cipheropts &= (0xFFFFFF00)
|
|
|
|
hc.cipheropts |= CAlgBlowfish64
|
2018-01-12 07:01:39 +00:00
|
|
|
break
|
2018-01-12 03:42:42 +00:00
|
|
|
case "H_SHA256":
|
2018-01-18 05:27:00 +00:00
|
|
|
log.Println("[extension arg = H_SHA256]")
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.cipheropts &= (0xFFFF00FF)
|
|
|
|
hc.cipheropts |= (HmacSHA256 << 8)
|
2018-01-12 03:42:42 +00:00
|
|
|
break
|
|
|
|
default:
|
2018-01-18 05:27:00 +00:00
|
|
|
log.Printf("[Dial ext \"%s\" ignored]\n", s)
|
2018-01-12 03:42:42 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 03:16:55 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 07:04:38 +00:00
|
|
|
func HKExDialSetup(c net.Conn, hc *Conn) (err error) {
|
|
|
|
// Send hkexnet.Conn parameters to remote side
|
|
|
|
// d is value for Herradura key exchange
|
|
|
|
fmt.Fprintf(c, "0x%s\n%08x:%08x\n", hc.h.D().Text(16),
|
|
|
|
hc.cipheropts, hc.opts)
|
|
|
|
|
|
|
|
d := big.NewInt(0)
|
|
|
|
_, err = fmt.Fscanln(c, d)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Read peer D over net.Conn (c)
|
|
|
|
_, err = fmt.Fscanf(c, "%08x:%08x\n",
|
|
|
|
&hc.cipheropts, &hc.opts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
hc.h.SetPeerD(d)
|
|
|
|
log.Printf("** local D:%s\n", hc.h.D().Text(16))
|
|
|
|
log.Printf("**(c)** peer D:%s\n", hc.h.PeerD().Text(16))
|
|
|
|
hc.h.ComputeFA()
|
|
|
|
log.Printf("**(c)** FA:%s\n", hc.h.FA())
|
|
|
|
|
|
|
|
hc.r, hc.rm, err = hc.getStream(hc.h.FA())
|
|
|
|
hc.w, hc.wm, err = hc.getStream(hc.h.FA())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func HKExAcceptSetup(c net.Conn, hc *Conn) (err error) {
|
|
|
|
// Read in hkexnet.Conn parameters over raw Conn c
|
|
|
|
// d is value for Herradura key exchange
|
|
|
|
d := big.NewInt(0)
|
|
|
|
_, err = fmt.Fscanln(c, d)
|
|
|
|
log.Printf("[Got d:%v]", d)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = fmt.Fscanf(c, "%08x:%08x\n",
|
|
|
|
&hc.cipheropts, &hc.opts)
|
|
|
|
log.Printf("[Got cipheropts, opts:%v, %v]", hc.cipheropts, hc.opts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
hc.h.SetPeerD(d)
|
|
|
|
log.Printf("** D:%s\n", hc.h.D().Text(16))
|
|
|
|
log.Printf("**(s)** peerD:%s\n", hc.h.PeerD().Text(16))
|
|
|
|
hc.h.ComputeFA()
|
|
|
|
log.Printf("**(s)** FA:%s\n", hc.h.FA())
|
|
|
|
|
|
|
|
// Send D and cipheropts/conn_opts to peer
|
|
|
|
fmt.Fprintf(c, "0x%s\n%08x:%08x\n", hc.h.D().Text(16),
|
|
|
|
hc.cipheropts, hc.opts)
|
|
|
|
|
|
|
|
hc.r, hc.rm, err = hc.getStream(hc.h.FA())
|
|
|
|
hc.w, hc.wm, err = hc.getStream(hc.h.FA())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-09-11 03:22:09 +00:00
|
|
|
// Dial as net.Dial(), but with implicit key exchange to set up secure
|
|
|
|
// channel on connect
|
|
|
|
//
|
2018-01-12 03:42:42 +00:00
|
|
|
// Can be called like net.Dial(), defaulting to C_AES_256/H_SHA256,
|
|
|
|
// or additional option arguments can be passed amongst the following:
|
|
|
|
//
|
|
|
|
// "C_AES_256" | "C_TWOFISH_128"
|
|
|
|
//
|
|
|
|
// "H_SHA256"
|
|
|
|
func Dial(protocol string, ipport string, extensions ...string) (hc *Conn, err error) {
|
2018-03-25 17:40:23 +00:00
|
|
|
// Open raw Conn c
|
2018-01-09 03:16:55 +00:00
|
|
|
c, err := net.Dial(protocol, ipport)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-03-25 17:40:23 +00:00
|
|
|
// Init hkexnet.Conn hc over net.Conn c
|
2018-09-11 03:22:09 +00:00
|
|
|
// NOTE: kex default of KEX_HERRADURA may be overridden by
|
|
|
|
// future extension args to applyConnExtensions(), which is
|
|
|
|
// called prior to Dial()
|
2018-09-06 20:50:56 +00:00
|
|
|
hc = &Conn{m: &sync.Mutex{}, c: c, closeStat: new(uint32), h: hkex.New(0, 0), dBuf: new(bytes.Buffer)}
|
2018-01-12 03:42:42 +00:00
|
|
|
hc.applyConnExtensions(extensions...)
|
2018-01-09 03:16:55 +00:00
|
|
|
|
2018-09-11 03:22:09 +00:00
|
|
|
// TODO: Factor out ALL params following this to helpers for
|
|
|
|
// specific KEx algs
|
|
|
|
fmt.Fprintf(c, "%02x\n", hc.kex)
|
|
|
|
// --
|
|
|
|
|
2018-09-11 07:04:38 +00:00
|
|
|
*hc.closeStat = CSEStillOpen // open or prematurely-closed status
|
2018-01-09 03:16:55 +00:00
|
|
|
|
2018-09-11 07:04:38 +00:00
|
|
|
// Perform Key Exchange according to client-request algorithm
|
|
|
|
switch hc.kex {
|
|
|
|
case KEX_HERRADURA:
|
|
|
|
if HKExDialSetup(c, hc) != nil {
|
|
|
|
return hc, nil
|
|
|
|
}
|
|
|
|
case KEX_FOO:
|
|
|
|
// For testing: set up as HKEx anyway, but server via Accept() should
|
|
|
|
// reject as invalid.
|
|
|
|
//if FooKExDialSetup(c, hc) != nil {
|
|
|
|
if HKExDialSetup(c, hc) != nil {
|
|
|
|
return hc, nil
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Printf("Invalid kex alg (%d), rejecting\n", hc.kex)
|
|
|
|
return nil, errors.New("Invalid kex alg")
|
2018-01-12 03:42:42 +00:00
|
|
|
}
|
2018-01-09 03:16:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-11 21:44:11 +00:00
|
|
|
// Close a hkex.Conn
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) Close() (err error) {
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.DisableChaff()
|
2018-09-06 20:50:56 +00:00
|
|
|
s := make([]byte, 4)
|
|
|
|
binary.BigEndian.PutUint32(s, *hc.closeStat)
|
|
|
|
hc.WritePacket(s, CSOExitStatus)
|
2018-06-30 02:23:11 +00:00
|
|
|
err = hc.c.Close()
|
2018-01-19 02:57:37 +00:00
|
|
|
log.Println("[Conn Closing]")
|
2018-01-09 03:16:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-18 00:39:01 +00:00
|
|
|
// LocalAddr returns the local network address.
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) LocalAddr() net.Addr {
|
2018-06-30 02:23:11 +00:00
|
|
|
return hc.c.LocalAddr()
|
2018-01-18 00:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoteAddr returns the remote network address.
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) RemoteAddr() net.Addr {
|
2018-06-30 02:23:11 +00:00
|
|
|
return hc.c.RemoteAddr()
|
2018-01-18 00:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDeadline sets the read and write deadlines associated
|
|
|
|
// with the connection. It is equivalent to calling both
|
|
|
|
// SetReadDeadline and SetWriteDeadline.
|
|
|
|
//
|
|
|
|
// A deadline is an absolute time after which I/O operations
|
|
|
|
// fail with a timeout (see type Error) instead of
|
|
|
|
// blocking. The deadline applies to all future and pending
|
|
|
|
// I/O, not just the immediately following call to Read or
|
|
|
|
// Write. After a deadline has been exceeded, the connection
|
|
|
|
// can be refreshed by setting a deadline in the future.
|
|
|
|
//
|
|
|
|
// An idle timeout can be implemented by repeatedly extending
|
|
|
|
// the deadline after successful Read or Write calls.
|
|
|
|
//
|
|
|
|
// A zero value for t means I/O operations will not time out.
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) SetDeadline(t time.Time) error {
|
2018-06-30 02:23:11 +00:00
|
|
|
return hc.c.SetDeadline(t)
|
2018-01-18 00:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetWriteDeadline sets the deadline for future Write calls
|
|
|
|
// and any currently-blocked Write call.
|
|
|
|
// Even if write times out, it may return n > 0, indicating that
|
|
|
|
// some of the data was successfully written.
|
|
|
|
// A zero value for t means Write will not time out.
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) SetWriteDeadline(t time.Time) error {
|
2018-06-30 02:23:11 +00:00
|
|
|
return hc.c.SetWriteDeadline(t)
|
2018-01-18 00:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetReadDeadline sets the deadline for future Read calls
|
|
|
|
// and any currently-blocked Read call.
|
|
|
|
// A zero value for t means Read will not time out.
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) SetReadDeadline(t time.Time) error {
|
2018-06-30 02:23:11 +00:00
|
|
|
return hc.c.SetReadDeadline(t)
|
2018-01-18 00:39:01 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 03:16:55 +00:00
|
|
|
/*---------------------------------------------------------------------*/
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// HKExListener is a Listener conforming to net.Listener
|
|
|
|
//
|
|
|
|
// See go doc net.Listener
|
2018-01-09 03:16:55 +00:00
|
|
|
type HKExListener struct {
|
|
|
|
l net.Listener
|
|
|
|
}
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// Listen for a connection
|
|
|
|
//
|
|
|
|
// See go doc net.Listen
|
2018-01-09 03:16:55 +00:00
|
|
|
func Listen(protocol string, ipport string) (hl HKExListener, e error) {
|
|
|
|
l, err := net.Listen(protocol, ipport)
|
|
|
|
if err != nil {
|
|
|
|
return HKExListener{nil}, err
|
|
|
|
}
|
2018-01-19 02:57:37 +00:00
|
|
|
log.Println("[Listening]")
|
2018-01-09 03:16:55 +00:00
|
|
|
hl.l = l
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-01-27 00:15:39 +00:00
|
|
|
// Close a hkex Listener - closes the Listener.
|
|
|
|
// Any blocked Accept operations will be unblocked and return errors.
|
2018-01-13 06:13:01 +00:00
|
|
|
//
|
2018-01-27 00:15:39 +00:00
|
|
|
// See go doc net.Listener.Close
|
2018-01-18 00:39:01 +00:00
|
|
|
func (hl HKExListener) Close() error {
|
2018-01-19 02:57:37 +00:00
|
|
|
log.Println("[Listener Closed]")
|
2018-01-13 06:13:01 +00:00
|
|
|
return hl.l.Close()
|
2018-01-09 03:16:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 00:15:39 +00:00
|
|
|
// Addr returns a the listener's network address.
|
|
|
|
//
|
|
|
|
// See go doc net.Listener.Addr
|
|
|
|
func (hl HKExListener) Addr() net.Addr {
|
2018-02-17 02:43:37 +00:00
|
|
|
return hl.l.Addr()
|
2018-01-27 00:15:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 21:44:11 +00:00
|
|
|
// Accept a client connection, conforming to net.Listener.Accept()
|
2018-01-13 06:13:01 +00:00
|
|
|
//
|
|
|
|
// See go doc net.Listener.Accept
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hl *HKExListener) Accept() (hc Conn, err error) {
|
2018-03-25 17:40:23 +00:00
|
|
|
// Open raw Conn c
|
2018-01-09 03:16:55 +00:00
|
|
|
c, err := hl.l.Accept()
|
|
|
|
if err != nil {
|
2018-09-06 20:50:56 +00:00
|
|
|
hc := Conn{m: &sync.Mutex{}, c: nil, h: nil, closeStat: new(uint32), cipheropts: 0, opts: 0,
|
2018-05-04 06:53:47 +00:00
|
|
|
r: nil, w: nil}
|
|
|
|
return hc, err
|
2018-01-09 03:16:55 +00:00
|
|
|
}
|
2018-01-19 02:57:37 +00:00
|
|
|
log.Println("[Accepted]")
|
2018-01-12 03:42:42 +00:00
|
|
|
|
2018-09-11 03:22:09 +00:00
|
|
|
hc = Conn{ /*kex: from client,*/ m: &sync.Mutex{}, c: c, h: hkex.New(0, 0), closeStat: new(uint32), WinCh: make(chan WinSize, 1),
|
2018-05-05 06:39:19 +00:00
|
|
|
dBuf: new(bytes.Buffer)}
|
2018-01-09 03:16:55 +00:00
|
|
|
|
2018-09-11 03:22:09 +00:00
|
|
|
// TODO: Factor out ALL params following this to helpers for
|
|
|
|
// specific KEx algs
|
|
|
|
var kexAlg uint8
|
|
|
|
_, err = fmt.Fscanln(c, &kexAlg)
|
|
|
|
if err != nil {
|
|
|
|
return hc, err
|
|
|
|
}
|
2018-09-11 07:04:38 +00:00
|
|
|
log.Printf("[Client proposed KEx alg: %v]\n", kexAlg)
|
2018-09-11 03:22:09 +00:00
|
|
|
// --
|
|
|
|
|
2018-09-11 07:04:38 +00:00
|
|
|
switch kexAlg {
|
|
|
|
case KEX_HERRADURA:
|
|
|
|
log.Printf("[KEx alg %d accepted]\n", kexAlg)
|
|
|
|
if HKExAcceptSetup(c, &hc) != nil {
|
|
|
|
return hc, nil
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Printf("[KEx alg %d rejected]\n", kexAlg)
|
|
|
|
return hc, errors.New("KEx rejected")
|
2018-01-09 03:16:55 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2018-01-17 02:30:57 +00:00
|
|
|
|
2018-01-09 03:16:55 +00:00
|
|
|
/*---------------------------------------------------------------------*/
|
2018-01-13 06:13:01 +00:00
|
|
|
|
|
|
|
// Read into a byte slice
|
|
|
|
//
|
|
|
|
// See go doc io.Reader
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc Conn) Read(b []byte) (n int, err error) {
|
2018-02-17 02:46:29 +00:00
|
|
|
//log.Printf("[Decrypting...]\r\n")
|
2018-03-26 02:58:04 +00:00
|
|
|
for {
|
2018-06-30 02:23:11 +00:00
|
|
|
//log.Printf("hc.dBuf.Len(): %d\n", hc.dBuf.Len())
|
|
|
|
if hc.dBuf.Len() > 0 /* len(b) */ {
|
2018-03-26 02:58:04 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2018-04-15 20:29:06 +00:00
|
|
|
var ctrlStatOp uint8
|
2018-04-15 19:58:24 +00:00
|
|
|
var hmacIn [4]uint8
|
2018-03-26 02:58:04 +00:00
|
|
|
var payloadLen uint32
|
|
|
|
|
2018-04-29 02:28:37 +00:00
|
|
|
// Read ctrl/status opcode (CSOHmacInvalid on hmac mismatch)
|
2018-06-30 02:23:11 +00:00
|
|
|
err = binary.Read(hc.c, binary.BigEndian, &ctrlStatOp)
|
2018-04-29 02:28:37 +00:00
|
|
|
log.Printf("[ctrlStatOp: %v]\n", ctrlStatOp)
|
|
|
|
if ctrlStatOp == CSOHmacInvalid {
|
2018-04-15 20:29:06 +00:00
|
|
|
// Other side indicated channel tampering, close channel
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.Close()
|
2018-04-15 20:29:06 +00:00
|
|
|
return 1, errors.New("** ALERT - remote end detected HMAC mismatch - possible channel tampering **")
|
|
|
|
}
|
|
|
|
|
2018-04-15 19:58:24 +00:00
|
|
|
// Read the hmac and payload len first
|
2018-06-30 02:23:11 +00:00
|
|
|
err = binary.Read(hc.c, binary.BigEndian, &hmacIn)
|
2018-03-26 06:00:37 +00:00
|
|
|
// Normal client 'exit' from interactive session will cause
|
|
|
|
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
|
2018-03-27 04:58:42 +00:00
|
|
|
if err != nil {
|
2018-03-26 06:00:37 +00:00
|
|
|
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
|
2018-09-06 07:16:44 +00:00
|
|
|
//fmt.Println("[1]unexpected Read() err:", err)
|
2018-09-03 02:58:13 +00:00
|
|
|
log.Println("[1]unexpected Read() err:", err)
|
2018-03-26 04:47:38 +00:00
|
|
|
} else {
|
2018-09-06 07:16:44 +00:00
|
|
|
//fmt.Println("[Client hung up]")
|
2018-03-26 06:00:37 +00:00
|
|
|
log.Println("[Client hung up]")
|
2018-03-26 04:47:38 +00:00
|
|
|
}
|
2018-03-27 04:58:42 +00:00
|
|
|
return 0, err
|
2018-03-26 02:58:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
err = binary.Read(hc.c, binary.BigEndian, &payloadLen)
|
2018-03-26 02:58:04 +00:00
|
|
|
if err != nil {
|
2018-03-26 06:00:37 +00:00
|
|
|
if err.Error() != "EOF" {
|
2018-09-03 02:58:13 +00:00
|
|
|
log.Println("[2]unexpected Read() err:", err)
|
2018-04-28 23:05:33 +00:00
|
|
|
}
|
2018-03-26 02:58:04 +00:00
|
|
|
}
|
2018-04-28 23:05:33 +00:00
|
|
|
|
2018-09-03 02:58:13 +00:00
|
|
|
if payloadLen > MAX_PAYLOAD_LEN {
|
2018-04-28 23:05:33 +00:00
|
|
|
log.Printf("[Insane payloadLen:%v]\n", payloadLen)
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.Close()
|
2018-04-28 23:05:33 +00:00
|
|
|
return 1, errors.New("Insane payloadLen")
|
2018-03-26 02:58:04 +00:00
|
|
|
}
|
2018-04-28 23:05:33 +00:00
|
|
|
|
2018-03-26 02:58:04 +00:00
|
|
|
var payloadBytes = make([]byte, payloadLen)
|
2018-06-30 02:23:11 +00:00
|
|
|
n, err = io.ReadFull(hc.c, payloadBytes)
|
2018-03-26 02:58:04 +00:00
|
|
|
|
|
|
|
// Normal client 'exit' from interactive session will cause
|
|
|
|
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
|
|
|
|
if err != nil && err.Error() != "EOF" {
|
|
|
|
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
|
2018-09-03 02:58:13 +00:00
|
|
|
log.Println("[3]unexpected Read() err:", err)
|
2018-03-26 02:58:04 +00:00
|
|
|
} else {
|
|
|
|
log.Println("[Client hung up]")
|
|
|
|
}
|
2018-02-17 02:46:29 +00:00
|
|
|
}
|
2018-02-17 06:12:27 +00:00
|
|
|
|
2018-04-15 19:58:24 +00:00
|
|
|
log.Printf(" <:ctext:\r\n%s\r\n", hex.Dump(payloadBytes[:n]))
|
2018-03-26 02:58:04 +00:00
|
|
|
|
|
|
|
db := bytes.NewBuffer(payloadBytes[:n]) //copying payloadBytes to db
|
|
|
|
// The StreamReader acts like a pipe, decrypting
|
|
|
|
// whatever is available and forwarding the result
|
|
|
|
// to the parameter of Read() as a normal io.Reader
|
2018-06-30 02:23:11 +00:00
|
|
|
rs := &cipher.StreamReader{S: hc.r, R: db}
|
2018-03-26 02:58:04 +00:00
|
|
|
// The caller isn't necessarily reading the full payload so we need
|
|
|
|
// to decrypt ot an intermediate buffer, draining it on demand of caller
|
|
|
|
decryptN, err := rs.Read(payloadBytes)
|
2018-04-15 19:58:24 +00:00
|
|
|
log.Printf(" <-ptext:\r\n%s\r\n", hex.Dump(payloadBytes[:n]))
|
2018-03-26 02:58:04 +00:00
|
|
|
if err != nil {
|
2018-09-06 07:16:44 +00:00
|
|
|
//fmt.Print(err)
|
|
|
|
//panic(err)
|
|
|
|
} else {
|
2018-04-28 23:05:33 +00:00
|
|
|
|
2018-09-06 07:16:44 +00:00
|
|
|
// Throw away pkt if it's chaff (ie., caller to Read() won't see this data)
|
|
|
|
if ctrlStatOp == CSOChaff {
|
|
|
|
log.Printf("[Chaff pkt, discarded (len %d)]\n", decryptN)
|
|
|
|
} else if ctrlStatOp == CSOTermSize {
|
|
|
|
fmt.Sscanf(string(payloadBytes), "%d %d", &hc.Rows, &hc.Cols)
|
|
|
|
log.Printf("[TermSize pkt: rows %v cols %v]\n", hc.Rows, hc.Cols)
|
|
|
|
hc.WinCh <- WinSize{hc.Rows, hc.Cols}
|
|
|
|
} else if ctrlStatOp == CSOExitStatus {
|
|
|
|
if len(payloadBytes) > 0 {
|
2018-09-06 20:50:56 +00:00
|
|
|
hc.SetStatus(binary.BigEndian.Uint32(payloadBytes))
|
2018-09-06 07:16:44 +00:00
|
|
|
//!// If remote end is closing with an error, reply we're closing ours
|
|
|
|
//!if hc.GetStatus() != 0 {
|
|
|
|
//! log.Print("CSOExitStatus:", hc.GetStatus())
|
2018-09-05 05:24:16 +00:00
|
|
|
hc.Close()
|
2018-09-06 07:16:44 +00:00
|
|
|
//!}
|
|
|
|
} else {
|
|
|
|
log.Println("[truncated payload, cannot determine CSOExitStatus]")
|
2018-09-06 20:50:56 +00:00
|
|
|
*hc.closeStat = CSETruncCSO
|
2018-09-05 05:24:16 +00:00
|
|
|
}
|
2018-08-06 04:43:21 +00:00
|
|
|
} else {
|
2018-09-06 07:16:44 +00:00
|
|
|
hc.dBuf.Write(payloadBytes)
|
|
|
|
//log.Printf("hc.dBuf: %s\n", hex.Dump(hc.dBuf.Bytes()))
|
2018-08-06 04:43:21 +00:00
|
|
|
}
|
2018-03-26 02:58:04 +00:00
|
|
|
|
2018-09-06 07:16:44 +00:00
|
|
|
// Re-calculate hmac, compare with received value
|
|
|
|
hc.rm.Write(payloadBytes)
|
|
|
|
hTmp := hc.rm.Sum(nil)[0:4]
|
|
|
|
log.Printf("<%04x) HMAC:(i)%s (c)%02x\r\n", decryptN, hex.EncodeToString([]byte(hmacIn[0:])), hTmp)
|
2018-04-15 19:58:24 +00:00
|
|
|
|
2018-09-06 20:50:56 +00:00
|
|
|
if *hc.closeStat == CSETruncCSO {
|
2018-09-06 07:16:44 +00:00
|
|
|
log.Println("[cannot verify HMAC]")
|
|
|
|
} else {
|
|
|
|
// Log alert if hmac didn't match, corrupted channel
|
|
|
|
if !bytes.Equal(hTmp, []byte(hmacIn[0:])) /*|| hmacIn[0] > 0xf8*/ {
|
|
|
|
fmt.Println("** ALERT - detected HMAC mismatch, possible channel tampering **")
|
|
|
|
_, _ = hc.c.Write([]byte{CSOHmacInvalid})
|
|
|
|
}
|
2018-08-06 04:43:21 +00:00
|
|
|
}
|
2018-04-15 19:58:24 +00:00
|
|
|
}
|
2018-02-17 03:25:11 +00:00
|
|
|
}
|
2018-04-28 23:05:33 +00:00
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
retN := hc.dBuf.Len()
|
2018-03-26 04:47:38 +00:00
|
|
|
if retN > len(b) {
|
|
|
|
retN = len(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Read() got %d bytes\n", retN)
|
2018-06-30 02:23:11 +00:00
|
|
|
copy(b, hc.dBuf.Next(retN))
|
2018-03-26 04:47:38 +00:00
|
|
|
return retN, nil
|
2018-01-09 03:16:55 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 06:13:01 +00:00
|
|
|
// Write a byte slice
|
|
|
|
//
|
|
|
|
// See go doc io.Writer
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc Conn) Write(b []byte) (n int, err error) {
|
|
|
|
n, err = hc.WritePacket(b, CSONone)
|
2018-05-01 09:39:45 +00:00
|
|
|
return n, err
|
2018-04-29 02:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write a byte slice with specified ctrlStatusOp byte
|
2018-09-05 05:24:16 +00:00
|
|
|
func (hc *Conn) WritePacket(b []byte, op byte) (n int, err error) {
|
2018-02-17 02:46:29 +00:00
|
|
|
//log.Printf("[Encrypting...]\r\n")
|
2018-04-15 19:58:24 +00:00
|
|
|
var hmacOut []uint8
|
2018-03-26 02:58:04 +00:00
|
|
|
var payloadLen uint32
|
2018-09-11 07:04:38 +00:00
|
|
|
|
|
|
|
if hc.m == nil || hc.wm == nil {
|
|
|
|
return 0, errors.New("Secure chan not ready for writing")
|
|
|
|
}
|
|
|
|
|
2018-05-04 21:40:06 +00:00
|
|
|
// N.B. Originally this Lock() surrounded only the
|
2018-06-30 02:23:11 +00:00
|
|
|
// calls to binary.Write(hc.c ..) however there appears
|
2018-05-04 21:40:06 +00:00
|
|
|
// to be some other unshareable state in the Conn
|
|
|
|
// struct that must be protected to serialize main and
|
|
|
|
// chaff data written to it.
|
|
|
|
//
|
|
|
|
// Would be nice to determine if the mutex scope
|
|
|
|
// could be tightened.
|
2018-09-05 05:24:16 +00:00
|
|
|
hc.m.Lock()
|
|
|
|
//fmt.Printf("--== TOTAL payloadLen (b):%d\n", len(b))
|
|
|
|
payloadLen = uint32(len(b))
|
|
|
|
//!fmt.Printf(" --== payloadLen:%d\n", payloadLen)
|
|
|
|
log.Printf(" :>ptext:\r\n%s\r\n", hex.Dump(b[0:payloadLen]))
|
|
|
|
|
|
|
|
// Calculate hmac on payload
|
|
|
|
hc.wm.Write(b[0:payloadLen])
|
|
|
|
hmacOut = hc.wm.Sum(nil)[0:4]
|
|
|
|
|
|
|
|
log.Printf(" (%04x> HMAC(o):%s\r\n", payloadLen, hex.EncodeToString(hmacOut))
|
|
|
|
|
|
|
|
var wb bytes.Buffer
|
|
|
|
// The StreamWriter acts like a pipe, forwarding whatever is
|
|
|
|
// written to it through the cipher, encrypting as it goes
|
|
|
|
ws := &cipher.StreamWriter{S: hc.w, W: &wb}
|
|
|
|
_, err = ws.Write(b[0:payloadLen])
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
log.Printf(" ->ctext:\r\n%s\r\n", hex.Dump(wb.Bytes()))
|
2018-09-03 02:58:13 +00:00
|
|
|
|
2018-09-05 05:24:16 +00:00
|
|
|
ctrlStatOp := op
|
|
|
|
err = binary.Write(hc.c, binary.BigEndian, &ctrlStatOp)
|
|
|
|
if err == nil {
|
|
|
|
// Write hmac LSB, payloadLen followed by payload
|
|
|
|
err = binary.Write(hc.c, binary.BigEndian, hmacOut)
|
2018-05-04 06:53:47 +00:00
|
|
|
if err == nil {
|
2018-09-05 05:24:16 +00:00
|
|
|
err = binary.Write(hc.c, binary.BigEndian, payloadLen)
|
2018-05-04 06:53:47 +00:00
|
|
|
if err == nil {
|
2018-09-05 05:24:16 +00:00
|
|
|
n, err = hc.c.Write(wb.Bytes())
|
|
|
|
} else {
|
|
|
|
//fmt.Println("[c]WriteError!")
|
2018-05-04 06:53:47 +00:00
|
|
|
}
|
2018-09-05 05:24:16 +00:00
|
|
|
} else {
|
|
|
|
//fmt.Println("[b]WriteError!")
|
2018-05-04 06:53:47 +00:00
|
|
|
}
|
2018-09-05 05:24:16 +00:00
|
|
|
} else {
|
|
|
|
//fmt.Println("[a]WriteError!")
|
2018-01-13 06:13:01 +00:00
|
|
|
}
|
2018-09-05 05:24:16 +00:00
|
|
|
hc.m.Unlock()
|
2018-04-28 23:05:33 +00:00
|
|
|
|
2018-02-17 06:12:27 +00:00
|
|
|
if err != nil {
|
2018-03-27 04:58:42 +00:00
|
|
|
log.Println(err)
|
2018-02-17 06:12:27 +00:00
|
|
|
}
|
2018-01-09 03:16:55 +00:00
|
|
|
return
|
|
|
|
}
|
2018-05-02 19:28:56 +00:00
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) EnableChaff() {
|
|
|
|
hc.chaff.shutdown = false
|
|
|
|
hc.chaff.enabled = true
|
2018-05-07 00:41:09 +00:00
|
|
|
log.Println("Chaffing ENABLED")
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.chaffHelper()
|
2018-05-07 00:41:09 +00:00
|
|
|
}
|
2018-05-04 06:53:47 +00:00
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) DisableChaff() {
|
|
|
|
hc.chaff.enabled = false
|
2018-06-27 03:14:43 +00:00
|
|
|
log.Println("Chaffing DISABLED")
|
|
|
|
}
|
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) ShutdownChaff() {
|
|
|
|
hc.chaff.shutdown = true
|
2018-06-27 03:14:43 +00:00
|
|
|
log.Println("Chaffing SHUTDOWN")
|
|
|
|
}
|
|
|
|
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) SetupChaff(msecsMin uint, msecsMax uint, szMax uint) {
|
|
|
|
hc.chaff.msecsMin = msecsMin //move these to params of chaffHelper() ?
|
|
|
|
hc.chaff.msecsMax = msecsMax
|
|
|
|
hc.chaff.szMax = szMax
|
2018-05-04 06:53:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helper routine to spawn a chaffing goroutine for each Conn
|
2018-06-30 02:23:11 +00:00
|
|
|
func (hc *Conn) chaffHelper() {
|
2018-05-04 06:53:47 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
var nextDuration int
|
2018-06-30 02:23:11 +00:00
|
|
|
if hc.chaff.enabled {
|
|
|
|
bufTmp := make([]byte, rand.Intn(int(hc.chaff.szMax)))
|
|
|
|
min := int(hc.chaff.msecsMin)
|
|
|
|
nextDuration = rand.Intn(int(hc.chaff.msecsMax)-min) + min
|
2018-05-07 00:41:09 +00:00
|
|
|
_, _ = rand.Read(bufTmp)
|
2018-06-30 02:23:11 +00:00
|
|
|
_, err := hc.WritePacket(bufTmp, CSOChaff)
|
2018-05-04 06:53:47 +00:00
|
|
|
if err != nil {
|
2018-05-04 21:40:06 +00:00
|
|
|
log.Println("[ *** error - chaffHelper quitting *** ]")
|
2018-06-30 02:23:11 +00:00
|
|
|
hc.chaff.enabled = false
|
2018-05-04 06:53:47 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
time.Sleep(time.Duration(nextDuration) * time.Millisecond)
|
2018-06-30 02:23:11 +00:00
|
|
|
if hc.chaff.shutdown {
|
2018-06-27 03:14:43 +00:00
|
|
|
log.Println("*** chaffHelper shutting down")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2018-05-04 06:53:47 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|