Skip to content

Commit bf291eb

Browse files
committed
secure: harden session version signing
1 parent 4edf401 commit bf291eb

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/pion/rtp v1.10.1
88
github.com/pion/webrtc/v3 v3.2.40
99
github.com/quic-go/quic-go v0.59.1
10-
golang.org/x/crypto v0.41.0
1110
)
1211

1312
require (
@@ -53,6 +52,7 @@ require (
5352
github.com/stretchr/testify v1.11.1 // indirect
5453
github.com/wlynxg/anet v0.0.5 // indirect
5554
github.com/yuin/goldmark v1.7.8 // indirect
55+
golang.org/x/crypto v0.41.0 // indirect
5656
golang.org/x/image v0.24.0 // indirect
5757
golang.org/x/net v0.43.0 // indirect
5858
golang.org/x/sys v0.35.0 // indirect

internal/secure/session.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
// Copyright (c) 2026 Suryansh Deshwal
2+
// Licensed under the Apache License, Version 2.0
3+
14
package secure
25

36
import (
47
"crypto/aes"
58
"crypto/cipher"
69
"crypto/ecdh"
710
"crypto/ed25519"
11+
"crypto/hkdf"
812
"crypto/rand"
913
"crypto/sha256"
1014
"encoding/base64"
@@ -14,8 +18,6 @@ import (
1418
"io"
1519
"net"
1620

17-
"golang.org/x/crypto/hkdf"
18-
1921
"github.com/vx6/vx6/internal/identity"
2022
"github.com/vx6/vx6/internal/proto"
2123
)
@@ -140,9 +142,8 @@ func handshake(conn net.Conn, kind byte, id identity.Identity, initiator bool) (
140142

141143
func deriveKey(sharedSecret, transcript []byte) ([]byte, error) {
142144
salt := sha256.Sum256(transcript)
143-
kdf := hkdf.New(sha256.New, sharedSecret, salt[:], []byte("vx6-session-v2"))
144-
key := make([]byte, 32)
145-
if _, err := io.ReadFull(kdf, key); err != nil {
145+
key, err := hkdf.Key(sha256.New, sharedSecret, salt[:], "vx6-session-v2", 32)
146+
if err != nil {
146147
return nil, err
147148
}
148149
return key, nil
@@ -221,7 +222,7 @@ func (c *Conn) Write(p []byte) (int, error) {
221222
}
222223

223224
func buildHello(id identity.Identity, kind byte, eph []byte) (hello, error) {
224-
sig := ed25519.Sign(id.PrivateKey, signingPayload(kind, id.NodeID, eph))
225+
sig := ed25519.Sign(id.PrivateKey, signingPayload(sessionVersion, kind, id.NodeID, eph))
225226
return hello{
226227
Version: sessionVersion,
227228
NodeID: id.NodeID,
@@ -258,7 +259,7 @@ func readHello(r io.Reader, kind byte) (hello, error) {
258259
if identity.NodeIDFromPublicKey(ed25519.PublicKey(pub)) != h.NodeID {
259260
return hello{}, fmt.Errorf("handshake node id mismatch")
260261
}
261-
if !ed25519.Verify(ed25519.PublicKey(pub), signingPayload(kind, h.NodeID, eph), sig) {
262+
if !ed25519.Verify(ed25519.PublicKey(pub), signingPayload(h.Version, kind, h.NodeID, eph), sig) {
262263
return hello{}, fmt.Errorf("handshake signature verification failed")
263264
}
264265

@@ -281,9 +282,11 @@ func (h hello) ephemeralBytes() ([]byte, error) {
281282
return eph, nil
282283
}
283284

284-
func signingPayload(kind byte, nodeID string, eph []byte) []byte {
285+
func signingPayload(version uint8, kind byte, nodeID string, eph []byte) []byte {
285286
var out []byte
286287
out = append(out, []byte("vx6-secure\n")...)
288+
out = append(out, version)
289+
out = append(out, '\n')
287290
out = append(out, kind)
288291
out = append(out, '\n')
289292
out = append(out, []byte(nodeID)...)

0 commit comments

Comments
 (0)