Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: net/ssl/default_channel_id_store.cc

Issue 1076063002: Remove certificates from Channel ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 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/ssl/default_channel_id_store.h" 5 #include "net/ssl/default_channel_id_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "crypto/ec_private_key.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 // -------------------------------------------------------------------------- 15 // --------------------------------------------------------------------------
15 // Task 16 // Task
16 class DefaultChannelIDStore::Task { 17 class DefaultChannelIDStore::Task {
17 public: 18 public:
18 virtual ~Task(); 19 virtual ~Task();
19 20
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const GetChannelIDCallback& callback) 55 const GetChannelIDCallback& callback)
55 : server_identifier_(server_identifier), 56 : server_identifier_(server_identifier),
56 callback_(callback) { 57 callback_(callback) {
57 } 58 }
58 59
59 DefaultChannelIDStore::GetChannelIDTask::~GetChannelIDTask() { 60 DefaultChannelIDStore::GetChannelIDTask::~GetChannelIDTask() {
60 } 61 }
61 62
62 void DefaultChannelIDStore::GetChannelIDTask::Run( 63 void DefaultChannelIDStore::GetChannelIDTask::Run(
63 DefaultChannelIDStore* store) { 64 DefaultChannelIDStore* store) {
64 base::Time expiration_time; 65 scoped_ptr<crypto::ECPrivateKey> key_result;
65 std::string private_key_result; 66 int err = store->GetChannelID(server_identifier_, &key_result,
66 std::string cert_result; 67 GetChannelIDCallback());
67 int err = store->GetChannelID(
68 server_identifier_, &expiration_time, &private_key_result,
69 &cert_result, GetChannelIDCallback());
70 DCHECK(err != ERR_IO_PENDING); 68 DCHECK(err != ERR_IO_PENDING);
71 69
72 InvokeCallback(base::Bind(callback_, err, server_identifier_, 70 InvokeCallback(base::Bind(callback_, err, server_identifier_,
73 expiration_time, private_key_result, cert_result)); 71 base::Passed(key_result.Pass())));
74 } 72 }
75 73
76 // -------------------------------------------------------------------------- 74 // --------------------------------------------------------------------------
77 // SetChannelIDTask 75 // SetChannelIDTask
78 class DefaultChannelIDStore::SetChannelIDTask 76 class DefaultChannelIDStore::SetChannelIDTask
79 : public DefaultChannelIDStore::Task { 77 : public DefaultChannelIDStore::Task {
80 public: 78 public:
81 SetChannelIDTask(const std::string& server_identifier, 79 SetChannelIDTask(scoped_ptr<ChannelID> channel_id);
82 base::Time creation_time,
83 base::Time expiration_time,
84 const std::string& private_key,
85 const std::string& cert);
86 ~SetChannelIDTask() override; 80 ~SetChannelIDTask() override;
87 void Run(DefaultChannelIDStore* store) override; 81 void Run(DefaultChannelIDStore* store) override;
88 82
89 private: 83 private:
90 std::string server_identifier_; 84 scoped_ptr<ChannelID> channel_id_;
91 base::Time creation_time_;
92 base::Time expiration_time_;
93 std::string private_key_;
94 std::string cert_;
95 }; 85 };
96 86
97 DefaultChannelIDStore::SetChannelIDTask::SetChannelIDTask( 87 DefaultChannelIDStore::SetChannelIDTask::SetChannelIDTask(
98 const std::string& server_identifier, 88 scoped_ptr<ChannelID> channel_id)
99 base::Time creation_time, 89 : channel_id_(channel_id.Pass()) {
100 base::Time expiration_time,
101 const std::string& private_key,
102 const std::string& cert)
103 : server_identifier_(server_identifier),
104 creation_time_(creation_time),
105 expiration_time_(expiration_time),
106 private_key_(private_key),
107 cert_(cert) {
108 } 90 }
109 91
110 DefaultChannelIDStore::SetChannelIDTask::~SetChannelIDTask() { 92 DefaultChannelIDStore::SetChannelIDTask::~SetChannelIDTask() {
111 } 93 }
112 94
113 void DefaultChannelIDStore::SetChannelIDTask::Run( 95 void DefaultChannelIDStore::SetChannelIDTask::Run(
114 DefaultChannelIDStore* store) { 96 DefaultChannelIDStore* store) {
115 store->SyncSetChannelID(server_identifier_, creation_time_, 97 store->SyncSetChannelID(channel_id_.Pass());
116 expiration_time_, private_key_, cert_);
117 } 98 }
118 99
119 // -------------------------------------------------------------------------- 100 // --------------------------------------------------------------------------
120 // DeleteChannelIDTask 101 // DeleteChannelIDTask
121 class DefaultChannelIDStore::DeleteChannelIDTask 102 class DefaultChannelIDStore::DeleteChannelIDTask
122 : public DefaultChannelIDStore::Task { 103 : public DefaultChannelIDStore::Task {
123 public: 104 public:
124 DeleteChannelIDTask(const std::string& server_identifier, 105 DeleteChannelIDTask(const std::string& server_identifier,
125 const base::Closure& callback); 106 const base::Closure& callback);
126 ~DeleteChannelIDTask() override; 107 ~DeleteChannelIDTask() override;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 GetAllChannelIDsTask(const GetChannelIDListCallback& callback) 187 GetAllChannelIDsTask(const GetChannelIDListCallback& callback)
207 : callback_(callback) { 188 : callback_(callback) {
208 } 189 }
209 190
210 DefaultChannelIDStore::GetAllChannelIDsTask:: 191 DefaultChannelIDStore::GetAllChannelIDsTask::
211 ~GetAllChannelIDsTask() { 192 ~GetAllChannelIDsTask() {
212 } 193 }
213 194
214 void DefaultChannelIDStore::GetAllChannelIDsTask::Run( 195 void DefaultChannelIDStore::GetAllChannelIDsTask::Run(
215 DefaultChannelIDStore* store) { 196 DefaultChannelIDStore* store) {
216 ChannelIDList cert_list; 197 ChannelIDList key_list;
217 store->SyncGetAllChannelIDs(&cert_list); 198 store->SyncGetAllChannelIDs(&key_list);
218 199
219 InvokeCallback(base::Bind(callback_, cert_list)); 200 InvokeCallback(base::Bind(callback_, key_list));
220 } 201 }
221 202
222 // -------------------------------------------------------------------------- 203 // --------------------------------------------------------------------------
223 // DefaultChannelIDStore 204 // DefaultChannelIDStore
224 205
225 DefaultChannelIDStore::DefaultChannelIDStore( 206 DefaultChannelIDStore::DefaultChannelIDStore(
226 PersistentStore* store) 207 PersistentStore* store)
227 : initialized_(false), 208 : initialized_(false),
228 loaded_(false), 209 loaded_(false),
229 store_(store), 210 store_(store),
230 weak_ptr_factory_(this) {} 211 weak_ptr_factory_(this) {}
231 212
232 int DefaultChannelIDStore::GetChannelID( 213 int DefaultChannelIDStore::GetChannelID(
233 const std::string& server_identifier, 214 const std::string& server_identifier,
234 base::Time* expiration_time, 215 scoped_ptr<crypto::ECPrivateKey>* key_result,
235 std::string* private_key_result,
236 std::string* cert_result,
237 const GetChannelIDCallback& callback) { 216 const GetChannelIDCallback& callback) {
238 DCHECK(CalledOnValidThread()); 217 DCHECK(CalledOnValidThread());
239 InitIfNecessary(); 218 InitIfNecessary();
240 219
241 if (!loaded_) { 220 if (!loaded_) {
242 EnqueueTask(scoped_ptr<Task>( 221 EnqueueTask(scoped_ptr<Task>(
243 new GetChannelIDTask(server_identifier, callback))); 222 new GetChannelIDTask(server_identifier, callback)));
244 return ERR_IO_PENDING; 223 return ERR_IO_PENDING;
245 } 224 }
246 225
247 ChannelIDMap::iterator it = channel_ids_.find(server_identifier); 226 ChannelIDMap::iterator it = channel_ids_.find(server_identifier);
248 227
249 if (it == channel_ids_.end()) 228 if (it == channel_ids_.end())
250 return ERR_FILE_NOT_FOUND; 229 return ERR_FILE_NOT_FOUND;
251 230
252 ChannelID* channel_id = it->second; 231 ChannelID* channel_id = it->second;
253 *expiration_time = channel_id->expiration_time(); 232 key_result->reset(channel_id->key()->Copy());
254 *private_key_result = channel_id->private_key();
255 *cert_result = channel_id->cert();
256 233
257 return OK; 234 return OK;
258 } 235 }
259 236
260 void DefaultChannelIDStore::SetChannelID( 237 void DefaultChannelIDStore::SetChannelID(scoped_ptr<ChannelID> channel_id) {
261 const std::string& server_identifier, 238 auto task = new SetChannelIDTask(channel_id.Pass());
262 base::Time creation_time, 239 RunOrEnqueueTask(scoped_ptr<Task>(task));
263 base::Time expiration_time,
264 const std::string& private_key,
265 const std::string& cert) {
266 RunOrEnqueueTask(scoped_ptr<Task>(new SetChannelIDTask(
267 server_identifier, creation_time, expiration_time, private_key,
268 cert)));
269 } 240 }
270 241
271 void DefaultChannelIDStore::DeleteChannelID( 242 void DefaultChannelIDStore::DeleteChannelID(
272 const std::string& server_identifier, 243 const std::string& server_identifier,
273 const base::Closure& callback) { 244 const base::Closure& callback) {
274 RunOrEnqueueTask(scoped_ptr<Task>( 245 RunOrEnqueueTask(scoped_ptr<Task>(
275 new DeleteChannelIDTask(server_identifier, callback))); 246 new DeleteChannelIDTask(server_identifier, callback)));
276 } 247 }
277 248
278 void DefaultChannelIDStore::DeleteAllCreatedBetween( 249 void DefaultChannelIDStore::DeleteAllCreatedBetween(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 UMA_HISTOGRAM_COUNTS_100("DomainBoundCerts.TaskWaitCount", 327 UMA_HISTOGRAM_COUNTS_100("DomainBoundCerts.TaskWaitCount",
357 waiting_tasks_.size()); 328 waiting_tasks_.size());
358 329
359 330
360 for (ScopedVector<Task>::iterator i = waiting_tasks_.begin(); 331 for (ScopedVector<Task>::iterator i = waiting_tasks_.begin();
361 i != waiting_tasks_.end(); ++i) 332 i != waiting_tasks_.end(); ++i)
362 (*i)->Run(this); 333 (*i)->Run(this);
363 waiting_tasks_.clear(); 334 waiting_tasks_.clear();
364 } 335 }
365 336
366 void DefaultChannelIDStore::SyncSetChannelID( 337 void DefaultChannelIDStore::SyncSetChannelID(scoped_ptr<ChannelID> channel_id) {
367 const std::string& server_identifier,
368 base::Time creation_time,
369 base::Time expiration_time,
370 const std::string& private_key,
371 const std::string& cert) {
372 DCHECK(CalledOnValidThread()); 338 DCHECK(CalledOnValidThread());
373 DCHECK(loaded_); 339 DCHECK(loaded_);
374 340
375 InternalDeleteChannelID(server_identifier); 341 InternalDeleteChannelID(channel_id->server_identifier());
376 InternalInsertChannelID( 342 InternalInsertChannelID(channel_id.Pass());
377 server_identifier,
378 new ChannelID(
379 server_identifier, creation_time, expiration_time, private_key,
380 cert));
381 } 343 }
382 344
383 void DefaultChannelIDStore::SyncDeleteChannelID( 345 void DefaultChannelIDStore::SyncDeleteChannelID(
384 const std::string& server_identifier) { 346 const std::string& server_identifier) {
385 DCHECK(CalledOnValidThread()); 347 DCHECK(CalledOnValidThread());
386 DCHECK(loaded_); 348 DCHECK(loaded_);
387 InternalDeleteChannelID(server_identifier); 349 InternalDeleteChannelID(server_identifier);
388 } 350 }
389 351
390 void DefaultChannelIDStore::SyncDeleteAllCreatedBetween( 352 void DefaultChannelIDStore::SyncDeleteAllCreatedBetween(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 return; // There is nothing to delete. 409 return; // There is nothing to delete.
448 410
449 ChannelID* channel_id = it->second; 411 ChannelID* channel_id = it->second;
450 if (store_.get()) 412 if (store_.get())
451 store_->DeleteChannelID(*channel_id); 413 store_->DeleteChannelID(*channel_id);
452 channel_ids_.erase(it); 414 channel_ids_.erase(it);
453 delete channel_id; 415 delete channel_id;
454 } 416 }
455 417
456 void DefaultChannelIDStore::InternalInsertChannelID( 418 void DefaultChannelIDStore::InternalInsertChannelID(
457 const std::string& server_identifier, 419 scoped_ptr<ChannelID> channel_id) {
458 ChannelID* channel_id) {
459 DCHECK(CalledOnValidThread()); 420 DCHECK(CalledOnValidThread());
460 DCHECK(loaded_); 421 DCHECK(loaded_);
461 422
462 if (store_.get()) 423 if (store_.get())
463 store_->AddChannelID(*channel_id); 424 store_->AddChannelID(*(channel_id.get()));
464 channel_ids_[server_identifier] = channel_id; 425 const std::string& server_identifier = channel_id->server_identifier();
426 channel_ids_[server_identifier] = channel_id.release();
465 } 427 }
466 428
467 DefaultChannelIDStore::PersistentStore::PersistentStore() {} 429 DefaultChannelIDStore::PersistentStore::PersistentStore() {}
468 430
469 DefaultChannelIDStore::PersistentStore::~PersistentStore() {} 431 DefaultChannelIDStore::PersistentStore::~PersistentStore() {}
470 432
471 } // namespace net 433 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698