1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/cryptohome/cryptohome_parameters.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include "base/memory/values_equivalent.h"
#include "base/notreached.h"
#include "chromeos/ash/components/cryptohome/common_types.h"
#include "chromeos/ash/components/cryptohome/cryptohome_util.h"
#include "chromeos/ash/components/dbus/cryptohome/key.pb.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/known_user.h"
namespace cryptohome {
namespace {
using ::ash::ChallengeResponseKey;
} // anonymous namespace
Identification::Identification() = default;
Identification::Identification(const AccountId& account_id)
: id_(GetCryptohomeId(account_id)) {}
Identification::Identification(const std::string& id) : id_(id) {}
Identification Identification::FromString(const std::string& id) {
return Identification(id);
}
bool Identification::operator==(const Identification& other) const {
return id_ == other.id_;
}
bool Identification::operator<(const Identification& right) const {
return id_ < right.id_;
}
AccountIdentifier CreateAccountIdentifierFromAccountId(const AccountId& id) {
AccountIdentifier out;
out.set_account_id(GetCryptohomeId(id));
return out;
}
AccountIdentifier CreateAccountIdentifierFromIdentification(
const Identification& id) {
AccountIdentifier out;
out.set_account_id(id.id());
return out;
}
KeyDefinition::ProviderData::ProviderData() = default;
KeyDefinition::ProviderData::ProviderData(const std::string& name)
: name(name) {}
KeyDefinition::ProviderData::ProviderData(const ProviderData& other)
: name(other.name) {
if (other.number) {
number = std::make_unique<int64_t>(*other.number);
}
if (other.bytes) {
bytes = std::make_unique<std::string>(*other.bytes);
}
}
KeyDefinition::ProviderData::ProviderData(const std::string& name,
int64_t number)
: name(name), number(new int64_t(number)) {}
KeyDefinition::ProviderData::ProviderData(const std::string& name,
const std::string& bytes)
: name(name), bytes(new std::string(bytes)) {}
void KeyDefinition::ProviderData::operator=(const ProviderData& other) {
name = other.name;
number.reset(other.number ? new int64_t(*other.number) : nullptr);
bytes.reset(other.bytes ? new std::string(*other.bytes) : nullptr);
}
KeyDefinition::ProviderData::~ProviderData() = default;
bool KeyDefinition::ProviderData::operator==(const ProviderData& other) const {
return name == other.name && base::ValuesEquivalent(number, other.number) &&
base::ValuesEquivalent(bytes, other.bytes);
}
bool KeyDefinition::Policy::operator==(const Policy& other) const {
return low_entropy_credential == other.low_entropy_credential &&
auth_locked == other.auth_locked;
}
bool KeyDefinition::Policy::operator!=(const Policy& other) const {
return !(*this == other);
}
KeyDefinition KeyDefinition::CreateForPassword(
const std::string& secret,
const KeyLabel& label,
int /*AuthKeyPrivileges*/ privileges) {
KeyDefinition key_def;
key_def.type = TYPE_PASSWORD;
key_def.label = label;
key_def.privileges = privileges;
key_def.secret = secret;
return key_def;
}
KeyDefinition KeyDefinition::CreateForChallengeResponse(
const std::vector<ChallengeResponseKey>& challenge_response_keys,
const KeyLabel& label,
int /*AuthKeyPrivileges*/ privileges) {
KeyDefinition key_def;
key_def.type = TYPE_CHALLENGE_RESPONSE;
key_def.label = label;
key_def.privileges = privileges;
key_def.challenge_response_keys = challenge_response_keys;
return key_def;
}
KeyDefinition::KeyDefinition() = default;
KeyDefinition::KeyDefinition(const KeyDefinition& other) = default;
KeyDefinition::~KeyDefinition() = default;
bool KeyDefinition::operator==(const KeyDefinition& other) const {
if (type != other.type || label != other.label ||
privileges != other.privileges || policy != other.policy ||
revision != other.revision ||
challenge_response_keys != other.challenge_response_keys ||
provider_data.size() != other.provider_data.size()) {
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 KeyLabel& label)
: key(key), label(label) {}
Authorization::Authorization(const KeyDefinition& key_def)
: key(key_def.secret), label(key_def.label) {}
bool Authorization::operator==(const Authorization& other) const {
return key == other.key && label == other.label;
}
Authorization::~Authorization() = default;
} // namespace cryptohome
|