| OLD | NEW |
| 1 # Copyright (c) 2011 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 """A bare-bones test server for testing cloud policy support. | 5 """A bare-bones test server for testing cloud policy support. |
| 6 | 6 |
| 7 This implements a simple cloud policy test server that can be used to test | 7 This implements a simple cloud policy test server that can be used to test |
| 8 chrome's device management service client. The policy information is read from | 8 chrome's device management service client. The policy information is read from |
| 9 the file named device_management in the server's data directory. It contains | 9 the file named device_management in the server's data directory. It contains |
| 10 enforced and recommended policies for the device and user scope, and a list | 10 enforced and recommended policies for the device and user scope, and a list |
| 11 of managed users. | 11 of managed users. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 # ASN.1 object identifier for PKCS#1/RSA. | 72 # ASN.1 object identifier for PKCS#1/RSA. |
| 73 PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01' | 73 PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01' |
| 74 | 74 |
| 75 # SHA256 sum of "0". | 75 # SHA256 sum of "0". |
| 76 SHA256_0 = hashlib.sha256('0').digest() | 76 SHA256_0 = hashlib.sha256('0').digest() |
| 77 | 77 |
| 78 # List of bad machine identifiers that trigger the |valid_serial_number_missing| | 78 # List of bad machine identifiers that trigger the |valid_serial_number_missing| |
| 79 # flag to be set set in the policy fetch response. | 79 # flag to be set set in the policy fetch response. |
| 80 BAD_MACHINE_IDS = [ '123490EN400015' ]; | 80 BAD_MACHINE_IDS = [ '123490EN400015' ]; |
| 81 | 81 |
| 82 # List of machines that trigger the server to send kiosk enrollment response |
| 83 # for the register request. |
| 84 KIOSK_MACHINE_IDS = [ 'KIOSK' ]; |
| 85 |
| 82 class RequestHandler(object): | 86 class RequestHandler(object): |
| 83 """Decodes and handles device management requests from clients. | 87 """Decodes and handles device management requests from clients. |
| 84 | 88 |
| 85 The handler implements all the request parsing and protobuf message decoding | 89 The handler implements all the request parsing and protobuf message decoding |
| 86 and encoding. It calls back into the server to lookup, register, and | 90 and encoding. It calls back into the server to lookup, register, and |
| 87 unregister clients. | 91 unregister clients. |
| 88 """ | 92 """ |
| 89 | 93 |
| 90 def __init__(self, server, path, headers, request): | 94 def __init__(self, server, path, headers, request): |
| 91 """Initialize the handler. | 95 """Initialize the handler. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 206 |
| 203 token_info = self._server.RegisterDevice(device_id, | 207 token_info = self._server.RegisterDevice(device_id, |
| 204 msg.machine_id, | 208 msg.machine_id, |
| 205 msg.type) | 209 msg.type) |
| 206 | 210 |
| 207 # Send back the reply. | 211 # Send back the reply. |
| 208 response = dm.DeviceManagementResponse() | 212 response = dm.DeviceManagementResponse() |
| 209 response.register_response.device_management_token = ( | 213 response.register_response.device_management_token = ( |
| 210 token_info['device_token']) | 214 token_info['device_token']) |
| 211 response.register_response.machine_name = token_info['machine_name'] | 215 response.register_response.machine_name = token_info['machine_name'] |
| 216 response.register_response.enrollment_type = token_info['enrollment_mode'] |
| 212 | 217 |
| 213 self.DumpMessage('Response', response) | 218 self.DumpMessage('Response', response) |
| 214 | 219 |
| 215 return (200, response.SerializeToString()) | 220 return (200, response.SerializeToString()) |
| 216 | 221 |
| 217 def ProcessUnregister(self, msg): | 222 def ProcessUnregister(self, msg): |
| 218 """Handles a register request. | 223 """Handles a register request. |
| 219 | 224 |
| 220 Checks for authorization, unregisters the device and constructs the | 225 Checks for authorization, unregisters the device and constructs the |
| 221 response. | 226 response. |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 """ | 598 """ |
| 594 dmtoken_chars = [] | 599 dmtoken_chars = [] |
| 595 while len(dmtoken_chars) < 32: | 600 while len(dmtoken_chars) < 32: |
| 596 dmtoken_chars.append(random.choice('0123456789abcdef')) | 601 dmtoken_chars.append(random.choice('0123456789abcdef')) |
| 597 dmtoken = ''.join(dmtoken_chars) | 602 dmtoken = ''.join(dmtoken_chars) |
| 598 allowed_policy_types = { | 603 allowed_policy_types = { |
| 599 dm.DeviceRegisterRequest.USER: ['google/chromeos/user'], | 604 dm.DeviceRegisterRequest.USER: ['google/chromeos/user'], |
| 600 dm.DeviceRegisterRequest.DEVICE: ['google/chromeos/device'], | 605 dm.DeviceRegisterRequest.DEVICE: ['google/chromeos/device'], |
| 601 dm.DeviceRegisterRequest.TT: ['google/chromeos/user'], | 606 dm.DeviceRegisterRequest.TT: ['google/chromeos/user'], |
| 602 } | 607 } |
| 608 if machine_id in KIOSK_MACHINE_IDS: |
| 609 enrollment_mode = dm.DeviceRegisterResponse.KIOSK |
| 610 else: |
| 611 enrollment_mode = dm.DeviceRegisterResponse.ENTERPRISE |
| 603 self._registered_tokens[dmtoken] = { | 612 self._registered_tokens[dmtoken] = { |
| 604 'device_id': device_id, | 613 'device_id': device_id, |
| 605 'device_token': dmtoken, | 614 'device_token': dmtoken, |
| 606 'allowed_policy_types': allowed_policy_types[type], | 615 'allowed_policy_types': allowed_policy_types[type], |
| 607 'machine_name': 'chromeos-' + machine_id, | 616 'machine_name': 'chromeos-' + machine_id, |
| 608 'machine_id': machine_id, | 617 'machine_id': machine_id, |
| 618 'enrollment_mode': enrollment_mode, |
| 609 } | 619 } |
| 610 return self._registered_tokens[dmtoken] | 620 return self._registered_tokens[dmtoken] |
| 611 | 621 |
| 612 def UpdateMachineId(self, dmtoken, machine_id): | 622 def UpdateMachineId(self, dmtoken, machine_id): |
| 613 """Updates the machine identifier for a registered device. | 623 """Updates the machine identifier for a registered device. |
| 614 | 624 |
| 615 Args: | 625 Args: |
| 616 dmtoken: The device management token provided by the client. | 626 dmtoken: The device management token provided by the client. |
| 617 machine_id: Updated hardware identifier value. | 627 machine_id: Updated hardware identifier value. |
| 618 """ | 628 """ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 632 return self._registered_tokens.get(dmtoken, None) | 642 return self._registered_tokens.get(dmtoken, None) |
| 633 | 643 |
| 634 def UnregisterDevice(self, dmtoken): | 644 def UnregisterDevice(self, dmtoken): |
| 635 """Unregisters a device identified by the given DM token. | 645 """Unregisters a device identified by the given DM token. |
| 636 | 646 |
| 637 Args: | 647 Args: |
| 638 dmtoken: The device management token provided by the client. | 648 dmtoken: The device management token provided by the client. |
| 639 """ | 649 """ |
| 640 if dmtoken in self._registered_tokens.keys(): | 650 if dmtoken in self._registered_tokens.keys(): |
| 641 del self._registered_tokens[dmtoken] | 651 del self._registered_tokens[dmtoken] |
| OLD | NEW |