| 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 #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 { | 10 namespace policy { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 // Constants for the possible device modes that can be stored in the lockbox. | 13 // Constants for the possible device modes that can be stored in the lockbox. |
| 14 const char kConsumerDeviceMode[] = "consumer"; | 14 const char kConsumerDeviceMode[] = "consumer"; |
| 15 const char kEnterpiseDeviceMode[] = "enterprise"; | 15 const char kEnterpiseDeviceMode[] = "enterprise"; |
| 16 const char kKioskDeviceMode[] = "kiosk"; | 16 const char kKioskDeviceMode[] = "kiosk"; |
| 17 const char kUnknownDeviceMode[] = "unknown"; | 17 const char kUnknownDeviceMode[] = "unknown"; |
| 18 | 18 |
| 19 // Field names in the lockbox. | 19 // Field names in the lockbox. |
| 20 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id"; | 20 const char kAttrEnterpriseDeviceId[] = "enterprise.device_id"; |
| 21 const char kAttrEnterpriseDomain[] = "enterprise.domain"; | 21 const char kAttrEnterpriseDomain[] = "enterprise.domain"; |
| 22 const char kAttrEnterpriseMode[] = "enterprise.mode"; | 22 const char kAttrEnterpriseMode[] = "enterprise.mode"; |
| 23 const char kAttrEnterpriseOwned[] = "enterprise.owned"; | 23 const char kAttrEnterpriseOwned[] = "enterprise.owned"; |
| 24 const char kAttrEnterpriseUser[] = "enterprise.user"; | 24 const char kAttrEnterpriseUser[] = "enterprise.user"; |
| 25 | 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. | 26 // Translates DeviceMode constants to strings used in the lockbox. |
| 37 std::string GetDeviceModeString(DeviceMode mode) { | 27 std::string GetDeviceModeString(DeviceMode mode) { |
| 38 switch (mode) { | 28 switch (mode) { |
| 39 case DEVICE_MODE_CONSUMER: | 29 case DEVICE_MODE_CONSUMER: |
| 40 return kConsumerDeviceMode; | 30 return kConsumerDeviceMode; |
| 41 case DEVICE_MODE_ENTERPRISE: | 31 case DEVICE_MODE_ENTERPRISE: |
| 42 return kEnterpiseDeviceMode; | 32 return kEnterpiseDeviceMode; |
| 43 case DEVICE_MODE_KIOSK: | 33 case DEVICE_MODE_KIOSK: |
| 44 return kKioskDeviceMode; | 34 return kKioskDeviceMode; |
| 45 case DEVICE_MODE_PENDING: | 35 case DEVICE_MODE_PENDING: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 device_locked_(false), | 61 device_locked_(false), |
| 72 registration_mode_(DEVICE_MODE_PENDING) {} | 62 registration_mode_(DEVICE_MODE_PENDING) {} |
| 73 | 63 |
| 74 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( | 64 EnterpriseInstallAttributes::LockResult EnterpriseInstallAttributes::LockDevice( |
| 75 const std::string& user, | 65 const std::string& user, |
| 76 DeviceMode device_mode, | 66 DeviceMode device_mode, |
| 77 const std::string& device_id) { | 67 const std::string& device_id) { |
| 78 CHECK_NE(device_mode, DEVICE_MODE_PENDING); | 68 CHECK_NE(device_mode, DEVICE_MODE_PENDING); |
| 79 CHECK_NE(device_mode, DEVICE_MODE_NOT_SET); | 69 CHECK_NE(device_mode, DEVICE_MODE_NOT_SET); |
| 80 | 70 |
| 71 std::string domain = ExtractDomainName(user); |
| 72 |
| 81 // Check for existing lock first. | 73 // Check for existing lock first. |
| 82 if (device_locked_) { | 74 if (device_locked_) { |
| 83 return !registration_user_.empty() && user == registration_user_ ? | 75 return !registration_domain_.empty() && domain == registration_domain_ ? |
| 84 LOCK_SUCCESS : LOCK_WRONG_USER; | 76 LOCK_SUCCESS : LOCK_WRONG_USER; |
| 85 } | 77 } |
| 86 | 78 |
| 87 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady()) | 79 if (!cryptohome_ || !cryptohome_->InstallAttributesIsReady()) |
| 88 return LOCK_NOT_READY; | 80 return LOCK_NOT_READY; |
| 89 | 81 |
| 90 // Clearing the TPM password seems to be always a good deal. | 82 // Clearing the TPM password seems to be always a good deal. |
| 91 if (cryptohome_->TpmIsEnabled() && | 83 if (cryptohome_->TpmIsEnabled() && |
| 92 !cryptohome_->TpmIsBeingOwned() && | 84 !cryptohome_->TpmIsBeingOwned() && |
| 93 cryptohome_->TpmIsOwned()) { | 85 cryptohome_->TpmIsOwned()) { |
| 94 cryptohome_->TpmClearStoredPassword(); | 86 cryptohome_->TpmClearStoredPassword(); |
| 95 } | 87 } |
| 96 | 88 |
| 97 // Make sure we really have a working InstallAttrs. | 89 // Make sure we really have a working InstallAttrs. |
| 98 if (cryptohome_->InstallAttributesIsInvalid()) { | 90 if (cryptohome_->InstallAttributesIsInvalid()) { |
| 99 LOG(ERROR) << "Install attributes invalid."; | 91 LOG(ERROR) << "Install attributes invalid."; |
| 100 return LOCK_BACKEND_ERROR; | 92 return LOCK_BACKEND_ERROR; |
| 101 } | 93 } |
| 102 | 94 |
| 103 if (!cryptohome_->InstallAttributesIsFirstInstall()) | 95 if (!cryptohome_->InstallAttributesIsFirstInstall()) |
| 104 return LOCK_WRONG_USER; | 96 return LOCK_WRONG_USER; |
| 105 | 97 |
| 106 std::string domain = ExtractDomainName(user); | |
| 107 std::string mode = GetDeviceModeString(device_mode); | 98 std::string mode = GetDeviceModeString(device_mode); |
| 108 | 99 |
| 109 // Set values in the InstallAttrs and lock it. | 100 // Set values in the InstallAttrs and lock it. |
| 110 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") || | 101 if (!cryptohome_->InstallAttributesSet(kAttrEnterpriseOwned, "true") || |
| 111 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) || | 102 !cryptohome_->InstallAttributesSet(kAttrEnterpriseUser, user) || |
| 112 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) || | 103 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDomain, domain) || |
| 113 !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) || | 104 !cryptohome_->InstallAttributesSet(kAttrEnterpriseMode, mode) || |
| 114 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) { | 105 !cryptohome_->InstallAttributesSet(kAttrEnterpriseDeviceId, device_id)) { |
| 115 LOG(ERROR) << "Failed writing attributes"; | 106 LOG(ERROR) << "Failed writing attributes"; |
| 116 return LOCK_BACKEND_ERROR; | 107 return LOCK_BACKEND_ERROR; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return std::string(); | 143 return std::string(); |
| 153 | 144 |
| 154 return registration_device_id_; | 145 return registration_device_id_; |
| 155 } | 146 } |
| 156 | 147 |
| 157 DeviceMode EnterpriseInstallAttributes::GetMode() { | 148 DeviceMode EnterpriseInstallAttributes::GetMode() { |
| 158 ReadImmutableAttributes(); | 149 ReadImmutableAttributes(); |
| 159 return registration_mode_; | 150 return registration_mode_; |
| 160 } | 151 } |
| 161 | 152 |
| 153 // static |
| 154 std::string EnterpriseInstallAttributes::ExtractDomainName( |
| 155 const std::string& email) { |
| 156 size_t separator_pos = email.find('@'); |
| 157 if (separator_pos != email.npos && separator_pos < email.length() - 1) |
| 158 return email.substr(separator_pos + 1); |
| 159 else |
| 160 NOTREACHED() << "Not a proper email address: " << email; |
| 161 return std::string(); |
| 162 } |
| 163 |
| 162 void EnterpriseInstallAttributes::ReadImmutableAttributes() { | 164 void EnterpriseInstallAttributes::ReadImmutableAttributes() { |
| 163 if (device_locked_) | 165 if (device_locked_) |
| 164 return; | 166 return; |
| 165 | 167 |
| 166 if (cryptohome_ && cryptohome_->InstallAttributesIsReady()) { | 168 if (cryptohome_ && cryptohome_->InstallAttributesIsReady()) { |
| 167 registration_mode_ = DEVICE_MODE_NOT_SET; | 169 registration_mode_ = DEVICE_MODE_NOT_SET; |
| 168 if (!cryptohome_->InstallAttributesIsInvalid() && | 170 if (!cryptohome_->InstallAttributesIsInvalid() && |
| 169 !cryptohome_->InstallAttributesIsFirstInstall()) { | 171 !cryptohome_->InstallAttributesIsFirstInstall()) { |
| 170 device_locked_ = true; | 172 device_locked_ = true; |
| 171 std::string enterprise_owned; | 173 std::string enterprise_owned; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 199 registration_mode_ = GetDeviceModeFromString(mode); | 201 registration_mode_ = GetDeviceModeFromString(mode); |
| 200 } else if (enterprise_user.empty() && enterprise_owned != "true") { | 202 } else if (enterprise_user.empty() && enterprise_owned != "true") { |
| 201 // |registration_user_| is empty on consumer devices. | 203 // |registration_user_| is empty on consumer devices. |
| 202 registration_mode_ = DEVICE_MODE_CONSUMER; | 204 registration_mode_ = DEVICE_MODE_CONSUMER; |
| 203 } | 205 } |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 | 209 |
| 208 } // namespace policy | 210 } // namespace policy |
| OLD | NEW |