Add a DecryptCENC call after SelectKey for entitled sessions
Merge from Widevine repo of http://go/wvgerrit/154874 We do not require an error to come from SelectKey immediately, it can come from a following call to DecryptCENC. This adds a function Session::TestDecryptCENC to be called instead of SelectKey for the tests that use entitled sessions. Bug: 232225906 Test: tested with http://go/ag/20420224 Change-Id: If5695a5034cce371b6eb6bcf1b6467d84456c21d
This commit is contained in:
committed by
Fred Gylys-Colwell
parent
e88bcf51c8
commit
579b9144b5
@@ -1588,6 +1588,42 @@ void Session::TestDecryptCTR(bool select_key_first,
|
||||
}
|
||||
}
|
||||
|
||||
void Session::TestDecryptEntitled(OEMCryptoResult expected_result,
|
||||
OEMCrypto_SESSION session_id,
|
||||
const uint8_t* content_key_id,
|
||||
size_t content_key_id_length) {
|
||||
OEMCryptoResult select_result = OEMCrypto_SUCCESS;
|
||||
// Select the key (from FillSimpleMessage)
|
||||
select_result = OEMCrypto_SelectKey(
|
||||
session_id, reinterpret_cast<const uint8_t*>(content_key_id),
|
||||
content_key_id_length, OEMCrypto_CipherMode_CENC);
|
||||
|
||||
vector<uint8_t> unencrypted_data;
|
||||
vector<uint8_t> output_buffer;
|
||||
vector<uint8_t> encrypted_data(kTestSubsampleSectionSize);
|
||||
|
||||
vector<uint8_t> in_buffer(256);
|
||||
vector<uint8_t> out_buffer(in_buffer.size());
|
||||
OEMCrypto_SampleDescription sample_description;
|
||||
OEMCrypto_SubSampleDescription subsample_description;
|
||||
ASSERT_NO_FATAL_FAILURE(GenerateSimpleSampleDescription(
|
||||
in_buffer, out_buffer, &sample_description, &subsample_description));
|
||||
OEMCrypto_CENCEncryptPatternDesc pattern = {0, 0};
|
||||
|
||||
EncryptCTR(unencrypted_data, content_key_id, &sample_description.iv[0],
|
||||
&encrypted_data);
|
||||
// Try to decrypt the data with oemcrypto session id.
|
||||
const OEMCryptoResult decrypt_result =
|
||||
OEMCrypto_DecryptCENC(session_id, &sample_description, 1, &pattern);
|
||||
|
||||
// We only have a few errors that we test are reported.
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
TestDecryptResult(expected_result, select_result, decrypt_result))
|
||||
<< "Either SelectKey or DecryptCENC should return " << expected_result
|
||||
<< ", but they returned " << select_result << " and " << decrypt_result
|
||||
<< ", respectively.";
|
||||
}
|
||||
|
||||
void Session::TestDecryptResult(OEMCryptoResult expected_result,
|
||||
OEMCryptoResult actual_select_result,
|
||||
OEMCryptoResult actual_decrypt_result) {
|
||||
|
||||
Reference in New Issue
Block a user