Commit e7e066d0 authored by bartfab's avatar bartfab Committed by Commit bot

Merge cryptohome::RetrievedKeyData with cryptohome::KeyDefinition

cryptohome::RetrievedKeyData and cryptohome::KeyDefinition both represent
subsets of the Key protobuf. This CL merges the two classes and makes the
resulting cryptohome::KeyDefinition contain all of Key's fields.

TBR=pamg (manager_password_service.cc)

BUG=367847
TEST=Updated unit tests

Review URL: https://codereview.chromium.org/526353002

Cr-Commit-Position: refs/heads/master@{#294823}
parent 908d5240
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
#include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h"
#include <string> #include <string>
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -258,25 +258,22 @@ class CryptohomeAuthenticatorTest : public testing::Test { ...@@ -258,25 +258,22 @@ class CryptohomeAuthenticatorTest : public testing::Test {
void ExpectGetKeyDataExCall(scoped_ptr<int64> key_type, void ExpectGetKeyDataExCall(scoped_ptr<int64> key_type,
scoped_ptr<std::string> salt) { scoped_ptr<std::string> salt) {
key_data_.clear(); key_definitions_.clear();
key_data_.push_back(new cryptohome::RetrievedKeyData( key_definitions_.push_back(cryptohome::KeyDefinition(
cryptohome::RetrievedKeyData::TYPE_PASSWORD, std::string() /* secret */,
kCryptohomeGAIAKeyLabel, kCryptohomeGAIAKeyLabel,
1)); cryptohome::PRIV_DEFAULT));
key_data_.front()->privileges = cryptohome::PRIV_DEFAULT; cryptohome::KeyDefinition& key_definition = key_definitions_.back();
key_data_.front()->authorization_types.push_back( key_definition.revision = 1;
cryptohome::RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256);
if (key_type) { if (key_type) {
scoped_ptr<cryptohome::RetrievedKeyData::ProviderData> provider_data( key_definition.provider_data.push_back(
new cryptohome::RetrievedKeyData::ProviderData("type")); cryptohome::KeyDefinition::ProviderData("type"));
provider_data->number = key_type.Pass(); key_definition.provider_data.back().number = key_type.Pass();
key_data_.front()->provider_data.push_back(provider_data.release());
} }
if (salt) { if (salt) {
scoped_ptr<cryptohome::RetrievedKeyData::ProviderData> provider_data( key_definition.provider_data.push_back(
new cryptohome::RetrievedKeyData::ProviderData("salt")); cryptohome::KeyDefinition::ProviderData("salt"));
provider_data->bytes = salt.Pass(); key_definition.provider_data.back().bytes = salt.Pass();
key_data_.front()->provider_data.push_back(provider_data.release());
} }
EXPECT_CALL(*mock_homedir_methods_, GetKeyDataEx( EXPECT_CALL(*mock_homedir_methods_, GetKeyDataEx(
cryptohome::Identification(user_context_.GetUserID()), cryptohome::Identification(user_context_.GetUserID()),
...@@ -333,7 +330,7 @@ class CryptohomeAuthenticatorTest : public testing::Test { ...@@ -333,7 +330,7 @@ class CryptohomeAuthenticatorTest : public testing::Test {
UserContext user_context_with_transformed_key_; UserContext user_context_with_transformed_key_;
Key transformed_key_; Key transformed_key_;
ScopedVector<cryptohome::RetrievedKeyData> key_data_; std::vector<cryptohome::KeyDefinition> key_definitions_;
ScopedDeviceSettingsTestHelper device_settings_test_helper_; ScopedDeviceSettingsTestHelper device_settings_test_helper_;
ScopedTestCrosSettings test_cros_settings_; ScopedTestCrosSettings test_cros_settings_;
...@@ -359,7 +356,7 @@ class CryptohomeAuthenticatorTest : public testing::Test { ...@@ -359,7 +356,7 @@ class CryptohomeAuthenticatorTest : public testing::Test {
const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { const cryptohome::HomedirMethods::GetKeyDataCallback& callback) {
callback.Run(true /* success */, callback.Run(true /* success */,
cryptohome::MOUNT_ERROR_NONE, cryptohome::MOUNT_ERROR_NONE,
key_data_.Pass()); key_definitions_);
} }
}; };
......
...@@ -270,10 +270,18 @@ void SupervisedUserCreationControllerNew::OnMountSuccess( ...@@ -270,10 +270,18 @@ void SupervisedUserCreationControllerNew::OnMountSuccess(
creation_context_->salted_password, creation_context_->salted_password,
kCryptohomeSupervisedUserKeyLabel, kCryptohomeSupervisedUserKeyLabel,
kCryptohomeSupervisedUserKeyPrivileges); kCryptohomeSupervisedUserKeyPrivileges);
base::Base64Decode(creation_context_->encryption_key, std::string encryption_key;
&password_key.encryption_key); base::Base64Decode(creation_context_->encryption_key, &encryption_key);
base::Base64Decode(creation_context_->signature_key, password_key.authorization_data.push_back(
&password_key.signature_key); cryptohome::KeyDefinition::AuthorizationData(true /* encrypt */,
false /* sign */,
encryption_key));
std::string signature_key;
base::Base64Decode(creation_context_->signature_key, &signature_key);
password_key.authorization_data.push_back(
cryptohome::KeyDefinition::AuthorizationData(false /* encrypt */,
true /* sign */,
signature_key));
Key key(Key::KEY_TYPE_SALTED_PBKDF2_AES256_1234, Key key(Key::KEY_TYPE_SALTED_PBKDF2_AES256_1234,
std::string(), // The salt is stored elsewhere. std::string(), // The salt is stored elsewhere.
......
...@@ -164,9 +164,14 @@ void ManagerPasswordService::GetSupervisedUsersCallback( ...@@ -164,9 +164,14 @@ void ManagerPasswordService::GetSupervisedUsersCallback(
kCryptohomeSupervisedUserKeyLabel, kCryptohomeSupervisedUserKeyLabel,
cryptohome::PRIV_AUTHORIZED_UPDATE || cryptohome::PRIV_MOUNT); cryptohome::PRIV_AUTHORIZED_UPDATE || cryptohome::PRIV_MOUNT);
new_key_definition.revision = revision; new_key_definition.revision = revision;
new_key_definition.authorization_data.push_back(
new_key_definition.encryption_key = encryption_key; cryptohome::KeyDefinition::AuthorizationData(true /* encrypt */,
new_key_definition.signature_key = signature_key; false /* sign */,
encryption_key));
new_key_definition.authorization_data.push_back(
cryptohome::KeyDefinition::AuthorizationData(false /* encrypt */,
true /* sign */,
signature_key));
authenticator_->AddKey(manager_key, authenticator_->AddKey(manager_key,
new_key_definition, new_key_definition,
......
...@@ -15,25 +15,135 @@ bool Identification::operator==(const Identification& other) const { ...@@ -15,25 +15,135 @@ bool Identification::operator==(const Identification& other) const {
return user_id == other.user_id; return user_id == other.user_id;
} }
KeyDefinition::KeyDefinition(const std::string& key, KeyDefinition::AuthorizationData::Secret::Secret() : encrypt(false),
sign(false),
wrapped(false) {
}
KeyDefinition::AuthorizationData::Secret::Secret(
bool encrypt,
bool sign,
const std::string& symmetric_key,
const std::string& public_key,
bool wrapped)
: encrypt(encrypt),
sign(sign),
symmetric_key(symmetric_key),
public_key(public_key),
wrapped(wrapped) {
}
bool KeyDefinition::AuthorizationData::Secret::operator==(
const Secret& other) const {
return encrypt == other.encrypt &&
sign == other.sign &&
symmetric_key == other.symmetric_key &&
public_key == other.public_key &&
wrapped == other.wrapped;
}
KeyDefinition::AuthorizationData::AuthorizationData() : type(TYPE_HMACSHA256) {
}
KeyDefinition::AuthorizationData::AuthorizationData(
bool encrypt,
bool sign,
const std::string& symmetric_key) : type(TYPE_HMACSHA256) {
secrets.push_back(Secret(encrypt,
sign,
symmetric_key,
std::string() /* public_key */,
false /* wrapped */));
}
KeyDefinition::AuthorizationData::~AuthorizationData() {
}
bool KeyDefinition::AuthorizationData::operator==(
const AuthorizationData& other) const {
if (type != other.type || secrets.size() != other.secrets.size())
return false;
for (size_t i = 0; i < secrets.size(); ++i) {
if (!(secrets[i] == other.secrets[i]))
return false;
}
return true;
}
KeyDefinition::ProviderData::ProviderData() {
}
KeyDefinition::ProviderData::ProviderData(const std::string& name)
: name(name) {
}
KeyDefinition::ProviderData::ProviderData(const ProviderData& other)
: name(other.name) {
if (other.number)
number.reset(new int64(*other.number));
if (other.bytes)
bytes.reset(new std::string(*other.bytes));
}
void KeyDefinition::ProviderData::operator=(const ProviderData& other) {
name = other.name;
number.reset(other.number ? new int64(*other.number) : NULL);
bytes.reset(other.bytes ? new std::string(*other.bytes) : NULL);
}
KeyDefinition::ProviderData::~ProviderData() {
}
bool KeyDefinition::ProviderData::operator==(const ProviderData& other) const {
const bool has_number = number;
const bool other_has_number = other.number;
const bool has_bytes = bytes;
const bool other_has_bytes = other.bytes;
return name == other.name &&
has_number == other_has_number &&
has_bytes == other_has_bytes &&
(!has_number || (*number == *other.number)) &&
(!has_bytes || (*bytes == *other.bytes));
}
KeyDefinition::KeyDefinition() : type(TYPE_PASSWORD),
privileges(0),
revision(0) {
}
KeyDefinition::KeyDefinition(const std::string& secret,
const std::string& label, const std::string& label,
int /*AuthKeyPrivileges*/ privileges) int /*AuthKeyPrivileges*/ privileges)
: label(label), : type(TYPE_PASSWORD),
revision(1), label(label),
key(key), privileges(privileges),
privileges(privileges) { revision(0),
secret(secret) {
} }
KeyDefinition::~KeyDefinition() { KeyDefinition::~KeyDefinition() {
} }
bool KeyDefinition::operator==(const KeyDefinition& other) const { bool KeyDefinition::operator==(const KeyDefinition& other) const {
return label == other.label && if (type != other.type ||
revision == other.revision && label != other.label ||
key == other.key && privileges != other.privileges ||
encryption_key == other.encryption_key && revision != other.revision ||
signature_key == other.signature_key && authorization_data.size() != other.authorization_data.size() ||
privileges == other.privileges; provider_data.size() != other.provider_data.size()) {
return false;
}
for (size_t i = 0; i < authorization_data.size(); ++i) {
if (!(authorization_data[i] == other.authorization_data[i]))
return false;
}
for (size_t i = 0; i < provider_data.size(); ++i) {
if (!(provider_data[i] == other.provider_data[i]))
return false;
}
return true;
} }
Authorization::Authorization(const std::string& key, const std::string& label) Authorization::Authorization(const std::string& key, const std::string& label)
...@@ -42,7 +152,7 @@ Authorization::Authorization(const std::string& key, const std::string& label) ...@@ -42,7 +152,7 @@ Authorization::Authorization(const std::string& key, const std::string& label)
} }
Authorization::Authorization(const KeyDefinition& key_def) Authorization::Authorization(const KeyDefinition& key_def)
: key(key_def.key), : key(key_def.secret),
label(key_def.label) { label(key_def.label) {
} }
...@@ -50,24 +160,6 @@ bool Authorization::operator==(const Authorization& other) const { ...@@ -50,24 +160,6 @@ bool Authorization::operator==(const Authorization& other) const {
return key == other.key && label == other.label; return key == other.key && label == other.label;
} }
RetrievedKeyData::ProviderData::ProviderData(const std::string& name)
: name(name) {
}
RetrievedKeyData::ProviderData::~ProviderData() {
}
RetrievedKeyData::RetrievedKeyData(Type type,
const std::string& label,
int64 revision) : type(type),
label(label),
privileges(0),
revision(revision) {
}
RetrievedKeyData::~RetrievedKeyData() {
}
MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) { MountParameters::MountParameters(bool ephemeral) : ephemeral(ephemeral) {
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "chromeos/chromeos_export.h" #include "chromeos/chromeos_export.h"
namespace cryptohome { namespace cryptohome {
...@@ -34,68 +33,96 @@ struct CHROMEOS_EXPORT Identification { ...@@ -34,68 +33,96 @@ struct CHROMEOS_EXPORT Identification {
}; };
// Definition of the key (e.g. password) for the cryptohome. // Definition of the key (e.g. password) for the cryptohome.
// It contains authorization data along with extra parameters like perimissions // It contains authorization data along with extra parameters like permissions
// associated with this key. // associated with this key.
struct CHROMEOS_EXPORT KeyDefinition { struct CHROMEOS_EXPORT KeyDefinition {
KeyDefinition(const std::string& key,
const std::string& label,
int /*AuthKeyPrivileges*/ privileges);
~KeyDefinition();
bool operator==(const KeyDefinition& other) const;
std::string label;
int revision;
std::string key;
std::string encryption_key;
std::string signature_key;
// Privileges associated with key. Combination of |AuthKeyPrivileges| values.
int privileges;
};
// Authorization attempt data for user.
struct CHROMEOS_EXPORT Authorization {
Authorization(const std::string& key, const std::string& label);
explicit Authorization(const KeyDefinition& key);
bool operator==(const Authorization& other) const;
std::string key;
std::string label;
};
// Information about keys returned by GetKeyDataEx().
struct CHROMEOS_EXPORT RetrievedKeyData {
enum Type { enum Type {
TYPE_PASSWORD = 0 TYPE_PASSWORD = 0
}; };
enum AuthorizationType { struct AuthorizationData {
AUTHORIZATION_TYPE_HMACSHA256 = 0, enum Type {
AUTHORIZATION_TYPE_AES256CBC_HMACSHA256 TYPE_HMACSHA256 = 0,
TYPE_AES256CBC_HMACSHA256
};
struct Secret {
Secret();
Secret(bool encrypt,
bool sign,
const std::string& symmetric_key,
const std::string& public_key,
bool wrapped);
bool operator==(const Secret& other) const;
bool encrypt;
bool sign;
std::string symmetric_key;
std::string public_key;
bool wrapped;
};
AuthorizationData();
AuthorizationData(bool encrypt,
bool sign,
const std::string& symmetric_key);
~AuthorizationData();
bool operator==(const AuthorizationData& other) const;
Type type;
std::vector<Secret> secrets;
}; };
// This struct holds metadata that will be stored alongside the key. Each
// |ProviderData| entry must have a |name| and may hold either a |number| or a
// sequence of |bytes|. The metadata is entirely opaque to cryptohome. It is
// stored with the key and returned when requested but is never interpreted by
// cryptohome in any way. The metadata can be used to store information such
// as the hashing algorithm and the salt used to create the key.
struct ProviderData { struct ProviderData {
ProviderData();
explicit ProviderData(const std::string& name); explicit ProviderData(const std::string& name);
explicit ProviderData(const ProviderData& other);
void operator=(const ProviderData& other);
~ProviderData(); ~ProviderData();
bool operator==(const ProviderData& other) const;
std::string name; std::string name;
scoped_ptr<int64> number; scoped_ptr<int64> number;
scoped_ptr<std::string> bytes; scoped_ptr<std::string> bytes;
}; };
RetrievedKeyData(Type type, const std::string& label, int64 revision); KeyDefinition();
~RetrievedKeyData(); KeyDefinition(const std::string& secret,
const std::string& label,
int privileges);
~KeyDefinition();
bool operator==(const KeyDefinition& other) const;
Type type; Type type;
std::string label; std::string label;
// Privileges associated with key. Combination of |AuthKeyPrivileges| values. // Privileges associated with key. Combination of |AuthKeyPrivileges| values.
int privileges; int privileges;
int64 revision; int revision;
std::vector<AuthorizationType> authorization_types; std::string secret;
ScopedVector<ProviderData> provider_data;
std::vector<AuthorizationData> authorization_data;
std::vector<ProviderData> provider_data;
};
// Authorization attempt data for user.
struct CHROMEOS_EXPORT Authorization {
Authorization(const std::string& key, const std::string& label);
explicit Authorization(const KeyDefinition& key);
bool operator==(const Authorization& other) const;
std::string key;
std::string label;
}; };
// Parameters for Mount call. // Parameters for Mount call.
......
...@@ -27,8 +27,10 @@ namespace { ...@@ -27,8 +27,10 @@ namespace {
HomedirMethods* g_homedir_methods = NULL; HomedirMethods* g_homedir_methods = NULL;
void FillKeyProtobuf(const KeyDefinition& key_def, Key* key) { void FillKeyProtobuf(const KeyDefinition& key_def, Key* key) {
key->set_secret(key_def.key); key->set_secret(key_def.secret);
KeyData* data = key->mutable_data(); KeyData* data = key->mutable_data();
DCHECK_EQ(KeyDefinition::TYPE_PASSWORD, key_def.type);
data->set_type(KeyData::KEY_TYPE_PASSWORD);
data->set_label(key_def.label); data->set_label(key_def.label);
if (key_def.revision > 0) if (key_def.revision > 0)
...@@ -44,20 +46,48 @@ void FillKeyProtobuf(const KeyDefinition& key_def, Key* key) { ...@@ -44,20 +46,48 @@ void FillKeyProtobuf(const KeyDefinition& key_def, Key* key) {
PRIV_AUTHORIZED_UPDATE); PRIV_AUTHORIZED_UPDATE);
} }
if (key_def.encryption_key.empty() && key_def.signature_key.empty()) for (std::vector<KeyDefinition::AuthorizationData>::const_iterator auth_it =
return; key_def.authorization_data.begin();
auth_it != key_def.authorization_data.end(); ++auth_it) {
KeyAuthorizationData* auth_data = data->add_authorization_data();
switch (auth_it->type) {
case KeyDefinition::AuthorizationData::TYPE_HMACSHA256:
auth_data->set_type(
KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_HMACSHA256);
break;
case KeyDefinition::AuthorizationData::TYPE_AES256CBC_HMACSHA256:
auth_data->set_type(
KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_AES256CBC_HMACSHA256);
break;
default:
NOTREACHED();
break;
}
KeyAuthorizationData* auth_data = data->add_authorization_data(); for (std::vector<KeyDefinition::AuthorizationData::Secret>::const_iterator
auth_data->set_type(KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_HMACSHA256); secret_it = auth_it->secrets.begin();
if (!key_def.encryption_key.empty()) { secret_it != auth_it->secrets.end(); ++secret_it) {
KeyAuthorizationSecret* secret = auth_data->add_secrets(); KeyAuthorizationSecret* secret = auth_data->add_secrets();
secret->mutable_usage()->set_encrypt(true); secret->mutable_usage()->set_encrypt(secret_it->encrypt);
secret->set_symmetric_key(key_def.encryption_key); secret->mutable_usage()->set_sign(secret_it->sign);
if (!secret_it->symmetric_key.empty())
secret->set_symmetric_key(secret_it->symmetric_key);
if (!secret_it->public_key.empty())
secret->set_public_key(secret_it->public_key);
secret->set_wrapped(secret_it->wrapped);
}
} }
if (!key_def.signature_key.empty()) {
KeyAuthorizationSecret* secret = auth_data->add_secrets(); for (std::vector<KeyDefinition::ProviderData>::const_iterator it =
secret->mutable_usage()->set_sign(true); key_def.provider_data.begin(); it != key_def.provider_data.end();
secret->set_symmetric_key(key_def.signature_key); ++it) {
KeyProviderData::Entry* entry =
data->mutable_provider_data()->add_entry();
entry->set_name(it->name);
if (it->number)
entry->set_number(*it->number);
if (it->bytes)
entry->set_bytes(*it->bytes);
} }
} }
...@@ -77,6 +107,35 @@ void FillAuthorizationProtobuf(const Authorization& auth, ...@@ -77,6 +107,35 @@ void FillAuthorizationProtobuf(const Authorization& auth,
key->set_secret(auth.key); key->set_secret(auth.key);
} }
void ParseAuthorizationDataProtobuf(
const KeyAuthorizationData& authorization_data_proto,
KeyDefinition::AuthorizationData* authorization_data) {
switch (authorization_data_proto.type()) {
case KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_HMACSHA256:
authorization_data->type =
KeyDefinition::AuthorizationData::TYPE_HMACSHA256;
break;
case KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_AES256CBC_HMACSHA256:
authorization_data->type =
KeyDefinition::AuthorizationData::TYPE_AES256CBC_HMACSHA256;
break;
default:
NOTREACHED();
return;
}
for (RepeatedPtrField<KeyAuthorizationSecret>::const_iterator it =
authorization_data_proto.secrets().begin();
it != authorization_data_proto.secrets().end(); ++it) {
authorization_data->secrets.push_back(
KeyDefinition::AuthorizationData::Secret(it->usage().encrypt(),
it->usage().sign(),
it->symmetric_key(),
it->public_key(),
it->wrapped()));
}
}
MountError MapError(CryptohomeErrorCode code) { MountError MapError(CryptohomeErrorCode code) {
switch (code) { switch (code) {
case CRYPTOHOME_ERROR_NOT_SET: case CRYPTOHOME_ERROR_NOT_SET:
...@@ -257,69 +316,60 @@ class HomedirMethodsImpl : public HomedirMethods { ...@@ -257,69 +316,60 @@ class HomedirMethodsImpl : public HomedirMethods {
bool result, bool result,
const BaseReply& reply) { const BaseReply& reply) {
if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) {
callback.Run(false, MOUNT_ERROR_FATAL, ScopedVector<RetrievedKeyData>()); callback.Run(false, MOUNT_ERROR_FATAL, std::vector<KeyDefinition>());
return; return;
} }
if (reply.has_error()) { if (reply.has_error()) {
if (reply.error() != CRYPTOHOME_ERROR_NOT_SET) { if (reply.error() != CRYPTOHOME_ERROR_NOT_SET) {
callback.Run(false, callback.Run(false,
MapError(reply.error()), MapError(reply.error()),
ScopedVector<RetrievedKeyData>()); std::vector<KeyDefinition>());
return; return;
} }
} }
if (!reply.HasExtension(GetKeyDataReply::reply)) { if (!reply.HasExtension(GetKeyDataReply::reply)) {
callback.Run(false, MOUNT_ERROR_FATAL, ScopedVector<RetrievedKeyData>()); callback.Run(false, MOUNT_ERROR_FATAL, std::vector<KeyDefinition>());
return; return;
} }
// Extract the contents of the |KeyData| protos returned. // Extract the contents of the |KeyData| protos returned.
const RepeatedPtrField<KeyData>& key_data_proto = const RepeatedPtrField<KeyData>& key_data =
reply.GetExtension(GetKeyDataReply::reply).key_data(); reply.GetExtension(GetKeyDataReply::reply).key_data();
ScopedVector<RetrievedKeyData> key_data_list; std::vector<KeyDefinition> key_definitions;
for (RepeatedPtrField<KeyData>::const_iterator it = key_data_proto.begin(); for (RepeatedPtrField<KeyData>::const_iterator it = key_data.begin();
it != key_data_proto.end(); ++it) { it != key_data.end(); ++it) {
// Extract |type|, |label| and |revision|. // Extract |type|, |label| and |revision|.
DCHECK_EQ(KeyData::KEY_TYPE_PASSWORD, it->type()); DCHECK_EQ(KeyData::KEY_TYPE_PASSWORD, it->type());
key_data_list.push_back(new RetrievedKeyData( key_definitions.push_back(KeyDefinition(std::string() /* secret */,
RetrievedKeyData::TYPE_PASSWORD, it->label(),
it->label(), 0 /* privileges */));
it->revision())); KeyDefinition& key_definition = key_definitions.back();
RetrievedKeyData* key_data = key_data_list.back(); key_definition.revision = it->revision();
// Extract |privileges|. // Extract |privileges|.
const KeyPrivileges& privileges = it->privileges(); const KeyPrivileges& privileges = it->privileges();
if (privileges.mount()) if (privileges.mount())
key_data->privileges |= PRIV_MOUNT; key_definition.privileges |= PRIV_MOUNT;
if (privileges.add()) if (privileges.add())
key_data->privileges |= PRIV_ADD; key_definition.privileges |= PRIV_ADD;
if (privileges.remove()) if (privileges.remove())
key_data->privileges |= PRIV_REMOVE; key_definition.privileges |= PRIV_REMOVE;
if (privileges.update()) if (privileges.update())
key_data->privileges |= PRIV_MIGRATE; key_definition.privileges |= PRIV_MIGRATE;
if (privileges.authorized_update()) if (privileges.authorized_update())
key_data->privileges |= PRIV_AUTHORIZED_UPDATE; key_definition.privileges |= PRIV_AUTHORIZED_UPDATE;
// Extract |authorization_data|. // Extract |authorization_data|.
for (RepeatedPtrField<KeyAuthorizationData>::const_iterator auth_it = for (RepeatedPtrField<KeyAuthorizationData>::const_iterator auth_it =
it->authorization_data().begin(); it->authorization_data().begin();
auth_it != it->authorization_data().end(); ++auth_it) { auth_it != it->authorization_data().end(); ++auth_it) {
switch (auth_it->type()) { key_definition.authorization_data.push_back(
case KeyAuthorizationData::KEY_AUTHORIZATION_TYPE_HMACSHA256: KeyDefinition::AuthorizationData());
key_data->authorization_types.push_back( ParseAuthorizationDataProtobuf(
RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256); *auth_it,
break; &key_definition.authorization_data.back());
case KeyAuthorizationData::
KEY_AUTHORIZATION_TYPE_AES256CBC_HMACSHA256:
key_data->authorization_types.push_back(
RetrievedKeyData::AUTHORIZATION_TYPE_AES256CBC_HMACSHA256);
break;
default:
NOTREACHED();
break;
}
} }
// Extract |provider_data|. // Extract |provider_data|.
...@@ -328,22 +378,22 @@ class HomedirMethodsImpl : public HomedirMethods { ...@@ -328,22 +378,22 @@ class HomedirMethodsImpl : public HomedirMethods {
provider_data_it != it->provider_data().entry().end(); provider_data_it != it->provider_data().entry().end();
++provider_data_it) { ++provider_data_it) {
// Extract |name|. // Extract |name|.
key_data->provider_data.push_back( key_definition.provider_data.push_back(
new RetrievedKeyData::ProviderData(provider_data_it->name())); KeyDefinition::ProviderData(provider_data_it->name()));
RetrievedKeyData::ProviderData* provider_data = KeyDefinition::ProviderData& provider_data =
key_data->provider_data.back(); key_definition.provider_data.back();
int data_items = 0; int data_items = 0;
// Extract |number|. // Extract |number|.
if (provider_data_it->has_number()) { if (provider_data_it->has_number()) {
provider_data->number.reset(new int64(provider_data_it->number())); provider_data.number.reset(new int64(provider_data_it->number()));
++data_items; ++data_items;
} }
// Extract |bytes|. // Extract |bytes|.
if (provider_data_it->has_bytes()) { if (provider_data_it->has_bytes()) {
provider_data->bytes.reset( provider_data.bytes.reset(
new std::string(provider_data_it->bytes())); new std::string(provider_data_it->bytes()));
++data_items; ++data_items;
} }
...@@ -352,7 +402,7 @@ class HomedirMethodsImpl : public HomedirMethods { ...@@ -352,7 +402,7 @@ class HomedirMethodsImpl : public HomedirMethods {
} }
} }
callback.Run(true, MOUNT_ERROR_NONE, key_data_list.Pass()); callback.Run(true, MOUNT_ERROR_NONE, key_definitions);
} }
void OnMountExCallback(const MountCallback& callback, void OnMountExCallback(const MountCallback& callback,
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#define CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_ #define CHROMEOS_CRYPTOHOME_HOMEDIR_METHODS_H_
#include <string> #include <string>
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/scoped_vector.h"
#include "chromeos/chromeos_export.h" #include "chromeos/chromeos_export.h"
#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/cryptohome_client.h"
...@@ -27,7 +27,7 @@ class CHROMEOS_EXPORT HomedirMethods { ...@@ -27,7 +27,7 @@ class CHROMEOS_EXPORT HomedirMethods {
typedef base::Callback<void( typedef base::Callback<void(
bool success, bool success,
MountError return_code, MountError return_code,
ScopedVector<RetrievedKeyData> key_data)> GetKeyDataCallback; const std::vector<KeyDefinition>& key_definitions)> GetKeyDataCallback;
typedef base::Callback< typedef base::Callback<
void(bool success, MountError return_code, const std::string& mount_hash)> void(bool success, MountError return_code, const std::string& mount_hash)>
MountCallback; MountCallback;
......
...@@ -55,9 +55,10 @@ class HomedirMethodsTest : public testing::Test { ...@@ -55,9 +55,10 @@ class HomedirMethodsTest : public testing::Test {
void RunProtobufMethodCallback( void RunProtobufMethodCallback(
const chromeos::CryptohomeClient::ProtobufMethodCallback& callback); const chromeos::CryptohomeClient::ProtobufMethodCallback& callback);
void StoreGetKeyDataExResult(bool success, void StoreGetKeyDataExResult(
MountError return_code, bool success,
ScopedVector<RetrievedKeyData> key_data); MountError return_code,
const std::vector<KeyDefinition>& key_definitions);
protected: protected:
chromeos::MockCryptohomeClient* cryptohome_client_; chromeos::MockCryptohomeClient* cryptohome_client_;
...@@ -68,7 +69,7 @@ class HomedirMethodsTest : public testing::Test { ...@@ -68,7 +69,7 @@ class HomedirMethodsTest : public testing::Test {
// The results of the most recent |HomedirMethods| method call. // The results of the most recent |HomedirMethods| method call.
bool success_; bool success_;
MountError return_code_; MountError return_code_;
ScopedVector<RetrievedKeyData> key_data_; std::vector<KeyDefinition> key_definitions_;
private: private:
DISALLOW_COPY_AND_ASSIGN(HomedirMethodsTest); DISALLOW_COPY_AND_ASSIGN(HomedirMethodsTest);
...@@ -106,10 +107,10 @@ void HomedirMethodsTest::RunProtobufMethodCallback( ...@@ -106,10 +107,10 @@ void HomedirMethodsTest::RunProtobufMethodCallback(
void HomedirMethodsTest::StoreGetKeyDataExResult( void HomedirMethodsTest::StoreGetKeyDataExResult(
bool success, bool success,
MountError return_code, MountError return_code,
ScopedVector<RetrievedKeyData> key_data) { const std::vector<KeyDefinition>& key_definitions) {
success_ = success; success_ = success;
return_code_ = return_code; return_code_ = return_code;
key_data_.swap(key_data); key_definitions_ = key_definitions;
} }
// Verifies that the result of a GetKeyDataEx() call is correctly parsed. // Verifies that the result of a GetKeyDataEx() call is correctly parsed.
...@@ -158,23 +159,23 @@ TEST_F(HomedirMethodsTest, GetKeyDataEx) { ...@@ -158,23 +159,23 @@ TEST_F(HomedirMethodsTest, GetKeyDataEx) {
// Verify that the call was successful and the result was correctly parsed. // Verify that the call was successful and the result was correctly parsed.
EXPECT_TRUE(success_); EXPECT_TRUE(success_);
EXPECT_EQ(MOUNT_ERROR_NONE, return_code_); EXPECT_EQ(MOUNT_ERROR_NONE, return_code_);
ASSERT_EQ(1u, key_data_.size()); ASSERT_EQ(1u, key_definitions_.size());
const RetrievedKeyData* retrieved_key_data = key_data_.front(); const KeyDefinition& key_definition = key_definitions_.front();
EXPECT_EQ(RetrievedKeyData::TYPE_PASSWORD, retrieved_key_data->type); EXPECT_EQ(KeyDefinition::TYPE_PASSWORD, key_definition.type);
EXPECT_EQ(PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE, EXPECT_EQ(PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE,
retrieved_key_data->privileges); key_definition.privileges);
EXPECT_EQ(kKeyRevision, retrieved_key_data->revision); EXPECT_EQ(kKeyRevision, key_definition.revision);
ASSERT_EQ(1u, retrieved_key_data->authorization_types.size()); ASSERT_EQ(1u, key_definition.authorization_data.size());
EXPECT_EQ(RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256, EXPECT_EQ(KeyDefinition::AuthorizationData::TYPE_HMACSHA256,
retrieved_key_data->authorization_types.front()); key_definition.authorization_data.front().type);
ASSERT_EQ(2u, retrieved_key_data->provider_data.size()); ASSERT_EQ(2u, key_definition.provider_data.size());
const RetrievedKeyData::ProviderData* provider_data = const KeyDefinition::ProviderData* provider_data =
retrieved_key_data->provider_data[0]; &key_definition.provider_data[0];
EXPECT_EQ(kProviderData1Name, provider_data->name); EXPECT_EQ(kProviderData1Name, provider_data->name);
ASSERT_TRUE(provider_data->number); ASSERT_TRUE(provider_data->number);
EXPECT_EQ(kProviderData1Number, *provider_data->number.get()); EXPECT_EQ(kProviderData1Number, *provider_data->number.get());
EXPECT_FALSE(provider_data->bytes); EXPECT_FALSE(provider_data->bytes);
provider_data = retrieved_key_data->provider_data[1]; provider_data = &key_definition.provider_data[1];
EXPECT_EQ(kProviderData2Name, provider_data->name); EXPECT_EQ(kProviderData2Name, provider_data->name);
EXPECT_FALSE(provider_data->number); EXPECT_FALSE(provider_data->number);
ASSERT_TRUE(provider_data->bytes); ASSERT_TRUE(provider_data->bytes);
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "chromeos/cryptohome/mock_homedir_methods.h" #include "chromeos/cryptohome/mock_homedir_methods.h"
#include "base/memory/scoped_vector.h" #include <vector>
#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/cryptohome/mock_async_method_caller.h" #include "chromeos/cryptohome/mock_async_method_caller.h"
...@@ -41,7 +42,7 @@ void MockHomedirMethods::DoCallback(const Callback& callback) { ...@@ -41,7 +42,7 @@ void MockHomedirMethods::DoCallback(const Callback& callback) {
} }
void MockHomedirMethods::DoGetDataCallback(const GetKeyDataCallback& callback) { void MockHomedirMethods::DoGetDataCallback(const GetKeyDataCallback& callback) {
callback.Run(success_, return_code_, ScopedVector<RetrievedKeyData>()); callback.Run(success_, return_code_, std::vector<KeyDefinition>());
} }
void MockHomedirMethods::DoMountCallback(const MountCallback& callback) { void MockHomedirMethods::DoMountCallback(const MountCallback& callback) {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "chromeos/login/auth/cryptohome_authenticator.h" #include "chromeos/login/auth/cryptohome_authenticator.h"
#include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
...@@ -175,32 +177,33 @@ void OnGetSystemSalt(AuthAttemptState* attempt, ...@@ -175,32 +177,33 @@ void OnGetSystemSalt(AuthAttemptState* attempt,
// |attempt->user_context| can be transformed with Chrome's default hashing // |attempt->user_context| can be transformed with Chrome's default hashing
// algorithm and the system salt. // algorithm and the system salt.
// The resulting key is then passed to cryptohome's MountEx(). // The resulting key is then passed to cryptohome's MountEx().
void OnGetKeyDataEx(AuthAttemptState* attempt, void OnGetKeyDataEx(
scoped_refptr<CryptohomeAuthenticator> resolver, AuthAttemptState* attempt,
bool ephemeral, scoped_refptr<CryptohomeAuthenticator> resolver,
bool create_if_nonexistent, bool ephemeral,
bool success, bool create_if_nonexistent,
cryptohome::MountError return_code, bool success,
ScopedVector<cryptohome::RetrievedKeyData> key_data) { cryptohome::MountError return_code,
const std::vector<cryptohome::KeyDefinition>& key_definitions) {
if (success) { if (success) {
if (key_data.size() == 1) { if (key_definitions.size() == 1) {
cryptohome::RetrievedKeyData* key_data_entry = key_data.front(); const cryptohome::KeyDefinition& key_definition = key_definitions.front();
DCHECK_EQ(kCryptohomeGAIAKeyLabel, key_data_entry->label); DCHECK_EQ(kCryptohomeGAIAKeyLabel, key_definition.label);
// Extract the key type and salt from |key_data|, if present. // Extract the key type and salt from |key_definition|, if present.
scoped_ptr<int64> type; scoped_ptr<int64> type;
scoped_ptr<std::string> salt; scoped_ptr<std::string> salt;
for (ScopedVector<cryptohome::RetrievedKeyData::ProviderData>:: for (std::vector<cryptohome::KeyDefinition::ProviderData>::
const_iterator it = key_data_entry->provider_data.begin(); const_iterator it = key_definition.provider_data.begin();
it != key_data_entry->provider_data.end(); ++it) { it != key_definition.provider_data.end(); ++it) {
if ((*it)->name == kKeyProviderDataTypeName) { if (it->name == kKeyProviderDataTypeName) {
if ((*it)->number) if (it->number)
type.reset(new int64(*(*it)->number)); type.reset(new int64(*it->number));
else else
NOTREACHED(); NOTREACHED();
} else if ((*it)->name == kKeyProviderDataSaltName) { } else if (it->name == kKeyProviderDataSaltName) {
if ((*it)->bytes) if (it->bytes)
salt.reset(new std::string(*(*it)->bytes)); salt.reset(new std::string(*it->bytes));
else else
NOTREACHED(); NOTREACHED();
} }
...@@ -226,7 +229,7 @@ void OnGetKeyDataEx(AuthAttemptState* attempt, ...@@ -226,7 +229,7 @@ void OnGetKeyDataEx(AuthAttemptState* attempt,
return; return;
} }
} else { } else {
LOG(ERROR) << "GetKeyDataEx() returned " << key_data.size() LOG(ERROR) << "GetKeyDataEx() returned " << key_definitions.size()
<< " entries."; << " entries.";
} }
} }
......
...@@ -89,7 +89,7 @@ void ExtendedAuthenticator::CreateMount( ...@@ -89,7 +89,7 @@ void ExtendedAuthenticator::CreateMount(
mount.create_keys.push_back(keys[i]); mount.create_keys.push_back(keys[i]);
} }
UserContext context(user_id); UserContext context(user_id);
Key key(keys.front().key); Key key(keys.front().secret);
key.SetLabel(keys.front().label); key.SetLabel(keys.front().label);
context.SetKey(key); context.SetKey(key);
......
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