uses fast cryptography algorithms with 128bit security margin, strong
mutual zero-knowledge authentication and perfect-forward secrecy
property. An attacker can not know anything from captured traffic, even
-if pre-shared key is compromised.
+if pre-shared key is compromised. Rehandshake is performed by client
+every 4 GiB of transfered data.
Also you can provide up and down scripts that will be executed after
either connection is initiated (up-script in background), or is went
S20BS = 64
HeartBeatSize = 12
HeartBeatMark = "\x00\x00\x00HEARTBEAT"
+ // Maximal amount of bytes transfered with single key (4 GiB)
+ MaxBytesPerKey = 4294967296
)
type TAP interface {
var p *Peer
timeouts := 0
+ bytes := 0
states := make(map[string]*Handshake)
nonce := make([]byte, NonceSize)
keyAuth := new([KeySize]byte)
}
heartbeat := time.Tick(time.Second * time.Duration(timeout/3))
+ go func() { <-heartbeat }()
heartbeatMark := []byte(HeartBeatMark)
termSignal := make(chan os.Signal, 1)
if finished {
break
}
+ if !serverMode && bytes > MaxBytesPerKey {
+ states[remote.String()] = HandshakeStart(conn, remote, key)
+ bytes = 0
+ }
select {
case <-termSignal:
finished = true
}
if p != nil {
fmt.Print("[HS-OK]")
+ if peer == nil {
+ go ScriptCall(upPath)
+ }
peer = p
delete(states, addr)
- go ScriptCall(upPath)
}
continue
}
peer.nonceRecv = nonceRecv
timeouts = 0
frame = buf[S20BS : S20BS+udpPkt.size-NonceSize-poly1305.TagSize]
+ bytes += len(frame)
if string(frame[0:HeartBeatSize]) == HeartBeatMark {
continue
}
copy(keyAuth[:], buf[:KeySize])
dataToSend := buf[S20BS-NonceSize : S20BS+ethPktSize]
poly1305.Sum(tag, dataToSend, keyAuth)
+ bytes += len(dataToSend)
if _, err := conn.WriteTo(append(dataToSend, tag[:]...), peer.addr); err != nil {
log.Println("Error sending UDP", err)
}