diff --git a/nm-proxy/manager/manager.go b/nm-proxy/manager/manager.go index 39d2e77b..01df6466 100644 --- a/nm-proxy/manager/manager.go +++ b/nm-proxy/manager/manager.go @@ -67,23 +67,17 @@ type ManagerAction struct { } func StartProxyManager(manageChan chan *ManagerAction) { - for { - - select { - case mI := <-manageChan: - log.Printf("-------> PROXY-MANAGER: %+v\n", mI) - switch mI.Action { - case AddInterface: - - mI.SetIngressGateway() - err := mI.AddInterfaceToProxy() - if err != nil { - log.Printf("failed to add interface: [%s] to proxy: %v\n ", mI.Payload.InterfaceName, err) - } - case DeleteInterface: - mI.DeleteInterface() + for mI := range manageChan { + log.Printf("-------> PROXY-MANAGER: %+v\n", mI) + switch mI.Action { + case AddInterface: + mI.SetIngressGateway() + err := mI.AddInterfaceToProxy() + if err != nil { + log.Printf("failed to add interface: [%s] to proxy: %v\n ", mI.Payload.InterfaceName, err) } - + case DeleteInterface: + mI.DeleteInterface() } } } diff --git a/nm-proxy/packet/packet_helper.go b/nm-proxy/packet/packet_helper.go index 8f96b49d..990616ba 100644 --- a/nm-proxy/packet/packet_helper.go +++ b/nm-proxy/packet/packet_helper.go @@ -3,11 +3,12 @@ package packet import ( "golang.org/x/crypto/blake2s" "golang.org/x/crypto/chacha20poly1305" - "golang.org/x/crypto/poly1305" "golang.zx2c4.com/wireguard/tai64n" "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) +const poly1305TagSize = 16 + var ( InitialChainKey [blake2s.Size]byte InitialHash [blake2s.Size]byte @@ -23,8 +24,8 @@ type MessageInitiation struct { Type MessageType Sender uint32 Ephemeral NoisePublicKey - Static [NoisePublicKeySize + poly1305.TagSize]byte - Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte + Static [NoisePublicKeySize + poly1305TagSize]byte + Timestamp [tai64n.TimestampSize + poly1305TagSize]byte MAC1 [blake2s.Size128]byte MAC2 [blake2s.Size128]byte } diff --git a/nm-proxy/packet/utils.go b/nm-proxy/packet/utils.go index 8f3df6e6..38380466 100644 --- a/nm-proxy/packet/utils.go +++ b/nm-proxy/packet/utils.go @@ -108,6 +108,7 @@ type ( func sharedSecret(sk *NoisePrivateKey, pk NoisePublicKey) (ss [NoisePublicKeySize]byte) { apk := (*[NoisePublicKeySize]byte)(&pk) ask := (*[NoisePrivateKeySize]byte)(sk) + //lint:ignore SA1019 no need of back and forth conversion between arrays and slices required by curve25519.X25519 function curve25519.ScalarMult(&ss, ask, apk) return ss } diff --git a/nm-proxy/proxy/proxy.go b/nm-proxy/proxy/proxy.go index e9f55419..ebf8ce6e 100644 --- a/nm-proxy/proxy/proxy.go +++ b/nm-proxy/proxy/proxy.go @@ -2,7 +2,6 @@ package proxy import ( "context" - "errors" "fmt" "log" "net" @@ -97,27 +96,6 @@ func GetInterfaceListenAddr(port int) (*net.UDPAddr, error) { return udpAddr, nil } -func getBoardCastAddress() ([]net.Addr, error) { - localnets, err := net.Interfaces() - if err != nil { - return nil, err - } - var ( - ief net.Interface - addrs []net.Addr - ) - for _, ief = range localnets { - if ief.Flags&net.FlagBroadcast != 0 && ief.Flags&net.FlagUp != 0 { - addrs, err = ief.Addrs() - if err == nil { - return addrs, nil - } - - } - } - return nil, errors.New("couldn't obtain the broadcast addr") -} - // func StartSniffer(ctx context.Context, ifaceName, ingGwAddr, extClientAddr string, port int) { // log.Println("Starting Packet Sniffer for iface: ", ifaceName) // var ( diff --git a/nm-proxy/proxy/proxy_helper.go b/nm-proxy/proxy/proxy_helper.go index d8a1c59d..a4be9395 100644 --- a/nm-proxy/proxy/proxy_helper.go +++ b/nm-proxy/proxy/proxy_helper.go @@ -174,12 +174,6 @@ func (p *Proxy) ProxyPeer() { wg.Wait() } -func test(n int, buffer []byte) { - data := buffer[:n] - srcKeyHash := data[n-32 : n-16] - dstKeyHash := data[n-16:] - log.Printf("--------> TEST PACKET [ SRCKEYHASH: %x ], [ DSTKEYHASH: %x ] \n", srcKeyHash, dstKeyHash) -} func (p *Proxy) updateEndpoint() error { udpAddr, err := net.ResolveUDPAddr("udp", p.LocalConn.LocalAddr().String())