1*1a96fba6SXin Li // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be 3*1a96fba6SXin Li // found in the LICENSE file. 4*1a96fba6SXin Li 5*1a96fba6SXin Li #ifndef LIBBRILLO_POLICY_DEVICE_POLICY_H_ 6*1a96fba6SXin Li #define LIBBRILLO_POLICY_DEVICE_POLICY_H_ 7*1a96fba6SXin Li 8*1a96fba6SXin Li #include <stdint.h> 9*1a96fba6SXin Li 10*1a96fba6SXin Li #include <set> 11*1a96fba6SXin Li #include <string> 12*1a96fba6SXin Li #include <utility> 13*1a96fba6SXin Li #include <vector> 14*1a96fba6SXin Li 15*1a96fba6SXin Li #include <base/macros.h> 16*1a96fba6SXin Li #include <base/time/time.h> 17*1a96fba6SXin Li 18*1a96fba6SXin Li #pragma GCC visibility push(default) 19*1a96fba6SXin Li 20*1a96fba6SXin Li namespace policy { 21*1a96fba6SXin Li 22*1a96fba6SXin Li // This class holds device settings that are to be enforced across all users. 23*1a96fba6SXin Li // It is also responsible for loading the policy blob from disk and verifying 24*1a96fba6SXin Li // the signature against the owner's key. 25*1a96fba6SXin Li // 26*1a96fba6SXin Li // This class defines the interface for querying device policy on ChromeOS. 27*1a96fba6SXin Li // The implementation is hidden in DevicePolicyImpl to prevent protobuf 28*1a96fba6SXin Li // definition from leaking into the libraries using this interface. 29*1a96fba6SXin Li class DevicePolicy { 30*1a96fba6SXin Li public: 31*1a96fba6SXin Li // Identifiers of a USB device or device family. 32*1a96fba6SXin Li struct UsbDeviceId { 33*1a96fba6SXin Li // USB Vendor Identifier (aka idVendor). 34*1a96fba6SXin Li uint16_t vendor_id; 35*1a96fba6SXin Li 36*1a96fba6SXin Li // USB Product Identifier (aka idProduct). 37*1a96fba6SXin Li uint16_t product_id; 38*1a96fba6SXin Li }; 39*1a96fba6SXin Li 40*1a96fba6SXin Li // Time interval represented by two |day_of_week| and |time| pairs. The start 41*1a96fba6SXin Li // of the interval is inclusive and the end is exclusive. The time represented 42*1a96fba6SXin Li // by those pairs will be interpreted to be in the local timezone. Because of 43*1a96fba6SXin Li // this, there exists the possibility of intervals being repeated or skipped 44*1a96fba6SXin Li // in a day with daylight savings transitions, this is expected behavior. 45*1a96fba6SXin Li struct WeeklyTimeInterval { 46*1a96fba6SXin Li // Value is from 1 to 7 (1 = Monday, 2 = Tuesday, etc.). All values outside 47*1a96fba6SXin Li // this range are invalid and will be discarded. 48*1a96fba6SXin Li int start_day_of_week; 49*1a96fba6SXin Li // Time since the start of the day. This value will be interpreted to be in 50*1a96fba6SXin Li // the system's current timezone when used for range checking. 51*1a96fba6SXin Li base::TimeDelta start_time; 52*1a96fba6SXin Li int end_day_of_week; 53*1a96fba6SXin Li base::TimeDelta end_time; 54*1a96fba6SXin Li }; 55*1a96fba6SXin Li 56*1a96fba6SXin Li // Identifies a <day, percentage> pair in a staging schedule. 57*1a96fba6SXin Li struct DayPercentagePair { 58*1a96fba6SXin Li bool operator==(const DayPercentagePair& other) const { 59*1a96fba6SXin Li return days == other.days && percentage == other.percentage; 60*1a96fba6SXin Li } 61*1a96fba6SXin Li int days; 62*1a96fba6SXin Li int percentage; 63*1a96fba6SXin Li }; 64*1a96fba6SXin Li 65*1a96fba6SXin Li DevicePolicy(); 66*1a96fba6SXin Li virtual ~DevicePolicy(); 67*1a96fba6SXin Li 68*1a96fba6SXin Li // Load device policy off of disk into |policy_|. 69*1a96fba6SXin Li // Returns true unless there is a policy on disk and loading it fails. 70*1a96fba6SXin Li virtual bool LoadPolicy() = 0; 71*1a96fba6SXin Li 72*1a96fba6SXin Li // Returns true if OOBE has been completed and if the device has been enrolled 73*1a96fba6SXin Li // as an enterprise or enterpriseAD device. 74*1a96fba6SXin Li virtual bool IsEnterpriseEnrolled() const = 0; 75*1a96fba6SXin Li 76*1a96fba6SXin Li // Writes the value of the DevicePolicyRefreshRate policy in |rate|. Returns 77*1a96fba6SXin Li // true on success. 78*1a96fba6SXin Li virtual bool GetPolicyRefreshRate(int* rate) const = 0; 79*1a96fba6SXin Li 80*1a96fba6SXin Li // Writes the value of the UserWhitelist policy in |user_whitelist|. Returns 81*1a96fba6SXin Li // true on success. 82*1a96fba6SXin Li virtual bool GetUserWhitelist( 83*1a96fba6SXin Li std::vector<std::string>* user_whitelist) const = 0; 84*1a96fba6SXin Li 85*1a96fba6SXin Li // Writes the value of the GuestModeEnabled policy in |guest_mode_enabled|. 86*1a96fba6SXin Li // Returns true on success. 87*1a96fba6SXin Li virtual bool GetGuestModeEnabled(bool* guest_mode_enabled) const = 0; 88*1a96fba6SXin Li 89*1a96fba6SXin Li // Writes the value of the CameraEnabled policy in |camera_enabled|. Returns 90*1a96fba6SXin Li // true on success. 91*1a96fba6SXin Li virtual bool GetCameraEnabled(bool* camera_enabled) const = 0; 92*1a96fba6SXin Li 93*1a96fba6SXin Li // Writes the value of the ShowUserNamesOnSignIn policy in |show_user_names|. 94*1a96fba6SXin Li // Returns true on success. 95*1a96fba6SXin Li virtual bool GetShowUserNames(bool* show_user_names) const = 0; 96*1a96fba6SXin Li 97*1a96fba6SXin Li // Writes the value of the DataRoamingEnabled policy in |data_roaming_enabled| 98*1a96fba6SXin Li // Returns true on success. 99*1a96fba6SXin Li virtual bool GetDataRoamingEnabled(bool* data_roaming_enabled) const = 0; 100*1a96fba6SXin Li 101*1a96fba6SXin Li // Writes the value of the AllowNewUsers policy in |allow_new_users|. Returns 102*1a96fba6SXin Li // true on success. 103*1a96fba6SXin Li virtual bool GetAllowNewUsers(bool* allow_new_users) const = 0; 104*1a96fba6SXin Li 105*1a96fba6SXin Li // Writes the value of MetricEnabled policy in |metrics_enabled|. Returns true 106*1a96fba6SXin Li // on success. 107*1a96fba6SXin Li virtual bool GetMetricsEnabled(bool* metrics_enabled) const = 0; 108*1a96fba6SXin Li 109*1a96fba6SXin Li // Writes the value of ReportVersionInfo policy in |report_version_info|. 110*1a96fba6SXin Li // Returns true on success. 111*1a96fba6SXin Li virtual bool GetReportVersionInfo(bool* report_version_info) const = 0; 112*1a96fba6SXin Li 113*1a96fba6SXin Li // Writes the value of ReportActivityTimes policy in |report_activity_times|. 114*1a96fba6SXin Li // Returns true on success. 115*1a96fba6SXin Li virtual bool GetReportActivityTimes(bool* report_activity_times) const = 0; 116*1a96fba6SXin Li 117*1a96fba6SXin Li // Writes the value of ReportBootMode policy in |report_boot_mode|. Returns 118*1a96fba6SXin Li // true on success. 119*1a96fba6SXin Li virtual bool GetReportBootMode(bool* report_boot_mode) const = 0; 120*1a96fba6SXin Li 121*1a96fba6SXin Li // Writes the value of the EphemeralUsersEnabled policy in 122*1a96fba6SXin Li // |ephemeral_users_enabled|. Returns true on success. 123*1a96fba6SXin Li virtual bool GetEphemeralUsersEnabled( 124*1a96fba6SXin Li bool* ephemeral_users_enabled) const = 0; 125*1a96fba6SXin Li 126*1a96fba6SXin Li // Writes the value of the release channel policy in |release_channel|. 127*1a96fba6SXin Li // Returns true on success. 128*1a96fba6SXin Li virtual bool GetReleaseChannel(std::string* release_channel) const = 0; 129*1a96fba6SXin Li 130*1a96fba6SXin Li // Writes the value of the release_channel_delegated policy in 131*1a96fba6SXin Li // |release_channel_delegated|. Returns true on success. 132*1a96fba6SXin Li virtual bool GetReleaseChannelDelegated( 133*1a96fba6SXin Li bool* release_channel_delegated) const = 0; 134*1a96fba6SXin Li 135*1a96fba6SXin Li // Writes the value of the update_disabled policy in |update_disabled|. 136*1a96fba6SXin Li // Returns true on success. 137*1a96fba6SXin Li virtual bool GetUpdateDisabled(bool* update_disabled) const = 0; 138*1a96fba6SXin Li 139*1a96fba6SXin Li // Writes the value of the target_version_prefix policy in 140*1a96fba6SXin Li // |target_version_prefix|. Returns true on success. 141*1a96fba6SXin Li virtual bool GetTargetVersionPrefix( 142*1a96fba6SXin Li std::string* target_version_prefix) const = 0; 143*1a96fba6SXin Li 144*1a96fba6SXin Li // Writes the value of the rollback_to_target_version policy in 145*1a96fba6SXin Li // |rollback_to_target_version|. |rollback_to_target_version| will be one of 146*1a96fba6SXin Li // the values in AutoUpdateSettingsProto's RollbackToTargetVersion enum. 147*1a96fba6SXin Li // Returns true on success. 148*1a96fba6SXin Li virtual bool GetRollbackToTargetVersion( 149*1a96fba6SXin Li int* rollback_to_target_version) const = 0; 150*1a96fba6SXin Li 151*1a96fba6SXin Li // Writes the value of the rollback_allowed_milestones policy in 152*1a96fba6SXin Li // |rollback_allowed_milestones|. Returns true on success. 153*1a96fba6SXin Li virtual bool GetRollbackAllowedMilestones( 154*1a96fba6SXin Li int* rollback_allowed_milestones) const = 0; 155*1a96fba6SXin Li 156*1a96fba6SXin Li // Writes the value of the scatter_factor_in_seconds policy in 157*1a96fba6SXin Li // |scatter_factor_in_seconds|. Returns true on success. 158*1a96fba6SXin Li virtual bool GetScatterFactorInSeconds( 159*1a96fba6SXin Li int64_t* scatter_factor_in_seconds) const = 0; 160*1a96fba6SXin Li 161*1a96fba6SXin Li // Writes the connection types on which updates are allowed to 162*1a96fba6SXin Li // |connection_types|. The identifiers returned are intended to be consistent 163*1a96fba6SXin Li // with what the connection manager users: ethernet, wifi, wimax, bluetooth, 164*1a96fba6SXin Li // cellular. 165*1a96fba6SXin Li virtual bool GetAllowedConnectionTypesForUpdate( 166*1a96fba6SXin Li std::set<std::string>* connection_types) const = 0; 167*1a96fba6SXin Li 168*1a96fba6SXin Li // Writes the value of the OpenNetworkConfiguration policy in 169*1a96fba6SXin Li // |open_network_configuration|. Returns true on success. 170*1a96fba6SXin Li virtual bool GetOpenNetworkConfiguration( 171*1a96fba6SXin Li std::string* open_network_configuration) const = 0; 172*1a96fba6SXin Li 173*1a96fba6SXin Li // Writes the name of the device owner in |owner|. For enterprise enrolled 174*1a96fba6SXin Li // devices, this will be an empty string. 175*1a96fba6SXin Li // Returns true on success. 176*1a96fba6SXin Li virtual bool GetOwner(std::string* owner) const = 0; 177*1a96fba6SXin Li 178*1a96fba6SXin Li // Write the value of http_downloads_enabled policy in 179*1a96fba6SXin Li // |http_downloads_enabled|. Returns true on success. 180*1a96fba6SXin Li virtual bool GetHttpDownloadsEnabled(bool* http_downloads_enabled) const = 0; 181*1a96fba6SXin Li 182*1a96fba6SXin Li // Writes the value of au_p2p_enabled policy in 183*1a96fba6SXin Li // |au_p2p_enabled|. Returns true on success. 184*1a96fba6SXin Li virtual bool GetAuP2PEnabled(bool* au_p2p_enabled) const = 0; 185*1a96fba6SXin Li 186*1a96fba6SXin Li // Writes the value of allow_kiosk_app_control_chrome_version policy in 187*1a96fba6SXin Li // |allow_kiosk_app_control_chrome_version|. Returns true on success. 188*1a96fba6SXin Li virtual bool GetAllowKioskAppControlChromeVersion( 189*1a96fba6SXin Li bool* allow_kiosk_app_control_chrome_version) const = 0; 190*1a96fba6SXin Li 191*1a96fba6SXin Li // Writes the value of the UsbDetachableWhitelist policy in |usb_whitelist|. 192*1a96fba6SXin Li // Returns true on success. 193*1a96fba6SXin Li virtual bool GetUsbDetachableWhitelist( 194*1a96fba6SXin Li std::vector<UsbDeviceId>* usb_whitelist) const = 0; 195*1a96fba6SXin Li 196*1a96fba6SXin Li // Writes the value of the kiosk app id into |app_id_out|. 197*1a96fba6SXin Li // Only succeeds if the device is in auto-launched kiosk mode. 198*1a96fba6SXin Li virtual bool GetAutoLaunchedKioskAppId(std::string* app_id_out) const = 0; 199*1a96fba6SXin Li 200*1a96fba6SXin Li // Returns true if the policy data indicates that the device is enterprise 201*1a96fba6SXin Li // managed. Note that this potentially could be faked by an exploit, therefore 202*1a96fba6SXin Li // InstallAttributesReader must be used when tamper-proof evidence of the 203*1a96fba6SXin Li // management state is required. 204*1a96fba6SXin Li virtual bool IsEnterpriseManaged() const = 0; 205*1a96fba6SXin Li 206*1a96fba6SXin Li // Writes the value of the DeviceSecondFactorAuthentication policy in 207*1a96fba6SXin Li // |mode_out|. |mode_out| is one of the values from 208*1a96fba6SXin Li // DeviceSecondFactorAuthenticationProto's U2fMode enum (e.g. DISABLED, 209*1a96fba6SXin Li // U2F or U2F_EXTENDED). Returns true on success. 210*1a96fba6SXin Li virtual bool GetSecondFactorAuthenticationMode(int* mode_out) const = 0; 211*1a96fba6SXin Li 212*1a96fba6SXin Li // Writes the valid time intervals to |intervals_out|. These 213*1a96fba6SXin Li // intervals are taken from the disallowed time intervals field in the 214*1a96fba6SXin Li // AutoUpdateSettingsProto. Returns true if the intervals in the proto are 215*1a96fba6SXin Li // valid. 216*1a96fba6SXin Li virtual bool GetDisallowedTimeIntervals( 217*1a96fba6SXin Li std::vector<WeeklyTimeInterval>* intervals_out) const = 0; 218*1a96fba6SXin Li 219*1a96fba6SXin Li // Writes the value of the DeviceUpdateStagingSchedule policy to 220*1a96fba6SXin Li // |staging_schedule_out|. Returns true on success. 221*1a96fba6SXin Li // The schedule is a list of <days, percentage> pairs. The percentages are 222*1a96fba6SXin Li // expected to be mononically increasing in the range of [1, 100]. Similarly, 223*1a96fba6SXin Li // days are expected to be monotonically increasing in the range [1, 28]. Each 224*1a96fba6SXin Li // pair describes the |percentage| of the fleet that is expected to receive an 225*1a96fba6SXin Li // update after |days| days after an update was discovered. e.g. [<4, 30>, <8, 226*1a96fba6SXin Li // 100>] means that 30% of devices should be updated in the first 4 days, and 227*1a96fba6SXin Li // then 100% should be updated after 8 days. 228*1a96fba6SXin Li virtual bool GetDeviceUpdateStagingSchedule( 229*1a96fba6SXin Li std::vector<DayPercentagePair>* staging_schedule_out) const = 0; 230*1a96fba6SXin Li 231*1a96fba6SXin Li // Writes the value of the DeviceQuickFixBuildToken to 232*1a96fba6SXin Li // |device_quick_fix_build_token|. 233*1a96fba6SXin Li // Returns true if it has been written, or false if the policy was not set. 234*1a96fba6SXin Li virtual bool GetDeviceQuickFixBuildToken( 235*1a96fba6SXin Li std::string* device_quick_fix_build_token) const = 0; 236*1a96fba6SXin Li 237*1a96fba6SXin Li // Writes the value of the Directory API ID to |directory_api_id_out|. 238*1a96fba6SXin Li // Returns true on success, false if the ID is not available (eg if the device 239*1a96fba6SXin Li // is not enrolled). 240*1a96fba6SXin Li virtual bool GetDeviceDirectoryApiId( 241*1a96fba6SXin Li std::string* directory_api_id_out) const = 0; 242*1a96fba6SXin Li 243*1a96fba6SXin Li private: 244*1a96fba6SXin Li // Verifies that the policy signature is correct. 245*1a96fba6SXin Li virtual bool VerifyPolicySignature() = 0; 246*1a96fba6SXin Li 247*1a96fba6SXin Li DISALLOW_COPY_AND_ASSIGN(DevicePolicy); 248*1a96fba6SXin Li }; 249*1a96fba6SXin Li } // namespace policy 250*1a96fba6SXin Li 251*1a96fba6SXin Li #pragma GCC visibility pop 252*1a96fba6SXin Li 253*1a96fba6SXin Li #endif // LIBBRILLO_POLICY_DEVICE_POLICY_H_ 254