File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -384,6 +384,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
384
384
return false
385
385
}
386
386
387
+ seenExts := make (map [uint16 ]bool )
387
388
for ! extensions .Empty () {
388
389
var extension uint16
389
390
var extData cryptobyte.String
@@ -392,6 +393,11 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
392
393
return false
393
394
}
394
395
396
+ if seenExts [extension ] {
397
+ return false
398
+ }
399
+ seenExts [extension ] = true
400
+
395
401
switch extension {
396
402
case extensionServerName :
397
403
// RFC 6066, Section 3
@@ -750,6 +756,7 @@ func (m *serverHelloMsg) unmarshal(data []byte) bool {
750
756
return false
751
757
}
752
758
759
+ seenExts := make (map [uint16 ]bool )
753
760
for ! extensions .Empty () {
754
761
var extension uint16
755
762
var extData cryptobyte.String
@@ -758,6 +765,11 @@ func (m *serverHelloMsg) unmarshal(data []byte) bool {
758
765
return false
759
766
}
760
767
768
+ if seenExts [extension ] {
769
+ return false
770
+ }
771
+ seenExts [extension ] = true
772
+
761
773
switch extension {
762
774
case extensionStatusRequest :
763
775
m .ocspStapling = true
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package tls
6
6
7
7
import (
8
8
"bytes"
9
+ "encoding/hex"
9
10
"math/rand"
10
11
"reflect"
11
12
"strings"
@@ -463,3 +464,23 @@ func TestRejectEmptySCT(t *testing.T) {
463
464
t .Fatal ("Unmarshaled ServerHello with zero-length SCT" )
464
465
}
465
466
}
467
+
468
+ func TestRejectDuplicateExtensions (t * testing.T ) {
469
+ clientHelloBytes , err := hex .DecodeString ("010000440303000000000000000000000000000000000000000000000000000000000000000000000000001c0000000a000800000568656c6c6f0000000a000800000568656c6c6f" )
470
+ if err != nil {
471
+ t .Fatalf ("failed to decode test ClientHello: %s" , err )
472
+ }
473
+ var clientHelloCopy clientHelloMsg
474
+ if clientHelloCopy .unmarshal (clientHelloBytes ) {
475
+ t .Error ("Unmarshaled ClientHello with duplicate extensions" )
476
+ }
477
+
478
+ serverHelloBytes , err := hex .DecodeString ("02000030030300000000000000000000000000000000000000000000000000000000000000000000000000080005000000050000" )
479
+ if err != nil {
480
+ t .Fatalf ("failed to decode test ServerHello: %s" , err )
481
+ }
482
+ var serverHelloCopy serverHelloMsg
483
+ if serverHelloCopy .unmarshal (serverHelloBytes ) {
484
+ t .Fatal ("Unmarshaled ServerHello with duplicate extensions" )
485
+ }
486
+ }
You can’t perform that action at this time.
0 commit comments