@@ -25,6 +25,31 @@ import (
25
25
"time"
26
26
)
27
27
28
+ func allCipherSuitesIncludingTLS13 () []uint16 {
29
+ s := allCipherSuites ()
30
+ for _ , suite := range cipherSuitesTLS13 {
31
+ s = append (s , suite .id )
32
+ }
33
+ return s
34
+ }
35
+
36
+ func isTLS13CipherSuite (id uint16 ) bool {
37
+ for _ , suite := range cipherSuitesTLS13 {
38
+ if id == suite .id {
39
+ return true
40
+ }
41
+ }
42
+ return false
43
+ }
44
+
45
+ func generateKeyShare (group CurveID ) keyShare {
46
+ key , err := generateECDHEKey (rand .Reader , group )
47
+ if err != nil {
48
+ panic (err )
49
+ }
50
+ return keyShare {group : group , data : key .PublicKey ().Bytes ()}
51
+ }
52
+
28
53
func TestBoringServerProtocolVersion (t * testing.T ) {
29
54
test := func (t * testing.T , name string , v uint16 , msg string ) {
30
55
t .Run (name , func (t * testing.T ) {
@@ -60,30 +85,30 @@ func TestBoringServerProtocolVersion(t *testing.T) {
60
85
test (t , "VersionTLS10" , VersionTLS10 , "supported versions" )
61
86
test (t , "VersionTLS11" , VersionTLS11 , "supported versions" )
62
87
test (t , "VersionTLS12" , VersionTLS12 , "" )
63
- test (t , "VersionTLS13" , VersionTLS13 , "supported versions " )
88
+ test (t , "VersionTLS13" , VersionTLS13 , "" )
64
89
})
65
90
}
66
91
67
92
func isBoringVersion (v uint16 ) bool {
68
- return v == VersionTLS12
93
+ return v == VersionTLS12 || v == VersionTLS13
69
94
}
70
95
71
96
func isBoringCipherSuite (id uint16 ) bool {
72
97
switch id {
73
- case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
98
+ case TLS_AES_128_GCM_SHA256 ,
99
+ TLS_AES_256_GCM_SHA384 ,
100
+ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
74
101
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
75
102
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
76
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ,
77
- TLS_RSA_WITH_AES_128_GCM_SHA256 ,
78
- TLS_RSA_WITH_AES_256_GCM_SHA384 :
103
+ TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 :
79
104
return true
80
105
}
81
106
return false
82
107
}
83
108
84
109
func isBoringCurve (id CurveID ) bool {
85
110
switch id {
86
- case CurveP256 , CurveP384 , CurveP521 :
111
+ case CurveP256 , CurveP384 :
87
112
return true
88
113
}
89
114
return false
@@ -95,7 +120,7 @@ func isECDSA(id uint16) bool {
95
120
return suite .flags & suiteECSign == suiteECSign
96
121
}
97
122
}
98
- panic ( fmt . Sprintf ( "unknown cipher suite %#x" , id ))
123
+ return false // TLS 1.3 cipher suites are not tied to the signature algorithm.
99
124
}
100
125
101
126
func isBoringSignatureScheme (alg SignatureScheme ) bool {
@@ -107,7 +132,6 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
107
132
PKCS1WithSHA384 ,
108
133
ECDSAWithP384AndSHA384 ,
109
134
PKCS1WithSHA512 ,
110
- ECDSAWithP521AndSHA512 ,
111
135
PSSWithSHA256 ,
112
136
PSSWithSHA384 ,
113
137
PSSWithSHA512 :
@@ -118,10 +142,9 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
118
142
119
143
func TestBoringServerCipherSuites (t * testing.T ) {
120
144
serverConfig := testConfig .Clone ()
121
- serverConfig .CipherSuites = allCipherSuites ()
122
145
serverConfig .Certificates = make ([]Certificate , 1 )
123
146
124
- for _ , id := range allCipherSuites () {
147
+ for _ , id := range allCipherSuitesIncludingTLS13 () {
125
148
if isECDSA (id ) {
126
149
serverConfig .Certificates [0 ].Certificate = [][]byte {testECDSACertificate }
127
150
serverConfig .Certificates [0 ].PrivateKey = testECDSAPrivateKey
@@ -130,14 +153,20 @@ func TestBoringServerCipherSuites(t *testing.T) {
130
153
serverConfig .Certificates [0 ].PrivateKey = testRSAPrivateKey
131
154
}
132
155
serverConfig .BuildNameToCertificate ()
133
- t .Run (fmt .Sprintf ("suite=%#x " , id ), func (t * testing.T ) {
156
+ t .Run (fmt .Sprintf ("suite=%s " , CipherSuiteName ( id ) ), func (t * testing.T ) {
134
157
clientHello := & clientHelloMsg {
135
- vers : VersionTLS12 ,
136
- random : make ([]byte , 32 ),
137
- cipherSuites : []uint16 {id },
138
- compressionMethods : []uint8 {compressionNone },
139
- supportedCurves : defaultCurvePreferences (),
140
- supportedPoints : []uint8 {pointFormatUncompressed },
158
+ vers : VersionTLS12 ,
159
+ random : make ([]byte , 32 ),
160
+ cipherSuites : []uint16 {id },
161
+ compressionMethods : []uint8 {compressionNone },
162
+ supportedCurves : defaultCurvePreferences (),
163
+ keyShares : []keyShare {generateKeyShare (CurveP256 )},
164
+ supportedPoints : []uint8 {pointFormatUncompressed },
165
+ supportedVersions : []uint16 {VersionTLS12 },
166
+ supportedSignatureAlgorithms : defaultSupportedSignatureAlgorithmsFIPS ,
167
+ }
168
+ if isTLS13CipherSuite (id ) {
169
+ clientHello .supportedVersions = []uint16 {VersionTLS13 }
141
170
}
142
171
143
172
testClientHello (t , serverConfig , clientHello )
@@ -156,9 +185,6 @@ func TestBoringServerCipherSuites(t *testing.T) {
156
185
157
186
func TestBoringServerCurves (t * testing.T ) {
158
187
serverConfig := testConfig .Clone ()
159
- serverConfig .Certificates = make ([]Certificate , 1 )
160
- serverConfig .Certificates [0 ].Certificate = [][]byte {testECDSACertificate }
161
- serverConfig .Certificates [0 ].PrivateKey = testECDSAPrivateKey
162
188
serverConfig .BuildNameToCertificate ()
163
189
164
190
for _ , curveid := range defaultCurvePreferences () {
@@ -288,7 +314,7 @@ func TestBoringClientHello(t *testing.T) {
288
314
}
289
315
290
316
if ! isBoringVersion (hello .vers ) {
291
- t .Errorf ("client vers=%#x, want %#x (TLS 1.2) " , hello .vers , VersionTLS12 )
317
+ t .Errorf ("client vers=%#x" , hello .vers )
292
318
}
293
319
for _ , v := range hello .supportedVersions {
294
320
if ! isBoringVersion (v ) {
0 commit comments