Skip to content

Commit e3cf6bc

Browse files
daanpapeJoTurk
authored andcommitted
Comply with RFC5746 and RFC5246
- Re-implemented renegotiation to comply with RFC5746 and RFC5246 - Updated conn_test.go to comply with 120 column limit
1 parent f0c0987 commit e3cf6bc

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

conn_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,8 +2231,8 @@ func TestMultipleHelloVerifyRequest(t *testing.T) {
22312231
cancel()
22322232
}
22332233

2234-
// Assert that a DTLS Server always responds with RenegotiationInfo if
2235-
// a ClientHello contained that extension or not.
2234+
// Assert that a DTLS Server only responds with RenegotiationInfo if a ClientHello contained that
2235+
// extension according to RFC5746 section 3.6, RFC5246 section 7.4.1.4 and RFC5746 section 4.2.
22362236
func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
22372237
// Limit runtime in case of deadlocks
22382238
lim := test.TimeOut(10 * time.Second)
@@ -2245,8 +2245,8 @@ func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
22452245
resp := make([]byte, 1024)
22462246

22472247
for _, testCase := range []struct {
2248-
Name string
2249-
SendRenegotiationInfo bool
2248+
Name string
2249+
ExpectRenegotiationInfo bool
22502250
}{
22512251
{
22522252
"Include RenegotiationInfo",
@@ -2281,7 +2281,7 @@ func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
22812281
time.Sleep(50 * time.Millisecond)
22822282

22832283
extensions := []extension.Extension{}
2284-
if test.SendRenegotiationInfo {
2284+
if test.ExpectRenegotiationInfo {
22852285
extensions = append(extensions, &extension.RenegotiationInfo{
22862286
RenegotiatedConnection: 0,
22872287
})
@@ -2311,14 +2311,16 @@ func TestRenegotationInfo(t *testing.T) { //nolint:cyclop
23112311
serverHello, ok := record.Content.(*handshake.Handshake).Message.(*handshake.MessageServerHello)
23122312
assert.True(t, ok)
23132313

2314-
gotNegotationInfo := false
2314+
actualNegotationInfo := false
23152315
for _, v := range serverHello.Extensions {
23162316
if _, ok := v.(*extension.RenegotiationInfo); ok {
2317-
gotNegotationInfo = true
2317+
actualNegotationInfo = true
23182318
}
23192319
}
23202320

2321-
assert.True(t, gotNegotationInfo, "Expected RenegotiationInfo extension in ServerHello")
2321+
assert.True(t, test.ExpectRenegotiationInfo == actualNegotationInfo,
2322+
"NegotationInfo state in ServerHello is incorrect: expected(%t) actual(%t)",
2323+
test.ExpectRenegotiationInfo, actualNegotationInfo)
23222324
})
23232325
}
23242326
}

flight0handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ func flight0Parse(
8181
}
8282
case *extension.ServerName:
8383
state.serverName = ext.ServerName // remote server name
84+
case *extension.RenegotiationInfo:
85+
state.remoteSupportsRenegotiation = true
8486
case *extension.ALPN:
8587
state.peerSupportedProtocols = ext.ProtocolNameList
8688
case *extension.ConnectionID:

flight4handler.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,8 @@ func flight4Generate(
263263
_ *handshakeCache,
264264
cfg *handshakeConfig,
265265
) ([]*packet, *alert.Alert, error) {
266-
extensions := []extension.Extension{&extension.RenegotiationInfo{
267-
RenegotiatedConnection: 0,
268-
}}
266+
extensions := []extension.Extension{}
267+
269268
if (cfg.extendedMasterSecret == RequestExtendedMasterSecret ||
270269
cfg.extendedMasterSecret == RequireExtendedMasterSecret) && state.extendedMasterSecret {
271270
extensions = append(extensions, &extension.UseExtendedMasterSecret{
@@ -278,6 +277,11 @@ func flight4Generate(
278277
MasterKeyIdentifier: cfg.localSRTPMasterKeyIdentifier,
279278
})
280279
}
280+
if state.remoteSupportsRenegotiation {
281+
extensions = append(extensions, &extension.RenegotiationInfo{
282+
RenegotiatedConnection: 0,
283+
})
284+
}
281285
if state.cipherSuite.AuthenticationType() == CipherSuiteAuthenticationTypeCertificate {
282286
extensions = append(extensions, &extension.SupportedPointFormats{
283287
PointFormats: []elliptic.CurvePointFormat{elliptic.CurvePointFormatUncompressed},

state.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type State struct {
2626
cipherSuite CipherSuite // nil if a cipherSuite hasn't been chosen
2727
CipherSuiteID CipherSuiteID
2828

29+
remoteSupportsRenegotiation bool // True when Client Hello contained renegotiation extension
30+
2931
srtpProtectionProfile atomic.Value // Negotiated SRTPProtectionProfile
3032
remoteSRTPMasterKeyIdentifier []byte
3133

0 commit comments

Comments
 (0)