resolve merge conflicts of 4ad7784 to stage-aosp-master

Test: Build seems to be unrelatedly broken
Change-Id: I2df307aa1c7134f217c558495e1438412480f324
Merged-In: I6ccfe0894551ba068de9bf5e23fe4fd1e10e36b1
gugelfrei
Paul Crowley 7 years ago
commit ddb542f574

@ -134,9 +134,16 @@ static bool fill_key(const std::string& key, ext4_encryption_key* ext4_key) {
return true; return true;
} }
static std::string keyname(const std::string& raw_ref) { static char const* const NAME_PREFIXES[] = {
"ext4",
"f2fs",
"fscrypt",
nullptr
};
static std::string keyname(const std::string& prefix, const std::string& raw_ref) {
std::ostringstream o; std::ostringstream o;
o << "ext4:"; o << prefix << ":";
for (unsigned char i : raw_ref) { for (unsigned char i : raw_ref) {
o << std::hex << std::setw(2) << std::setfill('0') << (int)i; o << std::hex << std::setw(2) << std::setfill('0') << (int)i;
} }
@ -159,9 +166,10 @@ static bool install_key(const std::string& key, std::string* raw_ref) {
ext4_encryption_key ext4_key; ext4_encryption_key ext4_key;
if (!fill_key(key, &ext4_key)) return false; if (!fill_key(key, &ext4_key)) return false;
*raw_ref = generate_key_ref(ext4_key.raw, ext4_key.size); *raw_ref = generate_key_ref(ext4_key.raw, ext4_key.size);
auto ref = keyname(*raw_ref);
key_serial_t device_keyring; key_serial_t device_keyring;
if (!e4crypt_keyring(&device_keyring)) return false; if (!e4crypt_keyring(&device_keyring)) return false;
for (char const* const* name_prefix = NAME_PREFIXES; *name_prefix != nullptr; name_prefix++) {
auto ref = keyname(*name_prefix, *raw_ref);
key_serial_t key_id = key_serial_t key_id =
add_key("logon", ref.c_str(), (void*)&ext4_key, sizeof(ext4_key), device_keyring); add_key("logon", ref.c_str(), (void*)&ext4_key, sizeof(ext4_key), device_keyring);
if (key_id == -1) { if (key_id == -1) {
@ -170,7 +178,7 @@ static bool install_key(const std::string& key, std::string* raw_ref) {
} }
LOG(DEBUG) << "Added key " << key_id << " (" << ref << ") to keyring " << device_keyring LOG(DEBUG) << "Added key " << key_id << " (" << ref << ") to keyring " << device_keyring
<< " in process " << getpid(); << " in process " << getpid();
}
return true; return true;
} }
@ -527,9 +535,11 @@ bool e4crypt_vold_create_user_key(userid_t user_id, int serial, bool ephemeral)
} }
static bool evict_key(const std::string &raw_ref) { static bool evict_key(const std::string &raw_ref) {
auto ref = keyname(raw_ref);
key_serial_t device_keyring; key_serial_t device_keyring;
if (!e4crypt_keyring(&device_keyring)) return false; if (!e4crypt_keyring(&device_keyring)) return false;
bool success = true;
for (char const* const* name_prefix = NAME_PREFIXES; *name_prefix != nullptr; name_prefix++) {
auto ref = keyname(*name_prefix, raw_ref);
auto key_serial = keyctl_search(device_keyring, "logon", ref.c_str(), 0); auto key_serial = keyctl_search(device_keyring, "logon", ref.c_str(), 0);
// Unlink the key from the keyring. Prefer unlinking to revoking or // Unlink the key from the keyring. Prefer unlinking to revoking or
@ -538,10 +548,12 @@ static bool evict_key(const std::string &raw_ref) {
// referenced from places it shouldn't be. // referenced from places it shouldn't be.
if (keyctl_unlink(key_serial, device_keyring) != 0) { if (keyctl_unlink(key_serial, device_keyring) != 0) {
PLOG(ERROR) << "Failed to unlink key with serial " << key_serial << " ref " << ref; PLOG(ERROR) << "Failed to unlink key with serial " << key_serial << " ref " << ref;
return false; success = false;
} } else {
LOG(DEBUG) << "Unlinked key with serial " << key_serial << " ref " << ref; LOG(DEBUG) << "Unlinked key with serial " << key_serial << " ref " << ref;
return true; }
}
return success;
} }
static bool evict_ce_key(userid_t user_id) { static bool evict_ce_key(userid_t user_id) {

Loading…
Cancel
Save