Sync oemcrypto files from cdm udc-dev to Android
Changes included in this CL: 166806: Update OEMCrypto_GetDeviceInformation() | https://widevine-internal-review.googlesource.com/c/cdm/+/166806 166808: Update Android L3 after OEMCrypto_GetDeviceInformation() signature changes | https://widevine-internal-review.googlesource.com/c/cdm/+/166808 166809: Decode device info and write it to CSR payload | https://widevine-internal-review.googlesource.com/c/cdm/+/166809 167158: Fix Android include path and copy_files | https://widevine-internal-review.googlesource.com/c/cdm/+/167158 167159: Fix common typos and use inclusive language suggested by Android linter | https://widevine-internal-review.googlesource.com/c/cdm/+/167159 165618: Explicitly state python3 where needed. | https://widevine-internal-review.googlesource.com/c/cdm/+/165618 166757: Update Android.bp for Android | https://widevine-internal-review.googlesource.com/c/cdm/+/166757 164993: Refactor basic oemcrypto unit tests | https://widevine-internal-review.googlesource.com/c/cdm/+/164993 164978: Update OEMCrypto Unit Test Docs | https://widevine-internal-review.googlesource.com/c/cdm/+/164978 166941: Update make files for OEMCrypto | https://widevine-internal-review.googlesource.com/c/cdm/+/166941 165279: Refactor license unit tests | https://widevine-internal-review.googlesource.com/c/cdm/+/165279 165318: Refactor provisioning unit tests | https://widevine-internal-review.googlesource.com/c/cdm/+/165318 164800: Add extra check for renew on license load unit test | https://widevine-internal-review.googlesource.com/c/cdm/+/164800 165860: Remove duplicate definition of MaybeHex() | https://widevine-internal-review.googlesource.com/c/cdm/+/165860 164889: Updated CoreCommonRequestFromMessage and fix test | https://widevine-internal-review.googlesource.com/c/cdm/+/164889 164967: Add OPK pre-hook and post-hook error codes | https://widevine-internal-review.googlesource.com/c/cdm/+/164967 165140: Add hidden device_id_length to v18 provisioning message | https://widevine-internal-review.googlesource.com/c/cdm/+/165140 165204: Fix memory leak in oemcrypto test | https://widevine-internal-review.googlesource.com/c/cdm/+/165204 165958: Fix oemcrypto_generic_verify_fuzz mutator signature offset | https://widevine-internal-review.googlesource.com/c/cdm/+/165958 166037: Support SHA-256 in OEMCrypto Session Util | https://widevine-internal-review.googlesource.com/c/cdm/+/166037 Test: Run GtsMediaTests on Pixel 7 Bug: 270612144 Change-Id: Iff0820a2de7d043a820470a130af65b0dcadb759
This commit is contained in:
@@ -94,7 +94,9 @@ cc_test {
|
||||
"libwv_kdo",
|
||||
],
|
||||
|
||||
shared_libs: ["libprotobuf-cpp-lite"],
|
||||
shared_libs: [
|
||||
"libprotobuf-cpp-lite",
|
||||
],
|
||||
|
||||
srcs: [
|
||||
"test/odk_test.cpp",
|
||||
|
||||
@@ -106,6 +106,8 @@ typedef enum OEMCryptoResult {
|
||||
OPK_ERROR_REMOTE_CALL = OPK_ERROR_BASE,
|
||||
OPK_ERROR_INCOMPATIBLE_VERSION = OPK_ERROR_BASE + 1,
|
||||
OPK_ERROR_NO_PERSISTENT_DATA = OPK_ERROR_BASE + 2,
|
||||
OPK_ERROR_PREHOOK_FAILURE = OPK_ERROR_BASE + 3,
|
||||
OPK_ERROR_POSTHOOK_FAILURE = OPK_ERROR_BASE + 4,
|
||||
} OEMCryptoResult;
|
||||
/* clang-format on */
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ bool CreateCoreLicenseResponseFromProto(
|
||||
const oemcrypto_core_message::features::CoreMessageFeatures& features,
|
||||
const std::string& serialized_license,
|
||||
const ODK_LicenseRequest& core_request,
|
||||
const std::string& core_request_sha256, const bool nonce_required,
|
||||
const bool uses_padding, std::string* oemcrypto_core_message);
|
||||
const std::string& core_request_sha256, bool nonce_required,
|
||||
bool uses_padding, std::string* oemcrypto_core_message);
|
||||
|
||||
/**
|
||||
* Counterpart (serializer) of ODK_ParseProvisioning (deserializer)
|
||||
@@ -60,7 +60,7 @@ bool CreateCoreProvisioningResponseFromProto(
|
||||
const oemcrypto_core_message::features::CoreMessageFeatures& features,
|
||||
const std::string& serialized_provisioning_response,
|
||||
const ODK_ProvisioningRequest& core_request,
|
||||
const OEMCrypto_PrivateKeyType device_key_type,
|
||||
OEMCrypto_PrivateKeyType device_key_type,
|
||||
std::string* oemcrypto_core_message);
|
||||
|
||||
} // namespace serialize
|
||||
|
||||
@@ -68,35 +68,14 @@ namespace oemcrypto_core_message {
|
||||
* Input structure for CreateCommonResponse
|
||||
*/
|
||||
struct ODK_CommonRequest {
|
||||
uint32_t message_type;
|
||||
uint32_t message_length;
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Output structure for CoreLicenseRequestFromMessage
|
||||
* Input structure for CreateCoreLicenseResponse
|
||||
*/
|
||||
struct ODK_LicenseRequest {
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* Output structure for CoreRenewalRequestFromMessage
|
||||
* Input structure for CreateCoreRenewalResponse
|
||||
*/
|
||||
struct ODK_RenewalRequest {
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
uint64_t playback_time_seconds;
|
||||
};
|
||||
|
||||
struct ODK_MessageCounter {
|
||||
uint64_t master_generation_number;
|
||||
uint32_t provisioning_count;
|
||||
@@ -107,7 +86,31 @@ struct ODK_MessageCounter {
|
||||
uint16_t patch_version;
|
||||
uint8_t soc_vendor[16];
|
||||
uint8_t chipset_model[16];
|
||||
uint8_t extra[16];
|
||||
uint8_t extra[12];
|
||||
};
|
||||
|
||||
/**
|
||||
* Output structure for CoreLicenseRequestFromMessage
|
||||
* Input structure for CreateCoreLicenseResponse
|
||||
*/
|
||||
struct ODK_LicenseRequest {
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
ODK_MessageCounter counter_info;
|
||||
};
|
||||
|
||||
/**
|
||||
* Output structure for CoreRenewalRequestFromMessage
|
||||
* Input structure for CreateCoreRenewalResponse
|
||||
*/
|
||||
struct ODK_RenewalRequest {
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
uint64_t playback_time_seconds;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -136,6 +139,7 @@ struct ODK_Provisioning40Request {
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
std::string device_info;
|
||||
ODK_MessageCounter counter_info;
|
||||
};
|
||||
|
||||
} // namespace oemcrypto_core_message
|
||||
|
||||
@@ -16,10 +16,10 @@ extern "C" {
|
||||
|
||||
/* The version of this library. */
|
||||
#define ODK_MAJOR_VERSION 18
|
||||
#define ODK_MINOR_VERSION 0
|
||||
#define ODK_MINOR_VERSION 1
|
||||
|
||||
/* ODK Version string. Date changed automatically on each release. */
|
||||
#define ODK_RELEASE_DATE "ODK v18.0 2022-12-14"
|
||||
#define ODK_RELEASE_DATE "ODK v18.1 2023-02-22"
|
||||
|
||||
/* The lowest version number for an ODK message. */
|
||||
#define ODK_FIRST_VERSION 16
|
||||
@@ -31,8 +31,8 @@ extern "C" {
|
||||
/* The max length of the encoded device info in CBOR format. Make sure it gets
|
||||
* updated when more device info is included. Refer to
|
||||
* https://www.rfc-editor.org/rfc/rfc8949.html#name-specification-of-the-cbor-e
|
||||
* for an estimation of the required length. */
|
||||
#define ODK_DEVICE_INFO_LEN_MAX 256
|
||||
* for an estimation of the required length. */
|
||||
#define ODK_DEVICE_INFO_LEN_MAX 768
|
||||
|
||||
/// @addtogroup odk_timer
|
||||
/// @{
|
||||
|
||||
@@ -106,6 +106,23 @@ static bool GetNonceFromMessage(const std::string& oemcrypto_core_message,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CopyCounterInfo(ODK_MessageCounter* dest, ODK_MessageCounterInfo* src) {
|
||||
if (!src || !dest) return false;
|
||||
|
||||
dest->master_generation_number = src->master_generation_number;
|
||||
dest->license_count = src->license_count;
|
||||
dest->provisioning_count = src->provisioning_count;
|
||||
dest->decrypt_count = src->decrypt_count;
|
||||
dest->major_version = src->major_version;
|
||||
dest->minor_version = src->minor_version;
|
||||
dest->patch_version = src->patch_version;
|
||||
memcpy(&dest->soc_vendor, &src->soc_vendor, sizeof(dest->soc_vendor));
|
||||
memcpy(&dest->chipset_model, &src->chipset_model,
|
||||
sizeof(dest->chipset_model));
|
||||
memcpy(&dest->extra, &src->extra, sizeof(dest->extra));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CoreLicenseRequestFromMessage(const std::string& oemcrypto_core_message,
|
||||
ODK_LicenseRequest* core_license_request) {
|
||||
ODK_NonceValues nonce;
|
||||
@@ -118,8 +135,16 @@ bool CoreLicenseRequestFromMessage(const std::string& oemcrypto_core_message,
|
||||
}
|
||||
const auto unpacker = Unpack_ODK_PreparedLicenseRequest;
|
||||
ODK_PreparedLicenseRequest prepared_license = {};
|
||||
return ParseRequest(ODK_License_Request_Type, oemcrypto_core_message,
|
||||
core_license_request, &prepared_license, unpacker);
|
||||
if (!ParseRequest(ODK_License_Request_Type, oemcrypto_core_message,
|
||||
core_license_request, &prepared_license, unpacker)) {
|
||||
return false;
|
||||
}
|
||||
if (!CopyCounterInfo(&core_license_request->counter_info,
|
||||
&prepared_license.counter_info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CoreRenewalRequestFromMessage(const std::string& oemcrypto_core_message,
|
||||
@@ -149,6 +174,32 @@ bool CoreProvisioningRequestFromMessage(
|
||||
if (!ParseRequest(ODK_Provisioning_Request_Type, oemcrypto_core_message,
|
||||
core_provisioning_request, &prepared_provision,
|
||||
unpacker)) {
|
||||
// check for edge case: initial v18 message which is 4 bytes smaller and
|
||||
// has 0's in the message counter struct
|
||||
const uint8_t* buf =
|
||||
reinterpret_cast<const uint8_t*>(oemcrypto_core_message.c_str());
|
||||
const size_t buf_length = oemcrypto_core_message.size();
|
||||
|
||||
if (!(buf_length + 4 == ODK_PROVISIONING_REQUEST_SIZE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Expected zero padding. Size is the new ODK Provisioning Request (core
|
||||
// message + const uint32_t + the rest) without the core message and const
|
||||
// uint32_t.
|
||||
uint8_t zeros[ODK_PROVISIONING_REQUEST_SIZE - 4 - ODK_CORE_MESSAGE_SIZE] =
|
||||
{0};
|
||||
|
||||
// Compare zeros against the old Provisioning Request (core message + the
|
||||
// rest).
|
||||
if (memcmp(zeros, buf + ODK_CORE_MESSAGE_SIZE, sizeof(zeros)) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(&prepared_provision.counter_info, 0,
|
||||
sizeof(prepared_provision.counter_info));
|
||||
} else if (!CopyCounterInfo(&core_provisioning_request->counter_info,
|
||||
&prepared_provision.counter_info)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -189,6 +240,10 @@ bool CoreProvisioning40RequestFromMessage(
|
||||
core_provisioning_request, &prepared_provision, unpacker)) {
|
||||
return false;
|
||||
}
|
||||
if (!CopyCounterInfo(&core_provisioning_request->counter_info,
|
||||
&prepared_provision.counter_info)) {
|
||||
return false;
|
||||
}
|
||||
const uint8_t* device_info = prepared_provision.device_info;
|
||||
const uint32_t device_info_length = prepared_provision.device_info_length;
|
||||
if (device_info_length > ODK_DEVICE_INFO_LEN_MAX) {
|
||||
@@ -242,8 +297,16 @@ bool CoreCommonRequestFromMessage(const std::string& oemcrypto_core_message,
|
||||
ODK_CommonRequest* common_request) {
|
||||
const auto unpacker = Unpack_ODK_PreparedCommonRequest;
|
||||
ODK_PreparedCommonRequest prepared_common = {};
|
||||
return ParseRequest(ODK_Common_Request_Type, oemcrypto_core_message,
|
||||
common_request, &prepared_common, unpacker);
|
||||
const bool success =
|
||||
ParseRequest(ODK_Common_Request_Type, oemcrypto_core_message,
|
||||
common_request, &prepared_common, unpacker);
|
||||
|
||||
if (success) {
|
||||
const auto& core_message = prepared_common.core_message;
|
||||
common_request->message_type = core_message.message_type;
|
||||
common_request->message_length = core_message.message_length;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
} // namespace deserialize
|
||||
|
||||
@@ -28,7 +28,7 @@ CoreMessageFeatures CoreMessageFeatures::DefaultFeatures(
|
||||
features.maximum_minor_version = 2; // 17.2
|
||||
break;
|
||||
case 18:
|
||||
features.maximum_minor_version = 0; // 18.0
|
||||
features.maximum_minor_version = 1; // 18.0
|
||||
break;
|
||||
default:
|
||||
features.maximum_minor_version = 0;
|
||||
|
||||
@@ -31,7 +31,7 @@ static OEMCryptoResult ODK_PrepareRequest(
|
||||
|
||||
/* The core message should be at the beginning of the buffer, and with a
|
||||
* shorter length. */
|
||||
if (sizeof(ODK_CoreMessage) > prepared_request_buffer_length) {
|
||||
if (ODK_CORE_MESSAGE_SIZE > prepared_request_buffer_length) {
|
||||
return ODK_ERROR_CORE_MESSAGE;
|
||||
}
|
||||
ODK_CoreMessage* core_message = (ODK_CoreMessage*)prepared_request_buffer;
|
||||
|
||||
@@ -194,6 +194,10 @@ void Pack_ODK_PreparedRenewalRequest(ODK_Message* msg,
|
||||
void Pack_ODK_PreparedProvisioningRequest(
|
||||
ODK_Message* msg, const ODK_PreparedProvisioningRequest* obj) {
|
||||
Pack_ODK_CoreMessage(msg, &obj->core_message);
|
||||
// Fake device_id_length for older servers, since we removed device id from
|
||||
// the v18 request
|
||||
uint32_t device_id_len = 64;
|
||||
Pack_uint32_t(msg, &device_id_len);
|
||||
Pack_ODK_MessageCounterInfo(msg, &obj->counter_info);
|
||||
}
|
||||
|
||||
@@ -483,6 +487,10 @@ void Unpack_ODK_PreparedRenewalRequest(ODK_Message* msg,
|
||||
void Unpack_ODK_PreparedProvisioningRequest(
|
||||
ODK_Message* msg, ODK_PreparedProvisioningRequest* obj) {
|
||||
Unpack_ODK_CoreMessage(msg, &obj->core_message);
|
||||
// Fake device_id_length for older servers, since we removed device id from
|
||||
// the v18 request
|
||||
uint32_t device_id_len = 0;
|
||||
Unpack_uint32_t(msg, &device_id_len);
|
||||
Unpack_ODK_MessageCounterInfo(msg, &obj->counter_info);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ extern "C" {
|
||||
/* odk pack */
|
||||
void Pack_ODK_PreparedLicenseRequest(ODK_Message* msg,
|
||||
const ODK_PreparedLicenseRequest* obj);
|
||||
void Pack_ODK_PreparedLicenseRequestV16(
|
||||
void Pack_ODK_PreparedLicenseRequestV17(
|
||||
ODK_Message* msg, const ODK_PreparedLicenseRequestV17* obj);
|
||||
void Pack_ODK_PreparedRenewalRequest(ODK_Message* msg,
|
||||
const ODK_PreparedRenewalRequest* obj);
|
||||
|
||||
@@ -152,10 +152,11 @@ typedef struct {
|
||||
// without any padding added by the compiler. Make sure they get updated when
|
||||
// request structs change. Refer to test suite OdkSizeTest in
|
||||
// ../test/odk_test.cpp for validations of each of the defined request sizes.
|
||||
#define ODK_CORE_MESSAGE_SIZE 20u
|
||||
#define ODK_LICENSE_REQUEST_SIZE 90u
|
||||
#define ODK_RENEWAL_REQUEST_SIZE 28u
|
||||
#define ODK_PROVISIONING_REQUEST_SIZE 90u
|
||||
#define ODK_PROVISIONING40_REQUEST_SIZE 350u
|
||||
#define ODK_PROVISIONING_REQUEST_SIZE 94u
|
||||
#define ODK_PROVISIONING40_REQUEST_SIZE 862u
|
||||
#define ODK_RENEWED_PROVISIONING_REQUEST_SIZE 1694u
|
||||
#define ODK_MESSAGECOUNTERINFO_SIZE 70u
|
||||
|
||||
|
||||
@@ -3,13 +3,22 @@
|
||||
// License Agreement.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "OEMCryptoCENCCommon.h"
|
||||
#include "core_message_deserialize.h"
|
||||
#include "core_message_types.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "odk.h"
|
||||
#include "third_party/absl/strings/escaping.h"
|
||||
|
||||
namespace wvodk_test {
|
||||
|
||||
using oemcrypto_core_message::ODK_CommonRequest;
|
||||
using oemcrypto_core_message::ODK_ProvisioningRequest;
|
||||
using oemcrypto_core_message::deserialize::CoreCommonRequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreProvisioningRequestFromMessage;
|
||||
|
||||
TEST(CoreMessageTest, RenwalRequest) {
|
||||
std::string oem =
|
||||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst"
|
||||
@@ -36,4 +45,64 @@ TEST(CoreMessageTest, RenwalRequest) {
|
||||
char* m = reinterpret_cast<char*>(message);
|
||||
VLOG(0) << absl::BytesToHexString(std::string(m, core_message_length));
|
||||
}
|
||||
|
||||
TEST(CoreMessageTest, ParseCoreCommonRequestFromMessage) {
|
||||
// Core message header format:
|
||||
// message_type : 4 bytes
|
||||
// message_length : 4 bytes
|
||||
// minor_version : 2 bytes
|
||||
// major_version : 2 bytes
|
||||
// nonce : 4 bytes
|
||||
// session_id : 4 bytes
|
||||
const char kv16CoreMessageLicenseRequest[] =
|
||||
"0000000100000014000300100000000100000001";
|
||||
std::string oemcrypto_core_message =
|
||||
absl::HexStringToBytes(kv16CoreMessageLicenseRequest);
|
||||
ODK_CommonRequest odk_common_request;
|
||||
ASSERT_TRUE(CoreCommonRequestFromMessage(oemcrypto_core_message,
|
||||
&odk_common_request));
|
||||
EXPECT_EQ(odk_common_request.message_type, 1);
|
||||
EXPECT_EQ(odk_common_request.message_length, 20);
|
||||
EXPECT_EQ(odk_common_request.api_minor_version, 3);
|
||||
EXPECT_EQ(odk_common_request.api_major_version, 16);
|
||||
EXPECT_EQ(odk_common_request.nonce, 1);
|
||||
EXPECT_EQ(odk_common_request.session_id, 1);
|
||||
}
|
||||
|
||||
// Make sure that the first version of the V18 provisioning request (no hidden
|
||||
// 4-byte value, all 0s in message counter struct) will still parse with current
|
||||
// v18 code.
|
||||
TEST(CoreMessageTest, ProvisionRequestRoundtrip_V18_Initial) {
|
||||
std::vector<std::string> should_pass = {
|
||||
// Pulled from ODKTest provision round trip, extra 4 bytes removed
|
||||
"000000050000005e00000012deadbeefcafebabe000000000000000000000000"
|
||||
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000",
|
||||
// Same thing but v17 in nonce. Almost like testing on the v17 server (but
|
||||
// not quite since the v17 parsing code has been slightly changed anyway)
|
||||
"000000050000005e00000011deadbeefcafebabe000000000000000000000000"
|
||||
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000",
|
||||
};
|
||||
|
||||
ODK_ProvisioningRequest request;
|
||||
for (auto& tc : should_pass) {
|
||||
ASSERT_TRUE(CoreProvisioningRequestFromMessage(absl::HexStringToBytes(tc),
|
||||
&request));
|
||||
}
|
||||
|
||||
// Fail cases have non-zero values after the bytes interpreted as length
|
||||
std::vector<std::string> should_fail = {
|
||||
// Change a 0 to a 1 in the message counter
|
||||
"000000050000005e00000012deadbeefcafebabe000000000000000100000000"
|
||||
"000000000000000000000000000000000000000000000000000000000000000000000000"
|
||||
"00000000000000000000000000000000000000000000",
|
||||
};
|
||||
|
||||
for (auto& tc : should_fail) {
|
||||
ASSERT_FALSE(CoreProvisioningRequestFromMessage(absl::HexStringToBytes(tc),
|
||||
&request));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wvodk_test
|
||||
|
||||
@@ -25,11 +25,14 @@ namespace wvodk_test {
|
||||
|
||||
namespace {
|
||||
|
||||
using oemcrypto_core_message::ODK_CommonRequest;
|
||||
using oemcrypto_core_message::ODK_LicenseRequest;
|
||||
using oemcrypto_core_message::ODK_MessageCounter;
|
||||
using oemcrypto_core_message::ODK_Provisioning40Request;
|
||||
using oemcrypto_core_message::ODK_ProvisioningRequest;
|
||||
using oemcrypto_core_message::ODK_RenewalRequest;
|
||||
|
||||
using oemcrypto_core_message::deserialize::CoreCommonRequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreLicenseRequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreProvisioning40RequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreProvisioningRequestFromMessage;
|
||||
@@ -79,6 +82,29 @@ void SetDefaultSerializedProvisioningResponse(std::string* serialized_message) {
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckCounterInfoIsEqual(ODK_MessageCounterInfo* a, ODK_MessageCounter* b) {
|
||||
if (!a || !b) return false;
|
||||
|
||||
EXPECT_EQ(a->master_generation_number, b->master_generation_number);
|
||||
EXPECT_EQ(a->provisioning_count, b->provisioning_count);
|
||||
EXPECT_EQ(a->license_count, b->license_count);
|
||||
EXPECT_EQ(a->decrypt_count, b->decrypt_count);
|
||||
EXPECT_EQ(a->major_version, b->major_version);
|
||||
EXPECT_EQ(a->minor_version, b->minor_version);
|
||||
EXPECT_EQ(a->patch_version, b->patch_version);
|
||||
for (size_t i = 0; i < sizeof(a->soc_vendor); i++) {
|
||||
EXPECT_EQ(a->soc_vendor[i], b->soc_vendor[i]);
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(a->chipset_model); i++) {
|
||||
EXPECT_EQ(a->chipset_model[i], b->chipset_model[i]);
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(a->extra); i++) {
|
||||
EXPECT_EQ(a->extra[i], b->extra[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename F, typename G>
|
||||
void ValidateRequest(uint32_t message_type,
|
||||
const std::vector<ODK_Field>& extra_fields,
|
||||
@@ -610,7 +636,16 @@ TEST(OdkTest, LicenseRequestRoundtrip) {
|
||||
return ODK_PrepareCoreLicenseRequest(buf, SIZE_MAX, size, nonce_values,
|
||||
&counter_info);
|
||||
};
|
||||
auto kdo_parse_func = CoreLicenseRequestFromMessage;
|
||||
auto kdo_parse_func = [&](const std::string& oemcrypto_core_message,
|
||||
ODK_LicenseRequest* core_license_request) {
|
||||
bool ok = CoreLicenseRequestFromMessage(oemcrypto_core_message,
|
||||
core_license_request);
|
||||
if (!ok) return false;
|
||||
|
||||
ok = CheckCounterInfoIsEqual(&counter_info,
|
||||
&core_license_request->counter_info);
|
||||
return ok;
|
||||
};
|
||||
ValidateRequest<ODK_LicenseRequest>(ODK_License_Request_Type, extra_fields,
|
||||
odk_prepare_func, kdo_parse_func);
|
||||
}
|
||||
@@ -652,7 +687,11 @@ TEST(OdkTest, ProvisionRequestRoundtrip) {
|
||||
memset(counter_info.soc_vendor, 0xff, sizeof(counter_info.soc_vendor));
|
||||
memset(counter_info.chipset_model, 0xdd, sizeof(counter_info.chipset_model));
|
||||
memset(counter_info.extra, 0xee, sizeof(counter_info.extra));
|
||||
// Fake device_id_length for older servers, since we removed device id from
|
||||
// the v18 request
|
||||
uint32_t fake_device_id_length = 64;
|
||||
std::vector<ODK_Field> extra_fields = {
|
||||
{ODK_UINT32, &(fake_device_id_length), "fake_device_id_length"},
|
||||
{ODK_MESSAGECOUNTER, &counter_info, "counter_info"},
|
||||
};
|
||||
|
||||
@@ -666,6 +705,9 @@ TEST(OdkTest, ProvisionRequestRoundtrip) {
|
||||
ODK_ProvisioningRequest* core_provisioning_request) {
|
||||
bool ok = CoreProvisioningRequestFromMessage(oemcrypto_core_message,
|
||||
core_provisioning_request);
|
||||
if (!ok) return false;
|
||||
ok = CheckCounterInfoIsEqual(&counter_info,
|
||||
&core_provisioning_request->counter_info);
|
||||
return ok;
|
||||
};
|
||||
ValidateRequest<ODK_ProvisioningRequest>(ODK_Provisioning_Request_Type,
|
||||
@@ -704,6 +746,9 @@ TEST(OdkTest, ProvisionRequest40Roundtrip) {
|
||||
ODK_Provisioning40Request* core_provisioning_request) {
|
||||
bool ok = CoreProvisioning40RequestFromMessage(
|
||||
oemcrypto_core_message, core_provisioning_request);
|
||||
if (!ok) return false;
|
||||
ok = CheckCounterInfoIsEqual(&counter_info,
|
||||
&core_provisioning_request->counter_info);
|
||||
return ok;
|
||||
};
|
||||
ValidateRequest<ODK_Provisioning40Request>(ODK_Provisioning40_Request_Type,
|
||||
@@ -865,6 +910,34 @@ TEST(OdkTest, ProvisionResponseFromProto) {
|
||||
OEMCrypto_RSA_Private_Key, &oemcrypto_core_message));
|
||||
}
|
||||
|
||||
// Verify de-serialize common request.
|
||||
TEST(OdkTest, ParseCoreCommonRequestFromMessage) {
|
||||
std::string serialized_provisioning_resp;
|
||||
EXPECT_NO_FATAL_FAILURE(
|
||||
SetDefaultSerializedProvisioningResponse(&serialized_provisioning_resp));
|
||||
ODK_ProvisioningRequest core_request = {
|
||||
.api_minor_version = ODK_MINOR_VERSION,
|
||||
.api_major_version = ODK_MAJOR_VERSION,
|
||||
.nonce = 0xdeadbeef,
|
||||
.session_id = 0xcafebabe,
|
||||
};
|
||||
const CoreMessageFeatures features =
|
||||
CoreMessageFeatures::DefaultFeatures(ODK_MAJOR_VERSION);
|
||||
std::string oemcrypto_core_message;
|
||||
EXPECT_TRUE(CreateCoreProvisioningResponseFromProto(
|
||||
features, serialized_provisioning_resp, core_request,
|
||||
OEMCrypto_RSA_Private_Key, &oemcrypto_core_message));
|
||||
ODK_CommonRequest odk_common_request;
|
||||
ASSERT_TRUE(CoreCommonRequestFromMessage(oemcrypto_core_message,
|
||||
&odk_common_request));
|
||||
EXPECT_EQ(odk_common_request.message_type, 6u);
|
||||
EXPECT_EQ(odk_common_request.message_length, 48u);
|
||||
EXPECT_EQ(odk_common_request.api_minor_version, ODK_MINOR_VERSION);
|
||||
EXPECT_EQ(odk_common_request.api_major_version, ODK_MAJOR_VERSION);
|
||||
EXPECT_EQ(odk_common_request.nonce, 0xdeadbeef);
|
||||
EXPECT_EQ(odk_common_request.session_id, 0xcafebabe);
|
||||
}
|
||||
|
||||
class OdkVersionTest : public ::testing::Test,
|
||||
public ::testing::WithParamInterface<VersionParameters> {
|
||||
protected:
|
||||
@@ -1032,7 +1105,7 @@ std::vector<VersionParameters> TestCases() {
|
||||
// number.
|
||||
{16, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 16, 5},
|
||||
{17, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 17, 2},
|
||||
{18, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 18, 0},
|
||||
{18, ODK_MAJOR_VERSION, ODK_MINOR_VERSION, 18, 1},
|
||||
// Here are some known good versions. Make extra sure they work.
|
||||
{ODK_MAJOR_VERSION, 16, 3, 16, 3},
|
||||
{ODK_MAJOR_VERSION, 16, 4, 16, 4},
|
||||
|
||||
@@ -103,8 +103,8 @@ OEMCryptoResult ODK_WriteSingleField(uint8_t* buf, const ODK_Field* field);
|
||||
// Load buf to ODK_Field
|
||||
OEMCryptoResult ODK_ReadSingleField(const uint8_t* buf, const ODK_Field* field);
|
||||
OEMCryptoResult ODK_DumpSingleField(const uint8_t* buf, const ODK_Field* field);
|
||||
OEMCryptoResult ODK_IterFields(ODK_FieldMode mode, uint8_t* buf,
|
||||
const size_t size_in, size_t* size_out,
|
||||
OEMCryptoResult ODK_IterFields(ODK_FieldMode mode, uint8_t* buf, size_t size_in,
|
||||
size_t* size_out,
|
||||
const std::vector<ODK_Field>& fields);
|
||||
void ODK_ExpectEqualBuf(const void* s1, const void* s2, size_t n,
|
||||
const std::vector<ODK_Field>& fields);
|
||||
|
||||
Reference in New Issue
Block a user