|
| 1 | +From 3b9786402a33a7365faa4e1eb241ad12b2cca049 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Archana Ravindar < [email protected]> |
| 3 | +Date: Tue, 14 Jan 2025 16:26:20 +0530 |
| 4 | +Subject: [PATCH] TLS test fix |
| 5 | + |
| 6 | +--- |
| 7 | + src/crypto/tls/handshake_client_test.go | 30 +++++++++++++++---------- |
| 8 | + src/crypto/tls/handshake_server_test.go | 2 ++ |
| 9 | + src/crypto/tls/handshake_test.go | 5 +++++ |
| 10 | + src/crypto/tls/tls_test.go | 6 ++--- |
| 11 | + 4 files changed, 27 insertions(+), 16 deletions(-) |
| 12 | + |
| 13 | +diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go |
| 14 | +index 1666b58ef3..59bdedcc11 100644 |
| 15 | +--- a/src/crypto/tls/handshake_client_test.go |
| 16 | ++++ b/src/crypto/tls/handshake_client_test.go |
| 17 | +@@ -881,6 +881,7 @@ func testResumption(t *testing.T, version uint16) { |
| 18 | + MaxVersion: version, |
| 19 | + CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
| 20 | + Certificates: testConfig.Certificates, |
| 21 | ++ Time: testTime, |
| 22 | + } |
| 23 | + |
| 24 | + issuer, err := x509.ParseCertificate(testRSACertificateIssuer) |
| 25 | +@@ -897,6 +898,7 @@ func testResumption(t *testing.T, version uint16) { |
| 26 | + ClientSessionCache: NewLRUClientSessionCache(32), |
| 27 | + RootCAs: rootCAs, |
| 28 | + ServerName: "example.golang", |
| 29 | ++ Time: testTime, |
| 30 | + } |
| 31 | + |
| 32 | + testResumeState := func(test string, didResume bool) { |
| 33 | +@@ -943,7 +945,7 @@ func testResumption(t *testing.T, version uint16) { |
| 34 | + |
| 35 | + // An old session ticket is replaced with a ticket encrypted with a fresh key. |
| 36 | + ticket = getTicket() |
| 37 | +- serverConfig.Time = func() time.Time { return time.Now().Add(24*time.Hour + time.Minute) } |
| 38 | ++ serverConfig.Time = func() time.Time { return testTime().Add(24*time.Hour + time.Minute) } |
| 39 | + testResumeState("ResumeWithOldTicket", true) |
| 40 | + if bytes.Equal(ticket, getTicket()) { |
| 41 | + t.Fatal("old first ticket matches the fresh one") |
| 42 | +@@ -951,13 +953,13 @@ func testResumption(t *testing.T, version uint16) { |
| 43 | + |
| 44 | + // Once the session master secret is expired, a full handshake should occur. |
| 45 | + ticket = getTicket() |
| 46 | +- serverConfig.Time = func() time.Time { return time.Now().Add(24*8*time.Hour + time.Minute) } |
| 47 | ++ serverConfig.Time = func() time.Time { return testTime().Add(24*8*time.Hour + time.Minute) } |
| 48 | + testResumeState("ResumeWithExpiredTicket", false) |
| 49 | + if bytes.Equal(ticket, getTicket()) { |
| 50 | + t.Fatal("expired first ticket matches the fresh one") |
| 51 | + } |
| 52 | + |
| 53 | +- serverConfig.Time = func() time.Time { return time.Now() } // reset the time back |
| 54 | ++ serverConfig.Time = testTime // reset the time back |
| 55 | + key1 := randomKey() |
| 56 | + serverConfig.SetSessionTicketKeys([][32]byte{key1}) |
| 57 | + |
| 58 | +@@ -974,11 +976,11 @@ func testResumption(t *testing.T, version uint16) { |
| 59 | + testResumeState("KeyChangeFinish", true) |
| 60 | + |
| 61 | + // Age the session ticket a bit, but not yet expired. |
| 62 | +- serverConfig.Time = func() time.Time { return time.Now().Add(24*time.Hour + time.Minute) } |
| 63 | ++ serverConfig.Time = func() time.Time { return testTime().Add(24*time.Hour + time.Minute) } |
| 64 | + testResumeState("OldSessionTicket", true) |
| 65 | + ticket = getTicket() |
| 66 | + // Expire the session ticket, which would force a full handshake. |
| 67 | +- serverConfig.Time = func() time.Time { return time.Now().Add(24*8*time.Hour + time.Minute) } |
| 68 | ++ serverConfig.Time = func() time.Time { return testTime().Add(24*8*time.Hour + 2*time.Minute) } |
| 69 | + testResumeState("ExpiredSessionTicket", false) |
| 70 | + if bytes.Equal(ticket, getTicket()) { |
| 71 | + t.Fatal("new ticket wasn't provided after old ticket expired") |
| 72 | +@@ -986,7 +988,7 @@ func testResumption(t *testing.T, version uint16) { |
| 73 | + |
| 74 | + // Age the session ticket a bit at a time, but don't expire it. |
| 75 | + d := 0 * time.Hour |
| 76 | +- serverConfig.Time = func() time.Time { return time.Now().Add(d) } |
| 77 | ++ serverConfig.Time = func() time.Time { return testTime().Add(d) } |
| 78 | + deleteTicket() |
| 79 | + testResumeState("GetFreshSessionTicket", false) |
| 80 | + for i := 0; i < 13; i++ { |
| 81 | +@@ -997,7 +999,7 @@ func testResumption(t *testing.T, version uint16) { |
| 82 | + // handshake occurs for TLS 1.2. Resumption should still occur for |
| 83 | + // TLS 1.3 since the client should be using a fresh ticket sent over |
| 84 | + // by the server. |
| 85 | +- d += 12 * time.Hour |
| 86 | ++ d += 12*time.Hour + time.Minute |
| 87 | + if version == VersionTLS13 { |
| 88 | + testResumeState("ExpiredSessionTicket", true) |
| 89 | + } else { |
| 90 | +@@ -1013,6 +1015,7 @@ func testResumption(t *testing.T, version uint16) { |
| 91 | + MaxVersion: version, |
| 92 | + CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
| 93 | + Certificates: testConfig.Certificates, |
| 94 | ++ Time: testTime, |
| 95 | + } |
| 96 | + serverConfig.SetSessionTicketKeys([][32]byte{key2}) |
| 97 | + |
| 98 | +@@ -1038,6 +1041,7 @@ func testResumption(t *testing.T, version uint16) { |
| 99 | + CurvePreferences: []CurveID{CurveP521, CurveP384, CurveP256}, |
| 100 | + MaxVersion: version, |
| 101 | + Certificates: testConfig.Certificates, |
| 102 | ++ Time: testTime, |
| 103 | + } |
| 104 | + testResumeState("InitialHandshake", false) |
| 105 | + testResumeState("WithHelloRetryRequest", true) |
| 106 | +@@ -1047,6 +1051,7 @@ func testResumption(t *testing.T, version uint16) { |
| 107 | + MaxVersion: version, |
| 108 | + CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA}, |
| 109 | + Certificates: testConfig.Certificates, |
| 110 | ++ Time: testTime, |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | +@@ -1761,6 +1766,7 @@ func testVerifyConnection(t *testing.T, version uint16) { |
| 115 | + serverConfig := &Config{ |
| 116 | + MaxVersion: version, |
| 117 | + Certificates: []Certificate{testConfig.Certificates[0]}, |
| 118 | ++ Time: testTime, |
| 119 | + ClientCAs: rootCAs, |
| 120 | + NextProtos: []string{"protocol1"}, |
| 121 | + } |
| 122 | +@@ -1774,6 +1780,7 @@ func testVerifyConnection(t *testing.T, version uint16) { |
| 123 | + RootCAs: rootCAs, |
| 124 | + ServerName: "example.golang", |
| 125 | + Certificates: []Certificate{testConfig.Certificates[0]}, |
| 126 | ++ Time: testTime, |
| 127 | + NextProtos: []string{"protocol1"}, |
| 128 | + } |
| 129 | + test.configureClient(clientConfig, &clientCalled) |
| 130 | +@@ -1816,8 +1823,6 @@ func testVerifyPeerCertificate(t *testing.T, version uint16) { |
| 131 | + rootCAs := x509.NewCertPool() |
| 132 | + rootCAs.AddCert(issuer) |
| 133 | + |
| 134 | +- now := func() time.Time { return time.Unix(1476984729, 0) } |
| 135 | +- |
| 136 | + sentinelErr := errors.New("TestVerifyPeerCertificate") |
| 137 | + |
| 138 | + verifyPeerCertificateCallback := func(called *bool, rawCerts [][]byte, validatedChains [][]*x509.Certificate) error { |
| 139 | +@@ -2063,7 +2068,7 @@ func testVerifyPeerCertificate(t *testing.T, version uint16) { |
| 140 | + config.ServerName = "example.golang" |
| 141 | + config.ClientAuth = RequireAndVerifyClientCert |
| 142 | + config.ClientCAs = rootCAs |
| 143 | +- config.Time = now |
| 144 | ++ config.Time = testTime |
| 145 | + config.MaxVersion = version |
| 146 | + config.Certificates = make([]Certificate, 1) |
| 147 | + config.Certificates[0].Certificate = [][]byte{testRSACertificate} |
| 148 | +@@ -2080,7 +2085,7 @@ func testVerifyPeerCertificate(t *testing.T, version uint16) { |
| 149 | + config := testConfig.Clone() |
| 150 | + config.ServerName = "example.golang" |
| 151 | + config.RootCAs = rootCAs |
| 152 | +- config.Time = now |
| 153 | ++ config.Time = testTime |
| 154 | + config.MaxVersion = version |
| 155 | + test.configureClient(config, &clientCalled) |
| 156 | + clientErr := Client(c, config).Handshake() |
| 157 | +@@ -2394,7 +2399,7 @@ func testGetClientCertificate(t *testing.T, version uint16) { |
| 158 | + serverConfig.RootCAs = x509.NewCertPool() |
| 159 | + serverConfig.RootCAs.AddCert(issuer) |
| 160 | + serverConfig.ClientCAs = serverConfig.RootCAs |
| 161 | +- serverConfig.Time = func() time.Time { return time.Unix(1476984729, 0) } |
| 162 | ++ serverConfig.Time = testTime |
| 163 | + serverConfig.MaxVersion = version |
| 164 | + |
| 165 | + clientConfig := testConfig.Clone() |
| 166 | +@@ -2565,6 +2570,7 @@ func testResumptionKeepsOCSPAndSCT(t *testing.T, ver uint16) { |
| 167 | + ClientSessionCache: NewLRUClientSessionCache(32), |
| 168 | + ServerName: "example.golang", |
| 169 | + RootCAs: roots, |
| 170 | ++ Time: testTime, |
| 171 | + } |
| 172 | + serverConfig := testConfig.Clone() |
| 173 | + serverConfig.MaxVersion = ver |
| 174 | +diff --git a/src/crypto/tls/handshake_server_test.go b/src/crypto/tls/handshake_server_test.go |
| 175 | +index 04abdcca89..35b1d0835e 100644 |
| 176 | +--- a/src/crypto/tls/handshake_server_test.go |
| 177 | ++++ b/src/crypto/tls/handshake_server_test.go |
| 178 | +@@ -481,6 +481,7 @@ func testCrossVersionResume(t *testing.T, version uint16) { |
| 179 | + serverConfig := &Config{ |
| 180 | + CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 181 | + Certificates: testConfig.Certificates, |
| 182 | ++ Time: testTime, |
| 183 | + } |
| 184 | + clientConfig := &Config{ |
| 185 | + CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}, |
| 186 | +@@ -488,6 +489,7 @@ func testCrossVersionResume(t *testing.T, version uint16) { |
| 187 | + ClientSessionCache: NewLRUClientSessionCache(1), |
| 188 | + ServerName: "servername", |
| 189 | + MinVersion: VersionTLS10, |
| 190 | ++ Time: testTime, |
| 191 | + } |
| 192 | + |
| 193 | + // Establish a session at TLS 1.1. |
| 194 | +diff --git a/src/crypto/tls/handshake_test.go b/src/crypto/tls/handshake_test.go |
| 195 | +index bacc8b7d4f..27ab19ef31 100644 |
| 196 | +--- a/src/crypto/tls/handshake_test.go |
| 197 | ++++ b/src/crypto/tls/handshake_test.go |
| 198 | +@@ -429,6 +429,11 @@ func fromHex(s string) []byte { |
| 199 | + return b |
| 200 | + } |
| 201 | + |
| 202 | ++// testTime is 2016-10-20T17:32:09.000Z, which is within the validity period of |
| 203 | ++// [testRSACertificate], [testRSACertificateIssuer], [testRSA2048Certificate], |
| 204 | ++// [testRSA2048CertificateIssuer], and [testECDSACertificate]. |
| 205 | ++var testTime = func() time.Time { return time.Unix(1476984729, 0) } |
| 206 | ++ |
| 207 | + var testRSACertificate = fromHex("3082024b308201b4a003020102020900e8f09d3fe25beaa6300d06092a864886f70d01010b0500301f310b3009060355040a1302476f3110300e06035504031307476f20526f6f74301e170d3136303130313030303030305a170d3235303130313030303030305a301a310b3009060355040a1302476f310b300906035504031302476f30819f300d06092a864886f70d010101050003818d0030818902818100db467d932e12270648bc062821ab7ec4b6a25dfe1e5245887a3647a5080d92425bc281c0be97799840fb4f6d14fd2b138bc2a52e67d8d4099ed62238b74a0b74732bc234f1d193e596d9747bf3589f6c613cc0b041d4d92b2b2423775b1c3bbd755dce2054cfa163871d1e24c4f31d1a508baab61443ed97a77562f414c852d70203010001a38193308190300e0603551d0f0101ff0404030205a0301d0603551d250416301406082b0601050507030106082b06010505070302300c0603551d130101ff0402300030190603551d0e041204109f91161f43433e49a6de6db680d79f60301b0603551d230414301280104813494d137e1631bba301d5acab6e7b30190603551d1104123010820e6578616d706c652e676f6c616e67300d06092a864886f70d01010b0500038181009d30cc402b5b50a061cbbae55358e1ed8328a9581aa938a495a1ac315a1a84663d43d32dd90bf297dfd320643892243a00bccf9c7db74020015faad3166109a276fd13c3cce10c5ceeb18782f16c04ed73bbb343778d0c1cf10fa1d8408361c94c722b9daedb4606064df4c1b33ec0d1bd42d4dbfe3d1360845c21d33be9fae7") |
| 208 | + |
| 209 | + var testRSACertificateIssuer = fromHex("3082021930820182a003020102020900ca5e4e811a965964300d06092a864886f70d01010b0500301f310b3009060355040a1302476f3110300e06035504031307476f20526f6f74301e170d3136303130313030303030305a170d3235303130313030303030305a301f310b3009060355040a1302476f3110300e06035504031307476f20526f6f7430819f300d06092a864886f70d010101050003818d0030818902818100d667b378bb22f34143b6cd2008236abefaf2852adf3ab05e01329e2c14834f5105df3f3073f99dab5442d45ee5f8f57b0111c8cb682fbb719a86944eebfffef3406206d898b8c1b1887797c9c5006547bb8f00e694b7a063f10839f269f2c34fff7a1f4b21fbcd6bfdfb13ac792d1d11f277b5c5b48600992203059f2a8f8cc50203010001a35d305b300e0603551d0f0101ff040403020204301d0603551d250416301406082b0601050507030106082b06010505070302300f0603551d130101ff040530030101ff30190603551d0e041204104813494d137e1631bba301d5acab6e7b300d06092a864886f70d01010b050003818100c1154b4bab5266221f293766ae4138899bd4c5e36b13cee670ceeaa4cbdf4f6679017e2fe649765af545749fe4249418a56bd38a04b81e261f5ce86b8d5c65413156a50d12449554748c59a30c515bc36a59d38bddf51173e899820b282e40aa78c806526fd184fb6b4cf186ec728edffa585440d2b3225325f7ab580e87dd76") |
| 210 | +diff --git a/src/crypto/tls/tls_test.go b/src/crypto/tls/tls_test.go |
| 211 | +index c3f16c704a..83100a7490 100644 |
| 212 | +--- a/src/crypto/tls/tls_test.go |
| 213 | ++++ b/src/crypto/tls/tls_test.go |
| 214 | +@@ -1098,8 +1098,6 @@ func TestConnectionState(t *testing.T) { |
| 215 | + rootCAs := x509.NewCertPool() |
| 216 | + rootCAs.AddCert(issuer) |
| 217 | + |
| 218 | +- now := func() time.Time { return time.Unix(1476984729, 0) } |
| 219 | +- |
| 220 | + const alpnProtocol = "golang" |
| 221 | + const serverName = "example.golang" |
| 222 | + var scts = [][]byte{[]byte("dummy sct 1"), []byte("dummy sct 2")} |
| 223 | +@@ -1115,7 +1113,7 @@ func TestConnectionState(t *testing.T) { |
| 224 | + } |
| 225 | + t.Run(name, func(t *testing.T) { |
| 226 | + config := &Config{ |
| 227 | +- Time: now, |
| 228 | ++ Time: testTime, |
| 229 | + Rand: zeroSource{}, |
| 230 | + Certificates: make([]Certificate, 1), |
| 231 | + MaxVersion: v, |
| 232 | +@@ -1726,7 +1724,7 @@ func testVerifyCertificates(t *testing.T, version uint16) { |
| 233 | + var serverVerifyPeerCertificates, clientVerifyPeerCertificates bool |
| 234 | + |
| 235 | + clientConfig := testConfig.Clone() |
| 236 | +- clientConfig.Time = func() time.Time { return time.Unix(1476984729, 0) } |
| 237 | ++ clientConfig.Time = testTime |
| 238 | + clientConfig.MaxVersion = version |
| 239 | + clientConfig.MinVersion = version |
| 240 | + clientConfig.RootCAs = rootCAs |
| 241 | +-- |
| 242 | +2.47.1 |
| 243 | + |
0 commit comments