/*
* 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[] = {0 x6d, 0 x65, 0 x73, 0 x73, 0 x61, 0 x67, 0 x65, 0 x0a};
unsigned int message_bin_len = 8 ;
/* The following test_hash is the SHA256 hash of the message consisting of these
* bytes : 0 x6d , 0 x65 , 0 x73 , 0 x73 , 0 x61 , 0 x67 , 0 x65 , 0 x0a
* prefixed by the appropriate DER prefix for SHA256 .
*/
const std::vector<uint8_t> test_hash{
0 x30, 0 x31, 0 x30, 0 x0d, 0 x06, 0 x09, 0 x60, 0 x86, 0 x48, 0 x01, 0 x65,
0 x03, 0 x04, 0 x02, 0 x01, 0 x05, 0 x00, 0 x04, 0 x20, 0 x00, 0 xcf, 0 x20,
0 xe0, 0 x7a, 0 xa9, 0 x69, 0 x9f, 0 x6c, 0 x4f, 0 x93, 0 x42, 0 x30, 0 xee,
0 xff, 0 x8f, 0 xc6, 0 xf6, 0 xcf, 0 xdd, 0 x57, 0 xc8, 0 xe5, 0 xaf, 0 x93,
0 x49, 0 x60, 0 x82, 0 xd7, 0 x5c, 0 xee, 0 x42};
/* 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{
0 x30, 0 x82, 0 x04, 0 xa4, 0 x02, 0 x01, 0 x00, 0 x02, 0 x82, 0 x01, 0 x01, 0 x00,
0 xca, 0 xc1, 0 x47, 0 xf3, 0 x2f, 0 xf9, 0 xd8, 0 x47, 0 x7f, 0 x3b, 0 x14, 0 xb7,
0 xde, 0 x0f, 0 xa8, 0 x41, 0 xe6, 0 x30, 0 x01, 0 x27, 0 x1b, 0 x8a, 0 x30, 0 x96,
0 xd0, 0 x50, 0 xa7, 0 xfc, 0 x19, 0 xe0, 0 xdf, 0 x71, 0 x6d, 0 x0e, 0 x8b, 0 x79,
0 x01, 0 xa8, 0 xe2, 0 x01, 0 x2d, 0 x26, 0 x93, 0 xad, 0 x3a, 0 x2d, 0 x84, 0 xa0,
0 x52, 0 x64, 0 xc9, 0 x49, 0 xdc, 0 xf5, 0 xa0, 0 xd0, 0 xd6, 0 xab, 0 xe1, 0 xc5,
0 x3d, 0 x39, 0 x53, 0 x6b, 0 xd5, 0 x12, 0 x33, 0 x6b, 0 xcd, 0 x88, 0 xb1, 0 xa4,
0 x6c, 0 x69, 0 x7f, 0 x1c, 0 x74, 0 x6c, 0 x27, 0 xd6, 0 xb8, 0 x09, 0 x1b, 0 x0d,
0 xb3, 0 xc7, 0 xd2, 0 xaf, 0 x52, 0 xad, 0 xf7, 0 x61, 0 x91, 0 xa1, 0 x39, 0 x58,
0 x99, 0 xa4, 0 x9b, 0 x7d, 0 x76, 0 xe2, 0 x26, 0 x56, 0 x86, 0 x60, 0 x1a, 0 x47,
0 xba, 0 xdd, 0 x94, 0 x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, 0 xef, 0 xc8, 0 x33, 0 x35,
0 x86, 0 xa1, 0 x19, 0 x34, 0 xca, 0 x6a, 0 x5b, 0 x43, 0 x2c, 0 x5b, 0 x31, 0 xaf,
0 xc5, 0 x0e, 0 xf8, 0 x12, 0 x91, 0 x16, 0 xb9, 0 x8b, 0 x01, 0 xf9, 0 xa8, 0 x9c,
0 x5b, 0 x9e, 0 xbb, 0 xc6, 0 x8d, 0 xf7, 0 xe7, 0 xeb, 0 x6f, 0 x04, 0 xbe, 0 xa9,
0 x06, 0 xba, 0 xed, 0 x9a, 0 xf9, 0 x6c, 0 xe1, 0 x3f, 0 x3e, 0 x27, 0 x79, 0 xdb,
0 x5a, 0 x8f, 0 x5b, 0 x4d, 0 xd4, 0 xd0, 0 xf5, 0 x2f, 0 xc4, 0 xaf, 0 xc9, 0 xc4,
0 x44, 0 x5b, 0 xf1, 0 xde, 0 x1a, 0 x91, 0 xb7, 0 x2b, 0 x24, 0 xc0, 0 xed, 0 xdd,
0 xb1, 0 x1f, 0 x57, 0 x82, 0 x82, 0 xd2, 0 xa5, 0 x58, 0 x7e, 0 xcd, 0 x91, 0 xf6,
0 x2c, 0 x46, 0 xb0, 0 x9b, 0 xc3, 0 x01, 0 x2c, 0 x85, 0 x38, 0 xba, 0 x6b, 0 x8c,
0 xfc, 0 x04, 0 x0a, 0 x8c, 0 xc1, 0 xde, 0 x42, 0 xd2, 0 x14, 0 x77, 0 xe1, 0 x1f,
0 x58, 0 xe9, 0 x78, 0 x63, 0 x10, 0 xf9, 0 x7d, 0 x68, 0 xdb, 0 xb4, 0 x63, 0 xa5,
0 x58, 0 x04, 0 x33, 0 xa5};
/* 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[] = {
0 x9a, 0 x89, 0 x5b, 0 x21, 0 x8e, 0 x01, 0 x79, 0 x59, 0 x64, 0 xf3, 0 xbf, 0 x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0 x34, 0 x0d, 0 xb6, 0 xcb, 0 xe0, 0 xca, 0 x14, 0 x1d, 0 x1b, 0 x81, 0 x93, 0 x4b,
0 xc0, 0 xc8, 0 x2c, 0 x33, 0 xd9, 0 x77, 0 xd6, 0 x5e, 0 x47, 0 x2a, 0 x67, 0 x5f,
0 xaa, 0 xd1, 0 x17, 0 xe8, 0 xa2, 0 xe4, 0 xa9, 0 xac, 0 xb2, 0 x65, 0 x49, 0 x58,
0 x57, 0 x7e, 0 x00, 0 xa8, 0 xae, 0 xd4, 0 x38, 0 x91, 0 x6c, 0 xb1, 0 x00, 0 xa0,
0 x4d, 0 xaa, 0 x1f, 0 x77, 0 xf3, 0 x44, 0 x6c, 0 x81, 0 xcf, 0 xa5, 0 x86, 0 x43,
0 x02, 0 x4a, 0 x67, 0 x01, 0 x5e, 0 x7a, 0 xde, 0 x98, 0 x90, 0 x1c, 0 xbf, 0 xfe,
0 xb5, 0 xb1, 0 x41, 0 xdf, 0 x2d, 0 xfe, 0 x80, 0 x1e, 0 xe2, 0 x78, 0 x50, 0 xd0,
0 x7b, 0 xde, 0 x9e, 0 xb2};
/* 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 ,
* used when WITH_FAKE_KEYBOX is set . 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] ^ 0 x42;
}
*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();
}
#if defined (WITH_FAKE_KEYBOX)
#define FAKE_KEYBOX_ONLY_TEST(name) name
#else
#define FAKE_KEYBOX_ONLY_TEST(name) DISABLED_## name
#endif
TEST_F(CastAuthTest, FAKE_KEYBOX_ONLY_TEST(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" )
Messung V0.5 in Prozent C=90 H=95 G=92