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:
Cong Lin
2023-02-27 18:25:02 -08:00
parent 3f7ecbc43e
commit e8add8eed8
44 changed files with 302003 additions and 298675 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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