Cleanup
This commit is contained in:
parent
0a7328ed5f
commit
c61319ed16
@ -1,6 +1,7 @@
|
|||||||
package peer
|
package peer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@ -38,6 +39,10 @@ func (sc *dataCipher) Key() [32]byte {
|
|||||||
return sc.key
|
return sc.key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sc *dataCipher) HasKey(k [32]byte) bool {
|
||||||
|
return bytes.Equal(k[:], sc.key[:])
|
||||||
|
}
|
||||||
|
|
||||||
func (sc *dataCipher) Encrypt(h Header, data, out []byte) []byte {
|
func (sc *dataCipher) Encrypt(h Header, data, out []byte) []byte {
|
||||||
const s = dataHeaderSize
|
const s = dataHeaderSize
|
||||||
out = out[:s+dataCipherOverhead+len(data)]
|
out = out[:s+dataCipherOverhead+len(data)]
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package peer
|
package peer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"time"
|
"time"
|
||||||
"vppn/m"
|
"vppn/m"
|
||||||
@ -21,7 +20,6 @@ type remoteFSM struct {
|
|||||||
lastSeen time.Time
|
lastSeen time.Time
|
||||||
traceID uint64
|
traceID uint64
|
||||||
probes map[uint64]sentProbe
|
probes map[uint64]sentProbe
|
||||||
sharedKey [32]byte
|
|
||||||
|
|
||||||
buf []byte
|
buf []byte
|
||||||
}
|
}
|
||||||
@ -117,7 +115,6 @@ func (r *remoteFSM) enterServer() stateFunc {
|
|||||||
|
|
||||||
r.pingTimer.Reset(pingInterval)
|
r.pingTimer.Reset(pingInterval)
|
||||||
r.lastSeen = time.Now()
|
r.lastSeen = time.Now()
|
||||||
clear(r.sharedKey[:])
|
|
||||||
return r.stateServer
|
return r.stateServer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,9 +171,8 @@ func (r *remoteFSM) stateServer_onSyn(msg controlMsg[packetSyn]) {
|
|||||||
conf.DirectAddr = msg.SrcAddr
|
conf.DirectAddr = msg.SrcAddr
|
||||||
|
|
||||||
// Update data cipher if the key has changed.
|
// Update data cipher if the key has changed.
|
||||||
if !bytes.Equal(r.sharedKey[:], p.SharedKey[:]) {
|
if !conf.DataCipher.HasKey(p.SharedKey) {
|
||||||
conf.DataCipher = newDataCipherFromKey(p.SharedKey)
|
conf.DataCipher = newDataCipherFromKey(p.SharedKey)
|
||||||
copy(r.sharedKey[:], p.SharedKey[:])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
r.updateConf(conf)
|
r.updateConf(conf)
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
package peer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/netip"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func addrPort4(a, b, c, d byte, port uint16) netip.AddrPort {
|
|
||||||
return netip.AddrPortFrom(netip.AddrFrom4([4]byte{a, b, c, d}), port)
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertType[T any](t *testing.T, obj any) T {
|
|
||||||
t.Helper()
|
|
||||||
x, ok := obj.(T)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("invalid type: %#v", obj)
|
|
||||||
}
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
func assertEqual[T comparable](t *testing.T, a, b T) {
|
|
||||||
t.Helper()
|
|
||||||
if a != b {
|
|
||||||
t.Fatal(a, " != ", b)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user