OEMCrypto v16.2
Merge from Widevine repo of http://go/wvgerrit/93404 This is the unit tests, reference code, and documentation for OEMCrypto v16.2. Backwards compatibility should work for a v15 OEMCrypto. Some review comments will be addressed in future CLs. Bug: 141247171 Test: Unit tests Test: Media GTS tests on bonito Change-Id: I9d427c07580e180c0a4cfdc4a68f538d351c0ddd
This commit is contained in:
@@ -106,6 +106,21 @@ typedef enum OEMCrypto_Usage_Entry_Status {
|
||||
kInactiveUnused = 4,
|
||||
} OEMCrypto_Usage_Entry_Status;
|
||||
|
||||
/*
|
||||
* OEMCrypto_LicenseType is used in the license message to indicate if the key
|
||||
* objects are for content keys, or for entitlement keys.
|
||||
*/
|
||||
typedef enum OEMCrypto_LicenseType {
|
||||
OEMCrypto_ContentLicense = 0,
|
||||
OEMCrypto_EntitlementLicense = 1
|
||||
} OEMCrypto_LicenseType;
|
||||
|
||||
/* Private key type used in the provisioning response. */
|
||||
typedef enum OEMCrypto_PrivateKeyType {
|
||||
OEMCrypto_RSA_Private_Key = 0,
|
||||
OEMCrypto_ECC_Private_Key = 1,
|
||||
} OEMCrypto_PrivateKeyType;
|
||||
|
||||
/*
|
||||
* OEMCrypto_Substring
|
||||
*
|
||||
|
||||
@@ -30,10 +30,12 @@ namespace serialize {
|
||||
* Parameters:
|
||||
* [in] parsed_lic
|
||||
* [in] core_request
|
||||
* [in] core_request_sha256
|
||||
* [out] oemcrypto_core_message
|
||||
*/
|
||||
bool CreateCoreLicenseResponse(const ODK_ParsedLicense& parsed_lic,
|
||||
const ODK_LicenseRequest& core_request,
|
||||
const std::string& core_request_sha256,
|
||||
std::string* oemcrypto_core_message);
|
||||
|
||||
/**
|
||||
@@ -41,9 +43,11 @@ bool CreateCoreLicenseResponse(const ODK_ParsedLicense& parsed_lic,
|
||||
*
|
||||
* Parameters:
|
||||
* [in] core_request
|
||||
* [in] renewal_duration_seconds
|
||||
* [out] oemcrypto_core_message
|
||||
*/
|
||||
bool CreateCoreRenewalResponse(const ODK_RenewalRequest& core_request,
|
||||
uint64_t renewal_duration_seconds,
|
||||
std::string* oemcrypto_core_message);
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,13 +30,16 @@ namespace serialize {
|
||||
*
|
||||
* Parameters:
|
||||
* [in] serialized_license
|
||||
* serialized video_widevine::License
|
||||
* [in] core_request
|
||||
* [out] oemcrypto_core_message
|
||||
serialized video_widevine::License
|
||||
* [in] core_request oemcrypto core message from request.
|
||||
* [in] core_request_sha256 - hash of serialized core request.
|
||||
* [in] nonce_required - if the device should require a nonce match.
|
||||
* [out] oemcrypto_core_message - the serialized oemcrypto core response.
|
||||
*/
|
||||
bool CreateCoreLicenseResponseFromProto(const std::string& serialized_license,
|
||||
const ODK_LicenseRequest& core_request,
|
||||
const std::string& core_request_sha256,
|
||||
const bool nonce_required,
|
||||
std::string* oemcrypto_core_message);
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,7 +64,8 @@ namespace oemcrypto_core_message {
|
||||
* Input structure for CreateCoreLicenseResponse
|
||||
*/
|
||||
struct ODK_LicenseRequest {
|
||||
uint32_t api_version;
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
};
|
||||
@@ -74,7 +75,8 @@ struct ODK_LicenseRequest {
|
||||
* Input structure for CreateCoreRenewalResponse
|
||||
*/
|
||||
struct ODK_RenewalRequest {
|
||||
uint32_t api_version;
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
uint64_t playback_time_seconds;
|
||||
@@ -85,7 +87,8 @@ struct ODK_RenewalRequest {
|
||||
* Input structure for CreateCoreProvisioningResponse
|
||||
*/
|
||||
struct ODK_ProvisioningRequest {
|
||||
uint32_t api_version;
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
std::string device_id;
|
||||
|
||||
@@ -65,7 +65,7 @@ extern "C" {
|
||||
* [out] timer_limits: the session's timer limits.
|
||||
* [out] clock_values: the session's clock values.
|
||||
* [out] nonce_values: the session's ODK nonce values.
|
||||
* [in] api_version: the API version of OEMCrypto.
|
||||
* [in] api_major_version: the API version of OEMCrypto.
|
||||
* [in] session_id: the session id of the newly created session.
|
||||
*
|
||||
* Returns:
|
||||
@@ -78,7 +78,7 @@ extern "C" {
|
||||
OEMCryptoResult ODK_InitializeSessionValues(ODK_TimerLimits* timer_limits,
|
||||
ODK_ClockValues* clock_values,
|
||||
ODK_NonceValues* nonce_values,
|
||||
uint32_t api_version,
|
||||
uint32_t api_major_version,
|
||||
uint32_t session_id);
|
||||
|
||||
/*
|
||||
@@ -127,7 +127,9 @@ OEMCryptoResult ODK_InitializeClockValues(ODK_ClockValues* clock_values,
|
||||
*
|
||||
* Description:
|
||||
* This function sets the values in the clock_values structure. It shall be
|
||||
* called from OEMCrypto_LoadUsageEntry.
|
||||
* called from OEMCrypto_LoadUsageEntry. When a usage entry from a v15 or
|
||||
* earlier license is loaded, the value time_of_license_loaded shall be used
|
||||
* in place of time_of_license_signed.
|
||||
*
|
||||
* Parameters:
|
||||
* [in/out] clock_values: the session's clock data.
|
||||
@@ -231,7 +233,7 @@ OEMCryptoResult ODK_UpdateLastPlaybackTime(uint64_t system_time_seconds,
|
||||
*
|
||||
* Description:
|
||||
* This function modifies the session's clock values to indicate that the
|
||||
* license has been deactiviated. It shall be called from
|
||||
* license has been deactivated. It shall be called from
|
||||
* OEMCrypto_DeactivateUsageEntry
|
||||
*
|
||||
* Parameters:
|
||||
@@ -256,8 +258,8 @@ OEMCryptoResult ODK_DeactivateUsageEntry(ODK_ClockValues* clock_values);
|
||||
*
|
||||
* This shall be called by OEMCrypto from OEMCrypto_PrepAndSignLicenseRequest.
|
||||
*
|
||||
* NOTE: if message pointer is null and/or input core_message_size is zero,
|
||||
* this function returns OEMCrypto_ERROR_SHORT_BUFFER and sets output
|
||||
* NOTE: if the message pointer is null and/or input core_message_size is
|
||||
* zero, this function returns OEMCrypto_ERROR_SHORT_BUFFER and sets output
|
||||
* core_message_size to the size needed.
|
||||
*
|
||||
* Parameters:
|
||||
@@ -271,7 +273,7 @@ OEMCryptoResult ODK_DeactivateUsageEntry(ODK_ClockValues* clock_values);
|
||||
*
|
||||
* Returns:
|
||||
* OEMCrypto_SUCCESS
|
||||
* OEMCrypto_ERROR_SHORT_BUFFER if core_message_size is too small
|
||||
* OEMCrypto_ERROR_SHORT_BUFFER: core_message_size is too small
|
||||
* OEMCrypto_ERROR_INVALID_CONTEXT
|
||||
*
|
||||
* Version:
|
||||
@@ -292,8 +294,14 @@ OEMCryptoResult ODK_PrepareCoreLicenseRequest(
|
||||
*
|
||||
* This shall be called by OEMCrypto from OEMCrypto_PrepAndSignRenewalRequest.
|
||||
*
|
||||
* NOTE: if message pointer is null and/or input core_message_size is zero,
|
||||
* this function returns OEMCrypto_ERROR_SHORT_BUFFER and sets output
|
||||
* If status in clock_values indicates that a license has not been loaded,
|
||||
* then this is a license release. The ODK library will change the value of
|
||||
* nonce_values.api_major_version to 15. This will make
|
||||
* OEMCrypto_PrepAndSignRenewalRequest sign just the message body, as it does
|
||||
* for all legacy licenses.
|
||||
*
|
||||
* NOTE: if the message pointer is null and/or input core_message_size is
|
||||
* zero, this function returns OEMCrypto_ERROR_SHORT_BUFFER and sets output
|
||||
* core_message_size to the size needed.
|
||||
*
|
||||
* Parameters:
|
||||
@@ -303,31 +311,33 @@ OEMCryptoResult ODK_PrepareCoreLicenseRequest(
|
||||
* [in/out] core_message_size: length of the core message at the beginning of
|
||||
* the message. (in) size of buffer reserved for the core message, in
|
||||
* bytes. (out) actual length of the core message, in bytes.
|
||||
* [in] nonce_values: pointer to the session's nonce data.
|
||||
* [in] clock_values: the session's clock values.
|
||||
* [in/out] nonce_values: pointer to the session's nonce data.
|
||||
* [in/out] clock_values: the session's clock values.
|
||||
* [in] system_time_seconds: the current time on OEMCrypto's clock, in
|
||||
* seconds.
|
||||
*
|
||||
* Returns:
|
||||
* OEMCrypto_SUCCESS
|
||||
* OEMCrypto_ERROR_SHORT_BUFFER if core_message_size is too small
|
||||
* OEMCrypto_ERROR_SHORT_BUFFER: core_message_size is too small
|
||||
* OEMCrypto_ERROR_INVALID_CONTEXT
|
||||
*
|
||||
* Version:
|
||||
* This method is new in version 16 of the API.
|
||||
*/
|
||||
OEMCryptoResult ODK_PrepareCoreRenewalRequest(
|
||||
uint8_t* message, size_t message_length, size_t* core_message_size,
|
||||
const ODK_NonceValues* nonce_values, ODK_ClockValues* clock_values,
|
||||
uint64_t system_time_seconds);
|
||||
OEMCryptoResult ODK_PrepareCoreRenewalRequest(uint8_t* message,
|
||||
size_t message_length,
|
||||
size_t* core_message_size,
|
||||
ODK_NonceValues* nonce_values,
|
||||
ODK_ClockValues* clock_values,
|
||||
uint64_t system_time_seconds);
|
||||
|
||||
/*
|
||||
* ODK_PrepareCoreProvisioningRequest
|
||||
*
|
||||
* Description:
|
||||
* Modifies the message to include a core provisioning request at the
|
||||
* beginning of the message buffer. The values in nonce_values, clock_values
|
||||
* and system_time_seconds are used to populate the message.
|
||||
* beginning of the message buffer. The values in nonce_values are used to
|
||||
* populate the message.
|
||||
*
|
||||
* This shall be called by OEMCrypto from
|
||||
* OEMCrypto_PrepAndSignProvisioningRequest.
|
||||
@@ -336,8 +346,8 @@ OEMCryptoResult ODK_PrepareCoreRenewalRequest(
|
||||
* OEMCrypto_GetDeviceID. The device ID shall be unique to the device, and
|
||||
* stable across reboots and factory resets for an L1 device.
|
||||
*
|
||||
* NOTE: if message pointer is null and/or input core_message_size is zero,
|
||||
* this function returns OEMCrypto_ERROR_SHORT_BUFFER and sets output
|
||||
* NOTE: if the message pointer is null and/or input core_message_size is
|
||||
* zero, this function returns OEMCrypto_ERROR_SHORT_BUFFER and sets output
|
||||
* core_message_size to the size needed.
|
||||
*
|
||||
* Parameters:
|
||||
@@ -356,7 +366,7 @@ OEMCryptoResult ODK_PrepareCoreRenewalRequest(
|
||||
*
|
||||
* Returns:
|
||||
* OEMCrypto_SUCCESS
|
||||
* OEMCrypto_ERROR_SHORT_BUFFER if core_message_size is too small
|
||||
* OEMCrypto_ERROR_SHORT_BUFFER: core_message_size is too small
|
||||
* OEMCrypto_ERROR_INVALID_CONTEXT
|
||||
*
|
||||
* Version:
|
||||
@@ -373,7 +383,7 @@ OEMCryptoResult ODK_PrepareCoreProvisioningRequest(
|
||||
* Description:
|
||||
* This function sets all limits in the timer_limits struct to the
|
||||
* key_duration and initializes the other values. The field
|
||||
* nonce_values.api_level will be set to 15. It shall be called from
|
||||
* nonce_values.api_major_version will be set to 15. It shall be called from
|
||||
* OEMCrypto_LoadKeys when loading a legacy license.
|
||||
*
|
||||
* Parameters:
|
||||
@@ -403,8 +413,12 @@ OEMCryptoResult ODK_InitializeV15Values(ODK_TimerLimits* timer_limits,
|
||||
* ODK_RefreshV15Values
|
||||
*
|
||||
* Description:
|
||||
* This function updates the clock_values as needed if the renewal is
|
||||
* accepted. The field nonce_values.api_level is verified to be 15.
|
||||
* This function updates the clock_values as needed if a v15 renewal is
|
||||
* accepted. The field nonce_values.api_major_version is verified to be 15.
|
||||
*
|
||||
* This is called from OEMCrypto_RefreshKeys for a valid license renewal.
|
||||
* OEMCrypto shall pass in the current system time, and the key duration from
|
||||
* the first object in the OEMCrypto_KeyRefreshObject.
|
||||
*
|
||||
* Parameters:
|
||||
* [in] timer_limits: The session's timer limits.
|
||||
@@ -412,6 +426,8 @@ OEMCryptoResult ODK_InitializeV15Values(ODK_TimerLimits* timer_limits,
|
||||
* [in] nonce_values: The session's ODK nonce values.
|
||||
* [in] system_time_seconds: The current time on the system clock, as
|
||||
* described in the document "License Duration and Renewal".
|
||||
* [in] new_key_duration: The duration from the first
|
||||
* OEMCrypto_KeyRefreshObject in key_array.
|
||||
* [out] timer_value: set to the new timer value. Only used if the return
|
||||
* value is ODK_SET_TIMER. This must be non-null if OEMCrypto uses a
|
||||
* hardware timer.
|
||||
@@ -432,27 +448,43 @@ OEMCryptoResult ODK_RefreshV15Values(const ODK_TimerLimits* timer_limits,
|
||||
ODK_ClockValues* clock_values,
|
||||
const ODK_NonceValues* nonce_values,
|
||||
uint64_t system_time_seconds,
|
||||
uint32_t new_key_duration,
|
||||
uint64_t* timer_value);
|
||||
|
||||
/*
|
||||
* ODK_ParseLicense
|
||||
*
|
||||
* Description:
|
||||
* The function ODK_ParseLicense will parse the message and verify
|
||||
*
|
||||
* 1. Either the nonce matches the one passed in or the license does not
|
||||
* require a nonce.
|
||||
* 2. The API version of the message matches.
|
||||
* 3. The session id matches.
|
||||
* The function ODK_ParseLicense will parse the message and set each
|
||||
* substring pointer to point to a location in the message body. The message
|
||||
* body is the buffer starting at message + core_message_length with size
|
||||
* message_length - core_message_length.
|
||||
* The function ODK_ParseLicense will parse the message and verify fields in
|
||||
* the message.
|
||||
*
|
||||
* If the message does not parse correctly, ODK_VerifyAndParseLicense will
|
||||
* return ODK_ERROR_CORE_MESSAGE that OEMCrypto should return to the CDM
|
||||
* layer above. If the api in the message is larger than 16, then
|
||||
* ODK_UNSUPPORTED_API is returned.
|
||||
* layer above.
|
||||
*
|
||||
* If the API in the message is not 16, then ODK_UNSUPPORTED_API is returned.
|
||||
*
|
||||
* If initial_license_load is true, and nonce_required in the license is
|
||||
* true, then the ODK library shall verify that nonce_values->nonce and
|
||||
* nonce_values->session_id are the same as those in the message. If
|
||||
* verification fails, then it shall return OEMCrypto_ERROR_INVALID_NONCE.
|
||||
*
|
||||
* If initial_license_load is false, and nonce_required is true, then
|
||||
* ODK_ParseLicense will set the values in nonce_values from those in the
|
||||
* message.
|
||||
*
|
||||
* The function ODK_ParseLicense will verify that each substring points to a
|
||||
* location in the message body. The message body is the buffer starting at
|
||||
* message + core_message_length with size message_length -
|
||||
* core_message_length.
|
||||
*
|
||||
* If initial_license_load is true, then ODK_ParseLicense shall verify that
|
||||
* the parameter request_hash matches request_hash in the parsed license. If
|
||||
* verification fails, then it shall return ODK_ERROR_CORE_MESSAGE. This was
|
||||
* computed by OEMCrypto when the license was requested.
|
||||
*
|
||||
* If usage_entry_present is true, then ODK_ParseLicense shall verify that
|
||||
* the pst in the license has a nonzero length.
|
||||
*
|
||||
* Parameters:
|
||||
* [in] message: pointer to the message buffer.
|
||||
@@ -463,6 +495,8 @@ OEMCryptoResult ODK_RefreshV15Values(const ODK_TimerLimits* timer_limits,
|
||||
* false when called for OEMCrypto_ReloadLicense.
|
||||
* [in] usage_entry_present: true if the session has a new usage entry
|
||||
* associated with it created via OEMCrypto_CreateNewUsageEntry.
|
||||
* [in] request_hash: the hash of the license request core message. This was
|
||||
* computed by OEMCrypto when the license request was signed.
|
||||
* [in/out] timer_limits: The session's timer limits. These will be updated.
|
||||
* [in/out] clock_values: The session's clock values. These will be updated.
|
||||
* [in/out] nonce_values: The session's nonce values. These will be updated.
|
||||
@@ -470,7 +504,7 @@ OEMCryptoResult ODK_RefreshV15Values(const ODK_TimerLimits* timer_limits,
|
||||
*
|
||||
* Returns:
|
||||
* OEMCrypto_SUCCESS
|
||||
* ODK_ERROR_CORE_MESSAGE if the message did not parse correctly, or there
|
||||
* ODK_ERROR_CORE_MESSAGE: if the message did not parse correctly, or there
|
||||
* were other incorrect values. An error should be returned to the CDM
|
||||
* layer.
|
||||
* ODK_UNSUPPORTED_API
|
||||
@@ -490,9 +524,12 @@ OEMCryptoResult ODK_ParseLicense(
|
||||
* ODK_ParseRenewal
|
||||
*
|
||||
* Description:
|
||||
* The function ODK_ParseRenewal will parse the message and verify that the
|
||||
* nonce values match those in the license. If the message does not parse
|
||||
* correctly, an error of ODK_ERROR_CORE_MESSAGE is returned.
|
||||
* The function ODK_ParseRenewal will parse the message and verify its
|
||||
* contents. If the message does not parse correctly, an error of
|
||||
* ODK_ERROR_CORE_MESSAGE is returned.
|
||||
*
|
||||
* ODK_ParseRenewal shall verify that all fields in nonce_values match those
|
||||
* in the license. Otherwise it shall return OEMCrypto_ERROR_INVALID_NONCE.
|
||||
*
|
||||
* After parsing the message, this function updates the clock_values based on
|
||||
* the timer_limits and the current system time. If playback may not
|
||||
@@ -504,8 +541,8 @@ OEMCryptoResult ODK_ParseLicense(
|
||||
* ODK_DISABLE_TIMER, then playback time is not limited.
|
||||
*
|
||||
* If OEMCrypto uses a hardware timer, and this function returns
|
||||
* ODK_SET_TIMER, then the timer should be set to the value pointed to by
|
||||
* timer_value.
|
||||
* ODK_SET_TIMER, then OEMCrypto shall set the timer to the value pointed to
|
||||
* by timer_value.
|
||||
*
|
||||
* Parameters:
|
||||
* [in] message: pointer to the message buffer.
|
||||
@@ -522,15 +559,16 @@ OEMCryptoResult ODK_ParseLicense(
|
||||
* hardware timer.
|
||||
*
|
||||
* Returns:
|
||||
* ODK_ERROR_CORE_MESSAGE if the message did not parse correctly, or there
|
||||
* were other incorrect values. An error should be returned to the CDM
|
||||
* layer.
|
||||
* ODK_ERROR_CORE_MESSAGE: the message did not parse correctly, or there were
|
||||
* other incorrect values. An error should be returned to the CDM layer.
|
||||
* ODK_SET_TIMER: Success. The timer should be reset to the specified timer
|
||||
* value.
|
||||
* ODK_DISABLE_TIMER: Success, but disable timer. Unlimited playback is
|
||||
* allowed.
|
||||
* ODK_TIMER_EXPIRED: Set timer as disabled. Playback is not allowed.
|
||||
* ODK_UNSUPPORTED_API
|
||||
* ODK_STALE_RENEWAL: This renewal is not the most recently signed. It is
|
||||
* rejected.
|
||||
* OEMCrypto_ERROR_INVALID_NONCE
|
||||
*
|
||||
* Version:
|
||||
@@ -551,14 +589,21 @@ OEMCryptoResult ODK_ParseRenewal(const uint8_t* message, size_t message_length,
|
||||
* The function ODK_ParseProvisioning will parse the message and verify the
|
||||
* nonce values match those in the license.
|
||||
*
|
||||
* The function ODK_ParseProvisioning will parse the message and set each
|
||||
* substring pointer to point to a location in the message body. The message
|
||||
* body is the buffer starting at message + core_message_length with size
|
||||
* message_length - core_message_length.
|
||||
*
|
||||
* If the message does not parse correctly, ODK_ParseProvisioning will return
|
||||
* an error that OEMCrypto should return to the CDM layer above.
|
||||
*
|
||||
* If the API in the message is larger than 16, then ODK_UNSUPPORTED_API is
|
||||
* returned.
|
||||
*
|
||||
* ODK_ParseProvisioning shall verify that nonce_values->nonce and
|
||||
* nonce_values->session_id are the same as those in the message. Otherwise
|
||||
* it shall return OEMCrypto_ERROR_INVALID_NONCE.
|
||||
*
|
||||
* The function ODK_ParseProvisioning will verify that each substring points
|
||||
* to a location in the message body. The message body is the buffer starting
|
||||
* at message + core_message_length with size message_length -
|
||||
* core_message_length.
|
||||
*
|
||||
* Parameters:
|
||||
* [in] message: pointer to the message buffer.
|
||||
* [in] message_length: length of the entire message buffer.
|
||||
@@ -572,9 +617,8 @@ OEMCryptoResult ODK_ParseRenewal(const uint8_t* message, size_t message_length,
|
||||
*
|
||||
* Returns:
|
||||
* OEMCrypto_SUCCESS
|
||||
* ODK_ERROR_CORE_MESSAGE if the message did not parse correctly, or there
|
||||
* were other incorrect values. An error should be returned to the CDM
|
||||
* layer.
|
||||
* ODK_ERROR_CORE_MESSAGE: the message did not parse correctly, or there were
|
||||
* other incorrect values. An error should be returned to the CDM layer.
|
||||
* ODK_UNSUPPORTED_API
|
||||
* OEMCrypto_ERROR_INVALID_NONCE
|
||||
*
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
* source code may only be used and distributed under the Widevine Master
|
||||
* License Agreement.
|
||||
*/
|
||||
|
||||
#ifndef ODK_ASSERT_H_
|
||||
#define ODK_ASSERT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if (__STDC_VERSION__ >= 201112L)
|
||||
# include <assert.h>
|
||||
# define odk_static_assert static_assert
|
||||
#else
|
||||
# define odk_static_assert(msg, e) \
|
||||
enum { odk_static_assert = 1 / (!!((msg) && (e))) };
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ODK_ASSERT_H_ */
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
* source code may only be used and distributed under the Widevine Master
|
||||
* License Agreement.
|
||||
*/
|
||||
|
||||
#ifndef ODK_OVERFLOW_H_
|
||||
#define ODK_OVERFLOW_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef __has_builtin
|
||||
# define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
#if (defined(__GNUC__) && __GNUC__ >= 5) || \
|
||||
__has_builtin(__builtin_add_overflow)
|
||||
# define odk_sub_overflow_u64 __builtin_sub_overflow
|
||||
# define odk_add_overflow_u64 __builtin_add_overflow
|
||||
# define odk_add_overflow_ux __builtin_add_overflow
|
||||
#else
|
||||
int odk_sub_overflow_u64(uint64_t a, uint64_t b, uint64_t* c);
|
||||
int odk_add_overflow_u64(uint64_t a, uint64_t b, uint64_t* c);
|
||||
int odk_add_overflow_ux(size_t a, size_t b, size_t* c);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ODK_OVERFLOW_H_ */
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
* source code may only be used and distributed under the Widevine Master
|
||||
* License Agreement.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is auto-generated, do not edit
|
||||
*/
|
||||
#ifndef ODKITEE_SERIALIZER_H_
|
||||
#define ODKITEE_SERIALIZER_H_
|
||||
|
||||
#include "odk_structs_priv.h"
|
||||
#include "serialization_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* odk pack */
|
||||
void Pack_ODK_PreparedLicense(Message* msg, ODK_PreparedLicense const* obj);
|
||||
void Pack_ODK_RenewalMessage(Message* msg, ODK_RenewalMessage const* obj);
|
||||
void Pack_ODK_ProvisioningMessage(Message* msg,
|
||||
ODK_ProvisioningMessage const* obj);
|
||||
|
||||
/* odk unpack */
|
||||
void Unpack_ODK_LicenseResponse(Message* msg, ODK_LicenseResponse* obj);
|
||||
void Unpack_ODK_RenewalMessage(Message* msg, ODK_RenewalMessage* obj);
|
||||
void Unpack_ODK_ProvisioningResponse(Message* msg,
|
||||
ODK_ProvisioningResponse* obj);
|
||||
|
||||
/* kdo pack */
|
||||
void Pack_ODK_LicenseResponse(Message* msg, ODK_LicenseResponse const* obj);
|
||||
void Pack_ODK_ProvisioningResponse(Message* msg,
|
||||
ODK_ProvisioningResponse const* obj);
|
||||
|
||||
/* kdo unpack */
|
||||
void Unpack_ODK_PreparedLicense(Message* msg, ODK_PreparedLicense* obj);
|
||||
void Unpack_ODK_ProvisioningMessage(Message* msg, ODK_ProvisioningMessage* obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
#endif /* ODKITEE_SERIALIZER_H_ */
|
||||
@@ -8,63 +8,103 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "OEMCryptoCENCCommon.h"
|
||||
#include "odk_target.h"
|
||||
|
||||
#define ODK_MAX_NUM_KEYS 32
|
||||
/* The version of this library. */
|
||||
#define ODK_MAJOR_VERSION 16
|
||||
#define ODK_MINOR_VERSION 2
|
||||
|
||||
/* Some useful constants. */
|
||||
#define ODK_DEVICE_ID_LEN_MAX 64
|
||||
#define ODK_SHA256_HASH_SIZE 32
|
||||
|
||||
/*
|
||||
* ODK_TimerLimits is filled out by the function ODK_ParseLicense.
|
||||
* ODK_TimerLimits Structure
|
||||
*
|
||||
* The fields in this structure are defined in the core license response
|
||||
* message. This structure should be kept as part of the session and used
|
||||
* when calling the ODK timer functions described in the document "License
|
||||
* Duration and Renewal" distributed as part of the OEMCrypto v16 design.
|
||||
* Description:
|
||||
* Timer limits are specified in a license and are used to determine when
|
||||
* playback is allowed. See the document "License Duration and Renewal" for a
|
||||
* discussion on the time restrictions that may be placed on a license. The
|
||||
* fields in this structure are directly related to the fields in the core
|
||||
* license message. The fields are set when OEMCrypto calls the function
|
||||
* ODK_ParseLicense or ODK_InitializeV15Values.
|
||||
*
|
||||
* Fields:
|
||||
* soft_enforce_rental_duration: A boolean controlling the soft or hard
|
||||
* enforcement of rental duration.
|
||||
* soft_enforce_playback_duration: A boolean controlling the soft or hard
|
||||
* enforcement of playback duration.
|
||||
* earliest_playback_start_seconds: The earliest time that the first playback
|
||||
* is allowed. Measured in seconds since the license request was signed. For
|
||||
* most use cases, this is zero.
|
||||
* rental_duration_seconds: Window of time for the allowed first playback.
|
||||
* Measured in seconds since the earliest playback start. If
|
||||
* soft_enforce_rental_duration is true, this applies only to the first
|
||||
* playback. If soft_enforce_rental_duration is false, then this restricts
|
||||
* any playback. A value of zero means no limit.
|
||||
* total_playback_duration_seconds: Window of time for allowed playback.
|
||||
* Measured in seconds since the first playback start. If
|
||||
* soft_enforce_playback_duration is true, this applies only to the start of
|
||||
* playback for any session. If soft_enforce_playback_duration is false, then
|
||||
* this restricts any playback. A value of zero means no limit.
|
||||
* initial_renewal_duration_seconds: Window of time for allowed playback.
|
||||
* Measured in seconds since the first playback start. This value is only
|
||||
* used to start the renewal timer. After a renewal message is loaded, the
|
||||
* timer will be reset. A value of zero means no limit.
|
||||
*
|
||||
* Version:
|
||||
* This struct changed in API version 16.2.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t /*boolean*/ soft_expiry;
|
||||
uint64_t earliest_playback_start_seconds; /* since license signed. */
|
||||
uint64_t latest_playback_start_seconds; /* since license signed. */
|
||||
uint64_t initial_playback_duration_seconds; /* since playback start. */
|
||||
uint64_t renewal_playback_duration_seconds; /* since renewal signed. */
|
||||
uint64_t license_duration_seconds; /* since license signed. */
|
||||
bool soft_enforce_rental_duration;
|
||||
bool soft_enforce_playback_duration;
|
||||
uint64_t earliest_playback_start_seconds;
|
||||
uint64_t rental_duration_seconds;
|
||||
uint64_t total_playback_duration_seconds;
|
||||
uint64_t initial_renewal_duration_seconds;
|
||||
} ODK_TimerLimits;
|
||||
|
||||
/*
|
||||
* ODK_ParsedLicense holds fields from the core license response.
|
||||
*/
|
||||
typedef struct {
|
||||
OEMCrypto_Substring enc_mac_keys_iv;
|
||||
OEMCrypto_Substring enc_mac_keys;
|
||||
OEMCrypto_Substring pst;
|
||||
OEMCrypto_Substring srm_restriction_data;
|
||||
uint32_t /* OEMCrypto_LicenseType */ license_type;
|
||||
uint32_t nonce_required;
|
||||
ODK_TimerLimits timer_limits;
|
||||
uint8_t request_hash[ODK_SHA256_HASH_SIZE];
|
||||
uint32_t key_array_length; /* num_keys */
|
||||
OEMCrypto_KeyObject key_array[ODK_MAX_NUM_KEYS];
|
||||
} ODK_ParsedLicense;
|
||||
|
||||
/*
|
||||
* ODK_ParsedProvisioning holds fields from the core provisioning response.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t key_type;
|
||||
OEMCrypto_Substring enc_private_key;
|
||||
OEMCrypto_Substring enc_private_key_iv;
|
||||
OEMCrypto_Substring encrypted_message_key; /* Used for Prov 3.0 */
|
||||
} ODK_ParsedProvisioning;
|
||||
|
||||
/*
|
||||
* ODK_ClockValues keeps information about a session's current clock values
|
||||
* and timers.
|
||||
* ODK_ClockValues Structure
|
||||
*
|
||||
* Most of the fields in this structure are saved in the usage entry for each
|
||||
* session. This structure should be initialized when a usage entry is
|
||||
* created or loaded, and should be used to save a usage entry. It is
|
||||
* updated using ODK functions listed in the document "License Duration and
|
||||
* Renewal". The time values are based on OEMCrypto’s system clock.
|
||||
* Description:
|
||||
* Clock values are modified when decryption occurs or when a renewal is
|
||||
* processed. They are used to track the current status of the license --
|
||||
* i.e. has playback started? When does the timer expire? See the section
|
||||
* "Complete ODK API" of the document "Widevine Core Message Serialization"
|
||||
* for a complete list of all fields in this structure. Most of these values
|
||||
* shall be saved with the usage entry.
|
||||
*
|
||||
* All times are in seconds. Most of the fields in this structure are saved
|
||||
* in the usage entry. This structure should be initialized when a usage
|
||||
* entry is created or loaded, and should be used to save a usage entry. It
|
||||
* is updated using the ODK functions listed below. The time values are based
|
||||
* on OEMCrypto's system clock, as described in the document "License
|
||||
* Duration and Renewal".
|
||||
*
|
||||
* Fields:
|
||||
* time_of_license_signed: Time that the license request was signed, based on
|
||||
* OEMCrypto's system clock. This value shall be stored and reloaded with
|
||||
* usage entry as time_of_license_received.
|
||||
* time_of_first_decrypt: Time of the first decrypt or call select key, based
|
||||
* on OEMCrypto's system clock. This is 0 if the license has not been used to
|
||||
* decrypt any data. This value shall be stored and reloaded with usage entry.
|
||||
* time_of_last_decrypt: Time of the most recent decrypt call, based on
|
||||
* OEMCrypto's system clock. This value shall be stored and reloaded with
|
||||
* usage entry.
|
||||
* time_of_renewal_request: Time of the most recent renewal request, based on
|
||||
* OEMCrypto's system clock. This is used to verify that a renewal is not
|
||||
* stale.
|
||||
* time_when_timer_expires: Time that the current timer expires, based on
|
||||
* OEMCrypto's system clock. If the timer is active, this is used by the ODK
|
||||
* library to determine if it has expired.
|
||||
* timer_status: Used internally by the ODK library to indicate the current
|
||||
* timer status.
|
||||
* status: The license or usage entry status. This value shall be stored and
|
||||
* reloaded with usage entry.
|
||||
*
|
||||
* Version:
|
||||
* This struct changed in API version 16.2.
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t time_of_license_signed;
|
||||
@@ -77,20 +117,99 @@ typedef struct {
|
||||
} ODK_ClockValues;
|
||||
|
||||
/*
|
||||
* ODK_NonceValues are used to match a license or provisioning request to a
|
||||
* license or provisioning response. For this reason, the api_version might be
|
||||
* lower than that supported by OEMCrypto. The api_version matches the version
|
||||
* of the license. Similarly the nonce and session_id match the session that
|
||||
* generated the license request. For an offline license, these might not match
|
||||
* the session that is loading the license. We use the nonce to prevent a
|
||||
* license from being replayed. By also including a session_id in the license
|
||||
* request and license response, we prevent an attack using the birthday paradox
|
||||
* to generate nonce collisions on a single device.
|
||||
* ODK_NonceValues Structure
|
||||
*
|
||||
* Description:
|
||||
* Nonce values are used to match a license or provisioning request to a
|
||||
* license or provisioning response. They are also used to match a renewal
|
||||
* request and response to a license. For this reason, the api_version might
|
||||
* be lower than that supported by OEMCrypto. The api_version matches the
|
||||
* version of the license. Similarly the nonce and session_id match the
|
||||
* session that generated the license request. For an offline license, these
|
||||
* might not match the session that is loading the license. We use the nonce
|
||||
* to prevent a license from being replayed. By also including a session_id
|
||||
* in the license request and license response, we prevent an attack using
|
||||
* the birthday paradox to generate nonce collisions on a single device.
|
||||
*
|
||||
* Fields:
|
||||
* api_major_version: the API version of the license. This is initialized to
|
||||
* the API version of the ODK library, but may be lower.
|
||||
* api_minor_version: the minor version of the ODK library. This is used by
|
||||
* the server to verify that device is not using an obsolete version of the
|
||||
* ODK library.
|
||||
* nonce: a randomly generated number used to prevent replay attacks.
|
||||
* session_id: the session id of the session which signed the license or
|
||||
* provisioning request. It is used to prevent replay attacks from one
|
||||
* session to another.
|
||||
*
|
||||
* Version:
|
||||
* This struct changed in API version 16.2.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t api_version;
|
||||
uint16_t api_minor_version;
|
||||
uint16_t api_major_version;
|
||||
uint32_t nonce;
|
||||
uint32_t session_id;
|
||||
} ODK_NonceValues;
|
||||
|
||||
/*
|
||||
* ODK_ParsedLicense Structure
|
||||
*
|
||||
* Description:
|
||||
* The parsed license structure contains information from the license
|
||||
* message. The function ODK_ParseLicense will fill in the fields of this
|
||||
* message. All substrings are contained within the message body.
|
||||
*
|
||||
* Fields:
|
||||
* enc_mac_keys_iv: IV for decrypting new mac_key. Size is 128 bits.
|
||||
* enc_mac_keys: encrypted mac_keys for generating new mac_keys. Size is 512
|
||||
* bits.
|
||||
* pst: the Provider Session Token.
|
||||
* srm_restriction_data: optional data specifying the minimum SRM version.
|
||||
* license_type: specifies if the license contains content keys or
|
||||
* entitlement keys.
|
||||
* nonce_required: indicates if the license requires a nonce.
|
||||
* timer_limits: time limits of the for the license.
|
||||
* key_array_length: number of keys present.
|
||||
* key_array: set of keys to be installed.
|
||||
*
|
||||
* Version:
|
||||
* This struct changed in API version 16.2.
|
||||
*/
|
||||
typedef struct {
|
||||
OEMCrypto_Substring enc_mac_keys_iv;
|
||||
OEMCrypto_Substring enc_mac_keys;
|
||||
OEMCrypto_Substring pst;
|
||||
OEMCrypto_Substring srm_restriction_data;
|
||||
OEMCrypto_LicenseType license_type;
|
||||
bool nonce_required;
|
||||
ODK_TimerLimits timer_limits;
|
||||
uint32_t key_array_length;
|
||||
OEMCrypto_KeyObject key_array[ODK_MAX_NUM_KEYS];
|
||||
} ODK_ParsedLicense;
|
||||
|
||||
/*
|
||||
* ODK_ParsedProvisioning Structure
|
||||
*
|
||||
* Description:
|
||||
* The parsed provisioning structure contains information from the license
|
||||
* message. The function ODK_ParseProvisioning will fill in the fields of
|
||||
* this message. All substrings are contained within the message body.
|
||||
*
|
||||
* Fields:
|
||||
* key_type: indicates if this key is an RSA or ECC private key.
|
||||
* enc_private_key: encrypted private key for the DRM certificate.
|
||||
* enc_private_key_iv: IV for decrypting new private key. Size is 128 bits.
|
||||
* encrypted_message_key: used for provisioning 3.0 to derive keys.
|
||||
*
|
||||
* Version:
|
||||
* This struct changed in API version 16.2.
|
||||
*/
|
||||
typedef struct {
|
||||
OEMCrypto_PrivateKeyType key_type;
|
||||
OEMCrypto_Substring enc_private_key;
|
||||
OEMCrypto_Substring enc_private_key_iv;
|
||||
OEMCrypto_Substring encrypted_message_key; /* Used for Prov 3.0 */
|
||||
} ODK_ParsedProvisioning;
|
||||
|
||||
#endif /* WIDEVINE_ODK_INCLUDE_ODK_STRUCTS_H_ */
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
* source code may only be used and distributed under the Widevine Master
|
||||
* License Agreement.
|
||||
*/
|
||||
|
||||
#ifndef ODK_STRUCTS_PRIV_H_
|
||||
#define ODK_STRUCTS_PRIV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "OEMCryptoCENCCommon.h"
|
||||
#include "odk_structs.h"
|
||||
|
||||
typedef enum {
|
||||
ODK_License_Request_Type = 1,
|
||||
ODK_License_Response_Type = 2,
|
||||
ODK_Renewal_Request_Type = 3,
|
||||
ODK_Renewal_Response_Type = 4,
|
||||
ODK_Provisioning_Request_Type = 5,
|
||||
ODK_Provisioning_Response_Type = 6,
|
||||
} ODK_MessageType;
|
||||
|
||||
typedef struct {
|
||||
uint32_t message_type;
|
||||
uint32_t message_length;
|
||||
ODK_NonceValues nonce_values;
|
||||
} ODK_CoreMessage;
|
||||
|
||||
typedef struct {
|
||||
ODK_CoreMessage core_message;
|
||||
} ODK_PreparedLicense;
|
||||
|
||||
typedef struct {
|
||||
ODK_CoreMessage core_message;
|
||||
uint64_t playback_time;
|
||||
} ODK_RenewalMessage;
|
||||
|
||||
typedef struct {
|
||||
ODK_CoreMessage core_message;
|
||||
uint32_t device_id_length;
|
||||
uint8_t device_id[ODK_DEVICE_ID_LEN_MAX];
|
||||
} ODK_ProvisioningMessage;
|
||||
|
||||
typedef struct {
|
||||
ODK_CoreMessage core_message;
|
||||
ODK_ParsedLicense* parsed_license;
|
||||
} ODK_LicenseResponse;
|
||||
|
||||
typedef struct {
|
||||
ODK_ProvisioningMessage core_provisioning;
|
||||
ODK_ParsedProvisioning* parsed_provisioning;
|
||||
} ODK_ProvisioningResponse;
|
||||
|
||||
#endif // ODK_STRUCTS_PRIV_H_
|
||||
13
libwvdrmengine/oemcrypto/odk/include/odk_target.h
Normal file
13
libwvdrmengine/oemcrypto/odk/include/odk_target.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/* Copyright 2019 Google LLC. All rights reserved. This file is distributed */
|
||||
/* under the Widevine Master License Agreement. */
|
||||
|
||||
/* Partners are expected to edit this file to support target specific code */
|
||||
/* and limits. */
|
||||
|
||||
#ifndef WIDEVINE_ODK_INCLUDE_ODK_TARGET_H_
|
||||
#define WIDEVINE_ODK_INCLUDE_ODK_TARGET_H_
|
||||
|
||||
/* Maximum number of keys can be modified to suit target's resource tier. */
|
||||
#define ODK_MAX_NUM_KEYS 32
|
||||
|
||||
#endif /* WIDEVINE_ODK_INCLUDE_ODK_TARGET_H_ */
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
* source code may only be used and distributed under the Widevine Master
|
||||
* License Agreement.
|
||||
*/
|
||||
|
||||
#ifndef ODKITEE_SERIALIZATION_BASE_H_
|
||||
#define ODKITEE_SERIALIZATION_BASE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "OEMCryptoCENCCommon.h"
|
||||
|
||||
#define SIZE_OF_MESSAGE_STRUCT 64
|
||||
|
||||
/*
|
||||
* Description:
|
||||
* Point |msg| to stack-array |blk|.
|
||||
* |blk| is guaranteed large enough to hold a |Message| struct.
|
||||
* |blk| cannot be used in the same scope as a variable name.
|
||||
* |msg| points to valid memory in the same scope |AllocateMessage| is used.
|
||||
* Parameters:
|
||||
* msg: pointer to pointer to |Message| struct
|
||||
* blk: variable name for stack-array
|
||||
*/
|
||||
#define AllocateMessage(msg, blk) \
|
||||
uint8_t blk[SIZE_OF_MESSAGE_STRUCT]; \
|
||||
*(msg) = (Message*)(blk);
|
||||
|
||||
typedef struct _Message Message;
|
||||
|
||||
bool ValidMessage(Message* message);
|
||||
|
||||
void Pack_uint32_t(Message* message, const uint32_t* value);
|
||||
void Pack_uint64_t(Message* message, const uint64_t* value);
|
||||
void PackArray(Message* message, const uint8_t* base, size_t size);
|
||||
void Pack_OEMCrypto_Substring(Message* msg, const OEMCrypto_Substring* obj);
|
||||
|
||||
void Unpack_uint32_t(Message* message, uint32_t* value);
|
||||
void Unpack_uint64_t(Message* message, uint64_t* value);
|
||||
void UnpackArray(Message* message, uint8_t* base, size_t size); /* copy out */
|
||||
void Unpack_OEMCrypto_Substring(Message* msg, OEMCrypto_Substring* obj);
|
||||
|
||||
typedef enum {
|
||||
MESSAGE_STATUS_OK,
|
||||
MESSAGE_STATUS_UNKNOWN_ERROR,
|
||||
MESSAGE_STATUS_OVERFLOW_ERROR,
|
||||
MESSAGE_STATUS_UNDERFLOW_ERROR,
|
||||
MESSAGE_STATUS_PARSE_ERROR,
|
||||
MESSAGE_STATUS_NULL_POINTER_ERROR,
|
||||
MESSAGE_STATUS_API_VALUE_ERROR
|
||||
} MessageStatus;
|
||||
|
||||
/*
|
||||
* Create a message from a buffer. The message structure consumes the first
|
||||
* sizeof(Message) bytes of the buffer. The caller is responsible for ensuring
|
||||
* that the buffer remains allocated for the lifetime of the message.
|
||||
*/
|
||||
Message* CreateMessage(uint8_t* buffer, size_t buffer_size);
|
||||
|
||||
/*
|
||||
* Initialize a message structure to reference a separate buffer. The caller
|
||||
* is responsible for ensuring that the buffer remains allocated for the
|
||||
* lifetime of the message.
|
||||
*/
|
||||
void InitMessage(Message* message, uint8_t* buffer, size_t capacity);
|
||||
|
||||
/*
|
||||
* Reset an existing the message to an empty state
|
||||
*/
|
||||
void ResetMessage(Message* message);
|
||||
uint8_t* GetBase(Message* message);
|
||||
size_t GetCapacity(Message* message);
|
||||
size_t GetSize(Message* message);
|
||||
void SetSize(Message* message, size_t size);
|
||||
MessageStatus GetStatus(Message* message);
|
||||
void SetStatus(Message* message, MessageStatus status);
|
||||
size_t GetOffset(Message* message);
|
||||
|
||||
size_t SizeOfMessageStruct();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // ODKITEE_SERIALIZATION_BASE_H_
|
||||
Reference in New Issue
Block a user