OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Implement the storage of service tokens in memory. | 5 // Implement the storage of service tokens in memory. |
6 | 6 |
7 #include "chrome/browser/sync/util/user_settings.h" | 7 #include "chrome/browser/sync/util/user_settings.h" |
8 | 8 |
9 #include "chrome/browser/password_manager/encryptor.h" | 9 #include "chrome/browser/password_manager/encryptor.h" |
10 #include "chrome/common/sqlite_utils.h" | 10 #include "chrome/common/sqlite_utils.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 return; | 26 return; |
27 } | 27 } |
28 ScopedDBHandle dbhandle(this); | 28 ScopedDBHandle dbhandle(this); |
29 SQLStatement statement; | 29 SQLStatement statement; |
30 statement.prepare(dbhandle.get(), | 30 statement.prepare(dbhandle.get(), |
31 "INSERT INTO cookies " | 31 "INSERT INTO cookies " |
32 "(email, service_name, service_token) " | 32 "(email, service_name, service_token) " |
33 "values (?, ?, ?)"); | 33 "values (?, ?, ?)"); |
34 statement.bind_string(0, email); | 34 statement.bind_string(0, email); |
35 statement.bind_string(1, service_name); | 35 statement.bind_string(1, service_name); |
36 statement.bind_string(2, encrypted_service_token); | 36 statement.bind_blob(2, encrypted_service_token.data(), |
| 37 encrypted_service_token.size()); |
37 if (SQLITE_DONE != statement.step()) { | 38 if (SQLITE_DONE != statement.step()) { |
38 LOG(FATAL) << sqlite3_errmsg(dbhandle.get()); | 39 LOG(FATAL) << sqlite3_errmsg(dbhandle.get()); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 bool UserSettings::GetLastUserAndServiceToken(const std::string& service_name, | 43 bool UserSettings::GetLastUserAndServiceToken(const std::string& service_name, |
43 std::string* username, | 44 std::string* username, |
44 std::string* service_token) { | 45 std::string* service_token) { |
45 ScopedDBHandle dbhandle(this); | 46 ScopedDBHandle dbhandle(this); |
46 SQLStatement query; | 47 SQLStatement query; |
47 query.prepare(dbhandle.get(), | 48 query.prepare(dbhandle.get(), |
48 "SELECT email, service_token FROM cookies" | 49 "SELECT email, service_token FROM cookies" |
49 " WHERE service_name = ?"); | 50 " WHERE service_name = ?"); |
50 query.bind_string(0, service_name.c_str()); | 51 query.bind_string(0, service_name.c_str()); |
51 | 52 |
52 if (SQLITE_ROW == query.step()) { | 53 if (SQLITE_ROW == query.step()) { |
53 std::string encrypted_service_token; | 54 std::string encrypted_service_token; |
54 query.column_string(1, &encrypted_service_token); | 55 query.column_blob_as_string(1, &encrypted_service_token); |
55 if (!Encryptor::DecryptString(encrypted_service_token, service_token)) { | 56 if (!Encryptor::DecryptString(encrypted_service_token, service_token)) { |
56 LOG(ERROR) << "Decryption failed: " << encrypted_service_token; | 57 LOG(ERROR) << "Decryption failed: " << encrypted_service_token; |
57 return false; | 58 return false; |
58 } | 59 } |
59 *username = query.column_string(0); | 60 *username = query.column_string(0); |
60 | 61 |
61 LOG(INFO) << "Found service token for:" << *username | 62 LOG(INFO) << "Found service token for:" << *username |
62 << " @ " << service_name << " returning: " << *service_token; | 63 << " @ " << service_name << " returning: " << *service_token; |
63 | 64 |
64 return true; | 65 return true; |
65 } | 66 } |
66 | 67 |
67 LOG(INFO) << "Couldn't find service token for " << service_name; | 68 LOG(INFO) << "Couldn't find service token for " << service_name; |
68 | 69 |
69 return false; | 70 return false; |
70 } | 71 } |
71 | 72 |
72 } // namespace browser_sync | 73 } // namespace browser_sync |
OLD | NEW |