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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user