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