Skip to content

Commit ab5f89b

Browse files
committed
Implement TLS_EMPTY_RENEGOTIATION_INFO_SCSV
1 parent d5761ac commit ab5f89b

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

conn_test.go

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,18 @@ func testServer(
281281
return conn, conn.HandshakeContext(ctx)
282282
}
283283

284-
func sendClientHello(cookie []byte, ca net.Conn, sequenceNumber uint64, extensions []extension.Extension) error {
284+
func sendClientHello(
285+
cookie []byte,
286+
ca net.Conn,
287+
sequenceNumber uint64,
288+
extensions []extension.Extension,
289+
cipherSuiteIDsOverride ...uint16,
290+
) error {
291+
cipherSuites := cipherSuiteIDsOverride
292+
if len(cipherSuites) == 0 {
293+
cipherSuites = cipherSuiteIDs(defaultCipherSuites())
294+
}
295+
285296
packet, err := (&recordlayer.RecordLayer{
286297
Header: recordlayer.Header{
287298
Version: protocol.Version1_2,
@@ -294,7 +305,7 @@ func sendClientHello(cookie []byte, ca net.Conn, sequenceNumber uint64, extensio
294305
Message: &handshake.MessageClientHello{
295306
Version: protocol.Version1_2,
296307
Cookie: cookie,
297-
CipherSuiteIDs: cipherSuiteIDs(defaultCipherSuites()),
308+
CipherSuiteIDs: cipherSuites,
298309
CompressionMethods: defaultCompressionMethods(),
299310
Extensions: extensions,
300311
},
@@ -2328,16 +2339,24 @@ func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
23282339
resp := make([]byte, 1024)
23292340

23302341
for _, testCase := range []struct {
2331-
Name string
2332-
ExpectRenegotiationInfo bool
2342+
Name string
2343+
ExpectRenegotiationInfo bool
2344+
SendRenegotiationInfoExt bool
2345+
IncludeRenegotiationSCSV bool
23332346
}{
23342347
{
2335-
"Include RenegotiationInfo",
2336-
true,
2348+
Name: "Include RenegotiationInfo",
2349+
ExpectRenegotiationInfo: true,
2350+
SendRenegotiationInfoExt: true,
23372351
},
23382352
{
2339-
"No RenegotiationInfo",
2340-
false,
2353+
Name: "RenegotiationInfo SCSV",
2354+
ExpectRenegotiationInfo: true,
2355+
IncludeRenegotiationSCSV: true,
2356+
},
2357+
{
2358+
Name: "No RenegotiationInfo",
2359+
ExpectRenegotiationInfo: false,
23412360
},
23422361
} {
23432362
test := testCase
@@ -2364,12 +2383,16 @@ func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
23642383
time.Sleep(50 * time.Millisecond)
23652384

23662385
extensions := []extension.Extension{}
2367-
if test.ExpectRenegotiationInfo {
2386+
if test.SendRenegotiationInfoExt {
23682387
extensions = append(extensions, &extension.RenegotiationInfo{
23692388
RenegotiatedConnection: 0,
23702389
})
23712390
}
2372-
err := sendClientHello([]byte{}, ca, 0, extensions)
2391+
cipherSuites := cipherSuiteIDs(defaultCipherSuites())
2392+
if test.IncludeRenegotiationSCSV {
2393+
cipherSuites = append(cipherSuites, renegotiationInfoSCSV)
2394+
}
2395+
err := sendClientHello([]byte{}, ca, 0, extensions, cipherSuites...)
23732396
assert.NoError(t, err)
23742397

23752398
n, err := ca.Read(resp)
@@ -2381,7 +2404,7 @@ func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
23812404
helloVerifyRequest, ok := record.Content.(*handshake.Handshake).Message.(*handshake.MessageHelloVerifyRequest)
23822405
assert.True(t, ok)
23832406

2384-
err = sendClientHello(helloVerifyRequest.Cookie, ca, 1, extensions)
2407+
err = sendClientHello(helloVerifyRequest.Cookie, ca, 1, extensions, cipherSuites...)
23852408
assert.NoError(t, err)
23862409

23872410
n, err = ca.Read(resp)

flight0handler.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import (
1414
"github.com/pion/dtls/v3/pkg/protocol/handshake"
1515
)
1616

17-
//nolint:cyclop
17+
// renegotiationInfoSCSV is TLS_EMPTY_RENEGOTIATION_INFO_SCSV defined in RFC 5746.
18+
// https://datatracker.ietf.org/doc/html/rfc5746#section-3.3.
19+
const renegotiationInfoSCSV uint16 = 0x00ff
20+
21+
//nolint:cyclop,gocognit
1822
func flight0Parse(
1923
_ context.Context,
2024
_ flightConn,
@@ -52,6 +56,11 @@ func flight0Parse(
5256

5357
cipherSuites := []CipherSuite{}
5458
for _, id := range clientHello.CipherSuiteIDs {
59+
if id == renegotiationInfoSCSV {
60+
state.remoteSupportsRenegotiation = true
61+
62+
continue
63+
}
5564
if c := cipherSuiteForID(CipherSuiteID(id), cfg.customCipherSuites); c != nil {
5665
cipherSuites = append(cipherSuites, c)
5766
}

0 commit comments

Comments
 (0)