| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "net/http/disk_based_cert_cache.h" | 5 #include "net/http/disk_based_cert_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &write_data); | 137 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &write_data); |
| 138 ASSERT_TRUE(encoded); | 138 ASSERT_TRUE(encoded); |
| 139 if (corrupt_data) { | 139 if (corrupt_data) { |
| 140 for (size_t i = 0; i < write_data.size(); i += 20) | 140 for (size_t i = 0; i < write_data.size(); i += 20) |
| 141 ++write_data[i]; | 141 ++write_data[i]; |
| 142 } | 142 } |
| 143 scoped_refptr<IOBuffer> buffer(new IOBuffer(write_data.size())); | 143 scoped_refptr<IOBuffer> buffer(new IOBuffer(write_data.size())); |
| 144 memcpy(buffer->data(), write_data.data(), write_data.size()); | 144 memcpy(buffer->data(), write_data.data(), write_data.size()); |
| 145 rv = entry->WriteData(0 /* index */, | 145 rv = entry->WriteData(0 /* index */, |
| 146 0 /* offset */, | 146 0 /* offset */, |
| 147 buffer, | 147 buffer.get(), |
| 148 write_data.size(), | 148 write_data.size(), |
| 149 callback.callback(), | 149 callback.callback(), |
| 150 true /* truncate */); | 150 true /* truncate */); |
| 151 ASSERT_EQ(static_cast<int>(write_data.size()), callback.GetResult(rv)); | 151 ASSERT_EQ(static_cast<int>(write_data.size()), callback.GetResult(rv)); |
| 152 entry->Close(); | 152 entry->Close(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Checks that the the certificate corresponding to |cert_data| is an existing, | 155 // Checks that the the certificate corresponding to |cert_data| is an existing, |
| 156 // correctly cached entry in |backend|. | 156 // correctly cached entry in |backend|. |
| 157 void CheckCertCached(disk_cache::Backend* backend, | 157 void CheckCertCached(disk_cache::Backend* backend, |
| 158 const TestCertMetaData& cert_data) { | 158 const TestCertMetaData& cert_data) { |
| 159 disk_cache::Entry* entry; | 159 disk_cache::Entry* entry; |
| 160 TestCompletionCallback callback; | 160 TestCompletionCallback callback; |
| 161 int rv = backend->OpenEntry(cert_data.cache_key, &entry, callback.callback()); | 161 int rv = backend->OpenEntry(cert_data.cache_key, &entry, callback.callback()); |
| 162 EXPECT_EQ(OK, callback.GetResult(rv)); | 162 EXPECT_EQ(OK, callback.GetResult(rv)); |
| 163 scoped_refptr<X509Certificate> cert( | 163 scoped_refptr<X509Certificate> cert( |
| 164 ImportCertFromFile(GetTestCertsDirectory(), cert_data.file_name)); | 164 ImportCertFromFile(GetTestCertsDirectory(), cert_data.file_name)); |
| 165 std::string write_data; | 165 std::string write_data; |
| 166 bool encoded = | 166 bool encoded = |
| 167 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &write_data); | 167 X509Certificate::GetDEREncoded(cert->os_cert_handle(), &write_data); |
| 168 ASSERT_TRUE(encoded); | 168 ASSERT_TRUE(encoded); |
| 169 int entry_size = entry->GetDataSize(0 /* index */); | 169 int entry_size = entry->GetDataSize(0 /* index */); |
| 170 scoped_refptr<IOBuffer> buffer(new IOBuffer(entry_size)); | 170 scoped_refptr<IOBuffer> buffer(new IOBuffer(entry_size)); |
| 171 rv = entry->ReadData( | 171 rv = entry->ReadData(0 /* index */, |
| 172 0 /* index */, 0 /* offset */, buffer, entry_size, callback.callback()); | 172 0 /* offset */, |
| 173 buffer.get(), |
| 174 entry_size, |
| 175 callback.callback()); |
| 173 EXPECT_EQ(entry_size, callback.GetResult(rv)); | 176 EXPECT_EQ(entry_size, callback.GetResult(rv)); |
| 174 entry->Close(); | 177 entry->Close(); |
| 175 X509Certificate::OSCertHandle cached_cert_handle = | 178 X509Certificate::OSCertHandle cached_cert_handle = |
| 176 X509Certificate::CreateOSCertHandleFromBytes(buffer->data(), entry_size); | 179 X509Certificate::CreateOSCertHandleFromBytes(buffer->data(), entry_size); |
| 177 EXPECT_TRUE(X509Certificate::IsSameOSCert(cached_cert_handle, | 180 EXPECT_TRUE(X509Certificate::IsSameOSCert(cached_cert_handle, |
| 178 cert->os_cert_handle())); | 181 cert->os_cert_handle())); |
| 179 X509Certificate::FreeOSCertHandle(cached_cert_handle); | 182 X509Certificate::FreeOSCertHandle(cached_cert_handle); |
| 180 } | 183 } |
| 181 | 184 |
| 182 } // namespace | 185 } // namespace |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 526 |
| 524 cache.GetCertificate(kCert1.cache_key, get_callback2.callback()); | 527 cache.GetCertificate(kCert1.cache_key, get_callback2.callback()); |
| 525 get_callback2.WaitForResult(); | 528 get_callback2.WaitForResult(); |
| 526 EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback2.cert_handle(), | 529 EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback2.cert_handle(), |
| 527 cert->os_cert_handle())); | 530 cert->os_cert_handle())); |
| 528 EXPECT_EQ(1U, cache.mem_cache_hits_for_testing()); | 531 EXPECT_EQ(1U, cache.mem_cache_hits_for_testing()); |
| 529 ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1)); | 532 ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1)); |
| 530 } | 533 } |
| 531 | 534 |
| 532 } // namespace net | 535 } // namespace net |
| OLD | NEW |