From 0947bd185bd9da6cffd937505ec24cbb52310677 Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Wed, 26 Feb 2020 13:14:20 -0800 Subject: [PATCH] Fix nonce problem in license renewal Merge from Widevine repo of http://go/wvgerrit/94523 For OEMCrypto v16, a renewal does not get a new nonce. Bug: 149856581 Test: WvCdmRequestLicenseTest.StreamingLicenseRenewal Change-Id: I258f0bcb9c9a417310785f130d32d66fa7430185 --- libwvdrmengine/cdm/core/src/license.cpp | 34 +++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/libwvdrmengine/cdm/core/src/license.cpp b/libwvdrmengine/cdm/core/src/license.cpp index 9549f0cd..d8c8c4a9 100644 --- a/libwvdrmengine/cdm/core/src/license.cpp +++ b/libwvdrmengine/cdm/core/src/license.cpp @@ -457,19 +457,25 @@ CdmResponseType CdmLicense::PrepareKeyUpdateRequest( current_license->set_seconds_since_last_played(seconds_since_last_played); } - // Get/set the nonce. This value will be reflected in the Key Control Block - // of the license response. - uint32_t nonce; - CdmResponseType status = crypto_session_->GenerateNonce(&nonce); - - switch (status) { - case NO_ERROR: - break; - case SESSION_LOST_STATE_ERROR: - case SYSTEM_INVALIDATED_ERROR: - return status; - default: - return LICENSE_RENEWAL_NONCE_GENERATION_ERROR; + uint32_t api_version = 0; + if (!crypto_session_->GetApiVersion(&api_version)) { + LOGW("Unknown API Version"); + api_version = 15; + } + uint32_t nonce = 0; + if (api_version < 16) { + // For a pre-v16 license, get/set the nonce. This value will be reflected + // in the Key Control Block of the license response. + const CdmResponseType status = crypto_session_->GenerateNonce(&nonce); + switch (status) { + case NO_ERROR: + break; + case SESSION_LOST_STATE_ERROR: + case SYSTEM_INVALIDATED_ERROR: + return status; + default: + return LICENSE_RENEWAL_NONCE_GENERATION_ERROR; + } } license_request.set_key_control_nonce(nonce); LOGD("nonce = %u", nonce); @@ -482,7 +488,7 @@ CdmResponseType CdmLicense::PrepareKeyUpdateRequest( // Construct signature and core message. std::string core_message; std::string license_request_signature; - status = crypto_session_->PrepareAndSignRenewalRequest( + const CdmResponseType status = crypto_session_->PrepareAndSignRenewalRequest( serialized_license_req, &core_message, &license_request_signature); if (status != NO_ERROR) return status;