diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-02 15:28:38 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-02 15:28:38 +0200 |
commit | 2aa0daf4d58ffc930fde611e7efe6ae3c9515130 (patch) | |
tree | d99a2a65be02ab3b6d4a965ab4f1d6165a981549 /src/send.go | |
parent | 1e620427bd01b1e897c57752359f7dbb28e34bff (diff) |
Fixed transport header problem
Diffstat (limited to 'src/send.go')
-rw-r--r-- | src/send.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/send.go b/src/send.go index 7a10560..3fe4733 100644 --- a/src/send.go +++ b/src/send.go @@ -171,8 +171,6 @@ func (peer *Peer) RoutineNonce() { } } - logger.Println("PACKET:", packet) - // wait for key pair for { @@ -221,8 +219,6 @@ func (peer *Peer) RoutineNonce() { work.peer = peer work.mutex.Lock() - logger.Println("WORK:", work) - packet = nil // drop packets until there is space @@ -263,7 +259,7 @@ func (device *Device) RoutineEncryption() { // pad packet - padding := device.mtu - len(work.packet) + padding := device.mtu - len(work.packet) - MessageTransportSize if padding < 0 { work.Drop() continue @@ -272,19 +268,30 @@ func (device *Device) RoutineEncryption() { for n := 0; n < padding; n += 1 { work.packet = append(work.packet, 0) } - device.log.Debug.Println(work.packet) + content := work.packet[MessageTransportHeaderSize:] + copy(content, work.packet) + + // prepare header - // encrypt + binary.LittleEndian.PutUint32(work.packet[:4], MessageTransportType) + binary.LittleEndian.PutUint32(work.packet[4:8], work.keyPair.remoteIndex) + binary.LittleEndian.PutUint64(work.packet[8:16], work.nonce) + + device.log.Debug.Println(work.packet, work.nonce) + + // encrypt content binary.LittleEndian.PutUint64(nonce[4:], work.nonce) - work.packet = work.keyPair.send.Seal( - work.packet[:0], + work.keyPair.send.Seal( + content[:0], nonce[:], - work.packet, + content, nil, ) work.mutex.Unlock() + device.log.Debug.Println(work.packet, work.nonce) + // initiate new handshake work.peer.KeepKeyFreshSending() |