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

Side by Side Diff: chrome/browser/autofill/wallet/wallet_client.cc

Issue 11773037: Implementation of sensitive card information escrowing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing Ilya's final comments Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/autofill/wallet/wallet_client.h" 5 #include "chrome/browser/autofill/wallet/wallet_client.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/string_split.h" 12 #include "base/string_split.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/autofill/wallet/cart.h" 15 #include "chrome/browser/autofill/wallet/cart.h"
16 #include "chrome/browser/autofill/wallet/full_wallet.h" 16 #include "chrome/browser/autofill/wallet/full_wallet.h"
17 #include "chrome/browser/autofill/wallet/wallet_address.h" 17 #include "chrome/browser/autofill/wallet/wallet_address.h"
18 #include "chrome/browser/autofill/wallet/wallet_items.h" 18 #include "chrome/browser/autofill/wallet/wallet_items.h"
19 #include "chrome/browser/autofill/wallet/wallet_service_url.h" 19 #include "chrome/browser/autofill/wallet/wallet_service_url.h"
20 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 #include "net/http/http_status_code.h" 21 #include "net/http/http_status_code.h"
22 #include "net/url_request/url_fetcher.h" 22 #include "net/url_request/url_fetcher.h"
23 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
24 24
25 namespace { 25 namespace {
26 26
27 const char kEncryptOtpBodyFormat[] = "cvv=%s:%s"; 27 const char kEncryptOtpBodyFormat[] = "cvv=%s:%s";
28 const char kEscrowSensitiveInformationFormat[] = "gid=%s&cardNumber=%s&cvv=%s";
28 const char kJsonMimeType[] = "application/json"; 29 const char kJsonMimeType[] = "application/json";
29 const char kApplicationMimeType[] = "application/x-www-form-urlencoded"; 30 const char kApplicationMimeType[] = "application/x-www-form-urlencoded";
30 const size_t kMaxBits = 63; 31 const size_t kMaxBits = 63;
31 32
32 } // anonymous namespace 33 } // anonymous namespace
33 34
34 namespace wallet { 35 namespace wallet {
35 36
36 void WalletClient::AcceptLegalDocuments( 37 void WalletClient::AcceptLegalDocuments(
37 const std::vector<std::string>& document_ids, 38 const std::vector<std::string>& document_ids,
38 const std::string& google_transaction_id, 39 const std::string& google_transaction_id,
39 WalletClient::WalletClientObserver* observer) { 40 WalletClient::WalletClientObserver* observer) {
40 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); 41 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
41
42 request_type_ = ACCEPT_LEGAL_DOCUMENTS; 42 request_type_ = ACCEPT_LEGAL_DOCUMENTS;
43 43
44 DictionaryValue request_dict; 44 DictionaryValue request_dict;
45 request_dict.SetString("api_key", wallet::kApiKey); 45 request_dict.SetString("api_key", wallet::kApiKey);
46 request_dict.SetString("google_transaction_id", google_transaction_id); 46 request_dict.SetString("google_transaction_id", google_transaction_id);
47 ListValue* docs_list = new ListValue(); 47 ListValue* docs_list = new ListValue();
48 for (std::vector<std::string>::const_iterator it = document_ids.begin(); 48 for (std::vector<std::string>::const_iterator it = document_ids.begin();
49 it != document_ids.end(); 49 it != document_ids.end();
50 ++it) { 50 ++it) {
51 docs_list->AppendString(*it); 51 docs_list->AppendString(*it);
52 } 52 }
53 request_dict.Set("accepted_legal_document", docs_list); 53 request_dict.Set("accepted_legal_document", docs_list);
54 54
55 std::string post_body; 55 std::string post_body;
56 base::JSONWriter::Write(&request_dict, &post_body); 56 base::JSONWriter::Write(&request_dict, &post_body);
57 57
58 MakeWalletRequest(GetAcceptLegalDocumentsUrl(), 58 MakeWalletRequest(GetAcceptLegalDocumentsUrl(),
59 post_body, 59 post_body,
60 observer, 60 observer,
61 kJsonMimeType); 61 kJsonMimeType);
62 } 62 }
63 63
64 void WalletClient::EncryptOtp( 64 void WalletClient::EncryptOtp(
65 const void* otp, 65 const void* otp,
66 size_t length, 66 size_t length,
67 WalletClient::WalletClientObserver* observer) { 67 WalletClient::WalletClientObserver* observer) {
68 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); 68 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
69 size_t num_bits = length * 8; 69 size_t num_bits = length * 8;
70 DCHECK_LT(num_bits, kMaxBits); 70 DCHECK_LT(num_bits, kMaxBits);
71 71
72 request_type_ = ENCRYPT_OTP; 72 request_type_ = ENCRYPT_OTP;
73 73
74 std::string post_body = StringPrintf(kEncryptOtpBodyFormat, 74 std::string post_body = StringPrintf(kEncryptOtpBodyFormat,
75 base::HexEncode(&num_bits, 1).c_str(), 75 base::HexEncode(&num_bits, 1).c_str(),
76 base::HexEncode(otp, length).c_str()); 76 base::HexEncode(otp, length).c_str());
77 77
78 MakeWalletRequest(GetSecureUrl(), post_body, observer, kApplicationMimeType); 78 MakeWalletRequest(GetEncryptionUrl(),
79 post_body,
80 observer,
81 kApplicationMimeType);
79 } 82 }
80 83
84 void WalletClient::EscrowSensitiveInformation(
85 const std::string& primary_account_number,
86 const std::string& card_verification_number,
87 const std::string& obfuscated_gaia_id,
88 WalletClient::WalletClientObserver* observer) {
89 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
90 request_type_ = ESCROW_SENSITIVE_INFORMATION;
91
92 std::string post_body = StringPrintf(kEscrowSensitiveInformationFormat,
93 obfuscated_gaia_id.c_str(),
94 primary_account_number.c_str(),
95 card_verification_number.c_str());
96
97 MakeWalletRequest(GetEscrowUrl(), post_body, observer, kApplicationMimeType);
98 }
99
100
81 void WalletClient::GetFullWallet( 101 void WalletClient::GetFullWallet(
82 const std::string& instrument_id, 102 const std::string& instrument_id,
83 const std::string& address_id, 103 const std::string& address_id,
84 const std::string& merchant_domain, 104 const std::string& merchant_domain,
85 const Cart& cart, 105 const Cart& cart,
86 const std::string& google_transaction_id, 106 const std::string& google_transaction_id,
87 const std::string& encrypted_otp, 107 const std::string& encrypted_otp,
88 const std::string& session_material, 108 const std::string& session_material,
89 WalletClient::WalletClientObserver* observer) { 109 WalletClient::WalletClientObserver* observer) {
90 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); 110 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
91
92 request_type_ = GET_FULL_WALLET; 111 request_type_ = GET_FULL_WALLET;
93 112
94 DictionaryValue request_dict; 113 DictionaryValue request_dict;
95 request_dict.SetString("api_key", wallet::kApiKey); 114 request_dict.SetString("api_key", wallet::kApiKey);
96 request_dict.SetString("risk_params", GetRiskParams()); 115 request_dict.SetString("risk_params", GetRiskParams());
97 request_dict.SetString("selected_instrument_id", instrument_id); 116 request_dict.SetString("selected_instrument_id", instrument_id);
98 request_dict.SetString("selected_address_id", address_id); 117 request_dict.SetString("selected_address_id", address_id);
99 request_dict.SetString("merchant_domain", merchant_domain); 118 request_dict.SetString("merchant_domain", merchant_domain);
100 request_dict.SetString("google_transaction_id", google_transaction_id); 119 request_dict.SetString("google_transaction_id", google_transaction_id);
101 request_dict.Set("cart", cart.ToDictionary().release()); 120 request_dict.Set("cart", cart.ToDictionary().release());
102 request_dict.SetString("encrypted_otp", encrypted_otp); 121 request_dict.SetString("encrypted_otp", encrypted_otp);
103 request_dict.SetString("session_material", session_material); 122 request_dict.SetString("session_material", session_material);
104 123
105 std::string post_body; 124 std::string post_body;
106 base::JSONWriter::Write(&request_dict, &post_body); 125 base::JSONWriter::Write(&request_dict, &post_body);
107 126
108 MakeWalletRequest(GetGetFullWalletUrl(), post_body, observer, kJsonMimeType); 127 MakeWalletRequest(GetGetFullWalletUrl(), post_body, observer, kJsonMimeType);
109 } 128 }
110 129
111 void WalletClient::GetWalletItems( 130 void WalletClient::GetWalletItems(
112 WalletClient::WalletClientObserver* observer) { 131 WalletClient::WalletClientObserver* observer) {
113 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); 132 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
114
115 request_type_ = GET_WALLET_ITEMS; 133 request_type_ = GET_WALLET_ITEMS;
116 134
117 DictionaryValue request_dict; 135 DictionaryValue request_dict;
118 request_dict.SetString("api_key", wallet::kApiKey); 136 request_dict.SetString("api_key", wallet::kApiKey);
119 request_dict.SetString("risk_params", GetRiskParams()); 137 request_dict.SetString("risk_params", GetRiskParams());
120 138
121 std::string post_body; 139 std::string post_body;
122 base::JSONWriter::Write(&request_dict, &post_body); 140 base::JSONWriter::Write(&request_dict, &post_body);
123 141
124 MakeWalletRequest(GetGetWalletItemsUrl(), post_body, observer, kJsonMimeType); 142 MakeWalletRequest(GetGetWalletItemsUrl(), post_body, observer, kJsonMimeType);
125 } 143 }
126 144
127 void WalletClient::SendExtendedAutofillStatus( 145 void WalletClient::SendExtendedAutofillStatus(
128 bool success, 146 bool success,
129 const std::string& merchant_domain, 147 const std::string& merchant_domain,
130 const std::string& reason, 148 const std::string& reason,
131 const std::string& google_transaction_id, 149 const std::string& google_transaction_id,
132 WalletClient::WalletClientObserver* observer) { 150 WalletClient::WalletClientObserver* observer) {
133 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); 151 DCHECK_EQ(NO_PENDING_REQUEST, request_type_);
134
135 request_type_ = SEND_STATUS; 152 request_type_ = SEND_STATUS;
136 153
137 DictionaryValue request_dict; 154 DictionaryValue request_dict;
138 request_dict.SetString("api_key", wallet::kApiKey); 155 request_dict.SetString("api_key", wallet::kApiKey);
139 request_dict.SetBoolean("success", success); 156 request_dict.SetBoolean("success", success);
140 request_dict.SetString("hostname", merchant_domain); 157 request_dict.SetString("hostname", merchant_domain);
141 if (!success) { 158 if (!success) {
142 // TODO(ahutter): Probably want to do some checks on reason. 159 // TODO(ahutter): Probably want to do some checks on reason.
143 request_dict.SetString("reason", reason); 160 request_dict.SetString("reason", reason);
144 } 161 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 request_type_ = NO_PENDING_REQUEST; 229 request_type_ = NO_PENDING_REQUEST;
213 observer_->OnNetworkError(response_code); 230 observer_->OnNetworkError(response_code);
214 return; 231 return;
215 } 232 }
216 } 233 }
217 234
218 RequestType type = request_type_; 235 RequestType type = request_type_;
219 request_type_ = NO_PENDING_REQUEST; 236 request_type_ = NO_PENDING_REQUEST;
220 237
221 switch (type) { 238 switch (type) {
222 case ACCEPT_LEGAL_DOCUMENTS: { 239 case ACCEPT_LEGAL_DOCUMENTS:
223 observer_->OnAcceptLegalDocuments(); 240 observer_->OnAcceptLegalDocuments();
224 break; 241 break;
225 } 242 case SEND_STATUS:
226 case SEND_STATUS: {
227 observer_->OnSendExtendedAutofillStatus(); 243 observer_->OnSendExtendedAutofillStatus();
228 break; 244 break;
229 }
230 case ENCRYPT_OTP: { 245 case ENCRYPT_OTP: {
231 if (!data.empty()) { 246 if (!data.empty()) {
232 std::vector<std::string> splits; 247 std::vector<std::string> splits;
233 base::SplitString(data, '|', &splits); 248 base::SplitString(data, '|', &splits);
234 if (splits.size() == 2) 249 if (splits.size() == 2)
235 observer_->OnEncryptOtp(splits[1], splits[0]); 250 observer_->OnEncryptOtp(splits[1], splits[0]);
236 else 251 else
237 observer_->OnNetworkError(response_code); 252 observer_->OnNetworkError(response_code);
238 } else { 253 } else {
239 observer_->OnWalletError(); 254 observer_->OnWalletError();
240 } 255 }
241 break; 256 break;
242 } 257 }
258 case ESCROW_SENSITIVE_INFORMATION:
259 if (!data.empty())
260 observer_->OnDidEscrowSensitiveInformation(data);
261 else
262 observer_->OnWalletError();
263 break;
243 case GET_FULL_WALLET: { 264 case GET_FULL_WALLET: {
244 if (response_dict.get()) { 265 if (response_dict.get()) {
245 scoped_ptr<FullWallet> full_wallet( 266 scoped_ptr<FullWallet> full_wallet(
246 FullWallet::CreateFullWallet(*response_dict)); 267 FullWallet::CreateFullWallet(*response_dict));
247 if (full_wallet.get()) 268 if (full_wallet.get())
248 observer_->OnGetFullWallet(full_wallet.get()); 269 observer_->OnGetFullWallet(full_wallet.get());
249 else 270 else
250 observer_->OnNetworkError(response_code); 271 observer_->OnNetworkError(response_code);
251 } else { 272 } else {
252 observer_->OnWalletError(); 273 observer_->OnWalletError();
(...skipping 23 matching lines...) Expand all
276 : context_getter_(context_getter), 297 : context_getter_(context_getter),
277 observer_(NULL), 298 observer_(NULL),
278 request_type_(NO_PENDING_REQUEST) { 299 request_type_(NO_PENDING_REQUEST) {
279 DCHECK(context_getter); 300 DCHECK(context_getter);
280 } 301 }
281 302
282 WalletClient::~WalletClient() {} 303 WalletClient::~WalletClient() {}
283 304
284 } // namespace wallet 305 } // namespace wallet
285 306
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/wallet_client.h ('k') | chrome/browser/autofill/wallet/wallet_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698