blob: 994c00c04c3a1673eed8e89d849948977316f1a1 [file] [log] [blame]
/*
* Copyright (C) 2022 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.
*/
#define TLOG_TAG "cast-auth-trusty-test"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <array>
#include <cstdint>
#include <binder/RpcSession.h>
#include <binder/RpcTransportTipcTrusty.h>
#include <lib/unittest/unittest.h>
#include <trusty_ipc.h>
#include <trusty_log.h>
#include <trusty_unittest.h>
#include <uapi/err.h>
#include "BpCastAuth.h"
// trusty_unittest.h doesn't provide these by default.
#define ASSERT_TRUE(val, args...) ASSERT_EQ(true, (bool)(val), ##args)
#define ASSERT_FALSE(val, args...) ASSERT_EQ(false, (bool)(val), ##args)
#define EXPECT_TRUE(val, args...) EXPECT_EQ(true, (bool)(val), ##args)
#define EXPECT_FALSE(val, args...) EXPECT_EQ(false, (bool)(val), ##args)
unsigned char message_bin[] = {0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a};
unsigned int message_bin_len = 8;
/* The following test_hash is the SHA256 hash of the message consisting of these
* bytes: 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x0a
* prefixed by the appropriate DER prefix for SHA256.
*/
const std::vector<uint8_t> test_hash{
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65,
0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20, 0x00, 0xcf, 0x20,
0xe0, 0x7a, 0xa9, 0x69, 0x9f, 0x6c, 0x4f, 0x93, 0x42, 0x30, 0xee,
0xff, 0x8f, 0xc6, 0xf6, 0xcf, 0xdd, 0x57, 0xc8, 0xe5, 0xaf, 0x93,
0x49, 0x60, 0x82, 0xd7, 0x5c, 0xee, 0x42};
/* The following is a test RSA 2048 bit key, generated using openssl genrsa. It
* is in PKCS1 RSAPrivateKey (DER) format.
*/
const std::vector<uint8_t> test_pkcs1_der{
0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00,
0xca, 0xc1, 0x47, 0xf3, 0x2f, 0xf9, 0xd8, 0x47, 0x7f, 0x3b, 0x14, 0xb7,
0xde, 0x0f, 0xa8, 0x41, 0xe6, 0x30, 0x01, 0x27, 0x1b, 0x8a, 0x30, 0x96,
0xd0, 0x50, 0xa7, 0xfc, 0x19, 0xe0, 0xdf, 0x71, 0x6d, 0x0e, 0x8b, 0x79,
0x01, 0xa8, 0xe2, 0x01, 0x2d, 0x26, 0x93, 0xad, 0x3a, 0x2d, 0x84, 0xa0,
0x52, 0x64, 0xc9, 0x49, 0xdc, 0xf5, 0xa0, 0xd0, 0xd6, 0xab, 0xe1, 0xc5,
0x3d, 0x39, 0x53, 0x6b, 0xd5, 0x12, 0x33, 0x6b, 0xcd, 0x88, 0xb1, 0xa4,
0x6c, 0x69, 0x7f, 0x1c, 0x74, 0x6c, 0x27, 0xd6, 0xb8, 0x09, 0x1b, 0x0d,
0xb3, 0xc7, 0xd2, 0xaf, 0x52, 0xad, 0xf7, 0x61, 0x91, 0xa1, 0x39, 0x58,
0x99, 0xa4, 0x9b, 0x7d, 0x76, 0xe2, 0x26, 0x56, 0x86, 0x60, 0x1a, 0x47,
0xba, 0xdd, 0x94, 0xf2, 0x19, 0x08, 0x8f, 0x66, 0x9f, 0x59, 0xb9, 0x69,
0x9f, 0x53, 0x76, 0xb4, 0x2b, 0xac, 0x32, 0x87, 0x6d, 0x48, 0xeb, 0x80,
0x56, 0x2f, 0x1c, 0x7b, 0x82, 0x5b, 0x45, 0x51, 0xe3, 0xc1, 0xa9,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0xc5, 0x0e, 0xf8, 0x12, 0x91, 0x16, 0xb9, 0x8b, 0x01, 0xf9, 0xa8, 0x9c,
0x5b, 0x9e, 0xbb, 0xc6, 0x8d, 0xf7, 0xe7, 0xeb, 0x6f, 0x04, 0xbe, 0xa9,
0x06, 0xba, 0xed, 0x9a, 0xf9, 0x6c, 0xe1, 0x3f, 0x3e, 0x27, 0x79, 0xdb,
0x5a, 0x8f, 0x5b, 0x4d, 0xd4, 0xd0, 0xf5, 0x2f, 0xc4, 0xaf, 0xc9, 0xc4,
0x44, 0x5b, 0xf1, 0xde, 0x1a, 0x91, 0xb7, 0x2b, 0x24, 0xc0, 0xed, 0xdd,
0xb1, 0x1f, 0x57, 0x82, 0x82, 0xd2, 0xa5, 0x58, 0x7e, 0xcd, 0x91, 0xf6,
0x2c, 0x46, 0xb0, 0x9b, 0xc3, 0x01, 0x2c, 0x85, 0x38, 0xba, 0x6b, 0x8c,
0xfc, 0x04, 0x0a, 0x8c, 0xc1, 0xde, 0x42, 0xd2, 0x14, 0x77, 0xe1, 0x1f,
0x58, 0xe9, 0x78, 0x63, 0x10, 0xf9, 0x7d, 0x68, 0xdb, 0xb4, 0x63, 0xa5,
0x58, 0x04, 0x33, 0xa5};
/* The following is the signature of the above message generated using
* "openssl dgst" with the above private key, using the PKCS1v1.5 signature
* algorithm and SHA256 hash.
* This should be the output of the TA, given the above key and hash.
*/
unsigned char test_signature[] = {
0x9a, 0x89, 0x5b, 0x21, 0x8e, 0x01, 0x79, 0x59, 0x64, 0xf3, 0xbf, 0x8f,
0x82, 0x14, 0xe8, 0x39, 0x97, 0x96, 0x78, 0x96, 0xc1, 0xcb, 0x02, 0x91,
0xf2, 0xb3, 0x17, 0x7b, 0xe6, 0xaf, 0xa9, 0x67, 0x7a, 0xc1, 0x89, 0xac,
0x99, 0x3f, 0x6f, 0x07, 0xe4, 0x02, 0x2f, 0xc5, 0x0c, 0xb2, 0x7b, 0x2b,
0xb5, 0x7b, 0xba, 0x41, 0xfc,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, 0xbf, 0xfe,
0xb5, 0xb1, 0x41, 0xdf, 0x2d, 0xfe, 0x80, 0x1e, 0xe2, 0x78, 0x50, 0xd0,
0x7b, 0xde, 0x9e, 0xb2};
/* The following function is solely for the purpose of testing. It "wraps" a key
* such that it can be unwrapped by the sample keybox implementation in Trusty
* As warned therein:
*
* THIS DOES NOT PROVIDE ANY SECURITY
*
* This is not a useful wrapping system. This is just intended as enough to mock
* that:
* 1. The wrapped data and unwrapped data are not the same.
* 2. The wrapped data will fail to unwrap if it is trivially tampered with.
*
* Note this wrapping function has no error checking. It's assumed to be called
* correctly i.e. such that the destination buffer (wrapped_keybox) is at least
* one byte bigger than the source buffer (keybox_plaintext).
*/
void keybox_wrap_for_test(const uint8_t* keybox_plaintext,
size_t keybox_plaintext_len,
uint8_t* wrapped_keybox,
size_t wrapped_keybox_buf_len,
size_t* wrapped_keybox_len) {
/* Generate checksum */
uint8_t checksum = 0;
for (size_t i = 0; i < keybox_plaintext_len; i++) {
checksum ^= keybox_plaintext[i];
}
/* Flip bits with masking byte */
for (size_t i = 0; i < keybox_plaintext_len; i++) {
wrapped_keybox[i] = keybox_plaintext[i] ^ 0x42;
}
*wrapped_keybox_len = keybox_plaintext_len + 1;
wrapped_keybox[keybox_plaintext_len] = checksum;
}
typedef struct {
android::sp<android::RpcSession> sess;
android::sp<ICastAuth> srv;
} CastAuthTest_t;
static void CastAuthTest_SetUp(CastAuthTest_t* state) {
int rc;
android::binder::unique_fd chan;
android::status_t status;
android::sp<android::IBinder> root;
rc = connect(ICastAuth::PORT().c_str(), IPC_CONNECT_WAIT_FOR_PORT);
ASSERT_GE(rc, 0);
chan.reset(rc);
state->sess = android::RpcSession::make(
android::RpcTransportCtxFactoryTipcTrusty::make());
ASSERT_NE(nullptr, state->sess.get());
status = state->sess->setupPreconnectedClient(
std::move(chan), []() { return android::binder::unique_fd(); });
ASSERT_EQ(android::OK, status);
root = state->sess->getRootObject();
ASSERT_NE(nullptr, root.get());
state->srv = ICastAuth::asInterface(root);
ASSERT_NE(nullptr, state->srv.get());
test_abort:;
}
static void CastAuthTest_TearDown(CastAuthTest_t* state) {
state->srv.clear();
}
TEST_F(CastAuthTest, ProvisionAndSignHash) {
std::vector<uint8_t> wrapped_keybox(test_pkcs1_der.size() + 1);
size_t wrapped_keybox_len;
keybox_wrap_for_test(test_pkcs1_der.data(), test_pkcs1_der.size(),
wrapped_keybox.data(), wrapped_keybox.size(),
&wrapped_keybox_len);
wrapped_keybox.resize(wrapped_keybox_len);
{
auto status = _state->srv->ProvisionKey(wrapped_keybox);
ASSERT_TRUE(status.isOk(), "ProvisionKey");
}
{
std::vector<uint8_t> signature(256);
auto status = _state->srv->SignHash(test_hash, &signature);
ASSERT_TRUE(status.isOk(), "SignHash");
ASSERT_EQ(signature.size(), sizeof(test_signature), "signature size");
for (unsigned int i = 0; i < signature.size(); ++i) {
EXPECT_EQ(signature[i], test_signature[i], "signature diff");
}
}
test_abort:;
}
TEST_F(CastAuthTest, ProvisionUnwrappedAndSignHash) {
{
auto status = _state->srv->ProvisionKey(test_pkcs1_der);
ASSERT_TRUE(status.isOk(), "ProvisionKey");
}
{
std::vector<uint8_t> signature(256);
auto status = _state->srv->SignHash(test_hash, &signature);
ASSERT_TRUE(status.isOk(), "SignHash");
ASSERT_EQ(signature.size(), sizeof(test_signature), "signature size");
for (unsigned int i = 0; i < signature.size(); ++i) {
EXPECT_EQ(signature[i], test_signature[i], "signature diff");
}
}
test_abort:;
}
PORT_TEST(CastAuthTest, "com.android.trusty.cast_auth.test")