From 08fb9ce43bbc948aad504670f54ba81376f42e3f Mon Sep 17 00:00:00 2001 From: Cong Lin Date: Fri, 15 Dec 2023 13:29:17 -0800 Subject: [PATCH] Replace binary cbor object with cppbor builders in oemcrypto tests Now that the Cppbor library is in place. Test: opk_ta_p40 Change-Id: I0641e1598d30b178ea2b1feeaf8d4f328be0b23a --- .../test/oemcrypto_provisioning_test.cpp | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp index 99897aea..fbb7a83c 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_provisioning_test.cpp @@ -377,21 +377,13 @@ TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadAPI18) { if (wvoec::global_features.api_version < 18) { GTEST_SKIP() << "Test for versions 18 and up only."; } - std::vector challenge(64, 0xaa); - // TODO: add cppbor support for oemcrypto tests for all targets. Before that, - // use hex values which are equivalent of the commented cppbor statement. - // std::vector device_info = cppbor::Map() - // .add("manufacturer", "google") - // .add("fused", 0) - // .add("other", "ignored") - // .canonicalize() - // .encode(); - // - std::vector device_info = { - 0xa3, 0x65, 0x66, 0x75, 0x73, 0x65, 0x64, 0x0, 0x65, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x67, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x64, - 0x6c, 0x6d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63, 0x74, 0x75, 0x72, - 0x65, 0x72, 0x66, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65}; + const std::vector challenge(64, 0xaa); + const std::vector device_info = cppbor::Map() + .add("manufacturer", "google") + .add("fused", 0) + .add("other", "ignored") + .canonicalize() + .encode(); std::vector signed_csr_payload; size_t signed_csr_payload_length = 0; OEMCryptoResult sts = OEMCrypto_GetDeviceSignedCsrPayload( @@ -416,12 +408,13 @@ TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadAPI18) { TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadInvalid) { std::vector signed_csr_payload; size_t signed_csr_payload_length = 0; - std::vector challenge(64, 0xaa); - std::vector device_info = { - 0xa3, 0x65, 0x66, 0x75, 0x73, 0x65, 0x64, 0x0, 0x65, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x67, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x64, - 0x6c, 0x6d, 0x61, 0x6e, 0x75, 0x66, 0x61, 0x63, 0x74, 0x75, 0x72, - 0x65, 0x72, 0x66, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65}; + const std::vector challenge(64, 0xaa); + const std::vector device_info = cppbor::Map() + .add("manufacturer", "google") + .add("fused", 0) + .add("other", "ignored") + .canonicalize() + .encode(); std::vector challenge_empty; OEMCryptoResult sts = OEMCrypto_GetDeviceSignedCsrPayload( challenge_empty.data(), challenge_empty.size(), device_info.data(), @@ -431,7 +424,7 @@ TEST_F(OEMCryptoProv40Test, GetDeviceSignedCsrPayloadInvalid) { ASSERT_EQ(sts, OEMCrypto_ERROR_INVALID_CONTEXT); // Oversized challenge - std::vector challenge_long(65, 0xaa); + const std::vector challenge_long(65, 0xaa); sts = OEMCrypto_GetDeviceSignedCsrPayload( challenge_long.data(), challenge_long.size(), device_info.data(), device_info.size(), signed_csr_payload.data(),