OLD | NEW |
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/extras/sqlite/sqlite_channel_id_store.h" | 5 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 db_.reset(); | 220 db_.reset(); |
221 return; | 221 return; |
222 } | 222 } |
223 | 223 |
224 while (smt.Step()) { | 224 while (smt.Step()) { |
225 std::vector<uint8_t> private_key_from_db, public_key_from_db; | 225 std::vector<uint8_t> private_key_from_db, public_key_from_db; |
226 smt.ColumnBlobAsVector(1, &private_key_from_db); | 226 smt.ColumnBlobAsVector(1, &private_key_from_db); |
227 smt.ColumnBlobAsVector(2, &public_key_from_db); | 227 smt.ColumnBlobAsVector(2, &public_key_from_db); |
228 std::unique_ptr<crypto::ECPrivateKey> key( | 228 std::unique_ptr<crypto::ECPrivateKey> key( |
229 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( | 229 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( |
230 ChannelIDService::kEPKIPassword, private_key_from_db, | 230 private_key_from_db, public_key_from_db)); |
231 public_key_from_db)); | |
232 if (!key) | 231 if (!key) |
233 continue; | 232 continue; |
234 std::unique_ptr<DefaultChannelIDStore::ChannelID> channel_id( | 233 std::unique_ptr<DefaultChannelIDStore::ChannelID> channel_id( |
235 new DefaultChannelIDStore::ChannelID( | 234 new DefaultChannelIDStore::ChannelID( |
236 smt.ColumnString(0), // host | 235 smt.ColumnString(0), // host |
237 base::Time::FromInternalValue(smt.ColumnInt64(3)), std::move(key))); | 236 base::Time::FromInternalValue(smt.ColumnInt64(3)), std::move(key))); |
238 channel_ids->push_back(std::move(channel_id)); | 237 channel_ids->push_back(std::move(channel_id)); |
239 } | 238 } |
240 | 239 |
241 UMA_HISTOGRAM_COUNTS_10000( | 240 UMA_HISTOGRAM_COUNTS_10000( |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 490 |
492 for (PendingOperationsList::iterator it = ops.begin(); it != ops.end(); | 491 for (PendingOperationsList::iterator it = ops.begin(); it != ops.end(); |
493 ++it) { | 492 ++it) { |
494 // Free the certs as we commit them to the database. | 493 // Free the certs as we commit them to the database. |
495 std::unique_ptr<PendingOperation> po(*it); | 494 std::unique_ptr<PendingOperation> po(*it); |
496 switch (po->op()) { | 495 switch (po->op()) { |
497 case PendingOperation::CHANNEL_ID_ADD: { | 496 case PendingOperation::CHANNEL_ID_ADD: { |
498 add_statement.Reset(true); | 497 add_statement.Reset(true); |
499 add_statement.BindString(0, po->channel_id().server_identifier()); | 498 add_statement.BindString(0, po->channel_id().server_identifier()); |
500 std::vector<uint8_t> private_key, public_key; | 499 std::vector<uint8_t> private_key, public_key; |
501 if (!po->channel_id().key()->ExportEncryptedPrivateKey( | 500 if (!po->channel_id().key()->ExportEncryptedPrivateKey(&private_key)) |
502 ChannelIDService::kEPKIPassword, 1, &private_key)) | |
503 continue; | 501 continue; |
504 if (!po->channel_id().key()->ExportPublicKey(&public_key)) | 502 if (!po->channel_id().key()->ExportPublicKey(&public_key)) |
505 continue; | 503 continue; |
506 add_statement.BindBlob( | 504 add_statement.BindBlob( |
507 1, private_key.data(), static_cast<int>(private_key.size())); | 505 1, private_key.data(), static_cast<int>(private_key.size())); |
508 add_statement.BindBlob(2, public_key.data(), | 506 add_statement.BindBlob(2, public_key.data(), |
509 static_cast<int>(public_key.size())); | 507 static_cast<int>(public_key.size())); |
510 add_statement.BindInt64( | 508 add_statement.BindInt64( |
511 3, po->channel_id().creation_time().ToInternalValue()); | 509 3, po->channel_id().creation_time().ToInternalValue()); |
512 if (!add_statement.Run()) | 510 if (!add_statement.Run()) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 backend_->SetForceKeepSessionState(); | 611 backend_->SetForceKeepSessionState(); |
614 } | 612 } |
615 | 613 |
616 SQLiteChannelIDStore::~SQLiteChannelIDStore() { | 614 SQLiteChannelIDStore::~SQLiteChannelIDStore() { |
617 backend_->Close(); | 615 backend_->Close(); |
618 // We release our reference to the Backend, though it will probably still have | 616 // We release our reference to the Backend, though it will probably still have |
619 // a reference if the background task runner has not run Close() yet. | 617 // a reference if the background task runner has not run Close() yet. |
620 } | 618 } |
621 | 619 |
622 } // namespace net | 620 } // namespace net |
OLD | NEW |