Commit 26916760 authored by drcrash's avatar drcrash Committed by Commit bot

Ensure that challenging user keys is unavailable on signin.

Returns a specific error saying the keys are not available in the
signin profile.

BUG=715121
TEST=unit tests

Review-Url: https://codereview.chromium.org/2838423003
Cr-Commit-Position: refs/heads/master@{#468019}
parent 638b48e2
...@@ -141,7 +141,7 @@ bool EPKPChallengeKeyBase::IsEnterpriseDevice() const { ...@@ -141,7 +141,7 @@ bool EPKPChallengeKeyBase::IsEnterpriseDevice() const {
} }
bool EPKPChallengeKeyBase::IsExtensionWhitelisted() const { bool EPKPChallengeKeyBase::IsExtensionWhitelisted() const {
if (chromeos::ProfileHelper::IsSigninProfile(profile_)) { if (!chromeos::ProfileHelper::Get()->GetUserByProfile(profile_)) {
// Only allow remote attestation for apps that were force-installed on the // Only allow remote attestation for apps that were force-installed on the
// login/signin screen. // login/signin screen.
// TODO(drcrash): Use a separate device-wide policy for the API. // TODO(drcrash): Use a separate device-wide policy for the API.
...@@ -340,7 +340,7 @@ void EPKPChallengeMachineKey::Run( ...@@ -340,7 +340,7 @@ void EPKPChallengeMachineKey::Run(
} }
// Check whether the user is managed unless the signin profile is used. // Check whether the user is managed unless the signin profile is used.
if (!chromeos::ProfileHelper::IsSigninProfile(profile_) && if (chromeos::ProfileHelper::Get()->GetUserByProfile(profile_) &&
!IsUserAffiliated()) { !IsUserAffiliated()) {
callback_.Run(false, kUserNotManaged); callback_.Run(false, kUserNotManaged);
return; return;
...@@ -443,6 +443,8 @@ const char EPKPChallengeUserKey::kKeyRegistrationFailedError[] = ...@@ -443,6 +443,8 @@ const char EPKPChallengeUserKey::kKeyRegistrationFailedError[] =
"Key registration failed."; "Key registration failed.";
const char EPKPChallengeUserKey::kUserPolicyDisabledError[] = const char EPKPChallengeUserKey::kUserPolicyDisabledError[] =
"Remote attestation is not enabled for your account."; "Remote attestation is not enabled for your account.";
const char EPKPChallengeUserKey::kUserKeyNotAvailable[] =
"User keys cannot be challenged in this profile.";
const char EPKPChallengeUserKey::kKeyName[] = "attest-ent-user"; const char EPKPChallengeUserKey::kKeyName[] = "attest-ent-user";
...@@ -477,6 +479,12 @@ void EPKPChallengeUserKey::Run(scoped_refptr<UIThreadExtensionFunction> caller, ...@@ -477,6 +479,12 @@ void EPKPChallengeUserKey::Run(scoped_refptr<UIThreadExtensionFunction> caller,
profile_ = ChromeExtensionFunctionDetails(caller.get()).GetProfile(); profile_ = ChromeExtensionFunctionDetails(caller.get()).GetProfile();
extension_ = scoped_refptr<const Extension>(caller->extension()); extension_ = scoped_refptr<const Extension>(caller->extension());
// Check if user keys are available in this profile.
if (!chromeos::ProfileHelper::Get()->GetUserByProfile(profile_)) {
callback_.Run(false, EPKPChallengeUserKey::kUserKeyNotAvailable);
return;
}
// Check if RA is enabled in the user policy. // Check if RA is enabled in the user policy.
if (!IsRemoteAttestationEnabledForUser()) { if (!IsRemoteAttestationEnabledForUser()) {
callback_.Run(false, kUserPolicyDisabledError); callback_.Run(false, kUserPolicyDisabledError);
......
...@@ -209,6 +209,7 @@ class EPKPChallengeUserKey : public EPKPChallengeKeyBase { ...@@ -209,6 +209,7 @@ class EPKPChallengeUserKey : public EPKPChallengeKeyBase {
public: public:
static const char kGetCertificateFailedError[]; static const char kGetCertificateFailedError[];
static const char kKeyRegistrationFailedError[]; static const char kKeyRegistrationFailedError[];
static const char kUserKeyNotAvailable[];
static const char kUserPolicyDisabledError[]; static const char kUserPolicyDisabledError[];
EPKPChallengeUserKey(); EPKPChallengeUserKey();
......
...@@ -409,8 +409,9 @@ class EPKPChallengeUserKeyTest : public EPKPChallengeKeyTestBase { ...@@ -409,8 +409,9 @@ class EPKPChallengeUserKeyTest : public EPKPChallengeKeyTestBase {
protected: protected:
static const char kArgs[]; static const char kArgs[];
EPKPChallengeUserKeyTest() explicit EPKPChallengeUserKeyTest(
: EPKPChallengeKeyTestBase(ProfileType::USER_PROFILE), ProfileType profile_type = ProfileType::USER_PROFILE)
: EPKPChallengeKeyTestBase(profile_type),
impl_(&mock_cryptohome_client_, impl_(&mock_cryptohome_client_,
&mock_async_method_caller_, &mock_async_method_caller_,
&mock_attestation_flow_, &mock_attestation_flow_,
...@@ -423,8 +424,10 @@ class EPKPChallengeUserKeyTest : public EPKPChallengeKeyTestBase { ...@@ -423,8 +424,10 @@ class EPKPChallengeUserKeyTest : public EPKPChallengeKeyTestBase {
void SetUp() override { void SetUp() override {
EPKPChallengeKeyTestBase::SetUp(); EPKPChallengeKeyTestBase::SetUp();
// Set the user preferences. if (profile_type_ == ProfileType::USER_PROFILE) {
prefs_->SetBoolean(prefs::kAttestationEnabled, true); // Set the user preferences.
prefs_->SetBoolean(prefs::kAttestationEnabled, true);
}
} }
// Returns an error string for the given code. // Returns an error string for the given code.
...@@ -578,6 +581,19 @@ TEST_F(EPKPChallengeUserKeyTest, AttestationPreparedDbusFailed) { ...@@ -578,6 +581,19 @@ TEST_F(EPKPChallengeUserKeyTest, AttestationPreparedDbusFailed) {
utils::RunFunctionAndReturnError(func_.get(), kArgs, browser())); utils::RunFunctionAndReturnError(func_.get(), kArgs, browser()));
} }
class EPKPChallengeUserKeySigninProfileTest : public EPKPChallengeUserKeyTest {
protected:
EPKPChallengeUserKeySigninProfileTest()
: EPKPChallengeUserKeyTest(ProfileType::SIGNIN_PROFILE) {}
};
TEST_F(EPKPChallengeUserKeySigninProfileTest, UserKeyNotAvailable) {
settings_helper_.SetBoolean(chromeos::kDeviceAttestationEnabled, false);
EXPECT_EQ(EPKPChallengeUserKey::kUserKeyNotAvailable,
utils::RunFunctionAndReturnError(func_.get(), kArgs, browser()));
}
class EPKPChallengeMachineKeyUnmanagedUserTest class EPKPChallengeMachineKeyUnmanagedUserTest
: public EPKPChallengeMachineKeyTest { : public EPKPChallengeMachineKeyTest {
protected: protected:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment