| OLD | NEW |
| 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/chromeos/network_settings/onc_utils.h" | 5 #include "chrome/browser/chromeos/network_settings/onc_utils.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/cros/onc_constants.h" | 10 #include "chrome/browser/chromeos/cros/onc_constants.h" |
| 11 #include "crypto/encryptor.h" | 11 #include "crypto/encryptor.h" |
| 12 #include "crypto/hmac.h" | 12 #include "crypto/hmac.h" |
| 13 #include "crypto/symmetric_key.h" | 13 #include "crypto/symmetric_key.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 namespace onc { | 18 namespace onc { |
| 19 | 19 |
| 20 const char kEmptyUnencryptedConfiguration[] = |
| 21 "{\"Type\":\"UnencryptedConfiguration\",\"NetworkConfigurations\":[]," |
| 22 "\"Certificates\":[]}"; |
| 23 |
| 20 scoped_ptr<base::DictionaryValue> ReadDictionaryFromJson( | 24 scoped_ptr<base::DictionaryValue> ReadDictionaryFromJson( |
| 21 const std::string& json, | 25 const std::string& json, |
| 22 std::string* error) { | 26 std::string* error) { |
| 23 base::Value* root = base::JSONReader::ReadAndReturnError( | 27 base::Value* root = base::JSONReader::ReadAndReturnError( |
| 24 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, error); | 28 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, error); |
| 25 | 29 |
| 26 base::DictionaryValue* dict_ptr = NULL; | 30 base::DictionaryValue* dict_ptr = NULL; |
| 27 if (root != NULL && !root->GetAsDictionary(&dict_ptr)) { | 31 if (root != NULL && !root->GetAsDictionary(&dict_ptr)) { |
| 28 if (error) { | 32 if (error) { |
| 29 *error = l10n_util::GetStringUTF8( | 33 *error = l10n_util::GetStringUTF8( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 51 std::string ciphertext; | 55 std::string ciphertext; |
| 52 | 56 |
| 53 if (!root.GetString(encrypted::kCiphertext, &ciphertext) || | 57 if (!root.GetString(encrypted::kCiphertext, &ciphertext) || |
| 54 !root.GetString(encrypted::kCipher, &cipher) || | 58 !root.GetString(encrypted::kCipher, &cipher) || |
| 55 !root.GetString(encrypted::kHMAC, &hmac) || | 59 !root.GetString(encrypted::kHMAC, &hmac) || |
| 56 !root.GetString(encrypted::kHMACMethod, &hmac_method) || | 60 !root.GetString(encrypted::kHMACMethod, &hmac_method) || |
| 57 !root.GetString(encrypted::kIV, &initial_vector) || | 61 !root.GetString(encrypted::kIV, &initial_vector) || |
| 58 !root.GetInteger(encrypted::kIterations, &iterations) || | 62 !root.GetInteger(encrypted::kIterations, &iterations) || |
| 59 !root.GetString(encrypted::kSalt, &salt) || | 63 !root.GetString(encrypted::kSalt, &salt) || |
| 60 !root.GetString(encrypted::kStretch, &stretch_method) || | 64 !root.GetString(encrypted::kStretch, &stretch_method) || |
| 61 !root.GetString(encrypted::kType, &onc_type) || | 65 !root.GetString(kType, &onc_type) || |
| 62 onc_type != kEncryptedConfiguration) { | 66 onc_type != kEncryptedConfiguration) { |
| 63 *error = l10n_util::GetStringUTF8( | 67 *error = l10n_util::GetStringUTF8( |
| 64 IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_MALFORMED); | 68 IDS_NETWORK_CONFIG_ERROR_ENCRYPTED_ONC_MALFORMED); |
| 65 return scoped_ptr<base::DictionaryValue>(); | 69 return scoped_ptr<base::DictionaryValue>(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 if (hmac_method != encrypted::kSHA1 || | 72 if (hmac_method != encrypted::kSHA1 || |
| 69 cipher != encrypted::kAES256 || | 73 cipher != encrypted::kAES256 || |
| 70 stretch_method != encrypted::kPBKDF2) { | 74 stretch_method != encrypted::kPBKDF2) { |
| 71 *error = l10n_util::GetStringUTF8( | 75 *error = l10n_util::GetStringUTF8( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ReadDictionaryFromJson(plaintext, error); | 147 ReadDictionaryFromJson(plaintext, error); |
| 144 if (new_root.get() == NULL && error->empty()) { | 148 if (new_root.get() == NULL && error->empty()) { |
| 145 *error = l10n_util::GetStringUTF8( | 149 *error = l10n_util::GetStringUTF8( |
| 146 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); | 150 IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); |
| 147 } | 151 } |
| 148 return new_root.Pass(); | 152 return new_root.Pass(); |
| 149 } | 153 } |
| 150 | 154 |
| 151 } // chromeos | 155 } // chromeos |
| 152 } // onc | 156 } // onc |
| OLD | NEW |