diff --git a/crypto/ext4crypt/Keymaster.cpp b/crypto/ext4crypt/Keymaster.cpp index 1e981b94..ec80ab58 100644 --- a/crypto/ext4crypt/Keymaster.cpp +++ b/crypto/ext4crypt/Keymaster.cpp @@ -130,14 +130,14 @@ bool KeymasterOperation::updateCompletely(const std::string& input, std::string* auto error = mDevice->update(mOpHandle, nullptr, &inputBlob, &inputConsumed, nullptr, &outputBlob); if (error != KM_ERROR_OK) { - LOG(ERROR) << "update failed, code " << error; + LOG(ERROR) << "update failed, code " << error << "\n"; mDevice = nullptr; return false; } output->append(reinterpret_cast(outputBlob.data), outputBlob.data_length); free(const_cast(outputBlob.data)); if (inputConsumed > toRead) { - LOG(ERROR) << "update reported too much input consumed"; + LOG(ERROR) << "update reported too much input consumed\n"; mDevice = nullptr; return false; } @@ -150,7 +150,7 @@ bool KeymasterOperation::finish() { auto error = mDevice->finish(mOpHandle, nullptr, nullptr, nullptr, nullptr); mDevice = nullptr; if (error != KM_ERROR_OK) { - LOG(ERROR) << "finish failed, code " << error; + LOG(ERROR) << "finish failed, code " << error << "\n"; return false; } return true; @@ -161,7 +161,7 @@ bool KeymasterOperation::finishWithOutput(std::string* output) { auto error = mDevice->finish(mOpHandle, nullptr, nullptr, nullptr, &outputBlob); mDevice = nullptr; if (error != KM_ERROR_OK) { - LOG(ERROR) << "finish failed, code " << error; + LOG(ERROR) << "finish failed, code " << error << "\n"; return false; } output->assign(reinterpret_cast(outputBlob.data), outputBlob.data_length); @@ -174,14 +174,14 @@ Keymaster::Keymaster() { const hw_module_t* module; int ret = hw_get_module_by_class(KEYSTORE_HARDWARE_MODULE_ID, NULL, &module); if (ret != 0) { - LOG(ERROR) << "hw_get_module_by_class returned " << ret; + LOG(ERROR) << "hw_get_module_by_class returned " << ret << "\n"; return; } if (module->module_api_version == KEYMASTER_MODULE_API_VERSION_1_0) { keymaster1_device_t* device; ret = keymaster1_open(module, &device); if (ret != 0) { - LOG(ERROR) << "keymaster1_open returned " << ret; + LOG(ERROR) << "keymaster1_open returned " << ret << "\n"; return; } mDevice = std::make_shared(device); @@ -189,12 +189,12 @@ Keymaster::Keymaster() { keymaster2_device_t* device; ret = keymaster2_open(module, &device); if (ret != 0) { - LOG(ERROR) << "keymaster2_open returned " << ret; + LOG(ERROR) << "keymaster2_open returned " << ret << "\n"; return; } mDevice = std::make_shared(device); } else { - LOG(ERROR) << "module_api_version is " << module->module_api_version; + LOG(ERROR) << "module_api_version is " << module->module_api_version << "\n"; return; } } @@ -203,7 +203,7 @@ Keymaster::Keymaster() { keymaster_key_blob_t keyBlob; auto error = mDevice->generate_key(&inParams, &keyBlob); if (error != KM_ERROR_OK) { - LOG(ERROR) << "generate_key failed, code " << error; + LOG(ERROR) << "generate_key failed, code " << error << "\n"; return false; } key->assign(reinterpret_cast(keyBlob.key_material), keyBlob.key_material_size); @@ -215,7 +215,7 @@ bool Keymaster::deleteKey(const std::string& key) { keymaster_key_blob_t keyBlob{reinterpret_cast(key.data()), key.size()}; auto error = mDevice->delete_key(&keyBlob); if (error != KM_ERROR_OK) { - LOG(ERROR) << "delete_key failed, code " << error; + LOG(ERROR) << "delete_key failed, code " << error << "\n"; return false; } return true; diff --git a/crypto/ext4crypt/Keymaster3.cpp b/crypto/ext4crypt/Keymaster3.cpp index d53096e6..f8774f24 100644 --- a/crypto/ext4crypt/Keymaster3.cpp +++ b/crypto/ext4crypt/Keymaster3.cpp @@ -56,17 +56,17 @@ bool KeymasterOperation::updateCompletely(const std::string& input, std::string* auto inputBlob = blob2hidlVec(reinterpret_cast(&*it), toRead); auto error = mDevice->update(mOpHandle, hidl_vec(), inputBlob, hidlCB); if (!error.isOk()) { - LOG(ERROR) << "update failed: " << error.description(); + LOG(ERROR) << "update failed: " << error.description() << "\n"; mDevice = nullptr; return false; } if (km_error != ErrorCode::OK) { - LOG(ERROR) << "update failed, code " << int32_t(km_error); + LOG(ERROR) << "update failed, code " << int32_t(km_error) << "\n"; mDevice = nullptr; return false; } if (inputConsumed > toRead) { - LOG(ERROR) << "update reported too much input consumed"; + LOG(ERROR) << "update reported too much input consumed\n"; mDevice = nullptr; return false; } @@ -88,11 +88,11 @@ bool KeymasterOperation::finish(std::string* output) { hidl_vec(), hidlCb); mDevice = nullptr; if (!error.isOk()) { - LOG(ERROR) << "finish failed: " << error.description(); + LOG(ERROR) << "finish failed: " << error.description() << "\n"; return false; } if (km_error != ErrorCode::OK) { - LOG(ERROR) << "finish failed, code " << int32_t(km_error); + LOG(ERROR) << "finish failed, code " << int32_t(km_error) << "\n"; return false; } return true; @@ -114,27 +114,27 @@ Keymaster::Keymaster() { auto error = mDevice->generateKey(inParams.hidl_data(), hidlCb); if (!error.isOk()) { - LOG(ERROR) << "generate_key failed: " << error.description(); + LOG(ERROR) << "generate_key failed: " << error.description() << "\n"; return false; } if (km_error != ErrorCode::OK) { - LOG(ERROR) << "generate_key failed, code " << int32_t(km_error); + LOG(ERROR) << "generate_key failed, code " << int32_t(km_error) << "\n"; return false; } return true; }*/ bool Keymaster::deleteKey(const std::string& key) { - LOG(ERROR) << "NOT deleting key in TWRP"; + LOG(ERROR) << "NOT deleting key in TWRP\n"; return false; /*auto keyBlob = blob2hidlVec(key); auto error = mDevice->deleteKey(keyBlob); if (!error.isOk()) { - LOG(ERROR) << "delete_key failed: " << error.description(); + LOG(ERROR) << "delete_key failed: " << error.description() << "\n"; return false; } if (ErrorCode(error) != ErrorCode::OK) { - LOG(ERROR) << "delete_key failed, code " << uint32_t(ErrorCode(error)); + LOG(ERROR) << "delete_key failed, code " << uint32_t(ErrorCode(error)) << "\n"; return false; } return true;*/ @@ -153,11 +153,11 @@ bool Keymaster::upgradeKey(const std::string& oldKey, const AuthorizationSet& in }; auto error = mDevice->upgradeKey(oldKeyBlob, inParams.hidl_data(), hidlCb); if (!error.isOk()) { - LOG(ERROR) << "upgrade_key failed: " << error.description(); + LOG(ERROR) << "upgrade_key failed: " << error.description() << "\n"; return false; } if (km_error != ErrorCode::OK) { - LOG(ERROR) << "upgrade_key failed, code " << int32_t(km_error); + LOG(ERROR) << "upgrade_key failed, code " << int32_t(km_error) << "\n"; return false; } return true; @@ -207,7 +207,7 @@ using namespace ::android::vold; int keymaster_compatibility_cryptfs_scrypt() { Keymaster dev; if (!dev) { - LOG(ERROR) << "Failed to initiate keymaster session"; + LOG(ERROR) << "Failed to initiate keymaster session\n"; return -1; } return dev.isSecure(); @@ -224,11 +224,11 @@ int keymaster_compatibility_cryptfs_scrypt() { Keymaster dev; std::string key; if (!dev) { - LOG(ERROR) << "Failed to initiate keymaster session"; + LOG(ERROR) << "Failed to initiate keymaster session\n"; return -1; } if (!key_buffer || !key_out_size) { - LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument"; + LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument\n"; return -1; } if (key_out_size) { @@ -276,11 +276,11 @@ int keymaster_sign_object_for_cryptfs_scrypt(const uint8_t* key_blob, { Keymaster dev; if (!dev) { - LOG(ERROR) << "Failed to initiate keymaster session"; + LOG(ERROR) << "Failed to initiate keymaster session\n"; return -1; } if (!key_blob || !object || !signature_buffer || !signature_buffer_size) { - LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument"; + LOG(ERROR) << __FILE__ << ":" << __LINE__ << ":Invalid argument\n"; return -1; } @@ -303,7 +303,7 @@ int keymaster_sign_object_for_cryptfs_scrypt(const uint8_t* key_blob, std::string newKey; bool ret = dev.upgradeKey(key, paramBuilder, &newKey); if(ret == false) { - LOG(ERROR) << "Error upgradeKey: "; + LOG(ERROR) << "Error upgradeKey: \n"; return -1; } @@ -312,7 +312,7 @@ int keymaster_sign_object_for_cryptfs_scrypt(const uint8_t* key_blob, } if (key_buffer_size < newKey.size()) { - LOG(ERROR) << "key buffer size is too small"; + LOG(ERROR) << "key buffer size is too small\n"; return -1; } @@ -322,24 +322,24 @@ int keymaster_sign_object_for_cryptfs_scrypt(const uint8_t* key_blob, } if (op.errorCode() != ErrorCode::OK) { - LOG(ERROR) << "Error starting keymaster signature transaction: " << int32_t(op.errorCode()); + LOG(ERROR) << "Error starting keymaster signature transaction: " << int32_t(op.errorCode()) << "\n"; return -1; } if (!op.updateCompletely(input, &output)) { LOG(ERROR) << "Error sending data to keymaster signature transaction: " - << uint32_t(op.errorCode()); + << uint32_t(op.errorCode()) << "\n"; return -1; } if (!op.finish(&output)) { - LOG(ERROR) << "Error finalizing keymaster signature transaction: " << int32_t(op.errorCode()); + LOG(ERROR) << "Error finalizing keymaster signature transaction: " << int32_t(op.errorCode()) << "\n"; return -1; } *signature_buffer = reinterpret_cast(malloc(output.size())); if (*signature_buffer == nullptr) { - LOG(ERROR) << "Error allocation buffer for keymaster signature"; + LOG(ERROR) << "Error allocation buffer for keymaster signature\n"; return -1; } *signature_buffer_size = output.size(); diff --git a/crypto/fde/cryptfs.cpp b/crypto/fde/cryptfs.cpp index 792708e8..4e7a9511 100644 --- a/crypto/fde/cryptfs.cpp +++ b/crypto/fde/cryptfs.cpp @@ -305,14 +305,14 @@ static int verify_and_update_hw_fde_passwd(const char *passwd, if (crypt_ftr->crypt_type == CRYPT_TYPE_DEFAULT) { new_passwd = (char*)malloc(strlen(DEFAULT_HEX_PASSWORD) + 1); if (new_passwd == NULL) { - SLOGE("System out of memory. Password verification incomplete"); + SLOGE("System out of memory. Password verification incomplete\n"); goto out; } strlcpy(new_passwd, DEFAULT_HEX_PASSWORD, strlen(DEFAULT_HEX_PASSWORD) + 1); } else { new_passwd = (char*)malloc(strlen(passwd) * 2 + 1); if (new_passwd == NULL) { - SLOGE("System out of memory. Password verification incomplete"); + SLOGE("System out of memory. Password verification incomplete\n"); goto out; } convert_key_to_hex_ascii_for_upgrade((const unsigned char*)passwd, @@ -322,7 +322,7 @@ static int verify_and_update_hw_fde_passwd(const char *passwd, (char*) crypt_ftr->crypto_type_name); if (key_index >=0) { crypt_ftr->failed_decrypt_count = 0; - SLOGI("Hex password verified...will try to update with Ascii value"); + SLOGI("Hex password verified...will try to update with Ascii value\n"); /* Before updating password, tie that with keymaster to tie with ROT */ if (get_keymaster_hw_fde_passwd(passwd, newpw, @@ -336,9 +336,9 @@ static int verify_and_update_hw_fde_passwd(const char *passwd, if (passwd_updated >= 0) { crypt_ftr->flags |= CRYPT_ASCII_PASSWORD_UPDATED; - SLOGI("Ascii password recorded and updated"); + SLOGI("Ascii password recorded and updated\n"); } else { - SLOGI("Passwd verified, could not update...Will try next time"); + SLOGI("Passwd verified, could not update...Will try next time\n"); } } else { ++crypt_ftr->failed_decrypt_count; @@ -415,7 +415,7 @@ static int keymaster_sign_object(struct crypt_mnt_ftr *ftr, SLOGI("Signing safely-padded object\n"); break; default: - SLOGE("Unknown KDF type %d", ftr->kdf_type); + SLOGE("Unknown KDF type %d\n", ftr->kdf_type); return -1; } @@ -549,7 +549,7 @@ initfail: return -1; } /*if (put_crypt_ftr_and_key(ftr) != 0) { - SLOGE("Failed to write upgraded key to disk"); + SLOGE("Failed to write upgraded key to disk\n"); }*/ SLOGD("Key upgraded successfully\n"); return 0; @@ -1205,13 +1205,13 @@ static int scrypt_keymaster(const char *passwd, const unsigned char *salt, INTERMEDIATE_BUF_SIZE); if (rc) { - SLOGE("scrypt failed"); + SLOGE("scrypt failed\n"); return -1; } if (keymaster_sign_object(ftr, ikey, INTERMEDIATE_BUF_SIZE, &signature, &signature_size)) { - SLOGE("Keymaster signing failed"); + SLOGE("Keymaster signing failed\n"); return -1; } @@ -1220,7 +1220,7 @@ static int scrypt_keymaster(const char *passwd, const unsigned char *salt, free(signature); if (rc) { - SLOGE("scrypt failed"); + SLOGE("scrypt failed\n"); return -1; } @@ -1242,7 +1242,7 @@ static int decrypt_master_key_aux(const char *passwd, unsigned char *salt, /* Turn the password into an intermediate key and IV that can decrypt the master key */ if (kdf(passwd, salt, ikey, kdf_params)) { - SLOGE("kdf failed"); + SLOGE("kdf failed\n"); return -1; } @@ -1308,7 +1308,7 @@ static int decrypt_master_key(const char *passwd, unsigned char *decrypted_maste decrypted_master_key, kdf, kdf_params, intermediate_key, intermediate_key_size); if (ret != 0) { - SLOGW("failure decrypting master key"); + SLOGW("failure decrypting master key\n"); } return ret; @@ -1494,7 +1494,7 @@ int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev, const unsigned char* key, int keysize, char* out_crypto_blkdev) { int fd = open(real_blkdev, O_RDONLY|O_CLOEXEC); if (fd == -1) { - SLOGE("Failed to open %s: %s", real_blkdev, strerror(errno)); + SLOGE("Failed to open %s: %s\n", real_blkdev, strerror(errno)); return -1; } @@ -1503,7 +1503,7 @@ int cryptfs_setup_ext_volume(const char* label, const char* real_blkdev, close(fd); if (nr_sec == 0) { - SLOGE("Failed to get size of %s: %s", real_blkdev, strerror(errno)); + SLOGE("Failed to get size of %s: %s\n", real_blkdev, strerror(errno)); return -1; } @@ -1535,12 +1535,12 @@ int check_unmounted_and_get_ftr(struct crypt_mnt_ftr* crypt_ftr) property_get("ro.crypto.state", encrypted_state, ""); if ( master_key_saved || strcmp(encrypted_state, "encrypted") ) { SLOGE("encrypted fs already validated or not running with encryption," - " aborting"); + " aborting\n"); return -1; } if (get_crypt_ftr_and_key(crypt_ftr)) { - SLOGE("Error getting crypt footer and key"); + SLOGE("Error getting crypt footer and key\n"); return -1; } @@ -1555,7 +1555,7 @@ int cryptfs_check_passwd_hw(const char* passwd) unsigned char master_key[KEY_LEN_BYTES]; /* get key */ if (get_crypt_ftr_and_key(&crypt_ftr)) { - SLOGE("Error getting crypt footer and key"); + SLOGE("Error getting crypt footer and key\n"); return -1; } @@ -1569,7 +1569,7 @@ int cryptfs_check_passwd_hw(const char* passwd) */ rc = cryptfs_get_master_key(&crypt_ftr, passwd, master_key); if (rc) { - SLOGE("password doesn't match"); + SLOGE("password doesn't match\n"); return rc; } @@ -1577,7 +1577,7 @@ int cryptfs_check_passwd_hw(const char* passwd) DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE); if (rc) { - SLOGE("Default password did not match on reboot encryption"); + SLOGE("Default password did not match on reboot encryption\n"); return rc; } } else { @@ -1593,7 +1593,7 @@ int cryptfs_check_passwd_hw(const char* passwd) int cryptfs_check_passwd(const char *passwd) { /*if (e4crypt_is_native()) { - SLOGE("cryptfs_check_passwd not valid for file encryption"); + SLOGE("cryptfs_check_passwd not valid for file encryption\n"); return -1; }*/ @@ -1602,7 +1602,7 @@ int cryptfs_check_passwd(const char *passwd) rc = check_unmounted_and_get_ftr(&crypt_ftr); if (rc) { - SLOGE("Could not get footer"); + SLOGE("Could not get footer\n"); return rc; } @@ -1615,7 +1615,7 @@ int cryptfs_check_passwd(const char *passwd) DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE); if (rc) { - SLOGE("Password did not match"); + SLOGE("Password did not match\n"); return rc; } @@ -1628,7 +1628,7 @@ int cryptfs_check_passwd(const char *passwd) rc = test_mount_encrypted_fs(&crypt_ftr, DEFAULT_PASSWORD, DATA_MNT_POINT, CRYPTO_BLOCK_DEVICE); if (rc) { - SLOGE("Default password did not match on reboot encryption"); + SLOGE("Default password did not match on reboot encryption\n"); return rc; } } @@ -1645,17 +1645,17 @@ int cryptfs_verify_passwd(const char *passwd) property_get("ro.crypto.state", encrypted_state, ""); if (strcmp(encrypted_state, "encrypted") ) { - SLOGE("device not encrypted, aborting"); + SLOGE("device not encrypted, aborting\n"); return -2; } if (!master_key_saved) { - SLOGE("encrypted fs not yet mounted, aborting"); + SLOGE("encrypted fs not yet mounted, aborting\n"); return -1; } if (!saved_mount_point) { - SLOGE("encrypted fs failed to save mount point, aborting"); + SLOGE("encrypted fs failed to save mount point, aborting\n"); return -1; } @@ -1735,7 +1735,7 @@ int cryptfs_get_master_key(struct crypt_mnt_ftr* ftr, const char* password, &intermediate_key_size); if (rc) { - SLOGE("Can't calculate intermediate key"); + SLOGE("Can't calculate intermediate key\n"); return rc; } @@ -1753,7 +1753,7 @@ int cryptfs_get_master_key(struct crypt_mnt_ftr* ftr, const char* password, free(intermediate_key); if (rc) { - SLOGE("Can't scrypt intermediate key"); + SLOGE("Can't scrypt intermediate key\n"); return rc; }