| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "net/base/ip_endpoint.h" | 8 #include "net/base/ip_endpoint.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 const string first_chlo_hash = "first chlo hash bytes"; | 143 const string first_chlo_hash = "first chlo hash bytes"; |
| 144 const string second_chlo_hash = "first chlo hash bytes"; | 144 const string second_chlo_hash = "first chlo hash bytes"; |
| 145 const QuicVersion quic_version = GetParam(); | 145 const QuicVersion quic_version = GetParam(); |
| 146 | 146 |
| 147 scoped_refptr<ProofSource::Chain> chain; | 147 scoped_refptr<ProofSource::Chain> chain; |
| 148 scoped_refptr<ProofSource::Chain> first_chain; | 148 scoped_refptr<ProofSource::Chain> first_chain; |
| 149 string error_details, signature, first_signature, first_cert_sct, cert_sct; | 149 string error_details, signature, first_signature, first_cert_sct, cert_sct; |
| 150 IPAddress server_ip; | 150 IPAddress server_ip; |
| 151 | 151 |
| 152 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, | 152 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, |
| 153 first_chlo_hash, &first_chain, &first_signature, | 153 first_chlo_hash, QuicTagVector(), &first_chain, |
| 154 &first_cert_sct)); | 154 &first_signature, &first_cert_sct)); |
| 155 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, | 155 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, |
| 156 second_chlo_hash, &chain, &signature, | 156 second_chlo_hash, QuicTagVector(), &chain, |
| 157 &cert_sct)); | 157 &signature, &cert_sct)); |
| 158 | 158 |
| 159 // Check that the proof source is caching correctly: | 159 // Check that the proof source is caching correctly: |
| 160 ASSERT_EQ(first_chain->certs, chain->certs); | 160 ASSERT_EQ(first_chain->certs, chain->certs); |
| 161 ASSERT_NE(signature, first_signature); | 161 ASSERT_NE(signature, first_signature); |
| 162 ASSERT_EQ(first_cert_sct, cert_sct); | 162 ASSERT_EQ(first_cert_sct, cert_sct); |
| 163 | 163 |
| 164 RunVerification(verifier.get(), hostname, port, server_config, quic_version, | 164 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 165 first_chlo_hash, chain->certs, signature, true); | 165 first_chlo_hash, chain->certs, signature, true); |
| 166 | 166 |
| 167 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, | 167 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 192 const string first_chlo_hash = "first chlo hash bytes"; | 192 const string first_chlo_hash = "first chlo hash bytes"; |
| 193 const string second_chlo_hash = "first chlo hash bytes"; | 193 const string second_chlo_hash = "first chlo hash bytes"; |
| 194 const QuicVersion quic_version = GetParam(); | 194 const QuicVersion quic_version = GetParam(); |
| 195 IPAddress server_ip; | 195 IPAddress server_ip; |
| 196 | 196 |
| 197 // Call synchronous version | 197 // Call synchronous version |
| 198 scoped_refptr<ProofSource::Chain> expected_chain; | 198 scoped_refptr<ProofSource::Chain> expected_chain; |
| 199 string expected_signature; | 199 string expected_signature; |
| 200 string expected_leaf_cert_sct; | 200 string expected_leaf_cert_sct; |
| 201 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, | 201 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, |
| 202 first_chlo_hash, &expected_chain, | 202 first_chlo_hash, QuicTagVector(), |
| 203 &expected_signature, &expected_leaf_cert_sct)); | 203 &expected_chain, &expected_signature, |
| 204 &expected_leaf_cert_sct)); |
| 204 | 205 |
| 205 // Call asynchronous version and compare results | 206 // Call asynchronous version and compare results |
| 206 bool called = false; | 207 bool called = false; |
| 207 bool ok; | 208 bool ok; |
| 208 scoped_refptr<ProofSource::Chain> chain; | 209 scoped_refptr<ProofSource::Chain> chain; |
| 209 string signature; | 210 string signature; |
| 210 string leaf_cert_sct; | 211 string leaf_cert_sct; |
| 211 std::unique_ptr<ProofSource::Callback> cb( | 212 std::unique_ptr<ProofSource::Callback> cb( |
| 212 new TestCallback(&called, &ok, &chain, &signature, &leaf_cert_sct)); | 213 new TestCallback(&called, &ok, &chain, &signature, &leaf_cert_sct)); |
| 213 source->GetProof(server_ip, hostname, server_config, quic_version, | 214 source->GetProof(server_ip, hostname, server_config, quic_version, |
| 214 first_chlo_hash, std::move(cb)); | 215 first_chlo_hash, QuicTagVector(), std::move(cb)); |
| 215 // TODO(gredner): whan GetProof really invokes the callback asynchronously, | 216 // TODO(gredner): whan GetProof really invokes the callback asynchronously, |
| 216 // figure out what to do here. | 217 // figure out what to do here. |
| 217 ASSERT_TRUE(called); | 218 ASSERT_TRUE(called); |
| 218 ASSERT_TRUE(ok); | 219 ASSERT_TRUE(ok); |
| 219 EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs)); | 220 EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs)); |
| 220 EXPECT_EQ(leaf_cert_sct, expected_leaf_cert_sct); | 221 EXPECT_EQ(leaf_cert_sct, expected_leaf_cert_sct); |
| 221 } | 222 } |
| 222 | 223 |
| 223 TEST_P(ProofTest, UseAfterFree) { | 224 TEST_P(ProofTest, UseAfterFree) { |
| 224 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); | 225 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
| 225 | 226 |
| 226 const string server_config = "server config bytes"; | 227 const string server_config = "server config bytes"; |
| 227 const string hostname = "test.example.com"; | 228 const string hostname = "test.example.com"; |
| 228 const string chlo_hash = "proof nonce bytes"; | 229 const string chlo_hash = "proof nonce bytes"; |
| 229 scoped_refptr<ProofSource::Chain> chain; | 230 scoped_refptr<ProofSource::Chain> chain; |
| 230 string error_details, signature, cert_sct; | 231 string error_details, signature, cert_sct; |
| 231 IPAddress server_ip; | 232 IPAddress server_ip; |
| 232 | 233 |
| 233 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, GetParam(), | 234 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, GetParam(), |
| 234 chlo_hash, &chain, &signature, &cert_sct)); | 235 chlo_hash, QuicTagVector(), &chain, &signature, |
| 236 &cert_sct)); |
| 235 | 237 |
| 236 // Make sure we can safely access results after deleting where they came from. | 238 // Make sure we can safely access results after deleting where they came from. |
| 237 EXPECT_FALSE(chain->HasOneRef()); | 239 EXPECT_FALSE(chain->HasOneRef()); |
| 238 source = nullptr; | 240 source = nullptr; |
| 239 EXPECT_TRUE(chain->HasOneRef()); | 241 EXPECT_TRUE(chain->HasOneRef()); |
| 240 | 242 |
| 241 EXPECT_FALSE(chain->certs.empty()); | 243 EXPECT_FALSE(chain->certs.empty()); |
| 242 for (const string& cert : chain->certs) { | 244 for (const string& cert : chain->certs) { |
| 243 EXPECT_FALSE(cert.empty()); | 245 EXPECT_FALSE(cert.empty()); |
| 244 } | 246 } |
| 245 } | 247 } |
| 246 | 248 |
| 247 } // namespace test | 249 } // namespace test |
| 248 } // namespace net | 250 } // namespace net |
| OLD | NEW |