| 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 "components/signin/core/browser/webdata/token_service_table.h" | 5 #include "components/signin/core/browser/webdata/token_service_table.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 sql::Statement s(db_->GetUniqueStatement( | 82 sql::Statement s(db_->GetUniqueStatement( |
| 83 "INSERT OR REPLACE INTO token_service " | 83 "INSERT OR REPLACE INTO token_service " |
| 84 "(service, encrypted_token) VALUES (?, ?)")); | 84 "(service, encrypted_token) VALUES (?, ?)")); |
| 85 s.BindString(0, service); | 85 s.BindString(0, service); |
| 86 s.BindBlob(1, encrypted_token.data(), | 86 s.BindBlob(1, encrypted_token.data(), |
| 87 static_cast<int>(encrypted_token.length())); | 87 static_cast<int>(encrypted_token.length())); |
| 88 | 88 |
| 89 return s.Run(); | 89 return s.Run(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool TokenServiceTable::GetAllTokens( | 92 TokenServiceTable::Result TokenServiceTable::GetAllTokens( |
| 93 std::map<std::string, std::string>* tokens) { | 93 std::map<std::string, std::string>* tokens) { |
| 94 sql::Statement s(db_->GetUniqueStatement( | 94 sql::Statement s(db_->GetUniqueStatement( |
| 95 "SELECT service, encrypted_token FROM token_service")); | 95 "SELECT service, encrypted_token FROM token_service")); |
| 96 | 96 |
| 97 if (!s.is_valid()) { | 97 if (!s.is_valid()) { |
| 98 LOG(ERROR) << "Failed to load tokens (invalid SQL statement)."; | 98 LOG(ERROR) << "Failed to load tokens (invalid SQL statement)."; |
| 99 base::RecordAction( | 99 base::RecordAction( |
| 100 base::UserMetricsAction("Signin_TokenTable_GetAllTokensInvalidSql")); | 100 base::UserMetricsAction("Signin_TokenTable_GetAllTokensInvalidSql")); |
| 101 return false; | 101 return TOKEN_DB_RESULT_SQL_INVALID_STATEMENT; |
| 102 } | 102 } |
| 103 | 103 |
| 104 Result result = TOKEN_DB_RESULT_SUCCESS; |
| 104 while (s.Step()) { | 105 while (s.Step()) { |
| 105 std::string encrypted_token; | 106 std::string encrypted_token; |
| 106 std::string decrypted_token; | 107 std::string decrypted_token; |
| 107 std::string service; | 108 std::string service; |
| 108 service = s.ColumnString(0); | 109 service = s.ColumnString(0); |
| 109 bool entry_ok = !service.empty() && | 110 bool entry_ok = !service.empty() && |
| 110 s.ColumnBlobAsString(1, &encrypted_token); | 111 s.ColumnBlobAsString(1, &encrypted_token); |
| 111 if (entry_ok) { | 112 if (entry_ok) { |
| 112 if (OSCrypt::DecryptString(encrypted_token, &decrypted_token)) { | 113 if (OSCrypt::DecryptString(encrypted_token, &decrypted_token)) { |
| 113 (*tokens)[service] = decrypted_token; | 114 (*tokens)[service] = decrypted_token; |
| 114 base::RecordAction( | 115 base::RecordAction( |
| 115 base::UserMetricsAction("Signin_TokenTable_LoadTokenSuccess")); | 116 base::UserMetricsAction("Signin_TokenTable_LoadTokenSuccess")); |
| 116 } else { | 117 } else { |
| 117 // Chrome relies on native APIs to encrypt and decrypt the tokens which | 118 // Chrome relies on native APIs to encrypt and decrypt the tokens which |
| 118 // may fail (see http://crbug.com/686485). | 119 // may fail (see http://crbug.com/686485). |
| 119 LOG(ERROR) << "Failed to decrypt token for service " << service; | 120 LOG(ERROR) << "Failed to decrypt token for service " << service; |
| 120 base::RecordAction( | 121 base::RecordAction( |
| 121 base::UserMetricsAction("Signin_TokenTable_DecryptFailed")); | 122 base::UserMetricsAction("Signin_TokenTable_DecryptFailed")); |
| 123 result = TOKEN_DB_RESULT_DECRYPT_ERROR; |
| 122 } | 124 } |
| 123 } else { | 125 } else { |
| 124 LOG(ERROR) << "Bad token entry for service " << service; | 126 LOG(ERROR) << "Bad token entry for service " << service; |
| 125 base::RecordAction(base::UserMetricsAction("Signin_TokenTable_BadEntry")); | 127 base::RecordAction(base::UserMetricsAction("Signin_TokenTable_BadEntry")); |
| 126 return false; | 128 result = TOKEN_DB_RESULT_BAD_ENTRY; |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 return true; | 131 return result; |
| 130 } | 132 } |
| OLD | NEW |