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

Side by Side Diff: chrome/browser/policy/test/local_policy_test_server.cc

Issue 2530023002: Fix policy test server key rotation feature (Closed)
Patch Set: Rename, add comments Created 4 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/policy/test/local_policy_test_server.h" 5 #include "chrome/browser/policy/test/local_policy_test_server.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/base_paths.h" 13 #include "base/base_paths.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/json/json_writer.h" 15 #include "base/json/json_writer.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/values.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
20 #include "crypto/rsa_private_key.h" 21 #include "crypto/rsa_private_key.h"
21 #include "net/test/python_utils.h" 22 #include "net/test/python_utils.h"
22 23
23 namespace policy { 24 namespace policy {
24 25
25 namespace { 26 namespace {
26 27
27 // Filename in the temporary directory storing the policy data. 28 // Filename in the temporary directory storing the policy data.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 base::FilePath signature_file = 108 base::FilePath signature_file =
108 server_data_dir_.GetPath().Append(kSigningKeySignatureFileName); 109 server_data_dir_.GetPath().Append(kSigningKeySignatureFileName);
109 bytes_written = base::WriteFile( 110 bytes_written = base::WriteFile(
110 signature_file, 111 signature_file,
111 signature.c_str(), 112 signature.c_str(),
112 signature.size()); 113 signature.size());
113 114
114 return bytes_written == static_cast<int>(signature.size()); 115 return bytes_written == static_cast<int>(signature.size());
115 } 116 }
116 117
118 void LocalPolicyTestServer::EnableAutomaticRotationOfSigningKeys() {
119 automatic_rotation_of_signing_keys_enabled_ = true;
120 }
121
117 void LocalPolicyTestServer::RegisterClient(const std::string& dm_token, 122 void LocalPolicyTestServer::RegisterClient(const std::string& dm_token,
118 const std::string& device_id) { 123 const std::string& device_id) {
119 CHECK(server_data_dir_.IsValid()); 124 CHECK(server_data_dir_.IsValid());
120 125
121 std::unique_ptr<base::DictionaryValue> client_dict( 126 std::unique_ptr<base::DictionaryValue> client_dict(
122 new base::DictionaryValue()); 127 new base::DictionaryValue());
123 client_dict->SetString(kClientStateKeyDeviceId, device_id); 128 client_dict->SetString(kClientStateKeyDeviceId, device_id);
124 client_dict->SetString(kClientStateKeyDeviceToken, dm_token); 129 client_dict->SetString(kClientStateKeyDeviceToken, dm_token);
125 client_dict->SetString(kClientStateKeyMachineName, std::string()); 130 client_dict->SetString(kClientStateKeyMachineName, std::string());
126 client_dict->SetString(kClientStateKeyMachineId, std::string()); 131 client_dict->SetString(kClientStateKeyMachineId, std::string());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 235 }
231 236
232 bool LocalPolicyTestServer::GenerateAdditionalArguments( 237 bool LocalPolicyTestServer::GenerateAdditionalArguments(
233 base::DictionaryValue* arguments) const { 238 base::DictionaryValue* arguments) const {
234 if (!net::LocalTestServer::GenerateAdditionalArguments(arguments)) 239 if (!net::LocalTestServer::GenerateAdditionalArguments(arguments))
235 return false; 240 return false;
236 241
237 arguments->SetString("config-file", config_file_.AsUTF8Unsafe()); 242 arguments->SetString("config-file", config_file_.AsUTF8Unsafe());
238 if (!policy_key_.empty()) 243 if (!policy_key_.empty())
239 arguments->SetString("policy-key", policy_key_.AsUTF8Unsafe()); 244 arguments->SetString("policy-key", policy_key_.AsUTF8Unsafe());
245 if (automatic_rotation_of_signing_keys_enabled_) {
246 arguments->Set("rotate-policy-keys-automatically",
247 base::Value::CreateNullValue());
248 }
240 if (server_data_dir_.IsValid()) { 249 if (server_data_dir_.IsValid()) {
241 arguments->SetString("data-dir", server_data_dir_.GetPath().AsUTF8Unsafe()); 250 arguments->SetString("data-dir", server_data_dir_.GetPath().AsUTF8Unsafe());
242 251
243 if (!clients_.empty()) { 252 if (!clients_.empty()) {
244 std::string json; 253 std::string json;
245 base::JSONWriter::Write(clients_, &json); 254 base::JSONWriter::Write(clients_, &json);
246 base::FilePath client_state_file = 255 base::FilePath client_state_file =
247 server_data_dir_.GetPath().Append(kClientStateFileName); 256 server_data_dir_.GetPath().Append(kClientStateFileName);
248 if (base::WriteFile(client_state_file, json.c_str(), json.size()) != 257 if (base::WriteFile(client_state_file, json.c_str(), json.size()) !=
249 static_cast<int>(json.size())) { 258 static_cast<int>(json.size())) {
250 return false; 259 return false;
251 } 260 }
252 arguments->SetString("client-state", client_state_file.AsUTF8Unsafe()); 261 arguments->SetString("client-state", client_state_file.AsUTF8Unsafe());
253 } 262 }
254 } 263 }
255 264
256 return true; 265 return true;
257 } 266 }
258 267
259 std::string LocalPolicyTestServer::GetSelector(const std::string& type, 268 std::string LocalPolicyTestServer::GetSelector(const std::string& type,
260 const std::string& entity_id) { 269 const std::string& entity_id) {
261 std::string selector = type; 270 std::string selector = type;
262 if (!entity_id.empty()) 271 if (!entity_id.empty())
263 selector = base::StringPrintf("%s/%s", type.c_str(), entity_id.c_str()); 272 selector = base::StringPrintf("%s/%s", type.c_str(), entity_id.c_str());
264 std::replace_if(selector.begin(), selector.end(), IsUnsafeCharacter, '_'); 273 std::replace_if(selector.begin(), selector.end(), IsUnsafeCharacter, '_');
265 return selector; 274 return selector;
266 } 275 }
267 276
268 } // namespace policy 277 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/test/local_policy_test_server.h ('k') | chrome/browser/policy/test/policy_testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698