Skip to content

Commit 02a6c0c

Browse files
committed
fixy fixy, improvey improvey
1 parent 28248b8 commit 02a6c0c

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

connection_state.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (cs *ConnectionState) Decrypt(l *slog.Logger, messageCounter uint64, out []
8181
return out, nil
8282
}
8383

84+
// VerifyRelay verifies AEAD protected (but not encrypted) relay frames. packet must be length-checked by the caller.
8485
func (cs *ConnectionState) VerifyRelay(l *slog.Logger, messageCounter uint64, packet []byte, nb []byte) error {
8586
cs.decryptLock.Lock()
8687
result := cs.window.Check(l, messageCounter)
@@ -89,15 +90,9 @@ func (cs *ConnectionState) VerifyRelay(l *slog.Logger, messageCounter uint64, pa
8990
return ErrAlreadySeen
9091
}
9192

92-
// The entire body is sent as AD, not encrypted.
93-
// The packet consists of a 16-byte parsed Nebula header, Associated Data-protected payload, and a trailing 16-byte AEAD signature value.
94-
// The packet is guaranteed to be at least 16 bytes at this point, b/c it got past the h.Parse() call above. If it's
95-
// otherwise malformed (meaning, there is no trailing 16 byte AEAD value), then this will result in at worst a 0-length slice
96-
// which will gracefully fail in the DecryptDanger call.
9793
signedPayload := packet[:len(packet)-cs.dKey.Overhead()]
9894
signatureValue := packet[len(packet)-cs.dKey.Overhead():]
99-
var err error
100-
_, err = cs.dKey.DecryptDanger(nil, signedPayload, signatureValue, messageCounter, nb)
95+
_, err := cs.dKey.DecryptDanger(nil, signedPayload, signatureValue, messageCounter, nb)
10196
if err != nil {
10297
return err
10398
}

outside.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ func (f *Interface) readOutsidePackets(via ViaSender, out []byte, packet []byte,
102102
return
103103
}
104104

105+
if len(packet) < header.Len+hostinfo.ConnectionState.dKey.Overhead() {
106+
f.messageMetrics.RxInvalid(1)
107+
if f.l.Enabled(context.Background(), slog.LevelDebug) {
108+
f.l.Debug("packet too small", "from", via, "length", len(packet))
109+
}
110+
return
111+
}
112+
105113
// All remaining packets are encrypted
106114
if isMessageRelay {
107115
// Relay packets are special, this branch should always early-return

0 commit comments

Comments
 (0)