Fixed broken test

This commit is contained in:
Mathias Hall-Andersen 2017-07-06 16:24:24 +02:00
parent 59f9316f51
commit 70179f8c8c
6 changed files with 15 additions and 15 deletions

View file

@ -32,7 +32,7 @@ type Device struct {
stop chan struct{} stop chan struct{}
} }
peers map[NoisePublicKey]*Peer peers map[NoisePublicKey]*Peer
mac MacStateDevice mac MACStateDevice
} }
func (device *Device) SetPrivateKey(sk NoisePrivateKey) { func (device *Device) SetPrivateKey(sk NoisePrivateKey) {

View file

@ -11,7 +11,7 @@ import (
"time" "time"
) )
type MacStateDevice struct { type MACStateDevice struct {
mutex sync.RWMutex mutex sync.RWMutex
refreshed time.Time refreshed time.Time
secret [blake2s.Size]byte secret [blake2s.Size]byte
@ -19,7 +19,7 @@ type MacStateDevice struct {
xaead cipher.AEAD xaead cipher.AEAD
} }
func (state *MacStateDevice) Init(pk NoisePublicKey) { func (state *MACStateDevice) Init(pk NoisePublicKey) {
state.mutex.Lock() state.mutex.Lock()
defer state.mutex.Unlock() defer state.mutex.Unlock()
func() { func() {
@ -32,7 +32,7 @@ func (state *MacStateDevice) Init(pk NoisePublicKey) {
state.refreshed = time.Time{} // never state.refreshed = time.Time{} // never
} }
func (state *MacStateDevice) CheckMAC1(msg []byte) bool { func (state *MACStateDevice) CheckMAC1(msg []byte) bool {
size := len(msg) size := len(msg)
startMac1 := size - (blake2s.Size128 * 2) startMac1 := size - (blake2s.Size128 * 2)
startMac2 := size - blake2s.Size128 startMac2 := size - blake2s.Size128
@ -47,7 +47,7 @@ func (state *MacStateDevice) CheckMAC1(msg []byte) bool {
return hmac.Equal(mac1[:], msg[startMac1:startMac2]) return hmac.Equal(mac1[:], msg[startMac1:startMac2])
} }
func (state *MacStateDevice) CheckMAC2(msg []byte, addr *net.UDPAddr) bool { func (state *MACStateDevice) CheckMAC2(msg []byte, addr *net.UDPAddr) bool {
state.mutex.RLock() state.mutex.RLock()
defer state.mutex.RUnlock() defer state.mutex.RUnlock()

View file

@ -9,7 +9,7 @@ import (
"time" "time"
) )
type MacStatePeer struct { type MACStatePeer struct {
mutex sync.RWMutex mutex sync.RWMutex
cookieSet time.Time cookieSet time.Time
cookie [blake2s.Size128]byte cookie [blake2s.Size128]byte
@ -18,7 +18,7 @@ type MacStatePeer struct {
xaead cipher.AEAD xaead cipher.AEAD
} }
func (state *MacStatePeer) Init(pk NoisePublicKey) { func (state *MACStatePeer) Init(pk NoisePublicKey) {
state.mutex.Lock() state.mutex.Lock()
defer state.mutex.Unlock() defer state.mutex.Unlock()
func() { func() {
@ -31,7 +31,7 @@ func (state *MacStatePeer) Init(pk NoisePublicKey) {
state.cookieSet = time.Time{} // never state.cookieSet = time.Time{} // never
} }
func (state *MacStatePeer) AddMacs(msg []byte) { func (state *MACStatePeer) AddMacs(msg []byte) {
size := len(msg) size := len(msg)
if size < blake2s.Size128*2 { if size < blake2s.Size128*2 {

View file

@ -57,8 +57,8 @@ type MessageInitiation struct {
Ephemeral NoisePublicKey Ephemeral NoisePublicKey
Static [NoisePublicKeySize + poly1305.TagSize]byte Static [NoisePublicKeySize + poly1305.TagSize]byte
Timestamp [TAI64NSize + poly1305.TagSize]byte Timestamp [TAI64NSize + poly1305.TagSize]byte
Mac1 [blake2s.Size128]byte MAC1 [blake2s.Size128]byte
Mac2 [blake2s.Size128]byte MAC2 [blake2s.Size128]byte
} }
type MessageResponse struct { type MessageResponse struct {
@ -67,8 +67,8 @@ type MessageResponse struct {
Receiver uint32 Receiver uint32
Ephemeral NoisePublicKey Ephemeral NoisePublicKey
Empty [poly1305.TagSize]byte Empty [poly1305.TagSize]byte
Mac1 [blake2s.Size128]byte MAC1 [blake2s.Size128]byte
Mac2 [blake2s.Size128]byte MAC2 [blake2s.Size128]byte
} }
type MessageTransport struct { type MessageTransport struct {

View file

@ -118,7 +118,7 @@ func TestNoiseHandshake(t *testing.T) {
var out []byte var out []byte
var nonce [12]byte var nonce [12]byte
out = key1.send.Seal(out, nonce[:], testMsg, nil) out = key1.send.Seal(out, nonce[:], testMsg, nil)
out, err = key2.recv.Open(out[:0], nonce[:], out, nil) out, err = key2.receive.Open(out[:0], nonce[:], out, nil)
assertNil(t, err) assertNil(t, err)
assertEqual(t, out, testMsg) assertEqual(t, out, testMsg)
}() }()
@ -129,7 +129,7 @@ func TestNoiseHandshake(t *testing.T) {
var out []byte var out []byte
var nonce [12]byte var nonce [12]byte
out = key2.send.Seal(out, nonce[:], testMsg, nil) out = key2.send.Seal(out, nonce[:], testMsg, nil)
out, err = key1.recv.Open(out[:0], nonce[:], out, nil) out, err = key1.receive.Open(out[:0], nonce[:], out, nil)
assertNil(t, err) assertNil(t, err)
assertEqual(t, out, testMsg) assertEqual(t, out, testMsg)
}() }()

View file

@ -39,7 +39,7 @@ type Peer struct {
outbound chan *QueueOutboundElement // sequential ordering of work outbound chan *QueueOutboundElement // sequential ordering of work
inbound chan *QueueInboundElement // sequential ordering of work inbound chan *QueueInboundElement // sequential ordering of work
} }
mac MacStatePeer mac MACStatePeer
} }
func (device *Device) NewPeer(pk NoisePublicKey) *Peer { func (device *Device) NewPeer(pk NoisePublicKey) *Peer {