132 lines
4.1 KiB
C++
132 lines
4.1 KiB
C++
// Copyright 2019 Google LLC. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine
|
|
// License Agreement.
|
|
|
|
#ifndef WIDEVINE_ODK_TEST_ODK_TEST_HELPER_H_
|
|
#define WIDEVINE_ODK_TEST_ODK_TEST_HELPER_H_
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "OEMCryptoCENCCommon.h"
|
|
#include "odk_structs.h"
|
|
#include "odk_structs_priv.h"
|
|
|
|
namespace wvodk_test {
|
|
|
|
enum ODK_FieldType {
|
|
ODK_UINT8,
|
|
ODK_UINT16,
|
|
ODK_UINT32,
|
|
ODK_UINT64,
|
|
ODK_INT64,
|
|
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
|
|
// and unpacks random data and can expect to get back the same thing.
|
|
ODK_LAST_STRESSABLE_TYPE = ODK_HASH,
|
|
// Put boolean after ODK_LAST_STRESSABLE_TYPE, so that we skip boolean type in
|
|
// SerializeFieldsStress because we unpack any nonzero to 'true'.
|
|
ODK_BOOL,
|
|
};
|
|
|
|
enum ODK_FieldMode {
|
|
ODK_READ,
|
|
ODK_WRITE,
|
|
ODK_DUMP,
|
|
};
|
|
|
|
struct ODK_Field {
|
|
ODK_FieldType type;
|
|
void* value;
|
|
std::string name;
|
|
};
|
|
|
|
// This structure contains all parameters available in message version v16
|
|
// through the current version.
|
|
struct ODK_LicenseResponseParams {
|
|
ODK_CoreMessage core_message;
|
|
bool initial_license_load;
|
|
bool usage_entry_present;
|
|
uint8_t request_hash[ODK_SHA256_HASH_SIZE];
|
|
ODK_TimerLimits timer_limits;
|
|
ODK_ClockValues clock_values;
|
|
ODK_ParsedLicense parsed_license;
|
|
std::vector<ODK_Field> extra_fields;
|
|
};
|
|
|
|
struct ODK_ReleaseResponseParams {
|
|
ODK_CoreMessage core_message;
|
|
uint32_t status;
|
|
uint32_t clock_security_level;
|
|
int64_t seconds_since_license_requested;
|
|
int64_t seconds_since_first_decrypt;
|
|
std::vector<ODK_Field> extra_fields;
|
|
};
|
|
|
|
struct ODK_RenewalResponseParams {
|
|
ODK_CoreMessage core_message;
|
|
uint64_t system_time;
|
|
uint64_t playback_clock;
|
|
uint64_t renewal_duration;
|
|
ODK_TimerLimits timer_limits;
|
|
ODK_ClockValues clock_values;
|
|
uint64_t playback_timer;
|
|
std::vector<ODK_Field> extra_fields;
|
|
};
|
|
|
|
struct ODK_ProvisioningResponseParams {
|
|
ODK_CoreMessage core_message;
|
|
uint8_t device_id[ODK_DEVICE_ID_LEN_MAX];
|
|
uint32_t device_id_length;
|
|
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);
|
|
void ODK_SetDefaultLicenseResponseParams(ODK_LicenseResponseParams* params,
|
|
uint32_t odk_major_version);
|
|
void ODK_SetDefaultReleaseResponseParams(ODK_ReleaseResponseParams* params);
|
|
void ODK_SetDefaultRenewalResponseParams(ODK_RenewalResponseParams* params);
|
|
void ODK_SetDefaultProvisioningResponseParams(
|
|
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);
|
|
|
|
// Copy ODK_Field to buf
|
|
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, 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);
|
|
void ODK_ResetOdkFields(std::vector<ODK_Field>* fields);
|
|
|
|
// Serialize core_message and extra_fields into buf
|
|
void ODK_BuildMessageBuffer(ODK_CoreMessage* core_message,
|
|
const std::vector<ODK_Field>& extra_fields,
|
|
uint8_t** buf, uint32_t* buf_size);
|
|
|
|
} // namespace wvodk_test
|
|
|
|
#endif // WIDEVINE_ODK_TEST_ODK_TEST_HELPER_H_
|