| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 comp_callback.WaitForResult(); | 86 comp_callback.WaitForResult(); |
| 87 ASSERT_EQ(expected_ok, ok); | 87 ASSERT_EQ(expected_ok, ok); |
| 88 break; | 88 break; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 class TestCallback : public ProofSource::Callback { | 92 class TestCallback : public ProofSource::Callback { |
| 93 public: | 93 public: |
| 94 explicit TestCallback(bool* called, | 94 explicit TestCallback(bool* called, |
| 95 bool* ok, | 95 bool* ok, |
| 96 scoped_refptr<ProofSource::Chain>* chain, | 96 QuicReferenceCountedPointer<ProofSource::Chain>* chain, |
| 97 QuicCryptoProof* proof) | 97 QuicCryptoProof* proof) |
| 98 : called_(called), ok_(ok), chain_(chain), proof_(proof) {} | 98 : called_(called), ok_(ok), chain_(chain), proof_(proof) {} |
| 99 | 99 |
| 100 void Run(bool ok, | 100 void Run(bool ok, |
| 101 const scoped_refptr<ProofSource::Chain>& chain, | 101 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, |
| 102 const QuicCryptoProof& proof, | 102 const QuicCryptoProof& proof, |
| 103 std::unique_ptr<ProofSource::Details> /* details */) override { | 103 std::unique_ptr<ProofSource::Details> /* details */) override { |
| 104 *ok_ = ok; | 104 *ok_ = ok; |
| 105 *chain_ = chain; | 105 *chain_ = chain; |
| 106 *proof_ = proof; | 106 *proof_ = proof; |
| 107 *called_ = true; | 107 *called_ = true; |
| 108 } | 108 } |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 bool* called_; | 111 bool* called_; |
| 112 bool* ok_; | 112 bool* ok_; |
| 113 scoped_refptr<ProofSource::Chain>* chain_; | 113 QuicReferenceCountedPointer<ProofSource::Chain>* chain_; |
| 114 QuicCryptoProof* proof_; | 114 QuicCryptoProof* proof_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class ProofTest : public ::testing::TestWithParam<QuicVersion> {}; | 117 class ProofTest : public ::testing::TestWithParam<QuicVersion> {}; |
| 118 | 118 |
| 119 } // namespace | 119 } // namespace |
| 120 | 120 |
| 121 INSTANTIATE_TEST_CASE_P(QuicVersion, | 121 INSTANTIATE_TEST_CASE_P(QuicVersion, |
| 122 ProofTest, | 122 ProofTest, |
| 123 ::testing::ValuesIn(AllSupportedVersions())); | 123 ::testing::ValuesIn(AllSupportedVersions())); |
| 124 | 124 |
| 125 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468. | 125 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468. |
| 126 TEST_P(ProofTest, DISABLED_Verify) { | 126 TEST_P(ProofTest, DISABLED_Verify) { |
| 127 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); | 127 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
| 128 std::unique_ptr<ProofVerifier> verifier( | 128 std::unique_ptr<ProofVerifier> verifier( |
| 129 CryptoTestUtils::ProofVerifierForTesting()); | 129 CryptoTestUtils::ProofVerifierForTesting()); |
| 130 | 130 |
| 131 const string server_config = "server config bytes"; | 131 const string server_config = "server config bytes"; |
| 132 const string hostname = "test.example.com"; | 132 const string hostname = "test.example.com"; |
| 133 const uint16_t port = 8443; | 133 const uint16_t port = 8443; |
| 134 const string first_chlo_hash = "first chlo hash bytes"; | 134 const string first_chlo_hash = "first chlo hash bytes"; |
| 135 const string second_chlo_hash = "first chlo hash bytes"; | 135 const string second_chlo_hash = "first chlo hash bytes"; |
| 136 const QuicVersion quic_version = GetParam(); | 136 const QuicVersion quic_version = GetParam(); |
| 137 | 137 |
| 138 scoped_refptr<ProofSource::Chain> chain; | 138 QuicReferenceCountedPointer<ProofSource::Chain> chain; |
| 139 scoped_refptr<ProofSource::Chain> first_chain; | 139 QuicReferenceCountedPointer<ProofSource::Chain> first_chain; |
| 140 string error_details; | 140 string error_details; |
| 141 QuicCryptoProof proof, first_proof; | 141 QuicCryptoProof proof, first_proof; |
| 142 QuicSocketAddress server_addr; | 142 QuicSocketAddress server_addr; |
| 143 | 143 |
| 144 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, | 144 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, |
| 145 quic_version, first_chlo_hash, QuicTagVector(), | 145 quic_version, first_chlo_hash, QuicTagVector(), |
| 146 &first_chain, &first_proof)); | 146 &first_chain, &first_proof)); |
| 147 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, | 147 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, |
| 148 quic_version, second_chlo_hash, QuicTagVector(), | 148 quic_version, second_chlo_hash, QuicTagVector(), |
| 149 &chain, &proof)); | 149 &chain, &proof)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 180 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); | 180 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
| 181 | 181 |
| 182 const string server_config = "server config bytes"; | 182 const string server_config = "server config bytes"; |
| 183 const string hostname = "test.example.com"; | 183 const string hostname = "test.example.com"; |
| 184 const string first_chlo_hash = "first chlo hash bytes"; | 184 const string first_chlo_hash = "first chlo hash bytes"; |
| 185 const string second_chlo_hash = "first chlo hash bytes"; | 185 const string second_chlo_hash = "first chlo hash bytes"; |
| 186 const QuicVersion quic_version = GetParam(); | 186 const QuicVersion quic_version = GetParam(); |
| 187 QuicSocketAddress server_addr; | 187 QuicSocketAddress server_addr; |
| 188 | 188 |
| 189 // Call synchronous version | 189 // Call synchronous version |
| 190 scoped_refptr<ProofSource::Chain> expected_chain; | 190 QuicReferenceCountedPointer<ProofSource::Chain> expected_chain; |
| 191 QuicCryptoProof expected_proof; | 191 QuicCryptoProof expected_proof; |
| 192 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, | 192 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, |
| 193 quic_version, first_chlo_hash, QuicTagVector(), | 193 quic_version, first_chlo_hash, QuicTagVector(), |
| 194 &expected_chain, &expected_proof)); | 194 &expected_chain, &expected_proof)); |
| 195 | 195 |
| 196 // Call asynchronous version and compare results | 196 // Call asynchronous version and compare results |
| 197 bool called = false; | 197 bool called = false; |
| 198 bool ok; | 198 bool ok; |
| 199 scoped_refptr<ProofSource::Chain> chain; | 199 QuicReferenceCountedPointer<ProofSource::Chain> chain; |
| 200 QuicCryptoProof proof; | 200 QuicCryptoProof proof; |
| 201 std::unique_ptr<ProofSource::Callback> cb( | 201 std::unique_ptr<ProofSource::Callback> cb( |
| 202 new TestCallback(&called, &ok, &chain, &proof)); | 202 new TestCallback(&called, &ok, &chain, &proof)); |
| 203 source->GetProof(server_addr, hostname, server_config, quic_version, | 203 source->GetProof(server_addr, hostname, server_config, quic_version, |
| 204 first_chlo_hash, QuicTagVector(), std::move(cb)); | 204 first_chlo_hash, QuicTagVector(), std::move(cb)); |
| 205 // TODO(gredner): whan GetProof really invokes the callback asynchronously, | 205 // TODO(gredner): whan GetProof really invokes the callback asynchronously, |
| 206 // figure out what to do here. | 206 // figure out what to do here. |
| 207 ASSERT_TRUE(called); | 207 ASSERT_TRUE(called); |
| 208 ASSERT_TRUE(ok); | 208 ASSERT_TRUE(ok); |
| 209 EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs)); | 209 EXPECT_THAT(chain->certs, ::testing::ContainerEq(expected_chain->certs)); |
| 210 EXPECT_EQ(proof.leaf_cert_scts, expected_proof.leaf_cert_scts); | 210 EXPECT_EQ(proof.leaf_cert_scts, expected_proof.leaf_cert_scts); |
| 211 } | 211 } |
| 212 | 212 |
| 213 TEST_P(ProofTest, UseAfterFree) { | 213 TEST_P(ProofTest, UseAfterFree) { |
| 214 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); | 214 std::unique_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
| 215 | 215 |
| 216 const string server_config = "server config bytes"; | 216 const string server_config = "server config bytes"; |
| 217 const string hostname = "test.example.com"; | 217 const string hostname = "test.example.com"; |
| 218 const string chlo_hash = "proof nonce bytes"; | 218 const string chlo_hash = "proof nonce bytes"; |
| 219 scoped_refptr<ProofSource::Chain> chain; | 219 QuicReferenceCountedPointer<ProofSource::Chain> chain; |
| 220 string error_details; | 220 string error_details; |
| 221 QuicCryptoProof proof; | 221 QuicCryptoProof proof; |
| 222 QuicSocketAddress server_addr; | 222 QuicSocketAddress server_addr; |
| 223 | 223 |
| 224 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, GetParam(), | 224 ASSERT_TRUE(source->GetProof(server_addr, hostname, server_config, GetParam(), |
| 225 chlo_hash, QuicTagVector(), &chain, &proof)); | 225 chlo_hash, QuicTagVector(), &chain, &proof)); |
| 226 | 226 |
| 227 // Make sure we can safely access results after deleting where they came from. | 227 // Make sure we can safely access results after deleting where they came from. |
| 228 EXPECT_FALSE(chain->HasOneRef()); | 228 EXPECT_FALSE(chain->HasOneRef()); |
| 229 source = nullptr; | 229 source = nullptr; |
| 230 EXPECT_TRUE(chain->HasOneRef()); | 230 EXPECT_TRUE(chain->HasOneRef()); |
| 231 | 231 |
| 232 EXPECT_FALSE(chain->certs.empty()); | 232 EXPECT_FALSE(chain->certs.empty()); |
| 233 for (const string& cert : chain->certs) { | 233 for (const string& cert : chain->certs) { |
| 234 EXPECT_FALSE(cert.empty()); | 234 EXPECT_FALSE(cert.empty()); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace test | 238 } // namespace test |
| 239 } // namespace net | 239 } // namespace net |
| OLD | NEW |