upPath = flag.String("up", "", "Path to up-script")
downPath = flag.String("down", "", "Path to down-script")
mtu = flag.Int("mtu", 1500, "MTU")
+ nonceDiff = flag.Int("noncediff", 1, "Allow nonce difference")
timeoutP = flag.Int("timeout", 60, "Timeout seconds")
verboseP = flag.Bool("v", false, "Increase verbosity")
)
flag.Parse()
timeout := *timeoutP
verbose := *verboseP
+ noncediff := uint64(*nonceDiff)
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
// Key decoding
state = &Handshake{addr: udpPkt.addr}
states[addr] = state
}
- p = state.Server(conn, key, udpPktData)
+ p = state.Server(noncediff, conn, key, udpPktData)
} else {
if !exists {
fmt.Print("[HS?]")
udpSinkReady <- true
continue
}
- p = state.Client(conn, key, udpPktData)
+ p = state.Client(noncediff, conn, key, udpPktData)
}
if p != nil {
fmt.Print("[HS-OK]")
continue
}
nonceRecv, _ := binary.Uvarint(udpPktData[:8])
- if peer.nonceRecv >= nonceRecv {
+ if nonceRecv < peer.nonceRecv-noncediff {
fmt.Print("R")
udpSinkReady <- true
continue
return &state
}
-func (h *Handshake) Server(conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
+func (h *Handshake) Server(noncediff uint64, conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
switch len(data) {
case 56: // R + ENC(PSK, dh_client_pub) + NULLs
fmt.Print("[HS1]")
}
// Switch peer
- peer := Peer{addr: h.addr, nonceOur: 0, nonceRecv: 0}
+ peer := Peer{
+ addr: h.addr,
+ nonceOur: noncediff + 0,
+ nonceRecv: noncediff + 0,
+ }
peer.key = KeyFromSecrets(h.sServer[:], decRs[8+8:])
fmt.Print("[OK]")
return &peer
return nil
}
-func (h *Handshake) Client(conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
+func (h *Handshake) Client(noncediff uint64, conn *net.UDPConn, key *[32]byte, data []byte) *Peer {
switch len(data) {
case 88: // ENC(PSK, dh_server_pub) + ENC(K, RS + SS) + NULLs
fmt.Print("[HS2]")
}
// Switch peer
- peer := Peer{addr: h.addr, nonceOur: 1, nonceRecv: 0}
+ peer := Peer{
+ addr: h.addr,
+ nonceOur: noncediff + 1,
+ nonceRecv: noncediff + 0,
+ }
peer.key = KeyFromSecrets(h.sServer[:], h.sClient[:])
fmt.Print("[OK]")
return &peer