Chromium Code Reviews| Index: chromeos/network/onc/onc_utils.cc |
| diff --git a/chrome/browser/chromeos/network_settings/onc_utils.cc b/chromeos/network/onc/onc_utils.cc |
| similarity index 70% |
| rename from chrome/browser/chromeos/network_settings/onc_utils.cc |
| rename to chromeos/network/onc/onc_utils.cc |
| index 9b57cbe97dafd4aeaff16cd65906b443781dba6d..49237caf8d6d13b72196b9b5c418949ede9138c3 100644 |
| --- a/chrome/browser/chromeos/network_settings/onc_utils.cc |
| +++ b/chromeos/network/onc/onc_utils.cc |
| @@ -2,21 +2,33 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/chromeos/network_settings/onc_utils.h" |
| +#include "chromeos/network/onc/onc_utils.h" |
| #include "base/base64.h" |
| #include "base/json/json_reader.h" |
| #include "base/values.h" |
| -#include "chrome/browser/chromeos/cros/onc_constants.h" |
| +#include "chromeos/network/onc/onc_constants.h" |
| #include "crypto/encryptor.h" |
| #include "crypto/hmac.h" |
| #include "crypto/symmetric_key.h" |
| -#include "grit/generated_resources.h" |
| -#include "ui/base/l10n/l10n_util.h" |
| namespace chromeos { |
| namespace onc { |
| +const char kResultSuccess[] = "Success"; |
| +const char kErrorNotAJsonDictionary[] = "Not a JSON dictionary"; |
| +const char kErrorEncryptedOncMalformed[] = "Encrypted ONC malformed"; |
| +const char kErrorEncryptedOncUnsupportedEncryption[] = |
| + "Encrypted ONC unsupported encryption"; |
| +const char kErrorEncryptedOncUnableToDecrypt[] = |
| + "Encrypted ONC unable to decrypt"; |
| +const char kErrorEncryptedOncTooManyIterations[] = |
| + "Encrypted ONC too many iterations"; |
| +const char kErrorEncryptedOncUnableToDecode[] = |
| + "Encrypted ONC unable to decode"; |
| +const char kErrorPropertyDictionaryMalformed[] = |
| + "Property dictionary malformed"; |
| + |
| scoped_ptr<base::DictionaryValue> ReadDictionaryFromJson( |
| const std::string& json, |
| std::string* error) { |
| @@ -25,13 +37,13 @@ scoped_ptr<base::DictionaryValue> ReadDictionaryFromJson( |
| base::DictionaryValue* dict_ptr = NULL; |
| if (root != NULL && !root->GetAsDictionary(&dict_ptr)) { |
| - if (error) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_NETWORK_NOT_A_JSON_DICTIONARY); |
| - } |
| + if (error) |
| + *error = kErrorNotAJsonDictionary; |
| delete root; |
| } |
| + if (error) |
| + *error = kResultSuccess; |
| return make_scoped_ptr(dict_ptr); |
| } |
| @@ -60,37 +72,37 @@ scoped_ptr<base::DictionaryValue> Decrypt(const std::string& passphrase, |
| !root.GetString(encrypted::kStretch, &stretch_method) || |
| !root.GetString(encrypted::kType, &onc_type) || |
| onc_type != kEncryptedConfiguration) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_MALFORMED); |
| + if (error) |
| + *error = kErrorEncryptedOncMalformed; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| if (hmac_method != encrypted::kSHA1 || |
| cipher != encrypted::kAES256 || |
| stretch_method != encrypted::kPBKDF2) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNSUPPORTED_ENCRYPTION); |
| + if (error) |
| + *error = kErrorEncryptedOncUnsupportedEncryption; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| // Make sure iterations != 0, since that's not valid. |
| if (iterations == 0) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECRYPT); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecrypt; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| // Simply a sanity check to make sure we can't lock up the machine |
| // for too long with a huge number (or a negative number). |
| if (iterations < 0 || iterations > kMaxIterationCount) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_TOO_MANY_ITERATIONS); |
| + if (error) |
| + *error = kErrorEncryptedOncTooManyIterations; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| if (!base::Base64Decode(salt, &salt)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECODE); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecode; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| @@ -102,49 +114,52 @@ scoped_ptr<base::DictionaryValue> Decrypt(const std::string& passphrase, |
| kKeySizeInBits)); |
| if (!base::Base64Decode(initial_vector, &initial_vector)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECODE); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecode; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| if (!base::Base64Decode(ciphertext, &ciphertext)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECODE); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecode; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| if (!base::Base64Decode(hmac, &hmac)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECODE); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecode; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| crypto::HMAC hmac_verifier(crypto::HMAC::SHA1); |
| if (!hmac_verifier.Init(key.get()) || |
| !hmac_verifier.Verify(ciphertext, hmac)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECRYPT); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecrypt; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| crypto::Encryptor decryptor; |
| if (!decryptor.Init(key.get(), crypto::Encryptor::CBC, initial_vector)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECRYPT); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecrypt; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| std::string plaintext; |
| if (!decryptor.Decrypt(ciphertext, &plaintext)) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_UNABLE_TO_DECRYPT); |
| + if (error) |
| + *error = kErrorEncryptedOncUnableToDecrypt; |
| return scoped_ptr<base::DictionaryValue>(); |
| } |
| scoped_ptr<base::DictionaryValue> new_root = |
| ReadDictionaryFromJson(plaintext, error); |
| if (new_root.get() == NULL && error->empty()) { |
| - *error = l10n_util::GetStringUTF8( |
| - IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
| + if (error) |
| + *error = kErrorPropertyDictionaryMalformed; |
|
pneubeck (no reviews)
2012/12/04 10:43:56
If we go on using prefixes for the constants, than
Greg Spencer (Chromium)
2012/12/07 18:12:27
Constant went away.
|
| } |
| + |
| + if (error) |
| + *error = kResultSuccess; |
|
pneubeck (no reviews)
2012/12/04 10:43:56
That overwrites the json error, as there is no ret
Greg Spencer (Chromium)
2012/12/07 18:12:27
good catch. Added return from last if.
|
| return new_root.Pass(); |
| } |