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

Side by Side Diff: chrome/browser/policy/enterprise_install_attributes.cc

Issue 9403010: Add support for kiosk mode on the client. Make sure the settings are written in the lockbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nitty nit. Created 8 years, 10 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
OLDNEW
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 #include "chrome/browser/policy/enterprise_install_attributes.h" 5 #include "chrome/browser/policy/enterprise_install_attributes.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 8 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
9 9
10 namespace policy {
11
10 namespace { 12 namespace {
13 // Constants for the possible device modes that can be stored in the lockbox.
14 const char kConsumerDeviceMode[] = "consumer";
15 const char kEnterpiseDeviceMode[] = "enterprise";
16 const char kKioskDeviceMode[] = "kiosk";
17 const char kUnknownDeviceMode[] = "unknown";
11 18
19 // Field names in the lockbox.
20 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id";
21 const char kAttrEnterpriseDomain[] = "enterprise.domain";
22 const char kAttrEnterpriseMode[] = "enterprise.mode";
12 const char kAttrEnterpriseOwned[] = "enterprise.owned"; 23 const char kAttrEnterpriseOwned[] = "enterprise.owned";
13 const char kAttrEnterpriseUser[] = "enterprise.user"; 24 const char kAttrEnterpriseUser[] = "enterprise.user";
14 25
26 // Extract the domain from a given email.
27 std::string ExtractDomainName(const std::string& email) {
28 size_t separator_pos = email.find('@');
29 if (separator_pos != email.npos && separator_pos < email.length() - 1)
30 return email.substr(separator_pos + 1);
31 else
32 NOTREACHED() << "Not a proper email address: " << email;
33 return std::string();
34 }
35
36 // Translates DeviceMode constants to strings used in the lockbox.
37 std::string GetDeviceModeString(DeviceMode mode) {
38 switch (mode) {
39 case DEVICE_MODE_CONSUMER:
40 return kConsumerDeviceMode;
41 case DEVICE_MODE_ENTERPRISE:
42 return kEnterpiseDeviceMode;
43 case DEVICE_MODE_KIOSK:
44 return kKioskDeviceMode;
45 case DEVICE_MODE_UNKNOWN:
46 break;
47 }
48 NOTREACHED() << "Invalid device mode: " << mode;
49 return kUnknownDeviceMode;
50 }
51
52 // Translates strings used in the lockbox to DeviceMode values.
53 DeviceMode GetDeviceModeFromString(
54 const std::string& mode) {
55 if (mode == kConsumerDeviceMode)
56 return DEVICE_MODE_CONSUMER;
57 else if (mode == kEnterpiseDeviceMode)
58 return DEVICE_MODE_ENTERPRISE;
59 else if (mode == kKioskDeviceMode)
60 return DEVICE_MODE_KIOSK;
61 NOTREACHED() << "Unknown device mode string: " << mode;
62 return DEVICE_MODE_UNKNOWN;
63 }
64
15 } // namespace 65 } // namespace
16 66
17 namespace policy {
18
19 EnterpriseInstallAttributes::EnterpriseInstallAttributes( 67 EnterpriseInstallAttributes::EnterpriseInstallAttributes(
20 chromeos::CryptohomeLibrary* cryptohome) 68 chromeos::CryptohomeLibrary* cryptohome)
21 : cryptohome_(cryptohome), 69 : cryptohome_(cryptohome),
22 device_locked_(false) {} 70 device_locked_(false),
71 registration_mode_(DEVICE_MODE_UNKNOWN) {}
23 72
24 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( 73 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice(
25 const std::string& user) { 74 const std::string& user,
75 DeviceMode device_mode,
76 const std::string& device_id) {
77 CHECK_NE(device_mode, DEVICE_MODE_UNKNOWN);
78
26 // Check for existing lock first. 79 // Check for existing lock first.
27 if (device_locked_) { 80 if (device_locked_) {
28 return !registration_user_.empty() && user == registration_user_ ? 81 return !registration_user_.empty() && user == registration_user_ ?
29 LOCK_SUCCESS : LOCK_WRONG_USER; 82 LOCK_SUCCESS : LOCK_WRONG_USER;
30 } 83 }
31 84
32 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady()) 85 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady())
33 return LOCK_NOT_READY; 86 return LOCK_NOT_READY;
34 87
35 // Clearing the TPM password seems to be always a good deal. 88 // Clearing the TPM password seems to be always a good deal.
36 if (cryptohome_->TpmIsEnabled() && 89 if (cryptohome_->TpmIsEnabled() &&
37 !cryptohome_->TpmIsBeingOwned() && 90 !cryptohome_->TpmIsBeingOwned() &&
38 cryptohome_->TpmIsOwned()) { 91 cryptohome_->TpmIsOwned()) {
39 cryptohome_->TpmClearStoredPassword(); 92 cryptohome_->TpmClearStoredPassword();
40 } 93 }
41 94
42 // Make sure we really have a working InstallAttrs. 95 // Make sure we really have a working InstallAttrs.
43 if (cryptohome_->InstallAttributesIsInvalid()) { 96 if (cryptohome_->InstallAttributesIsInvalid()) {
44 LOG(ERROR) << "Install attributes invalid."; 97 LOG(ERROR) << "Install attributes invalid.";
45 return LOCK_BACKEND_ERROR; 98 return LOCK_BACKEND_ERROR;
46 } 99 }
47 100
48 if (!cryptohome_->InstallAttributesIsFirstInstall()) 101 if (!cryptohome_->InstallAttributesIsFirstInstall())
49 return LOCK_WRONG_USER; 102 return LOCK_WRONG_USER;
50 103
104 std::string domain = ExtractDomainName(user);
105 std::string mode = GetDeviceModeString(device_mode);
106
51 // Set values in the InstallAttrs and lock it. 107 // Set values in the InstallAttrs and lock it.
52 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") || 108 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") ||
53 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user)) { 109 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) ||
110 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) ||
111 !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) ||
112 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) {
54 LOG(ERROR) << "Failed writing attributes"; 113 LOG(ERROR) << "Failed writing attributes";
55 return LOCK_BACKEND_ERROR; 114 return LOCK_BACKEND_ERROR;
56 } 115 }
57 116
58 if (!cryptohome_->InstallAttributesFinalize() || 117 if (!cryptohome_->InstallAttributesFinalize() ||
59 cryptohome_->InstallAttributesIsFirstInstall() || 118 cryptohome_->InstallAttributesIsFirstInstall() ||
60 GetRegistrationUser() != user) { 119 GetRegistrationUser() != user) {
61 LOG(ERROR) << "Failed locking."; 120 LOG(ERROR) << "Failed locking.";
62 return LOCK_BACKEND_ERROR; 121 return LOCK_BACKEND_ERROR;
63 } 122 }
(...skipping 12 matching lines...) Expand all
76 if (!device_locked_) 135 if (!device_locked_)
77 return std::string(); 136 return std::string();
78 137
79 return registration_user_; 138 return registration_user_;
80 } 139 }
81 140
82 std::string EnterpriseInstallAttributes::GetDomain() { 141 std::string EnterpriseInstallAttributes::GetDomain() {
83 if (!IsEnterpriseDevice()) 142 if (!IsEnterpriseDevice())
84 return std::string(); 143 return std::string();
85 144
86 std::string domain; 145 return registration_domain_;
87 size_t pos = registration_user_.find('@'); 146 }
88 if (pos != std::string::npos)
89 domain = registration_user_.substr(pos + 1);
90 147
91 return domain; 148 std::string EnterpriseInstallAttributes::GetDeviceId() {
149 if (!IsEnterpriseDevice())
150 return std::string();
151
152 return registration_device_id_;
153 }
154
155 DeviceMode EnterpriseInstallAttributes::GetMode() {
156 ReadImmutableAttributes();
157 return registration_mode_;
92 } 158 }
93 159
94 void EnterpriseInstallAttributes::ReadImmutableAttributes() { 160 void EnterpriseInstallAttributes::ReadImmutableAttributes() {
95 if (device_locked_) 161 if (device_locked_)
96 return; 162 return;
97 163
98 if (cryptohome_ && 164 if (cryptohome_ &&
99 cryptohome_->InstallAttributesIsReady() && 165 cryptohome_->InstallAttributesIsReady() &&
100 !cryptohome_->InstallAttributesIsInvalid() && 166 !cryptohome_->InstallAttributesIsInvalid() &&
101 !cryptohome_->InstallAttributesIsFirstInstall()) { 167 !cryptohome_->InstallAttributesIsFirstInstall()) {
102 device_locked_ = true; 168 device_locked_ = true;
103 std::string enterprise_owned; 169 std::string enterprise_owned;
104 std::string enterprise_user; 170 std::string enterprise_user;
105 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseOwned, 171 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseOwned,
106 &enterprise_owned) && 172 &enterprise_owned) &&
107 cryptohome_->InstallAttributesGet(kAttrEnterpriseUser, 173 cryptohome_->InstallAttributesGet(kAttrEnterpriseUser,
108 &enterprise_user) && 174 &enterprise_user) &&
109 enterprise_owned == "true" && 175 enterprise_owned == "true" &&
110 !enterprise_user.empty()) { 176 !enterprise_user.empty()) {
111 registration_user_ = enterprise_user; 177 registration_user_ = enterprise_user;
178
179 // Initialize the mode to the legacy enterprise mode here and update below
180 // if more information is present.
181 registration_mode_ = DEVICE_MODE_ENTERPRISE;
182
183 // If we could extract basic setting we should try to extract the extended
184 // ones too. We try to set these to defaults as good as possible if not
185 // present, which could happen for device enrolled in pre-R19 revisions of
186 // the code, before these new attributes were added.
187 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDomain,
188 &registration_domain_)) {
189 registration_domain_ = ExtractDomainName(registration_user_);
190 }
191 if (!cryptohome_->InstallAttributesGet(kAttrEnterpriseDeviceId,
192 &registration_device_id_)) {
193 registration_device_id_.clear();
194 }
195 std::string mode;
196 if (cryptohome_->InstallAttributesGet(kAttrEnterpriseMode, &mode))
197 registration_mode_ = GetDeviceModeFromString(mode);
198 } else if (enterprise_user.empty() && enterprise_owned != "true") {
199 // |registration_user_| is empty on consumer devices.
200 registration_mode_ = DEVICE_MODE_CONSUMER;
112 } 201 }
113 } 202 }
114 } 203 }
115 204
116 } // namespace policy 205 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/enterprise_install_attributes.h ('k') | chrome/browser/policy/enterprise_install_attributes_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698