| Index: chrome/browser/extensions/install_signer.cc
|
| diff --git a/chrome/browser/extensions/install_signer.cc b/chrome/browser/extensions/install_signer.cc
|
| index d7f74c01740528db33f354c3a8a52c21ca2c53e4..8a80bfcf229b4667b70caab66a9dc1ebfbf47236 100644
|
| --- a/chrome/browser/extensions/install_signer.cc
|
| +++ b/chrome/browser/extensions/install_signer.cc
|
| @@ -48,8 +48,14 @@ const char kInvalidIdsKey[] = "invalid_ids";
|
| const char kProtocolVersionKey[] = "protocol_version";
|
| const char kSaltKey[] = "salt";
|
| const char kSignatureKey[] = "signature";
|
| +const char kSignatureFormatVersionKey[] = "signature_format_version";
|
| const char kTimestampKey[] = "timestamp";
|
|
|
| +// This allows us to version the format of what we write into the prefs,
|
| +// allowing for forward migration, as well as detecting forwards/backwards
|
| +// incompatabilities, etc.
|
| +const int kSignatureFormatVersion = 2;
|
| +
|
| const size_t kSaltBytes = 32;
|
|
|
| const char kBackendUrl[] =
|
| @@ -109,6 +115,39 @@ bool ValidateExpireDateFormat(const std::string& input) {
|
| return true;
|
| }
|
|
|
| +// Sets the value of |key| in |dictionary| to be a list with the contents of
|
| +// |ids|.
|
| +void SetExtensionIdSet(base::DictionaryValue* dictionary,
|
| + const char* key,
|
| + const ExtensionIdSet& ids) {
|
| + base::ListValue* id_list = new base::ListValue();
|
| + for (ExtensionIdSet::const_iterator i = ids.begin(); i != ids.end(); ++i)
|
| + id_list->AppendString(*i);
|
| + dictionary->Set(key, id_list);
|
| +}
|
| +
|
| +// Tries to fetch a list of strings from |dictionay| for |key|, and inserts
|
| +// them into |ids|. The return value indicates success/failure. Note: on
|
| +// failure, |ids| might contain partial results, for instance if some of the
|
| +// members of the list were not strings.
|
| +bool GetExtensionIdSet(const base::DictionaryValue& dictionary,
|
| + const char* key,
|
| + ExtensionIdSet* ids) {
|
| + const base::ListValue* id_list = NULL;
|
| + if (!dictionary.GetList(key, &id_list))
|
| + return false;
|
| + for (base::ListValue::const_iterator i = id_list->begin();
|
| + i != id_list->end();
|
| + ++i) {
|
| + std::string id;
|
| + if (!(*i)->GetAsString(&id)) {
|
| + return false;
|
| + }
|
| + ids->insert(id);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace extensions {
|
| @@ -121,12 +160,9 @@ InstallSignature::~InstallSignature() {
|
| void InstallSignature::ToValue(base::DictionaryValue* value) const {
|
| CHECK(value);
|
|
|
| - base::ListValue* id_list = new base::ListValue();
|
| - for (ExtensionIdSet::const_iterator i = ids.begin(); i != ids.end();
|
| - ++i)
|
| - id_list->AppendString(*i);
|
| -
|
| - value->Set(kIdsKey, id_list);
|
| + value->SetInteger(kSignatureFormatVersionKey, kSignatureFormatVersion);
|
| + SetExtensionIdSet(value, kIdsKey, ids);
|
| + SetExtensionIdSet(value, kInvalidIdsKey, invalid_ids);
|
| value->SetString(kExpireDateKey, expire_date);
|
| std::string salt_base64;
|
| std::string signature_base64;
|
| @@ -144,6 +180,15 @@ scoped_ptr<InstallSignature> InstallSignature::FromValue(
|
|
|
| scoped_ptr<InstallSignature> result(new InstallSignature);
|
|
|
| + // For now we don't want to support any backwards compability, but in the
|
| + // future if we do, we would want to put the migration code here.
|
| + int format_version = 0;
|
| + if (!value.GetInteger(kSignatureFormatVersionKey, &format_version) ||
|
| + format_version != kSignatureFormatVersion) {
|
| + result.reset();
|
| + return result.Pass();
|
| + }
|
| +
|
| std::string salt_base64;
|
| std::string signature_base64;
|
| if (!value.GetString(kExpireDateKey, &result->expire_date) ||
|
| @@ -168,21 +213,12 @@ scoped_ptr<InstallSignature> InstallSignature::FromValue(
|
| result->timestamp = base::Time::FromInternalValue(timestamp_value);
|
| }
|
|
|
| - const base::ListValue* ids = NULL;
|
| - if (!value.GetList(kIdsKey, &ids)) {
|
| + if (!GetExtensionIdSet(value, kIdsKey, &result->ids) ||
|
| + !GetExtensionIdSet(value, kInvalidIdsKey, &result->invalid_ids)) {
|
| result.reset();
|
| return result.Pass();
|
| }
|
|
|
| - for (base::ListValue::const_iterator i = ids->begin(); i != ids->end(); ++i) {
|
| - std::string id;
|
| - if (!(*i)->GetAsString(&id)) {
|
| - result.reset();
|
| - return result.Pass();
|
| - }
|
| - result->ids.insert(id);
|
| - }
|
| -
|
| return result.Pass();
|
| }
|
|
|
| @@ -360,6 +396,7 @@ void InstallSigner::GetSignature(const SignatureCallback& callback) {
|
| url_fetcher_->SetUploadData("application/json", json);
|
| LogRequestStartHistograms();
|
| request_start_time_ = base::Time::Now();
|
| + VLOG(1) << "Sending request: " << json;
|
| url_fetcher_->Start();
|
| }
|
|
|
| @@ -384,6 +421,7 @@ void InstallSigner::ParseFetchResponse() {
|
| ReportErrorViaCallback();
|
| return;
|
| }
|
| + VLOG(1) << "Got response: " << response;
|
|
|
| // The response is JSON of the form:
|
| // {
|
| @@ -451,6 +489,7 @@ void InstallSigner::HandleSignatureResult(const std::string& signature,
|
| if (!signature.empty()) {
|
| result.reset(new InstallSignature);
|
| result->ids = valid_ids;
|
| + result->invalid_ids = invalid_ids;
|
| result->salt = salt_;
|
| result->signature = signature;
|
| result->expire_date = expire_date;
|
|
|