Resize OEMCrypto buffer-based results on success.
[ Merge of http://go/wvgerrit/151191 ] Within the CDM and OEMCrypto tests, there were a few OEMCrypto function calls where the final size of the output buffers were not being resized. For several of these functions, an initial call is made with zero-length output buffers, expecting OEMCrypto to return ERROR_SHORT_BUFFER; followed by a call with buffers at least as large as specified by OEMCrypto. However, for some operations, OEMCrypto makes an estimate on the final size on the first call, specifying the exact size only after performing the operations. This is the case for the wrapped key returned by OEMCrypto_LoadProvisioning(). The provisioning response contains a padded + encrypted DRM key. OEMCrypto does not know the actual size of the key until decrypted, and the actual DRM key might be smaller. There was a OEMCrypto test for OEMCrypto_BuildInformation() which was enforcing the wrong behaviour. This has been updated. Bug: 230661565 Test: oemcrypto_test Change-Id: Iad297d56ffbb085894641fdf8698ce5fd18edbf2
This commit is contained in:
@@ -237,6 +237,9 @@ RoundTrip<CoreRequest, PrepAndSignRequest, CoreResponse, ResponseData>::
|
||||
// We need to fill in core request and verify signature only for calls other
|
||||
// than OEMCryptoMemory buffer overflow test. Any test other than buffer
|
||||
// overflow will pass true.
|
||||
if (result == OEMCrypto_SUCCESS) {
|
||||
gen_signature.resize(gen_signature_length);
|
||||
}
|
||||
if (!verify_request || result != OEMCrypto_SUCCESS) return result;
|
||||
if (global_features.api_version >= kCoreMessagesAPI) {
|
||||
std::string core_message(reinterpret_cast<char*>(data.data()),
|
||||
@@ -466,11 +469,14 @@ OEMCryptoResult ProvisioningRoundTrip::LoadResponse(Session* session) {
|
||||
sizeof(response_data_));
|
||||
}
|
||||
size_t wrapped_key_length = 0;
|
||||
const OEMCryptoResult sts = LoadResponseNoRetry(session, &wrapped_key_length);
|
||||
OEMCryptoResult sts = LoadResponseNoRetry(session, &wrapped_key_length);
|
||||
if (sts != OEMCrypto_ERROR_SHORT_BUFFER) return sts;
|
||||
wrapped_rsa_key_.clear();
|
||||
wrapped_rsa_key_.assign(wrapped_key_length, 0);
|
||||
return LoadResponseNoRetry(session, &wrapped_key_length);
|
||||
sts = LoadResponseNoRetry(session, &wrapped_key_length);
|
||||
if (sts == OEMCrypto_SUCCESS) {
|
||||
wrapped_rsa_key_.resize(wrapped_key_length);
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
|
||||
#ifdef TEST_OEMCRYPTO_V15
|
||||
@@ -1589,6 +1595,7 @@ void Session::LoadOEMCert(bool verify_cert) {
|
||||
public_cert.resize(public_cert_length);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_GetOEMPublicCertificate(
|
||||
public_cert.data(), &public_cert_length));
|
||||
public_cert.resize(public_cert_length);
|
||||
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_LoadOEMPrivateKey(session_id()));
|
||||
|
||||
// The cert is a PKCS7 signed data type. First, parse it into an OpenSSL
|
||||
@@ -1871,6 +1878,8 @@ void Session::UpdateUsageEntry(std::vector<uint8_t>* header_buffer) {
|
||||
OEMCrypto_UpdateUsageEntry(
|
||||
session_id(), header_buffer->data(), &header_buffer_length,
|
||||
encrypted_usage_entry_.data(), &entry_buffer_length));
|
||||
header_buffer->resize(header_buffer_length);
|
||||
encrypted_usage_entry_.resize(entry_buffer_length);
|
||||
}
|
||||
|
||||
void Session::LoadUsageEntry(uint32_t index, const vector<uint8_t>& buffer) {
|
||||
@@ -1915,6 +1924,7 @@ void Session::GenerateReport(const std::string& pst,
|
||||
if (expected_result != OEMCrypto_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
pst_report_buffer_.resize(length);
|
||||
EXPECT_EQ(wvutil::Unpacked_PST_Report::report_size(pst.length()), length);
|
||||
vector<uint8_t> computed_signature(SHA_DIGEST_LENGTH);
|
||||
key_deriver_.ClientSignPstReport(pst_report_buffer_, &computed_signature);
|
||||
|
||||
Reference in New Issue
Block a user