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

Side by Side Diff: components/signin/core/browser/webdata/token_service_table.cc

Issue 2672603003: Avoid loading an empty token when decrypt failed (Closed)
Patch Set: Fix compile Created 3 years, 10 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 "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"
11 #include "base/metrics/user_metrics.h"
11 #include "components/os_crypt/os_crypt.h" 12 #include "components/os_crypt/os_crypt.h"
12 #include "components/webdata/common/web_database.h" 13 #include "components/webdata/common/web_database.h"
13 #include "sql/statement.h" 14 #include "sql/statement.h"
14 15
15 namespace { 16 namespace {
16 17
17 WebDatabaseTable::TypeKey GetKey() { 18 WebDatabaseTable::TypeKey GetKey() {
18 // We just need a unique constant. Use the address of a static that 19 // We just need a unique constant. Use the address of a static that
19 // COMDAT folding won't touch in an optimizing linker. 20 // COMDAT folding won't touch in an optimizing linker.
20 static int table_key = 0; 21 static int table_key = 0;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 static_cast<int>(encrypted_token.length())); 87 static_cast<int>(encrypted_token.length()));
87 88
88 return s.Run(); 89 return s.Run();
89 } 90 }
90 91
91 bool TokenServiceTable::GetAllTokens( 92 bool TokenServiceTable::GetAllTokens(
92 std::map<std::string, std::string>* tokens) { 93 std::map<std::string, std::string>* tokens) {
93 sql::Statement s(db_->GetUniqueStatement( 94 sql::Statement s(db_->GetUniqueStatement(
94 "SELECT service, encrypted_token FROM token_service")); 95 "SELECT service, encrypted_token FROM token_service"));
95 96
96 if (!s.is_valid()) 97 if (!s.is_valid()) {
98 LOG(ERROR) << "Failed to load tokens (invalid SQL statement).";
99 base::RecordAction(
100 base::UserMetricsAction("Signin_TokenTable_GetAllTokensInvalidSql"));
Alexei Svitkine (slow) 2017/02/02 17:22:13 These don't look like actions initiated by a user.
msarda 2017/02/06 10:36:47 Done.
97 return false; 101 return false;
102 }
98 103
99 while (s.Step()) { 104 while (s.Step()) {
100 std::string encrypted_token; 105 std::string encrypted_token;
101 std::string decrypted_token; 106 std::string decrypted_token;
102 std::string service; 107 std::string service;
103 service = s.ColumnString(0); 108 service = s.ColumnString(0);
104 bool entry_ok = !service.empty() && 109 bool entry_ok = !service.empty() &&
105 s.ColumnBlobAsString(1, &encrypted_token); 110 s.ColumnBlobAsString(1, &encrypted_token);
106 if (entry_ok) { 111 if (entry_ok) {
107 OSCrypt::DecryptString(encrypted_token, &decrypted_token); 112 if (OSCrypt::DecryptString(encrypted_token, &decrypted_token)) {
108 (*tokens)[service] = decrypted_token; 113 (*tokens)[service] = decrypted_token;
114 base::RecordAction(
115 base::UserMetricsAction("Signin_TokenTable_LoadTokenSuccess"));
116 } else {
117 // Chrome relies on native APIs to encrypt and decrypt the tokens which
118 // may fail (see http://crbug.com/686485).
119 LOG(ERROR) << "Failed to decrypt token for service " << service;
120 base::RecordAction(
121 base::UserMetricsAction("Signin_TokenTable_DecryptFailed"));
122 }
109 } else { 123 } else {
110 NOTREACHED(); 124 LOG(ERROR) << "Bad token entry for service " << service;
125 base::RecordAction(base::UserMetricsAction("Signin_TokenTable_BadEntry"));
111 return false; 126 return false;
112 } 127 }
113 } 128 }
114 return true; 129 return true;
115 } 130 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.cc ('k') | tools/metrics/actions/actions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698