@@ -25,6 +25,31 @@ import (
2525 "time"
2626)
2727
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+
2853func TestBoringServerProtocolVersion (t * testing.T ) {
2954 test := func (name string , v uint16 , msg string ) {
3055 t .Run (name , func (t * testing.T ) {
@@ -33,8 +58,11 @@ func TestBoringServerProtocolVersion(t *testing.T) {
3358 clientHello := & clientHelloMsg {
3459 vers : v ,
3560 random : make ([]byte , 32 ),
36- cipherSuites : allCipherSuites (),
61+ cipherSuites : allCipherSuitesIncludingTLS13 (),
3762 compressionMethods : []uint8 {compressionNone },
63+ supportedCurves : defaultCurvePreferences ,
64+ keyShares : []keyShare {generateKeyShare (CurveP256 )},
65+ supportedPoints : []uint8 {pointFormatUncompressed },
3866 supportedVersions : []uint16 {v },
3967 }
4068 testClientHelloFailure (t , serverConfig , clientHello , msg )
@@ -48,33 +76,33 @@ func TestBoringServerProtocolVersion(t *testing.T) {
4876
4977 fipstls .Force ()
5078 defer fipstls .Abandon ()
51- test ("VersionSSL30" , VersionSSL30 , "client offered only unsupported versions" )
52- test ("VersionTLS10" , VersionTLS10 , "client offered only unsupported versions" )
53- test ("VersionTLS11" , VersionTLS11 , "client offered only unsupported versions" )
54- test ("VersionTLS12" , VersionTLS12 , "" )
55- test ("VersionTLS13" , VersionTLS13 , "client offered only unsupported versions " )
79+ test ("VersionSSL30/fipstls " , VersionSSL30 , "client offered only unsupported versions" )
80+ test ("VersionTLS10/fipstls " , VersionTLS10 , "client offered only unsupported versions" )
81+ test ("VersionTLS11/fipstls " , VersionTLS11 , "client offered only unsupported versions" )
82+ test ("VersionTLS12/fipstls " , VersionTLS12 , "" )
83+ test ("VersionTLS13/fipstls " , VersionTLS13 , "" )
5684}
5785
5886func isBoringVersion (v uint16 ) bool {
59- return v == VersionTLS12
87+ return v == VersionTLS12 || v == VersionTLS13
6088}
6189
6290func isBoringCipherSuite (id uint16 ) bool {
6391 switch id {
64- case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
92+ case TLS_AES_128_GCM_SHA256 ,
93+ TLS_AES_256_GCM_SHA384 ,
94+ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ,
6595 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,
6696 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 ,
67- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 ,
68- TLS_RSA_WITH_AES_128_GCM_SHA256 ,
69- TLS_RSA_WITH_AES_256_GCM_SHA384 :
97+ TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 :
7098 return true
7199 }
72100 return false
73101}
74102
75103func isBoringCurve (id CurveID ) bool {
76104 switch id {
77- case CurveP256 , CurveP384 , CurveP521 :
105+ case CurveP256 , CurveP384 :
78106 return true
79107 }
80108 return false
@@ -86,7 +114,7 @@ func isECDSA(id uint16) bool {
86114 return suite .flags & suiteECSign == suiteECSign
87115 }
88116 }
89- panic ( fmt . Sprintf ( "unknown cipher suite %#x" , id ))
117+ return false // TLS 1.3 cipher suites are not tied to the signature algorithm.
90118}
91119
92120func isBoringSignatureScheme (alg SignatureScheme ) bool {
@@ -98,7 +126,6 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
98126 PKCS1WithSHA384 ,
99127 ECDSAWithP384AndSHA384 ,
100128 PKCS1WithSHA512 ,
101- ECDSAWithP521AndSHA512 ,
102129 PSSWithSHA256 ,
103130 PSSWithSHA384 ,
104131 PSSWithSHA512 :
@@ -109,10 +136,9 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
109136
110137func TestBoringServerCipherSuites (t * testing.T ) {
111138 serverConfig := testConfig .Clone ()
112- serverConfig .CipherSuites = allCipherSuites ()
113139 serverConfig .Certificates = make ([]Certificate , 1 )
114140
115- for _ , id := range allCipherSuites () {
141+ for _ , id := range allCipherSuitesIncludingTLS13 () {
116142 if isECDSA (id ) {
117143 serverConfig .Certificates [0 ].Certificate = [][]byte {testECDSACertificate }
118144 serverConfig .Certificates [0 ].PrivateKey = testECDSAPrivateKey
@@ -121,14 +147,19 @@ func TestBoringServerCipherSuites(t *testing.T) {
121147 serverConfig .Certificates [0 ].PrivateKey = testRSAPrivateKey
122148 }
123149 serverConfig .BuildNameToCertificate ()
124- t .Run (fmt .Sprintf ("suite=%#x " , id ), func (t * testing.T ) {
150+ t .Run (fmt .Sprintf ("suite=%s " , CipherSuiteName ( id ) ), func (t * testing.T ) {
125151 clientHello := & clientHelloMsg {
126152 vers : VersionTLS12 ,
127153 random : make ([]byte , 32 ),
128154 cipherSuites : []uint16 {id },
129155 compressionMethods : []uint8 {compressionNone },
130156 supportedCurves : defaultCurvePreferences ,
157+ keyShares : []keyShare {generateKeyShare (CurveP256 )},
131158 supportedPoints : []uint8 {pointFormatUncompressed },
159+ supportedVersions : []uint16 {VersionTLS12 },
160+ }
161+ if isTLS13CipherSuite (id ) {
162+ clientHello .supportedVersions = []uint16 {VersionTLS13 }
132163 }
133164
134165 testClientHello (t , serverConfig , clientHello )
@@ -160,7 +191,9 @@ func TestBoringServerCurves(t *testing.T) {
160191 cipherSuites : []uint16 {TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 },
161192 compressionMethods : []uint8 {compressionNone },
162193 supportedCurves : []CurveID {curveid },
194+ keyShares : []keyShare {generateKeyShare (curveid )},
163195 supportedPoints : []uint8 {pointFormatUncompressed },
196+ supportedVersions : []uint16 {VersionTLS12 },
164197 }
165198
166199 testClientHello (t , serverConfig , clientHello )
@@ -279,7 +312,7 @@ func TestBoringClientHello(t *testing.T) {
279312 }
280313
281314 if ! isBoringVersion (hello .vers ) {
282- t .Errorf ("client vers=%#x, want %#x (TLS 1.2) " , hello .vers , VersionTLS12 )
315+ t .Errorf ("client vers=%#x" , hello .vers )
283316 }
284317 for _ , v := range hello .supportedVersions {
285318 if ! isBoringVersion (v ) {
0 commit comments