Pick widevine oemcrypto-v18 change
No-Typo-Check: From a third party header file Bug: 260918793 Test: unit tests Test: atp v2/widevine-eng/drm_compliance Change-Id: I36effd6a10a99bdb2399ab1f4a0fad026d607c70
This commit is contained in:
@@ -113,15 +113,14 @@ OEMCryptoResult ODK_ParseRenewal(const uint8_t* message, size_t message_length,
|
||||
|
||||
OEMCryptoResult ODK_PrepareCoreProvisioningRequest(
|
||||
uint8_t* message, size_t message_length, size_t* core_message_length,
|
||||
const ODK_NonceValues* nonce_values, const uint8_t* device_id,
|
||||
size_t device_id_length) {
|
||||
const ODK_NonceValues* nonce_values,
|
||||
const ODK_MessageCounterInfo* counter_info) {
|
||||
OEMCryptoResult (*original_function)(uint8_t*, size_t, size_t*,
|
||||
const ODK_NonceValues*, const uint8_t*,
|
||||
size_t);
|
||||
const ODK_NonceValues*,
|
||||
const ODK_MessageCounterInfo*);
|
||||
original_function = dlsym(RTLD_NEXT, "ODK_PrepareCoreProvisioningRequest");
|
||||
OEMCryptoResult oem_crypto_result =
|
||||
(*original_function)(message, message_length, core_message_length,
|
||||
nonce_values, device_id, device_id_length);
|
||||
OEMCryptoResult oem_crypto_result = (*original_function)(
|
||||
message, message_length, core_message_length, nonce_values, counter_info);
|
||||
char* file_name = GetFileName("provisioning_request_corpus");
|
||||
|
||||
// Provisioning Request format expected by fuzzer - [Core Provisioning
|
||||
@@ -134,18 +133,19 @@ OEMCryptoResult ODK_PrepareCoreProvisioningRequest(
|
||||
OEMCryptoResult ODK_ParseProvisioning(
|
||||
const uint8_t* message, size_t message_length, size_t core_message_length,
|
||||
const ODK_NonceValues* nonce_values, const uint8_t* device_id,
|
||||
size_t device_id_length, ODK_ParsedProvisioning* parsed_response) {
|
||||
size_t device_id_length, ODK_MessageCounterInfo* counter_info,
|
||||
ODK_ParsedProvisioning* parsed_response) {
|
||||
struct ODK_ParseProvisioning_Args parse_provisioning_args;
|
||||
parse_provisioning_args.nonce_values = *nonce_values;
|
||||
memcpy(parse_provisioning_args.device_id, device_id, device_id_length);
|
||||
parse_provisioning_args.device_id_length = device_id_length;
|
||||
OEMCryptoResult (*original_function)(const uint8_t*, size_t, size_t,
|
||||
const ODK_NonceValues*, const uint8_t*,
|
||||
size_t, ODK_ParsedProvisioning*);
|
||||
OEMCryptoResult (*original_function)(
|
||||
const uint8_t*, size_t, size_t, const ODK_NonceValues*, const uint8_t*,
|
||||
size_t, ODK_MessageCounterInfo*, ODK_ParsedProvisioning*);
|
||||
original_function = dlsym(RTLD_NEXT, "ODK_ParseProvisioning");
|
||||
OEMCryptoResult oem_crypto_result = (*original_function)(
|
||||
message, message_length, core_message_length, nonce_values, device_id,
|
||||
device_id_length, parsed_response);
|
||||
device_id_length, counter_info, parsed_response);
|
||||
char* file_name = GetFileName("provisioning_response_corpus");
|
||||
|
||||
// Provisioning Response format expected by fuzzer -
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "odk.h"
|
||||
#include "odk_structs.h"
|
||||
|
||||
namespace oemcrypto_core_message {
|
||||
using features::CoreMessageFeatures;
|
||||
@@ -39,7 +40,10 @@ OEMCryptoResult odk_serialize_LicenseRequest(
|
||||
const void* in UNUSED, uint8_t* out, size_t* size,
|
||||
const ODK_LicenseRequest& core_license_request UNUSED,
|
||||
const ODK_NonceValues* nonce_values) {
|
||||
return ODK_PrepareCoreLicenseRequest(out, SIZE_MAX, size, nonce_values);
|
||||
// TODO(mattfedd): hook up counters to fuzzer
|
||||
const ODK_MessageCounterInfo counter_info = {0};
|
||||
return ODK_PrepareCoreLicenseRequest(out, SIZE_MAX, size, nonce_values,
|
||||
&counter_info);
|
||||
}
|
||||
|
||||
OEMCryptoResult odk_serialize_RenewalRequest(
|
||||
@@ -56,10 +60,10 @@ OEMCryptoResult odk_serialize_ProvisioningRequest(
|
||||
const void* in UNUSED, uint8_t* out, size_t* size,
|
||||
const ODK_ProvisioningRequest& core_provisioning,
|
||||
const ODK_NonceValues* nonce_values) {
|
||||
const std::string& device_id = core_provisioning.device_id;
|
||||
return ODK_PrepareCoreProvisioningRequest(
|
||||
out, SIZE_MAX, size, nonce_values,
|
||||
reinterpret_cast<const uint8_t*>(device_id.data()), device_id.size());
|
||||
// TODO(mattfedd): hook up counters to fuzzer
|
||||
const ODK_MessageCounterInfo counter_info = {0};
|
||||
return ODK_PrepareCoreProvisioningRequest(out, SIZE_MAX, size, nonce_values,
|
||||
&counter_info);
|
||||
}
|
||||
|
||||
OEMCryptoResult odk_deserialize_LicenseResponse(const uint8_t* message,
|
||||
@@ -69,9 +73,9 @@ OEMCryptoResult odk_deserialize_LicenseResponse(const uint8_t* message,
|
||||
ODK_ParsedLicense* parsed_lic) {
|
||||
return ODK_ParseLicense(message, SIZE_MAX, core_message_length,
|
||||
static_cast<bool>(a->initial_license_load),
|
||||
static_cast<bool>(a->usage_entry_present),
|
||||
static_cast<bool>(a->usage_entry_present), 0,
|
||||
&a->timer_limits, &a->clock_values, nonce_values,
|
||||
parsed_lic);
|
||||
parsed_lic, nullptr);
|
||||
}
|
||||
|
||||
OEMCryptoResult odk_deserialize_RenewalResponse(
|
||||
|
||||
@@ -6,14 +6,18 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "OEMCryptoCENCCommon.h"
|
||||
#include "core_message_deserialize.h"
|
||||
#include "core_message_features.h"
|
||||
#include "core_message_serialize.h"
|
||||
#include "core_message_serialize_proto.h"
|
||||
#include "core_message_types.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "odk_structs.h"
|
||||
#include "odk_structs_priv.h"
|
||||
#include "odk_test_helper.h"
|
||||
|
||||
@@ -22,10 +26,12 @@ namespace wvodk_test {
|
||||
namespace {
|
||||
|
||||
using oemcrypto_core_message::ODK_LicenseRequest;
|
||||
using oemcrypto_core_message::ODK_Provisioning40Request;
|
||||
using oemcrypto_core_message::ODK_ProvisioningRequest;
|
||||
using oemcrypto_core_message::ODK_RenewalRequest;
|
||||
|
||||
using oemcrypto_core_message::deserialize::CoreLicenseRequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreProvisioning40RequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreProvisioningRequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::CoreRenewalRequestFromMessage;
|
||||
using oemcrypto_core_message::deserialize::
|
||||
@@ -34,7 +40,10 @@ using oemcrypto_core_message::deserialize::
|
||||
using oemcrypto_core_message::features::CoreMessageFeatures;
|
||||
|
||||
using oemcrypto_core_message::serialize::CreateCoreLicenseResponse;
|
||||
using oemcrypto_core_message::serialize::CreateCoreProvisioning40Response;
|
||||
using oemcrypto_core_message::serialize::CreateCoreProvisioningResponse;
|
||||
using oemcrypto_core_message::serialize::
|
||||
CreateCoreProvisioningResponseFromProto;
|
||||
using oemcrypto_core_message::serialize::CreateCoreRenewalResponse;
|
||||
|
||||
constexpr uint32_t kExtraPayloadSize = 128u;
|
||||
@@ -59,6 +68,17 @@ void PrintTo(const VersionParameters& p, std::ostream* os) {
|
||||
<< p.response_minor_version;
|
||||
}
|
||||
|
||||
void SetDefaultSerializedProvisioningResponse(std::string* serialized_message) {
|
||||
// Create a dummy provisioning response
|
||||
video_widevine::ProvisioningResponse provisioning_response;
|
||||
provisioning_response.set_device_certificate("device_certificate");
|
||||
provisioning_response.set_device_rsa_key("device_rsa_key");
|
||||
provisioning_response.set_device_rsa_key_iv("device_rsa_key_iv");
|
||||
if (!provisioning_response.SerializeToString(serialized_message)) {
|
||||
FAIL();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, typename F, typename G>
|
||||
void ValidateRequest(uint32_t message_type,
|
||||
const std::vector<ODK_Field>& extra_fields,
|
||||
@@ -241,13 +261,19 @@ TEST(OdkTest, NullRequestTest) {
|
||||
memset(&nonce_values, 0, sizeof(nonce_values));
|
||||
ODK_ClockValues clock_values;
|
||||
memset(&clock_values, 0, sizeof(clock_values));
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
|
||||
// Assert that nullptr does not cause a core dump.
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, ODK_PrepareCoreLicenseRequest(
|
||||
nullptr, 0uL, nullptr, &nonce_values));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreLicenseRequest(nullptr, 0uL, nullptr, &nonce_values,
|
||||
&counter_info));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreLicenseRequest(nullptr, 0uL, &core_message_length,
|
||||
nullptr));
|
||||
nullptr, &counter_info));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreLicenseRequest(nullptr, 0uL, &core_message_length,
|
||||
&nonce_values, nullptr));
|
||||
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreRenewalRequest(nullptr, 0uL, nullptr, &nonce_values,
|
||||
@@ -261,10 +287,23 @@ TEST(OdkTest, NullRequestTest) {
|
||||
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
nullptr, 0uL, &core_message_length, nullptr, nullptr, 0uL));
|
||||
nullptr, 0uL, &core_message_length, nullptr, &counter_info));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreProvisioningRequest(nullptr, 0uL, nullptr,
|
||||
&nonce_values, nullptr, 0uL));
|
||||
&nonce_values, &counter_info));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
nullptr, 0uL, &core_message_length, &nonce_values, nullptr));
|
||||
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, ODK_PrepareCoreProvisioning40Request(
|
||||
nullptr, 0uL, &core_message_length,
|
||||
nullptr, nullptr, 0uL, &counter_info));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, ODK_PrepareCoreProvisioning40Request(
|
||||
nullptr, 0uL, nullptr, &nonce_values,
|
||||
nullptr, 0uL, &counter_info));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, ODK_PrepareCoreProvisioning40Request(
|
||||
nullptr, 0uL, &core_message_length,
|
||||
&nonce_values, nullptr, 0uL, nullptr));
|
||||
|
||||
// Null device id in provisioning request is ok
|
||||
uint8_t message[ODK_PROVISIONING_REQUEST_SIZE] = {0};
|
||||
@@ -272,7 +311,16 @@ TEST(OdkTest, NullRequestTest) {
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
message, ODK_PROVISIONING_REQUEST_SIZE, &core_message_length,
|
||||
&nonce_values, nullptr, 0uL));
|
||||
&nonce_values, &counter_info));
|
||||
|
||||
// Null device info in provisioning 4.0 request is ok
|
||||
uint8_t message_prov4[ODK_PROVISIONING40_REQUEST_SIZE] = {0};
|
||||
core_message_length = ODK_PROVISIONING40_REQUEST_SIZE;
|
||||
EXPECT_EQ(
|
||||
OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreProvisioning40Request(
|
||||
message_prov4, ODK_PROVISIONING40_REQUEST_SIZE, &core_message_length,
|
||||
&nonce_values, nullptr, 0uL, &counter_info));
|
||||
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreRenewedProvisioningRequest(
|
||||
@@ -316,26 +364,26 @@ TEST(OdkTest, NullResponseTest) {
|
||||
memset(&clock_values, 0, sizeof(clock_values));
|
||||
|
||||
// Assert that nullptr does not cause a core dump.
|
||||
EXPECT_EQ(
|
||||
ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true, true,
|
||||
&timer_limits, &clock_values, &nonce_values, nullptr));
|
||||
EXPECT_EQ(
|
||||
ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true, true,
|
||||
&timer_limits, &clock_values, nullptr, &parsed_license));
|
||||
EXPECT_EQ(
|
||||
ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true, true,
|
||||
&timer_limits, nullptr, &nonce_values, &parsed_license));
|
||||
EXPECT_EQ(
|
||||
ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true, true,
|
||||
nullptr, &clock_values, &nonce_values, &parsed_license));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true,
|
||||
true, 0, &timer_limits, &clock_values,
|
||||
&nonce_values, nullptr, nullptr));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true,
|
||||
true, 0, &timer_limits, &clock_values, nullptr,
|
||||
&parsed_license, nullptr));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true,
|
||||
true, 0, &timer_limits, nullptr, &nonce_values,
|
||||
&parsed_license, nullptr));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(message, message_size, core_message_length, true,
|
||||
true, 0, nullptr, &clock_values, &nonce_values,
|
||||
&parsed_license, nullptr));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseLicense(nullptr, message_size, core_message_length, true,
|
||||
true, &timer_limits, &clock_values, &nonce_values,
|
||||
&parsed_license));
|
||||
true, 0, &timer_limits, &clock_values,
|
||||
&nonce_values, &parsed_license, nullptr));
|
||||
|
||||
constexpr uint64_t system_time = 0;
|
||||
uint64_t timer_value = 0;
|
||||
@@ -373,6 +421,13 @@ TEST(OdkTest, NullResponseTest) {
|
||||
ODK_ParseProvisioning(nullptr, message_size, core_message_length,
|
||||
&nonce_values, device_id,
|
||||
ODK_DEVICE_ID_LEN_MAX, &parsed_response));
|
||||
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseProvisioning40(message, message_size, core_message_length,
|
||||
nullptr));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_ParseProvisioning40(nullptr, message_size, core_message_length,
|
||||
&nonce_values));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreLicenseRequest) {
|
||||
@@ -380,9 +435,12 @@ TEST(OdkTest, PrepareCoreLicenseRequest) {
|
||||
size_t core_message_length = sizeof(license_message);
|
||||
ODK_NonceValues nonce_values;
|
||||
memset(&nonce_values, 0, sizeof(nonce_values));
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS, ODK_PrepareCoreLicenseRequest(
|
||||
license_message, sizeof(license_message),
|
||||
&core_message_length, &nonce_values));
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreLicenseRequest(
|
||||
license_message, sizeof(license_message), &core_message_length,
|
||||
&nonce_values, &counter_info));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreLicenseRequestSize) {
|
||||
@@ -390,18 +448,20 @@ TEST(OdkTest, PrepareCoreLicenseRequestSize) {
|
||||
size_t core_message_length = sizeof(license_message);
|
||||
ODK_NonceValues nonce_values;
|
||||
memset(&nonce_values, 0, sizeof(nonce_values));
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
// message length smaller than core message length
|
||||
size_t core_message_length_invalid = core_message_length + 1;
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreLicenseRequest(
|
||||
license_message, sizeof(license_message),
|
||||
&core_message_length_invalid, &nonce_values));
|
||||
&core_message_length_invalid, &nonce_values, &counter_info));
|
||||
// message length larger than core message length
|
||||
uint8_t license_message_large[ODK_LICENSE_REQUEST_SIZE * 2] = {0};
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreLicenseRequest(license_message_large,
|
||||
sizeof(license_message_large),
|
||||
&core_message_length, &nonce_values));
|
||||
ODK_PrepareCoreLicenseRequest(
|
||||
license_message_large, sizeof(license_message_large),
|
||||
&core_message_length, &nonce_values, &counter_info));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreRenewalRequest) {
|
||||
@@ -446,12 +506,27 @@ TEST(OdkTest, PrepareCoreProvisioningRequest) {
|
||||
size_t core_message_length = sizeof(provisioning_message);
|
||||
ODK_NonceValues nonce_values;
|
||||
memset(&nonce_values, 0, sizeof(nonce_values));
|
||||
uint8_t device_id[ODK_DEVICE_ID_LEN_MAX] = {0};
|
||||
EXPECT_EQ(
|
||||
OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
provisioning_message, sizeof(provisioning_message),
|
||||
&core_message_length, &nonce_values, device_id, sizeof(device_id)));
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
provisioning_message, sizeof(provisioning_message),
|
||||
&core_message_length, &nonce_values, &counter_info));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreProvisioning40Request) {
|
||||
uint8_t provisioning_message[ODK_PROVISIONING40_REQUEST_SIZE] = {0};
|
||||
size_t core_message_length = sizeof(provisioning_message);
|
||||
ODK_NonceValues nonce_values;
|
||||
memset(&nonce_values, 0, sizeof(nonce_values));
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
uint8_t device_info[ODK_DEVICE_INFO_LEN_MAX] = {0};
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS,
|
||||
ODK_PrepareCoreProvisioning40Request(
|
||||
provisioning_message, sizeof(provisioning_message),
|
||||
&core_message_length, &nonce_values, device_info,
|
||||
sizeof(device_info), &counter_info));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreRenewedProvisioningRequest) {
|
||||
@@ -469,17 +544,19 @@ TEST(OdkTest, PrepareCoreRenewedProvisioningRequest) {
|
||||
OEMCrypto_RenewalACert, renewal_data, sizeof(renewal_data)));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreProvisioningRequestDeviceId) {
|
||||
uint8_t provisioning_message[ODK_PROVISIONING_REQUEST_SIZE] = {0};
|
||||
TEST(OdkTest, PrepareCoreProvisioning40RequestDeviceInfo) {
|
||||
uint8_t provisioning_message[ODK_PROVISIONING40_REQUEST_SIZE] = {0};
|
||||
size_t core_message_length = sizeof(provisioning_message);
|
||||
ODK_NonceValues nonce_values;
|
||||
memset(&nonce_values, 0, sizeof(nonce_values));
|
||||
uint8_t device_id_invalid[ODK_DEVICE_ID_LEN_MAX + 1] = {0};
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
uint8_t device_info_invalid[ODK_DEVICE_INFO_LEN_MAX + 1] = {0};
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
ODK_PrepareCoreProvisioning40Request(
|
||||
provisioning_message, sizeof(provisioning_message),
|
||||
&core_message_length, &nonce_values, device_id_invalid,
|
||||
sizeof(device_id_invalid)));
|
||||
&core_message_length, &nonce_values, device_info_invalid,
|
||||
sizeof(device_info_invalid), &counter_info));
|
||||
}
|
||||
|
||||
TEST(OdkTest, PrepareCoreRenewedProvisioningRequestDeviceId) {
|
||||
@@ -514,13 +591,27 @@ TEST(OdkTest, PrepareCoreRenewedProvisioningRequestRenewalDataInvalid) {
|
||||
|
||||
// Serialize and de-serialize license request
|
||||
TEST(OdkTest, LicenseRequestRoundtrip) {
|
||||
std::vector<ODK_Field> empty;
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
counter_info.master_generation_number = 0x12345678abcdffff;
|
||||
counter_info.provisioning_count = 12;
|
||||
counter_info.license_count = 50;
|
||||
counter_info.decrypt_count = 340;
|
||||
counter_info.major_version = ODK_MAJOR_VERSION;
|
||||
counter_info.minor_version = ODK_MINOR_VERSION;
|
||||
counter_info.patch_version = 4;
|
||||
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));
|
||||
std::vector<ODK_Field> extra_fields = {
|
||||
{ODK_MESSAGECOUNTER, &counter_info, "counter_info"},
|
||||
};
|
||||
auto odk_prepare_func = [&](uint8_t* const buf, size_t* size,
|
||||
ODK_NonceValues* nonce_values) {
|
||||
return ODK_PrepareCoreLicenseRequest(buf, SIZE_MAX, size, nonce_values);
|
||||
return ODK_PrepareCoreLicenseRequest(buf, SIZE_MAX, size, nonce_values,
|
||||
&counter_info);
|
||||
};
|
||||
auto kdo_parse_func = CoreLicenseRequestFromMessage;
|
||||
ValidateRequest<ODK_LicenseRequest>(ODK_License_Request_Type, empty,
|
||||
ValidateRequest<ODK_LicenseRequest>(ODK_License_Request_Type, extra_fields,
|
||||
odk_prepare_func, kdo_parse_func);
|
||||
}
|
||||
|
||||
@@ -550,17 +641,25 @@ TEST(OdkTest, RenewalRequestRoundtrip) {
|
||||
}
|
||||
|
||||
TEST(OdkTest, ProvisionRequestRoundtrip) {
|
||||
uint32_t device_id_length = ODK_DEVICE_ID_LEN_MAX / 2;
|
||||
uint8_t device_id[ODK_DEVICE_ID_LEN_MAX] = {0};
|
||||
memset(device_id, 0xff, device_id_length);
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
counter_info.master_generation_number = 0x12345678abcdffff;
|
||||
counter_info.provisioning_count = 12;
|
||||
counter_info.license_count = 50;
|
||||
counter_info.decrypt_count = 340;
|
||||
counter_info.major_version = ODK_MAJOR_VERSION;
|
||||
counter_info.minor_version = ODK_MINOR_VERSION;
|
||||
counter_info.patch_version = 4;
|
||||
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));
|
||||
std::vector<ODK_Field> extra_fields = {
|
||||
{ODK_UINT32, &device_id_length, "device_id_length"},
|
||||
{ODK_DEVICEID, device_id, "device_id"},
|
||||
{ODK_MESSAGECOUNTER, &counter_info, "counter_info"},
|
||||
};
|
||||
|
||||
auto odk_prepare_func = [&](uint8_t* const buf, size_t* size,
|
||||
const ODK_NonceValues* nonce_values) {
|
||||
return ODK_PrepareCoreProvisioningRequest(buf, SIZE_MAX, size, nonce_values,
|
||||
device_id, device_id_length);
|
||||
&counter_info);
|
||||
};
|
||||
auto kdo_parse_func =
|
||||
[&](const std::string& oemcrypto_core_message,
|
||||
@@ -574,6 +673,44 @@ TEST(OdkTest, ProvisionRequestRoundtrip) {
|
||||
kdo_parse_func);
|
||||
}
|
||||
|
||||
TEST(OdkTest, ProvisionRequest40Roundtrip) {
|
||||
uint32_t device_info_length = ODK_DEVICE_INFO_LEN_MAX / 2;
|
||||
uint8_t device_info[ODK_DEVICE_INFO_LEN_MAX] = {0};
|
||||
memset(device_info, 0xaa, device_info_length);
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
counter_info.master_generation_number = 0x12345678abcdffff;
|
||||
counter_info.provisioning_count = 12;
|
||||
counter_info.license_count = 50;
|
||||
counter_info.decrypt_count = 340;
|
||||
counter_info.major_version = ODK_MAJOR_VERSION;
|
||||
counter_info.minor_version = ODK_MINOR_VERSION;
|
||||
counter_info.patch_version = 4;
|
||||
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));
|
||||
std::vector<ODK_Field> extra_fields = {
|
||||
{ODK_UINT32, &device_info_length, "device_info_length"},
|
||||
{ODK_DEVICEINFO, device_info, "device_info"},
|
||||
{ODK_MESSAGECOUNTER, &counter_info, "counter_info"},
|
||||
};
|
||||
auto odk_prepare_func = [&](uint8_t* const buf, size_t* size,
|
||||
const ODK_NonceValues* nonce_values) {
|
||||
return ODK_PrepareCoreProvisioning40Request(
|
||||
buf, SIZE_MAX, size, nonce_values, device_info, device_info_length,
|
||||
&counter_info);
|
||||
};
|
||||
auto kdo_parse_func =
|
||||
[&](const std::string& oemcrypto_core_message,
|
||||
ODK_Provisioning40Request* core_provisioning_request) {
|
||||
bool ok = CoreProvisioning40RequestFromMessage(
|
||||
oemcrypto_core_message, core_provisioning_request);
|
||||
return ok;
|
||||
};
|
||||
ValidateRequest<ODK_Provisioning40Request>(ODK_Provisioning40_Request_Type,
|
||||
extra_fields, odk_prepare_func,
|
||||
kdo_parse_func);
|
||||
}
|
||||
|
||||
TEST(OdkTest, RenewedProvisionRequestRoundtrip) {
|
||||
uint32_t device_id_length = ODK_DEVICE_ID_LEN_MAX / 2;
|
||||
uint8_t device_id[ODK_DEVICE_ID_LEN_MAX] = {0};
|
||||
@@ -618,9 +755,9 @@ TEST(OdkTest, ParseLicenseErrorNonce) {
|
||||
params.core_message.nonce_values.nonce = 0;
|
||||
OEMCryptoResult err = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, &(params.timer_limits),
|
||||
params.usage_entry_present, 0, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license));
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(OEMCrypto_ERROR_INVALID_NONCE, err);
|
||||
delete[] buf;
|
||||
}
|
||||
@@ -635,9 +772,9 @@ TEST(OdkTest, ParseLicenseErrorUsageEntry) {
|
||||
params.usage_entry_present = false;
|
||||
OEMCryptoResult err = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, &(params.timer_limits),
|
||||
params.usage_entry_present, 0, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license));
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, err);
|
||||
delete[] buf;
|
||||
}
|
||||
@@ -653,9 +790,9 @@ TEST(OdkTest, ParseLicenseNullSubstring) {
|
||||
&buf_size);
|
||||
OEMCryptoResult result = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, &(params.timer_limits),
|
||||
params.usage_entry_present, 0, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license));
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS, result);
|
||||
delete[] buf;
|
||||
}
|
||||
@@ -671,9 +808,9 @@ TEST(OdkTest, ParseLicenseErrorSubstringOffset) {
|
||||
&buf_size);
|
||||
OEMCryptoResult err = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, &(params.timer_limits),
|
||||
params.usage_entry_present, 0, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license));
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, err);
|
||||
delete[] buf;
|
||||
|
||||
@@ -687,9 +824,9 @@ TEST(OdkTest, ParseLicenseErrorSubstringOffset) {
|
||||
&buf_size);
|
||||
err = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, &(params.timer_limits),
|
||||
params.usage_entry_present, 0, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license));
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, err);
|
||||
delete[] buf;
|
||||
}
|
||||
@@ -710,20 +847,22 @@ TEST(OdkTest, ParseRenewalErrorTimer) {
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
TEST(OdkTest, ParsePrivisioningErrorDeviceId) {
|
||||
ODK_ProvisioningResponseParams params;
|
||||
ODK_SetDefaultProvisioningResponseParams(¶ms);
|
||||
uint8_t* buf = nullptr;
|
||||
uint32_t buf_size = 0;
|
||||
ODK_BuildMessageBuffer(&(params.core_message), params.extra_fields, &buf,
|
||||
&buf_size);
|
||||
// temporarily mess up with device_id
|
||||
params.device_id[0] = 0;
|
||||
OEMCryptoResult err = ODK_ParseProvisioning(
|
||||
buf, buf_size + 16, buf_size, &(params.core_message.nonce_values),
|
||||
params.device_id, params.device_id_length, &(params.parsed_provisioning));
|
||||
EXPECT_EQ(ODK_ERROR_CORE_MESSAGE, err);
|
||||
delete[] buf;
|
||||
TEST(OdkTest, ProvisionResponseFromProto) {
|
||||
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));
|
||||
}
|
||||
|
||||
class OdkVersionTest : public ::testing::Test,
|
||||
@@ -735,8 +874,12 @@ class OdkVersionTest : public ::testing::Test,
|
||||
GetParam().response_major_version;
|
||||
params->core_message.nonce_values.api_minor_version =
|
||||
GetParam().response_minor_version;
|
||||
features_ =
|
||||
CoreMessageFeatures::DefaultFeatures(GetParam().maximum_major_version);
|
||||
if (GetParam().maximum_major_version > 0) {
|
||||
features_ = CoreMessageFeatures::DefaultFeatures(
|
||||
GetParam().maximum_major_version);
|
||||
} else {
|
||||
features_ = CoreMessageFeatures::kDefaultFeatures;
|
||||
}
|
||||
}
|
||||
CoreMessageFeatures features_;
|
||||
};
|
||||
@@ -756,9 +899,9 @@ TEST_P(OdkVersionTest, LicenseResponseRoundtrip) {
|
||||
auto odk_parse_func = [&](const uint8_t* buf, size_t size) {
|
||||
return ODK_ParseLicense(
|
||||
buf, size + kExtraPayloadSize, size, params.initial_license_load,
|
||||
params.usage_entry_present, &(params.timer_limits),
|
||||
params.usage_entry_present, 0, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license));
|
||||
&(params.parsed_license), nullptr);
|
||||
};
|
||||
const std::string request_hash_string(
|
||||
reinterpret_cast<const char*>(request_hash_read),
|
||||
@@ -806,7 +949,8 @@ TEST_P(OdkVersionTest, RenewalResponseRoundtrip) {
|
||||
|
||||
TEST_P(OdkVersionTest, ProvisionResponseRoundtrip) {
|
||||
ODK_ProvisioningResponseParams params;
|
||||
ODK_SetDefaultProvisioningResponseParams(¶ms);
|
||||
ODK_SetDefaultProvisioningResponseParams(¶ms,
|
||||
GetParam().response_major_version);
|
||||
SetRequestVersion(¶ms);
|
||||
// save a copy of params.device_id as it will be zero out during the test
|
||||
const uint32_t device_id_length = params.device_id_length;
|
||||
@@ -821,8 +965,12 @@ TEST_P(OdkVersionTest, ProvisionResponseRoundtrip) {
|
||||
};
|
||||
auto kdo_prepare_func = [&](ODK_ProvisioningRequest& core_request,
|
||||
std::string* oemcrypto_core_message) {
|
||||
// use device_id for V17 and V16
|
||||
core_request.device_id.assign(reinterpret_cast<char*>(device_id),
|
||||
device_id_length);
|
||||
// use counter info for V18
|
||||
memcpy(&core_request.counter_info, ¶ms.counter_info,
|
||||
sizeof(params.counter_info));
|
||||
return CreateCoreProvisioningResponse(features_, params.parsed_provisioning,
|
||||
core_request, oemcrypto_core_message);
|
||||
};
|
||||
@@ -831,12 +979,30 @@ TEST_P(OdkVersionTest, ProvisionResponseRoundtrip) {
|
||||
kdo_prepare_func);
|
||||
}
|
||||
|
||||
TEST_P(OdkVersionTest, Provision40ResponseRoundtrip) {
|
||||
ODK_Provisioning40ResponseParams params;
|
||||
ODK_SetDefaultProvisioning40ResponseParams(¶ms);
|
||||
SetRequestVersion(¶ms);
|
||||
|
||||
auto odk_parse_func = [&](const uint8_t* buf, size_t size) {
|
||||
OEMCryptoResult err = ODK_ParseProvisioning40(
|
||||
buf, size + 16, size, &(params.core_message.nonce_values));
|
||||
return err;
|
||||
};
|
||||
auto kdo_prepare_func = [&](ODK_Provisioning40Request& core_request,
|
||||
std::string* oemcrypto_core_message) {
|
||||
return CreateCoreProvisioning40Response(features_, core_request,
|
||||
oemcrypto_core_message);
|
||||
};
|
||||
ValidateResponse<ODK_Provisioning40Request>(
|
||||
GetParam(), &(params.core_message), params.extra_fields, odk_parse_func,
|
||||
kdo_prepare_func);
|
||||
}
|
||||
|
||||
// If the minor version is positive, we can test an older minor version.
|
||||
const uint16_t kOldMinor = ODK_MINOR_VERSION > 0 ? ODK_MINOR_VERSION - 1 : 0;
|
||||
// Similarly, if this isn't the first major version, we can test an older major
|
||||
// version.
|
||||
// TODO(b/163416999): Remove it in the future. This will be unecessarily
|
||||
// complicated after we upgrade to version 17.
|
||||
const uint16_t kOldMajor = ODK_MAJOR_VERSION > ODK_FIRST_VERSION
|
||||
? ODK_MAJOR_VERSION - 1
|
||||
: ODK_FIRST_VERSION;
|
||||
@@ -862,17 +1028,24 @@ std::vector<VersionParameters> TestCases() {
|
||||
{ODK_MAJOR_VERSION, kOldMajor, kOldMajorMinor, kOldMajor, kOldMajorMinor},
|
||||
// If the server is restricted to v16, then the response can be at
|
||||
// most 16.5
|
||||
// These tests cases must be updated whenever we roll the minor version
|
||||
// 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},
|
||||
// Here are some known good versions. Make extra sure they work.
|
||||
{16, 16, 3, 16, 3},
|
||||
{16, 16, 4, 16, 4},
|
||||
{16, 16, 5, 16, 5},
|
||||
{17, 16, 3, 16, 3},
|
||||
{17, 16, 4, 16, 4},
|
||||
{17, 16, 5, 16, 5},
|
||||
{17, 17, 0, 17, 0},
|
||||
{17, 17, 1, 17, 1},
|
||||
{17, 17, 2, 17, 2},
|
||||
{ODK_MAJOR_VERSION, 16, 3, 16, 3},
|
||||
{ODK_MAJOR_VERSION, 16, 4, 16, 4},
|
||||
{ODK_MAJOR_VERSION, 16, 5, 16, 5},
|
||||
{ODK_MAJOR_VERSION, 17, 1, 17, 1},
|
||||
{ODK_MAJOR_VERSION, 17, 2, 17, 2},
|
||||
{ODK_MAJOR_VERSION, 18, 0, 18, 0},
|
||||
{0, 16, 3, 16, 3},
|
||||
{0, 16, 4, 16, 4},
|
||||
{0, 16, 5, 16, 5},
|
||||
{0, 17, 1, 17, 1},
|
||||
{0, 17, 2, 17, 2},
|
||||
{0, 18, 0, 17, 2}, // Change to 18 when the default version is updated.
|
||||
};
|
||||
return test_cases;
|
||||
}
|
||||
@@ -888,11 +1061,14 @@ TEST(OdkSizeTest, LicenseRequest) {
|
||||
uint16_t api_major_version = 0;
|
||||
uint32_t nonce = 0;
|
||||
uint32_t session_id = 0;
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
ODK_NonceValues nonce_values{api_minor_version, api_major_version, nonce,
|
||||
session_id};
|
||||
EXPECT_EQ(OEMCrypto_ERROR_SHORT_BUFFER,
|
||||
ODK_PrepareCoreLicenseRequest(message, message_length,
|
||||
&core_message_length, &nonce_values));
|
||||
&core_message_length, &nonce_values,
|
||||
&counter_info));
|
||||
// the core_message_length should be appropriately set
|
||||
EXPECT_EQ(ODK_LICENSE_REQUEST_SIZE, core_message_length);
|
||||
}
|
||||
@@ -949,13 +1125,14 @@ TEST(OdkSizeTest, ProvisioningRequest) {
|
||||
uint16_t api_major_version = 0;
|
||||
uint32_t nonce = 0;
|
||||
uint32_t session_id = 0;
|
||||
uint32_t device_id_length = 0;
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
memset(&counter_info, 0, sizeof(counter_info));
|
||||
ODK_NonceValues nonce_values{api_minor_version, api_major_version, nonce,
|
||||
session_id};
|
||||
EXPECT_EQ(OEMCrypto_ERROR_SHORT_BUFFER,
|
||||
ODK_PrepareCoreProvisioningRequest(
|
||||
message, message_length, &core_message_length, &nonce_values,
|
||||
nullptr, device_id_length));
|
||||
ODK_PrepareCoreProvisioningRequest(message, message_length,
|
||||
&core_message_length,
|
||||
&nonce_values, &counter_info));
|
||||
// the core_message_length should be appropriately set
|
||||
EXPECT_EQ(ODK_PROVISIONING_REQUEST_SIZE, core_message_length);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -75,6 +78,7 @@ void ODK_SetDefaultLicenseResponseParams(ODK_LicenseResponseParams* params,
|
||||
.length = 3,
|
||||
.data = {0, 0, 0},
|
||||
}},
|
||||
.renewal_delay_base = OEMCrypto_License_Start,
|
||||
.key_array_length = 3,
|
||||
.key_array =
|
||||
{
|
||||
@@ -203,6 +207,11 @@ void ODK_SetDefaultLicenseResponseParams(ODK_LicenseResponseParams* params,
|
||||
".cmi_descriptor_data"});
|
||||
}
|
||||
}
|
||||
if (odk_major_version >= 18) {
|
||||
params->extra_fields.push_back(
|
||||
{ODK_UINT32, &(params->parsed_license.renewal_delay_base),
|
||||
".renewal_delay_base"});
|
||||
}
|
||||
params->extra_fields.push_back({ODK_UINT32,
|
||||
&(params->parsed_license.key_array_length),
|
||||
".key_array_length"});
|
||||
@@ -288,7 +297,7 @@ void ODK_SetDefaultRenewalResponseParams(ODK_RenewalResponseParams* params) {
|
||||
}
|
||||
|
||||
void ODK_SetDefaultProvisioningResponseParams(
|
||||
ODK_ProvisioningResponseParams* params) {
|
||||
ODK_ProvisioningResponseParams* params, uint32_t odk_major_version) {
|
||||
ODK_SetDefaultCoreFields(&(params->core_message),
|
||||
ODK_Provisioning_Response_Type);
|
||||
params->device_id_length = ODK_DEVICE_ID_LEN_MAX / 2;
|
||||
@@ -301,17 +310,34 @@ void ODK_SetDefaultProvisioningResponseParams(
|
||||
.enc_private_key_iv = {.offset = 2, .length = 3},
|
||||
.encrypted_message_key = {.offset = 4, .length = 5},
|
||||
};
|
||||
params->extra_fields = {
|
||||
{ODK_UINT32, &(params->device_id_length), "device_id_length"},
|
||||
{ODK_DEVICEID, params->device_id, "device_id"},
|
||||
{ODK_UINT32, &(params->parsed_provisioning).key_type, "key_type"},
|
||||
|
||||
params->extra_fields = {};
|
||||
// V17 uses device_id
|
||||
if (odk_major_version <= 17) {
|
||||
params->extra_fields.push_back(
|
||||
{ODK_UINT32, &(params->device_id_length), "device_id_length"});
|
||||
params->extra_fields.push_back(
|
||||
{ODK_DEVICEID, params->device_id, "device_id"});
|
||||
}
|
||||
|
||||
params->extra_fields.push_back(
|
||||
{ODK_UINT32, &(params->parsed_provisioning).key_type, "key_type"});
|
||||
params->extra_fields.push_back(
|
||||
{ODK_SUBSTRING, &(params->parsed_provisioning).enc_private_key,
|
||||
"enc_private_key"},
|
||||
"enc_private_key"});
|
||||
params->extra_fields.push_back(
|
||||
{ODK_SUBSTRING, &(params->parsed_provisioning).enc_private_key_iv,
|
||||
"enc_private_key_iv"},
|
||||
"enc_private_key_iv"});
|
||||
params->extra_fields.push_back(
|
||||
{ODK_SUBSTRING, &(params->parsed_provisioning).encrypted_message_key,
|
||||
"encrypted_message_key"},
|
||||
};
|
||||
"encrypted_message_key"});
|
||||
}
|
||||
|
||||
void ODK_SetDefaultProvisioning40ResponseParams(
|
||||
ODK_Provisioning40ResponseParams* params) {
|
||||
ODK_SetDefaultCoreFields(&(params->core_message),
|
||||
ODK_Provisioning_Response_Type);
|
||||
params->extra_fields = {};
|
||||
}
|
||||
|
||||
size_t ODK_FieldLength(ODK_FieldType type) {
|
||||
@@ -330,6 +356,10 @@ size_t ODK_FieldLength(ODK_FieldType type) {
|
||||
return sizeof(uint32_t) + sizeof(uint32_t);
|
||||
case ODK_DEVICEID:
|
||||
return ODK_DEVICE_ID_LEN_MAX;
|
||||
case ODK_MESSAGECOUNTER:
|
||||
return ODK_MESSAGECOUNTERINFO_SIZE;
|
||||
case ODK_DEVICEINFO:
|
||||
return ODK_DEVICE_INFO_LEN_MAX;
|
||||
case ODK_RENEWALDATA:
|
||||
return ODK_KEYBOX_RENEWAL_DATA_SIZE;
|
||||
case ODK_HASH:
|
||||
@@ -343,6 +373,9 @@ size_t ODK_AllocSize(ODK_FieldType type) {
|
||||
if (type == ODK_SUBSTRING) {
|
||||
return sizeof(OEMCrypto_Substring);
|
||||
}
|
||||
if (type == ODK_MESSAGECOUNTER) {
|
||||
return sizeof(ODK_MessageCounterInfo);
|
||||
}
|
||||
return ODK_FieldLength(type);
|
||||
}
|
||||
|
||||
@@ -388,6 +421,7 @@ OEMCryptoResult ODK_WriteSingleField(uint8_t* buf, const ODK_Field* field) {
|
||||
break;
|
||||
}
|
||||
case ODK_DEVICEID:
|
||||
case ODK_DEVICEINFO:
|
||||
case ODK_RENEWALDATA:
|
||||
case ODK_HASH: {
|
||||
const size_t field_len = ODK_FieldLength(field->type);
|
||||
@@ -396,6 +430,27 @@ OEMCryptoResult ODK_WriteSingleField(uint8_t* buf, const ODK_Field* field) {
|
||||
|
||||
break;
|
||||
}
|
||||
case ODK_MESSAGECOUNTER: {
|
||||
// Size required in field->value, which may get padding from the compiler.
|
||||
const size_t src_len = ODK_AllocSize(field->type);
|
||||
// Size taken up in serialized message buffer, which is tightly packed.
|
||||
const size_t dest_len = ODK_FieldLength(field->type);
|
||||
const uint8_t* const write_src = static_cast<uint8_t*>(field->value);
|
||||
|
||||
// Copy data from field to buf, fixing endian-ness
|
||||
ODK_MessageCounterInfo info;
|
||||
memcpy(&info, write_src, src_len);
|
||||
info.master_generation_number =
|
||||
oemcrypto_htobe64(info.master_generation_number);
|
||||
info.provisioning_count = oemcrypto_htobe32(info.provisioning_count);
|
||||
info.license_count = oemcrypto_htobe32(info.license_count);
|
||||
info.decrypt_count = oemcrypto_htobe32(info.decrypt_count);
|
||||
info.major_version = oemcrypto_htobe16(info.major_version);
|
||||
info.minor_version = oemcrypto_htobe16(info.minor_version);
|
||||
info.patch_version = oemcrypto_htobe16(info.patch_version);
|
||||
memcpy(buf, &info, dest_len);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return ODK_ERROR_CORE_MESSAGE;
|
||||
}
|
||||
@@ -448,6 +503,7 @@ OEMCryptoResult ODK_ReadSingleField(const uint8_t* buf,
|
||||
break;
|
||||
}
|
||||
case ODK_DEVICEID:
|
||||
case ODK_DEVICEINFO:
|
||||
case ODK_RENEWALDATA:
|
||||
case ODK_HASH: {
|
||||
const size_t field_len = ODK_FieldLength(field->type);
|
||||
@@ -455,6 +511,55 @@ OEMCryptoResult ODK_ReadSingleField(const uint8_t* buf,
|
||||
memcpy(id, buf, field_len);
|
||||
break;
|
||||
}
|
||||
case ODK_MESSAGECOUNTER: {
|
||||
// Size required in field->value, which may get padding from the compiler.
|
||||
const size_t dest_len = ODK_AllocSize(field->type);
|
||||
// Size taken up in serialized message buffer, which is tightly packed.
|
||||
const size_t src_len = ODK_FieldLength(field->type);
|
||||
uint8_t* const read_dest = static_cast<uint8_t*>(field->value);
|
||||
|
||||
// Copy data from buf to field, fixing endian-ness
|
||||
uint8_t temp_buf[sizeof(ODK_MessageCounterInfo)] = {0};
|
||||
memcpy(temp_buf, buf, src_len);
|
||||
|
||||
size_t index = 0;
|
||||
ODK_MessageCounterInfo info;
|
||||
uint64_t* u64 = reinterpret_cast<uint64_t*>(&temp_buf[index]);
|
||||
info.master_generation_number = oemcrypto_be64toh(*u64);
|
||||
index += sizeof(uint64_t);
|
||||
|
||||
uint32_t* u32 = reinterpret_cast<uint32_t*>(&temp_buf[index]);
|
||||
info.provisioning_count = oemcrypto_be32toh(*u32);
|
||||
index += sizeof(uint32_t);
|
||||
|
||||
u32 = reinterpret_cast<uint32_t*>(&temp_buf[index]);
|
||||
info.license_count = oemcrypto_be32toh(*u32);
|
||||
index += sizeof(uint32_t);
|
||||
|
||||
u32 = reinterpret_cast<uint32_t*>(&temp_buf[index]);
|
||||
info.decrypt_count = oemcrypto_be32toh(*u32);
|
||||
index += sizeof(uint32_t);
|
||||
|
||||
uint16_t* u16 = reinterpret_cast<uint16_t*>(&temp_buf[index]);
|
||||
info.major_version = oemcrypto_be16toh(*u16);
|
||||
index += sizeof(uint16_t);
|
||||
|
||||
u16 = reinterpret_cast<uint16_t*>(&temp_buf[index]);
|
||||
info.minor_version = oemcrypto_be16toh(*u16);
|
||||
index += sizeof(uint16_t);
|
||||
|
||||
u16 = reinterpret_cast<uint16_t*>(&temp_buf[index]);
|
||||
info.patch_version = oemcrypto_be16toh(*u16);
|
||||
index += sizeof(uint16_t);
|
||||
|
||||
memcpy(info.soc_vendor, &temp_buf[index], sizeof(info.soc_vendor));
|
||||
index += sizeof(info.soc_vendor);
|
||||
memcpy(info.chipset_model, &temp_buf[index], sizeof(info.chipset_model));
|
||||
index += sizeof(info.chipset_model);
|
||||
memcpy(info.extra, &temp_buf[index], sizeof(info.extra));
|
||||
memcpy(read_dest, &info, dest_len);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return ODK_ERROR_CORE_MESSAGE;
|
||||
}
|
||||
@@ -508,6 +613,8 @@ OEMCryptoResult ODK_DumpSingleField(const uint8_t* buf,
|
||||
break;
|
||||
}
|
||||
case ODK_DEVICEID:
|
||||
case ODK_MESSAGECOUNTER:
|
||||
case ODK_DEVICEINFO:
|
||||
case ODK_RENEWALDATA:
|
||||
case ODK_HASH: {
|
||||
const size_t field_len = ODK_FieldLength(field->type);
|
||||
|
||||
@@ -21,6 +21,8 @@ enum ODK_FieldType {
|
||||
ODK_UINT64,
|
||||
ODK_SUBSTRING,
|
||||
ODK_DEVICEID,
|
||||
ODK_DEVICEINFO,
|
||||
ODK_MESSAGECOUNTER,
|
||||
ODK_RENEWALDATA,
|
||||
ODK_HASH,
|
||||
// The "stressable" types are the ones we can put in a stress test that packs
|
||||
@@ -71,10 +73,17 @@ struct ODK_ProvisioningResponseParams {
|
||||
ODK_CoreMessage core_message;
|
||||
uint8_t device_id[ODK_DEVICE_ID_LEN_MAX];
|
||||
uint32_t device_id_length;
|
||||
uint32_t padding_u32;
|
||||
ODK_MessageCounterInfo counter_info;
|
||||
ODK_ParsedProvisioning parsed_provisioning;
|
||||
std::vector<ODK_Field> extra_fields;
|
||||
};
|
||||
|
||||
struct ODK_Provisioning40ResponseParams {
|
||||
ODK_CoreMessage core_message;
|
||||
std::vector<ODK_Field> extra_fields;
|
||||
};
|
||||
|
||||
// Default values in core_message for testing
|
||||
void ODK_SetDefaultCoreFields(ODK_CoreMessage* core_message,
|
||||
ODK_MessageType message_type);
|
||||
@@ -82,7 +91,9 @@ void ODK_SetDefaultLicenseResponseParams(ODK_LicenseResponseParams* params,
|
||||
uint32_t odk_major_version);
|
||||
void ODK_SetDefaultRenewalResponseParams(ODK_RenewalResponseParams* params);
|
||||
void ODK_SetDefaultProvisioningResponseParams(
|
||||
ODK_ProvisioningResponseParams* params);
|
||||
ODK_ProvisioningResponseParams* params, uint32_t odk_major_version);
|
||||
void ODK_SetDefaultProvisioning40ResponseParams(
|
||||
ODK_Provisioning40ResponseParams* params);
|
||||
|
||||
size_t ODK_FieldLength(ODK_FieldType type);
|
||||
size_t ODK_AllocSize(ODK_FieldType type);
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include "OEMCryptoCENCCommon.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "odk.h"
|
||||
#include "odk_structs.h"
|
||||
#include "odk_structs_priv.h"
|
||||
#include "odk_test_helper.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -23,6 +25,99 @@ constexpr uint64_t kRentalClockStart = 1000u;
|
||||
// renewal is not loaded.
|
||||
constexpr uint64_t kGracePeriod = 5u;
|
||||
|
||||
constexpr uint32_t kExtraPayloadSize = 128u;
|
||||
|
||||
constexpr uint32_t kSystemTime = 20u;
|
||||
|
||||
namespace wvodk_test {
|
||||
|
||||
TEST(OdkTimerBasicTest, ParseLicenseTimerSet) {
|
||||
// playback timer is successfully started
|
||||
::wvodk_test::ODK_LicenseResponseParams params;
|
||||
ODK_SetDefaultLicenseResponseParams(¶ms, ODK_MAJOR_VERSION);
|
||||
params.parsed_license.renewal_delay_base = OEMCrypto_License_Load;
|
||||
params.parsed_license.timer_limits.soft_enforce_rental_duration = false;
|
||||
params.parsed_license.timer_limits.soft_enforce_playback_duration = false;
|
||||
params.parsed_license.timer_limits.earliest_playback_start_seconds = 10;
|
||||
params.parsed_license.timer_limits.total_playback_duration_seconds = 0;
|
||||
params.parsed_license.timer_limits.rental_duration_seconds = 10;
|
||||
params.parsed_license.timer_limits.initial_renewal_duration_seconds = 0;
|
||||
OEMCryptoResult result =
|
||||
ODK_InitializeClockValues(¶ms.clock_values, kSystemTime);
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS, result);
|
||||
params.clock_values.time_of_license_request_signed = 5;
|
||||
params.clock_values.status = kActive;
|
||||
|
||||
uint8_t* buf = nullptr;
|
||||
uint32_t buf_size = 0;
|
||||
ODK_BuildMessageBuffer(&(params.core_message), params.extra_fields, &buf,
|
||||
&buf_size);
|
||||
|
||||
result = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, kSystemTime, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(ODK_SET_TIMER, result);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
TEST(OdkTimerBasicTest, ParseLicenseTimerDisabled) {
|
||||
// playback timer is successfully started
|
||||
::wvodk_test::ODK_LicenseResponseParams params;
|
||||
ODK_SetDefaultLicenseResponseParams(¶ms, ODK_MAJOR_VERSION);
|
||||
params.parsed_license.renewal_delay_base = OEMCrypto_License_Load;
|
||||
params.parsed_license.timer_limits.soft_enforce_rental_duration = true;
|
||||
params.parsed_license.timer_limits.earliest_playback_start_seconds = 3;
|
||||
params.parsed_license.timer_limits.total_playback_duration_seconds = 0;
|
||||
params.parsed_license.timer_limits.initial_renewal_duration_seconds = 0;
|
||||
params.clock_values.time_of_first_decrypt = 10;
|
||||
params.clock_values.time_of_license_request_signed = 5;
|
||||
params.clock_values.status = kActive;
|
||||
|
||||
uint8_t* buf = nullptr;
|
||||
uint32_t buf_size = 0;
|
||||
ODK_BuildMessageBuffer(&(params.core_message), params.extra_fields, &buf,
|
||||
&buf_size);
|
||||
|
||||
OEMCryptoResult result = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, kSystemTime, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(ODK_DISABLE_TIMER, result);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
TEST(OdkTimerBasicTest, ParseRenewalTimerExpired) {
|
||||
// playback timer is successfully started
|
||||
::wvodk_test::ODK_LicenseResponseParams params;
|
||||
ODK_SetDefaultLicenseResponseParams(¶ms, ODK_MAJOR_VERSION);
|
||||
|
||||
params.parsed_license.renewal_delay_base = OEMCrypto_License_Load;
|
||||
params.parsed_license.timer_limits.rental_duration_seconds = 5;
|
||||
params.parsed_license.timer_limits.earliest_playback_start_seconds = 3;
|
||||
OEMCryptoResult result =
|
||||
ODK_InitializeClockValues(¶ms.clock_values, kSystemTime);
|
||||
EXPECT_EQ(OEMCrypto_SUCCESS, result);
|
||||
params.clock_values.time_of_license_request_signed = 5;
|
||||
|
||||
uint8_t* buf = nullptr;
|
||||
uint32_t buf_size = 0;
|
||||
ODK_BuildMessageBuffer(&(params.core_message), params.extra_fields, &buf,
|
||||
&buf_size);
|
||||
|
||||
result = ODK_ParseLicense(
|
||||
buf, buf_size + kExtraPayloadSize, buf_size, params.initial_license_load,
|
||||
params.usage_entry_present, kSystemTime, &(params.timer_limits),
|
||||
&(params.clock_values), &(params.core_message.nonce_values),
|
||||
&(params.parsed_license), nullptr);
|
||||
EXPECT_EQ(ODK_TIMER_EXPIRED, result);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
} // namespace wvodk_test
|
||||
|
||||
TEST(OdkTimerBasicTest, NullTest) {
|
||||
// Assert that nullptr does not cause a core dump.
|
||||
ODK_InitializeClockValues(nullptr, 0u);
|
||||
|
||||
Reference in New Issue
Block a user