OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/install_signer.h" | 5 #include "chrome/browser/extensions/install_signer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> |
9 | 10 |
10 #include "base/base64.h" | 11 #include "base/base64.h" |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
14 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
15 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
18 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 const base::DictionaryValue& value) { | 185 const base::DictionaryValue& value) { |
185 | 186 |
186 scoped_ptr<InstallSignature> result(new InstallSignature); | 187 scoped_ptr<InstallSignature> result(new InstallSignature); |
187 | 188 |
188 // For now we don't want to support any backwards compability, but in the | 189 // For now we don't want to support any backwards compability, but in the |
189 // future if we do, we would want to put the migration code here. | 190 // future if we do, we would want to put the migration code here. |
190 int format_version = 0; | 191 int format_version = 0; |
191 if (!value.GetInteger(kSignatureFormatVersionKey, &format_version) || | 192 if (!value.GetInteger(kSignatureFormatVersionKey, &format_version) || |
192 format_version != kSignatureFormatVersion) { | 193 format_version != kSignatureFormatVersion) { |
193 result.reset(); | 194 result.reset(); |
194 return result.Pass(); | 195 return result; |
195 } | 196 } |
196 | 197 |
197 std::string salt_base64; | 198 std::string salt_base64; |
198 std::string signature_base64; | 199 std::string signature_base64; |
199 if (!value.GetString(kExpireDateKey, &result->expire_date) || | 200 if (!value.GetString(kExpireDateKey, &result->expire_date) || |
200 !value.GetString(kSaltKey, &salt_base64) || | 201 !value.GetString(kSaltKey, &salt_base64) || |
201 !value.GetString(kSignatureKey, &signature_base64) || | 202 !value.GetString(kSignatureKey, &signature_base64) || |
202 !base::Base64Decode(salt_base64, &result->salt) || | 203 !base::Base64Decode(salt_base64, &result->salt) || |
203 !base::Base64Decode(signature_base64, &result->signature)) { | 204 !base::Base64Decode(signature_base64, &result->signature)) { |
204 result.reset(); | 205 result.reset(); |
205 return result.Pass(); | 206 return result; |
206 } | 207 } |
207 | 208 |
208 // Note: earlier versions of the code did not write out a timestamp value | 209 // Note: earlier versions of the code did not write out a timestamp value |
209 // so older entries will not necessarily have this. | 210 // so older entries will not necessarily have this. |
210 if (value.HasKey(kTimestampKey)) { | 211 if (value.HasKey(kTimestampKey)) { |
211 std::string timestamp; | 212 std::string timestamp; |
212 int64_t timestamp_value = 0; | 213 int64_t timestamp_value = 0; |
213 if (!value.GetString(kTimestampKey, ×tamp) || | 214 if (!value.GetString(kTimestampKey, ×tamp) || |
214 !base::StringToInt64(timestamp, ×tamp_value)) { | 215 !base::StringToInt64(timestamp, ×tamp_value)) { |
215 result.reset(); | 216 result.reset(); |
216 return result.Pass(); | 217 return result; |
217 } | 218 } |
218 result->timestamp = base::Time::FromInternalValue(timestamp_value); | 219 result->timestamp = base::Time::FromInternalValue(timestamp_value); |
219 } | 220 } |
220 | 221 |
221 if (!GetExtensionIdSet(value, kIdsKey, &result->ids) || | 222 if (!GetExtensionIdSet(value, kIdsKey, &result->ids) || |
222 !GetExtensionIdSet(value, kInvalidIdsKey, &result->invalid_ids)) { | 223 !GetExtensionIdSet(value, kInvalidIdsKey, &result->invalid_ids)) { |
223 result.reset(); | 224 result.reset(); |
224 return result.Pass(); | 225 return result; |
225 } | 226 } |
226 | 227 |
227 return result.Pass(); | 228 return result; |
228 } | 229 } |
229 | 230 |
230 | 231 |
231 InstallSigner::InstallSigner(net::URLRequestContextGetter* context_getter, | 232 InstallSigner::InstallSigner(net::URLRequestContextGetter* context_getter, |
232 const ExtensionIdSet& ids) | 233 const ExtensionIdSet& ids) |
233 : ids_(ids), context_getter_(context_getter) { | 234 : ids_(ids), context_getter_(context_getter) { |
234 } | 235 } |
235 | 236 |
236 InstallSigner::~InstallSigner() { | 237 InstallSigner::~InstallSigner() { |
237 } | 238 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 result->timestamp = request_start_time_; | 501 result->timestamp = request_start_time_; |
501 bool verified = VerifySignature(*result); | 502 bool verified = VerifySignature(*result); |
502 UMA_HISTOGRAM_BOOLEAN("ExtensionInstallSigner.ResultWasValid", verified); | 503 UMA_HISTOGRAM_BOOLEAN("ExtensionInstallSigner.ResultWasValid", verified); |
503 UMA_HISTOGRAM_COUNTS_100("ExtensionInstallSigner.InvalidCount", | 504 UMA_HISTOGRAM_COUNTS_100("ExtensionInstallSigner.InvalidCount", |
504 invalid_ids.size()); | 505 invalid_ids.size()); |
505 if (!verified) | 506 if (!verified) |
506 result.reset(); | 507 result.reset(); |
507 } | 508 } |
508 | 509 |
509 if (!callback_.is_null()) | 510 if (!callback_.is_null()) |
510 callback_.Run(result.Pass()); | 511 callback_.Run(std::move(result)); |
511 } | 512 } |
512 | 513 |
513 | 514 |
514 } // namespace extensions | 515 } // namespace extensions |
OLD | NEW |