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

Side by Side Diff: chromeos/network/onc/onc_utils.cc

Issue 11469026: Extending ONC validator's logging. Completing toplevel validation. (Closed) Base URL: http://git.chromium.org/chromium/src.git@add_error_handling_to_validator
Patch Set: Rebased. Created 8 years 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
« no previous file with comments | « chromeos/network/onc/onc_utils.h ('k') | chromeos/network/onc/onc_validator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chromeos/network/onc/onc_utils.h" 5 #include "chromeos/network/onc/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/logging.h" 9 #include "base/logging.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chromeos/network/network_event_log.h" 11 #include "chromeos/network/network_event_log.h"
12 #include "chromeos/network/onc/onc_constants.h" 12 #include "chromeos/network/onc/onc_constants.h"
13 #include "crypto/encryptor.h" 13 #include "crypto/encryptor.h"
14 #include "crypto/hmac.h" 14 #include "crypto/hmac.h"
15 #include "crypto/symmetric_key.h" 15 #include "crypto/symmetric_key.h"
16 16
17 #define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message) 17 #define ONC_LOG_WARNING(message) NET_LOG_WARNING("ONC", message)
18 #define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message) 18 #define ONC_LOG_ERROR(message) NET_LOG_ERROR("ONC", message)
19 19
20 namespace chromeos { 20 namespace chromeos {
21 namespace onc { 21 namespace onc {
22 22
23 namespace { 23 namespace {
24 24
25 const char kUnableToDecrypt[] = "Unable to decrypt encrypted ONC"; 25 const char kUnableToDecrypt[] = "Unable to decrypt encrypted ONC";
26 const char kUnableToDecode[] = "Unable to decode encrypted ONC"; 26 const char kUnableToDecode[] = "Unable to decode encrypted ONC";
27 27
28 } // namespace 28 } // namespace
29 29
30 const char kEmptyUnencryptedConfiguration[] =
31 "{\"Type\":\"UnencryptedConfiguration\",\"NetworkConfigurations\":[],"
32 "\"Certificates\":[]}";
33
30 scoped_ptr<base::DictionaryValue> ReadDictionaryFromJson( 34 scoped_ptr<base::DictionaryValue> ReadDictionaryFromJson(
31 const std::string& json) { 35 const std::string& json) {
32 std::string error; 36 std::string error;
33 base::Value* root = base::JSONReader::ReadAndReturnError( 37 base::Value* root = base::JSONReader::ReadAndReturnError(
34 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); 38 json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
35 39
36 base::DictionaryValue* dict_ptr = NULL; 40 base::DictionaryValue* dict_ptr = NULL;
37 if (!root || !root->GetAsDictionary(&dict_ptr)) { 41 if (!root || !root->GetAsDictionary(&dict_ptr)) {
38 ONC_LOG_ERROR("Invalid JSON Dictionary: " + error); 42 ONC_LOG_ERROR("Invalid JSON Dictionary: " + error);
39 delete root; 43 delete root;
(...skipping 17 matching lines...) Expand all
57 std::string ciphertext; 61 std::string ciphertext;
58 62
59 if (!root.GetString(encrypted::kCiphertext, &ciphertext) || 63 if (!root.GetString(encrypted::kCiphertext, &ciphertext) ||
60 !root.GetString(encrypted::kCipher, &cipher) || 64 !root.GetString(encrypted::kCipher, &cipher) ||
61 !root.GetString(encrypted::kHMAC, &hmac) || 65 !root.GetString(encrypted::kHMAC, &hmac) ||
62 !root.GetString(encrypted::kHMACMethod, &hmac_method) || 66 !root.GetString(encrypted::kHMACMethod, &hmac_method) ||
63 !root.GetString(encrypted::kIV, &initial_vector) || 67 !root.GetString(encrypted::kIV, &initial_vector) ||
64 !root.GetInteger(encrypted::kIterations, &iterations) || 68 !root.GetInteger(encrypted::kIterations, &iterations) ||
65 !root.GetString(encrypted::kSalt, &salt) || 69 !root.GetString(encrypted::kSalt, &salt) ||
66 !root.GetString(encrypted::kStretch, &stretch_method) || 70 !root.GetString(encrypted::kStretch, &stretch_method) ||
67 !root.GetString(encrypted::kType, &onc_type) || 71 !root.GetString(kType, &onc_type) ||
68 onc_type != kEncryptedConfiguration) { 72 onc_type != kEncryptedConfiguration) {
69 73
70 ONC_LOG_ERROR("Encrypted ONC malformed."); 74 ONC_LOG_ERROR("Encrypted ONC malformed.");
71 return scoped_ptr<base::DictionaryValue>(); 75 return scoped_ptr<base::DictionaryValue>();
72 } 76 }
73 77
74 if (hmac_method != encrypted::kSHA1 || 78 if (hmac_method != encrypted::kSHA1 ||
75 cipher != encrypted::kAES256 || 79 cipher != encrypted::kAES256 ||
76 stretch_method != encrypted::kPBKDF2) { 80 stretch_method != encrypted::kPBKDF2) {
77 ONC_LOG_ERROR("Encrypted ONC unsupported encryption scheme."); 81 ONC_LOG_ERROR("Encrypted ONC unsupported encryption scheme.");
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return "none"; 159 return "none";
156 case ONC_SOURCE_USER_IMPORT: 160 case ONC_SOURCE_USER_IMPORT:
157 return "user import"; 161 return "user import";
158 } 162 }
159 NOTREACHED() << "unknown ONC source " << source; 163 NOTREACHED() << "unknown ONC source " << source;
160 return "unknown"; 164 return "unknown";
161 } 165 }
162 166
163 } // chromeos 167 } // chromeos
164 } // onc 168 } // onc
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_utils.h ('k') | chromeos/network/onc/onc_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698