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

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

Powered by Google App Engine
This is Rietveld 408576698