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

Side by Side Diff: net/tools/testserver/device_management.py

Issue 6880031: Merge server-side changes of the cloud policy protocol (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/proto/device_management_backend.proto ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.5 1 #!/usr/bin/python2.5
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A bare-bones test server for testing cloud policy support. 6 """A bare-bones test server for testing cloud policy support.
7 7
8 This implements a simple cloud policy test server that can be used to test 8 This implements a simple cloud policy test server that can be used to test
9 chrome's device management service client. The policy information is read from 9 chrome's device management service client. The policy information is read from
10 the file named device_management in the server's data directory. It contains 10 the file named device_management in the server's data directory. It contains
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 device_id = self.GetUniqueParam('deviceid') 170 device_id = self.GetUniqueParam('deviceid')
171 if not device_id: 171 if not device_id:
172 return (400, 'Missing device identifier') 172 return (400, 'Missing device identifier')
173 173
174 token_info = self._server.RegisterDevice(device_id, 174 token_info = self._server.RegisterDevice(device_id,
175 msg.machine_id, 175 msg.machine_id,
176 msg.type) 176 msg.type)
177 177
178 # Send back the reply. 178 # Send back the reply.
179 response = dm.DeviceManagementResponse() 179 response = dm.DeviceManagementResponse()
180 response.error = dm.DeviceManagementResponse.SUCCESS
181 response.register_response.device_management_token = ( 180 response.register_response.device_management_token = (
182 token_info['device_token']) 181 token_info['device_token'])
183 response.register_response.machine_name = token_info['machine_name'] 182 response.register_response.machine_name = token_info['machine_name']
184 183
185 self.DumpMessage('Response', response) 184 self.DumpMessage('Response', response)
186 185
187 return (200, response.SerializeToString()) 186 return (200, response.SerializeToString())
188 187
189 def ProcessUnregister(self, msg): 188 def ProcessUnregister(self, msg):
190 """Handles a register request. 189 """Handles a register request.
(...skipping 10 matching lines...) Expand all
201 # Check the management token. 200 # Check the management token.
202 token, response = self.CheckToken(); 201 token, response = self.CheckToken();
203 if not token: 202 if not token:
204 return response 203 return response
205 204
206 # Unregister the device. 205 # Unregister the device.
207 self._server.UnregisterDevice(token); 206 self._server.UnregisterDevice(token);
208 207
209 # Prepare and send the response. 208 # Prepare and send the response.
210 response = dm.DeviceManagementResponse() 209 response = dm.DeviceManagementResponse()
211 response.error = dm.DeviceManagementResponse.SUCCESS
212 response.unregister_response.CopyFrom(dm.DeviceUnregisterResponse()) 210 response.unregister_response.CopyFrom(dm.DeviceUnregisterResponse())
213 211
214 self.DumpMessage('Response', response) 212 self.DumpMessage('Response', response)
215 213
216 return (200, response.SerializeToString()) 214 return (200, response.SerializeToString())
217 215
218 def ProcessInitialPolicy(self, msg): 216 def ProcessInitialPolicy(self, msg):
219 """Handles a 'preregister policy' request. 217 """Handles a 'preregister policy' request.
220 218
221 Queries the list of managed users and responds the client if their user 219 Queries the list of managed users and responds the client if their user
(...skipping 18 matching lines...) Expand all
240 else: 238 else:
241 chrome_initial_settings.enrollment_provision = ( 239 chrome_initial_settings.enrollment_provision = (
242 dm.ChromeInitialSettingsProto.UNMANAGED); 240 dm.ChromeInitialSettingsProto.UNMANAGED);
243 241
244 policy_data = dm.PolicyData() 242 policy_data = dm.PolicyData()
245 policy_data.policy_type = msg.policy_type 243 policy_data.policy_type = msg.policy_type
246 policy_data.policy_value = chrome_initial_settings.SerializeToString() 244 policy_data.policy_value = chrome_initial_settings.SerializeToString()
247 245
248 # Prepare and send the response. 246 # Prepare and send the response.
249 response = dm.DeviceManagementResponse() 247 response = dm.DeviceManagementResponse()
250 response.error = dm.DeviceManagementResponse.SUCCESS
251 fetch_response = response.policy_response.response.add() 248 fetch_response = response.policy_response.response.add()
252 fetch_response.policy_data = ( 249 fetch_response.policy_data = (
253 policy_data.SerializeToString()) 250 policy_data.SerializeToString())
254 251
255 self.DumpMessage('Response', response) 252 self.DumpMessage('Response', response)
256 253
257 return (200, response.SerializeToString()) 254 return (200, response.SerializeToString())
258 255
259 def ProcessDevicePolicy(self, msg): 256 def ProcessDevicePolicy(self, msg):
260 """Handles a policy request that uses the deprecated protcol. 257 """Handles a policy request that uses the deprecated protcol.
261 TODO(gfeher): Remove this when we certainly don't need it. 258 TODO(gfeher): Remove this when we certainly don't need it.
262 259
263 Checks for authorization, encodes the policy into protobuf representation 260 Checks for authorization, encodes the policy into protobuf representation
264 and constructs the response. 261 and constructs the response.
265 262
266 Args: 263 Args:
267 msg: The DevicePolicyRequest message received from the client. 264 msg: The DevicePolicyRequest message received from the client.
268 265
269 Returns: 266 Returns:
270 A tuple of HTTP status code and response data to send to the client. 267 A tuple of HTTP status code and response data to send to the client.
271 """ 268 """
272 269
273 # Check the management token. 270 # Check the management token.
274 token, response = self.CheckToken() 271 token, response = self.CheckToken()
275 if not token: 272 if not token:
276 return response 273 return response
277 274
278 # Stuff the policy dictionary into a response message and send it back. 275 # Stuff the policy dictionary into a response message and send it back.
279 response = dm.DeviceManagementResponse() 276 response = dm.DeviceManagementResponse()
280 response.error = dm.DeviceManagementResponse.SUCCESS
281 response.policy_response.CopyFrom(dm.DevicePolicyResponse()) 277 response.policy_response.CopyFrom(dm.DevicePolicyResponse())
282 278
283 # Respond only if the client requested policy for the cros/device scope, 279 # Respond only if the client requested policy for the cros/device scope,
284 # since that's where chrome policy is supposed to live in. 280 # since that's where chrome policy is supposed to live in.
285 if msg.policy_scope == 'chromeos/device': 281 if msg.policy_scope == 'chromeos/device':
286 policy = self._server.policy['google/chromeos/user']['mandatory'] 282 policy = self._server.policy['google/chromeos/user']['mandatory']
287 setting = response.policy_response.setting.add() 283 setting = response.policy_response.setting.add()
288 setting.policy_key = 'chrome-policy' 284 setting.policy_key = 'chrome-policy'
289 policy_value = dm.GenericSetting() 285 policy_value = dm.GenericSetting()
290 for (key, value) in policy.iteritems(): 286 for (key, value) in policy.iteritems():
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 policy_data.request_token = token_info['device_token']; 478 policy_data.request_token = token_info['device_token'];
483 policy_data.policy_value = policy_value 479 policy_data.policy_value = policy_value
484 policy_data.machine_name = token_info['machine_name'] 480 policy_data.machine_name = token_info['machine_name']
485 if signing_key: 481 if signing_key:
486 policy_data.public_key_version = key_version 482 policy_data.public_key_version = key_version
487 policy_data.username = self._server.username 483 policy_data.username = self._server.username
488 policy_data.device_id = token_info['device_id'] 484 policy_data.device_id = token_info['device_id']
489 signed_data = policy_data.SerializeToString() 485 signed_data = policy_data.SerializeToString()
490 486
491 response = dm.DeviceManagementResponse() 487 response = dm.DeviceManagementResponse()
492 response.error = dm.DeviceManagementResponse.SUCCESS
493 fetch_response = response.policy_response.response.add() 488 fetch_response = response.policy_response.response.add()
494 fetch_response.policy_data = signed_data 489 fetch_response.policy_data = signed_data
495 if signing_key: 490 if signing_key:
496 fetch_response.policy_data_signature = ( 491 fetch_response.policy_data_signature = (
497 signing_key['private_key'].hashAndSign(signed_data).tostring()) 492 signing_key['private_key'].hashAndSign(signed_data).tostring())
498 if msg.public_key_version != key_version: 493 if msg.public_key_version != key_version:
499 fetch_response.new_public_key = signing_key['public_key'] 494 fetch_response.new_public_key = signing_key['public_key']
500 if req_key: 495 if req_key:
501 fetch_response.new_public_key_signature = ( 496 fetch_response.new_public_key_signature = (
502 req_key.hashAndSign(fetch_response.new_public_key).tostring()) 497 req_key.hashAndSign(fetch_response.new_public_key).tostring())
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 return self._registered_tokens.get(dmtoken, None) 650 return self._registered_tokens.get(dmtoken, None)
656 651
657 def UnregisterDevice(self, dmtoken): 652 def UnregisterDevice(self, dmtoken):
658 """Unregisters a device identified by the given DM token. 653 """Unregisters a device identified by the given DM token.
659 654
660 Args: 655 Args:
661 dmtoken: The device management token provided by the client. 656 dmtoken: The device management token provided by the client.
662 """ 657 """
663 if dmtoken in self._registered_tokens.keys(): 658 if dmtoken in self._registered_tokens.keys():
664 del self._registered_tokens[dmtoken] 659 del self._registered_tokens[dmtoken]
OLDNEW
« no previous file with comments | « chrome/browser/policy/proto/device_management_backend.proto ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698