Files
frameworks_base/cmds/incidentd/tests/IncidentKeyStore_test.cpp
Yao Chen 43706b4470 Add encryption in incidentd.
+ Sections which require encryption will be encryted on disk.

+ When the sections are requested by clients (e.g., permission controller, report assignee),
  incidentd will decrypte the data.

+ For efficiency, encryption is done ONLY for sections that require encryption.

+ Use Keystore API for key management.

Bug: 131084614
Test: incidentd_test
Change-Id: I84d6b86807ba5bbde1051e847b2df6e79e6b5be5
2019-04-23 15:20:38 -07:00

66 lines
2.0 KiB
C++

/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cipher/IncidentKeyStore.h"
#include <binder/ProcessState.h>
#include <gtest/gtest.h>
#include <fstream>
using namespace android::os::incidentd;
class IncidentKeyStoreTest : public ::testing::Test {
protected:
std::unique_ptr<IncidentKeyStore> incidentKeyStore;
void SetUp() override {
android::ProcessState::self()->startThreadPool();
incidentKeyStore = std::make_unique<IncidentKeyStore>(
static_cast<keystore::KeystoreClient*>(new keystore::KeystoreClientImpl));
};
void TearDown() override { incidentKeyStore = nullptr; };
};
TEST_F(IncidentKeyStoreTest, test_encrypt_decrypt) {
std::string plaintext;
plaintext.resize(4 * 1024, 'a');
std::string encrypted;
EXPECT_TRUE(incidentKeyStore->encrypt(plaintext, 0, &encrypted));
std::string decrypted;
EXPECT_TRUE(incidentKeyStore->decrypt(encrypted, &decrypted));
EXPECT_FALSE(encrypted.empty());
EXPECT_EQ(plaintext, decrypted);
}
TEST_F(IncidentKeyStoreTest, test_encrypt_empty_hash) {
std::string hash = "";
std::string encrypted;
EXPECT_FALSE(incidentKeyStore->encrypt(hash, 0, &encrypted));
EXPECT_TRUE(encrypted.empty());
}
TEST_F(IncidentKeyStoreTest, test_decrypt_empty_hash) {
std::string hash = "";
std::string decrypted;
EXPECT_FALSE(incidentKeyStore->decrypt(hash, &decrypted));
EXPECT_TRUE(decrypted.empty());
}