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 """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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 """ | 55 """ |
56 | 56 |
57 import base64 | 57 import base64 |
58 import BaseHTTPServer | 58 import BaseHTTPServer |
59 import cgi | 59 import cgi |
60 import glob | 60 import glob |
61 import google.protobuf.text_format | 61 import google.protobuf.text_format |
62 import hashlib | 62 import hashlib |
| 63 import json |
63 import logging | 64 import logging |
64 import os | 65 import os |
65 import random | 66 import random |
66 import re | 67 import re |
67 import sys | 68 import sys |
68 import time | 69 import time |
69 import tlslite | 70 import tlslite |
70 import tlslite.api | 71 import tlslite.api |
71 import tlslite.utils | 72 import tlslite.utils |
72 import tlslite.utils.cryptomath | 73 import tlslite.utils.cryptomath |
73 import urlparse | 74 import urlparse |
74 | 75 |
75 # The name and availability of the json module varies in python versions. | |
76 try: | |
77 import simplejson as json | |
78 except ImportError: | |
79 try: | |
80 import json | |
81 except ImportError: | |
82 logging.error('Could not import json') | |
83 json = None | |
84 | |
85 import asn1der | 76 import asn1der |
86 import testserver_base | 77 import testserver_base |
87 | 78 |
88 import device_management_backend_pb2 as dm | 79 import device_management_backend_pb2 as dm |
89 import cloud_policy_pb2 as cp | 80 import cloud_policy_pb2 as cp |
90 | 81 |
91 # Policy for extensions is not supported on Android nor iOS. | 82 # Policy for extensions is not supported on Android nor iOS. |
92 try: | 83 try: |
93 import chrome_extension_policy_pb2 as ep | 84 import chrome_extension_policy_pb2 as ep |
94 except ImportError: | 85 except ImportError: |
95 logging.error('Could not import chrome_extension_policy_pb2') | |
96 ep = None | 86 ep = None |
97 | 87 |
98 # Device policy is only available on Chrome OS builds. | 88 # Device policy is only available on Chrome OS builds. |
99 try: | 89 try: |
100 import chrome_device_policy_pb2 as dp | 90 import chrome_device_policy_pb2 as dp |
101 except ImportError: | 91 except ImportError: |
102 logging.error('Could not import chrome_device_policy_pb2') | |
103 dp = None | 92 dp = None |
104 | 93 |
105 # ASN.1 object identifier for PKCS#1/RSA. | 94 # ASN.1 object identifier for PKCS#1/RSA. |
106 PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01' | 95 PKCS1_RSA_OID = '\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01' |
107 | 96 |
108 # List of bad machine identifiers that trigger the |valid_serial_number_missing| | 97 # List of bad machine identifiers that trigger the |valid_serial_number_missing| |
109 # flag to be set set in the policy fetch response. | 98 # flag to be set set in the policy fetch response. |
110 BAD_MACHINE_IDS = [ '123490EN400015' ] | 99 BAD_MACHINE_IDS = [ '123490EN400015' ] |
111 | 100 |
112 # List of machines that trigger the server to send kiosk enrollment response | 101 # List of machines that trigger the server to send kiosk enrollment response |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 if msg.policy_type in ('google/android/user', | 732 if msg.policy_type in ('google/android/user', |
744 'google/chromeos/publicaccount', | 733 'google/chromeos/publicaccount', |
745 'google/chromeos/user', | 734 'google/chromeos/user', |
746 'google/chrome/user', | 735 'google/chrome/user', |
747 'google/ios/user'): | 736 'google/ios/user'): |
748 settings = cp.CloudPolicySettings() | 737 settings = cp.CloudPolicySettings() |
749 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) | 738 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) |
750 if payload is None: | 739 if payload is None: |
751 self.GatherUserPolicySettings(settings, policy.get(policy_key, {})) | 740 self.GatherUserPolicySettings(settings, policy.get(policy_key, {})) |
752 payload = settings.SerializeToString() | 741 payload = settings.SerializeToString() |
753 elif dp is not None and msg.policy_type == 'google/chromeos/device': | 742 elif msg.policy_type == 'google/chromeos/device': |
754 settings = dp.ChromeDeviceSettingsProto() | 743 settings = dp.ChromeDeviceSettingsProto() |
755 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) | 744 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) |
756 if payload is None: | 745 if payload is None: |
757 self.GatherDevicePolicySettings(settings, policy.get(policy_key, {})) | 746 self.GatherDevicePolicySettings(settings, policy.get(policy_key, {})) |
758 payload = settings.SerializeToString() | 747 payload = settings.SerializeToString() |
759 elif ep is not None and msg.policy_type == 'google/chrome/extension': | 748 elif msg.policy_type == 'google/chrome/extension': |
760 settings = ep.ExternalPolicyData() | 749 settings = ep.ExternalPolicyData() |
761 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) | 750 payload = self.server.ReadPolicyFromDataDir(policy_key, settings) |
762 if payload is None: | 751 if payload is None: |
763 payload = self.CreatePolicyForExternalPolicyData(policy_key) | 752 payload = self.CreatePolicyForExternalPolicyData(policy_key) |
764 else: | 753 else: |
765 response.error_code = 400 | 754 response.error_code = 400 |
766 response.error_message = 'Invalid policy type' | 755 response.error_message = 'Invalid policy type' |
767 return | 756 return |
768 else: | 757 else: |
769 response.error_code = 400 | 758 response.error_code = 400 |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 if (self.options.log_to_console): | 1276 if (self.options.log_to_console): |
1288 logger.addHandler(logging.StreamHandler()) | 1277 logger.addHandler(logging.StreamHandler()) |
1289 if (self.options.log_file): | 1278 if (self.options.log_file): |
1290 logger.addHandler(logging.FileHandler(self.options.log_file)) | 1279 logger.addHandler(logging.FileHandler(self.options.log_file)) |
1291 | 1280 |
1292 testserver_base.TestServerRunner.run_server(self) | 1281 testserver_base.TestServerRunner.run_server(self) |
1293 | 1282 |
1294 | 1283 |
1295 if __name__ == '__main__': | 1284 if __name__ == '__main__': |
1296 sys.exit(PolicyServerRunner().main()) | 1285 sys.exit(PolicyServerRunner().main()) |
OLD | NEW |