Updated crypto_session_fuzzer

Implemented google c++ code style changes for crypto_session_fuzzer

exec/s: 136
Test: ./crypto_session_fuzzer
Bug: 312374669

Change-Id: Ie490914858a35dfe0f8bfdd4a40f9be65d41b6bd
This commit is contained in:
Onkar Shinde
2023-12-12 08:34:01 +00:00
committed by Aditya Wazir
parent d866ba45aa
commit 982bec196b

View File

@@ -15,12 +15,13 @@
*
*/
#include <fuzzer/FuzzedDataProvider.h>
#include "crypto_session.h"
#include "entitlement_key_session.h"
#include "properties.h"
#include "string_conversions.h"
#include "wv_cdm_constants.h"
#include <fuzzer/FuzzedDataProvider.h>
using namespace wvcdm;
@@ -34,469 +35,469 @@ constexpr int32_t kDefaultSampleSize = 0;
class CryptoSessionFuzzer {
public:
CryptoSessionFuzzer(const uint8_t* data, size_t size) : mFdp(data, size) {};
void process();
CryptoSessionFuzzer(const uint8_t* data, size_t size) : fdp_(data, size){};
void Process();
void FillDecryptParams(CdmDecryptionParametersV16& params);
void SetKeyParams(CryptoKey& inputKey);
void setUp(CryptoSession* cryptoSession, const std::string& keyId,
void SetKeyParams(CryptoKey& input_key);
void SetUp(CryptoSession* crypto_session, const std::string& key_id,
std::string& message, std::string& signature,
std::string& coreMessage);
void initializeStripeBuffer(std::vector<uint8_t>* buffer, size_t size);
std::string& core_message);
void InitializeStripeBuffer(std::vector<uint8_t>* buffer, size_t size);
private:
FuzzedDataProvider mFdp;
FuzzedDataProvider fdp_;
};
void CryptoSessionFuzzer::initializeStripeBuffer(std::vector<uint8_t>* buffer,
void CryptoSessionFuzzer::InitializeStripeBuffer(std::vector<uint8_t>* buffer,
size_t size) {
buffer->assign(size, 0);
for (size_t i = 0; i < size; ++i) {
(*buffer)[i] = mFdp.ConsumeIntegral<uint8_t>();
(*buffer)[i] = fdp_.ConsumeIntegral<uint8_t>();
}
}
void CryptoSessionFuzzer::SetKeyParams(CryptoKey& inputKey) {
inputKey.set_key_data(mFdp.ConsumeRandomLengthString(kStringLength));
inputKey.set_key_data_iv(mFdp.ConsumeRandomLengthString(kStringLength));
inputKey.set_key_control(mFdp.ConsumeRandomLengthString(kStringLength));
inputKey.set_key_control_iv(mFdp.ConsumeRandomLengthString(kStringLength));
inputKey.set_cipher_mode(mFdp.ConsumeBool() ? kCipherModeCbc
void CryptoSessionFuzzer::SetKeyParams(CryptoKey& input_key) {
input_key.set_key_data(fdp_.ConsumeRandomLengthString(kStringLength));
input_key.set_key_data_iv(fdp_.ConsumeRandomLengthString(kStringLength));
input_key.set_key_control(fdp_.ConsumeRandomLengthString(kStringLength));
input_key.set_key_control_iv(fdp_.ConsumeRandomLengthString(kStringLength));
input_key.set_cipher_mode(fdp_.ConsumeBool() ? kCipherModeCbc
: kCipherModeCtr);
inputKey.set_track_label(mFdp.ConsumeRandomLengthString(kStringLength));
inputKey.set_entitlement_key_id(
mFdp.ConsumeRandomLengthString(kStringLength));
input_key.set_track_label(fdp_.ConsumeRandomLengthString(kStringLength));
input_key.set_entitlement_key_id(
fdp_.ConsumeRandomLengthString(kStringLength));
}
void CryptoSessionFuzzer::FillDecryptParams(
CdmDecryptionParametersV16& params) {
params.cipher_mode = mFdp.ConsumeBool() ? kCipherModeCbc : kCipherModeCtr;
params.observe_legacy_fields = mFdp.ConsumeBool();
uint32_t noOfSamples =
mFdp.ConsumeIntegralInRange<uint32_t>(kMinSamplesCount, kMaxSamplesCount);
params.cipher_mode = fdp_.ConsumeBool() ? kCipherModeCbc : kCipherModeCtr;
params.observe_legacy_fields = fdp_.ConsumeBool();
uint32_t no_of_samples =
fdp_.ConsumeIntegralInRange<uint32_t>(kMinSamplesCount, kMaxSamplesCount);
while (--noOfSamples) {
size_t sampleSize = 0;
uint32_t noOfSubSamples = mFdp.ConsumeIntegralInRange<uint32_t>(
while (--no_of_samples) {
size_t sample_size = 0;
uint32_t no_of_sub_samples = fdp_.ConsumeIntegralInRange<uint32_t>(
kMinSamplesCount, kMaxSamplesCount);
std::vector<CdmDecryptionSubsample> subSampleVector;
while (--noOfSubSamples) {
size_t clearBytes =
mFdp.ConsumeIntegralInRange<size_t>(kMinByte, kMaxByte);
size_t protectedBytes =
mFdp.ConsumeIntegralInRange<size_t>(kMinByte, kMaxByte);
CdmDecryptionSubsample subsample(clearBytes, protectedBytes);
sampleSize += clearBytes + protectedBytes;
subSampleVector.push_back(subsample);
std::vector<CdmDecryptionSubsample> sub_sample_vector;
while (--no_of_sub_samples) {
size_t clear_bytes =
fdp_.ConsumeIntegralInRange<size_t>(kMinByte, kMaxByte);
size_t protected_bytes =
fdp_.ConsumeIntegralInRange<size_t>(kMinByte, kMaxByte);
CdmDecryptionSubsample sub_sample(clear_bytes, protected_bytes);
sample_size += clear_bytes + protected_bytes;
sub_sample_vector.push_back(sub_sample);
}
std::vector<uint8_t> iv;
iv = mFdp.ConsumeBytes<uint8_t>(kIvSize);
iv = fdp_.ConsumeBytes<uint8_t>(kIvSize);
if (iv.size() != kIvSize) {
iv.resize(kIvSize, 0);
}
void* decryptBuffer;
std::vector<uint8_t> eBuffer;
for (int i = 0; i < sampleSize; ++i) {
eBuffer.push_back(
mFdp.ConsumeIntegralInRange<uint8_t>(kMinByte, kMaxByte));
void* decrypt_buffer;
std::vector<uint8_t> e_buffer;
for (int i = 0; i < sample_size; ++i) {
e_buffer.push_back(
fdp_.ConsumeIntegralInRange<uint8_t>(kMinByte, kMaxByte));
}
size_t decryptBufferOffset =
mFdp.ConsumeIntegralInRange<uint8_t>(kMinByte, kMaxByte);
CdmDecryptionSample sample(eBuffer.data(), decryptBuffer,
decryptBufferOffset, sampleSize, iv);
sample.subsamples = subSampleVector;
size_t decrypt_buffer_offset =
fdp_.ConsumeIntegralInRange<uint8_t>(kMinByte, kMaxByte);
CdmDecryptionSample sample(e_buffer.data(), decrypt_buffer,
decrypt_buffer_offset, sample_size, iv);
sample.subsamples = sub_sample_vector;
params.samples.push_back(sample);
}
}
void CryptoSessionFuzzer::setUp(CryptoSession* cryptoSession,
const std::string& keyId, std::string& message,
void CryptoSessionFuzzer::SetUp(CryptoSession* crypto_session,
const std::string& key_id, std::string& message,
std::string& signature,
std::string& coreMessage) {
bool shouldSpecifyAlgorithm;
std::string& core_message) {
bool should_specify_algorithm;
OEMCrypto_SignatureHashAlgorithm algorithm;
CdmLicenseKeyType keyType1 = kLicenseKeyTypeEntitlement;
cryptoSession->PrepareAndSignProvisioningRequest(
message, &coreMessage, &signature, shouldSpecifyAlgorithm, algorithm);
cryptoSession->PrepareAndSignLicenseRequest(
message, &coreMessage, &signature, shouldSpecifyAlgorithm, algorithm);
cryptoSession->LoadLicense(message, coreMessage, signature, keyType1);
CdmLicenseKeyType key_type_1 = kLicenseKeyTypeEntitlement;
crypto_session->PrepareAndSignProvisioningRequest(
message, &core_message, &signature, should_specify_algorithm, algorithm);
crypto_session->PrepareAndSignLicenseRequest(
message, &core_message, &signature, should_specify_algorithm, algorithm);
crypto_session->LoadLicense(message, core_message, signature, key_type_1);
CryptoKey inputKey;
inputKey.set_key_id(keyId);
CryptoSessionFuzzer::SetKeyParams(inputKey);
std::vector<CryptoKey> keys = { inputKey };
cryptoSession->LoadEntitledContentKeys(keys);
CryptoKey input_key;
input_key.set_key_id(key_id);
CryptoSessionFuzzer::SetKeyParams(input_key);
std::vector<CryptoKey> keys = {input_key};
crypto_session->LoadEntitledContentKeys(keys);
}
void CryptoSessionFuzzer::process() {
metrics::CryptoMetrics cryptoMetrics;
std::unique_ptr<CryptoSession> cryptoSession(
CryptoSession::MakeCryptoSession(&cryptoMetrics));
void CryptoSessionFuzzer::Process() {
metrics::CryptoMetrics crypto_metrics;
std::unique_ptr<CryptoSession> crypto_session(
CryptoSession::MakeCryptoSession(&crypto_metrics));
CdmLicenseKeyType keyType;
CdmLicenseKeyType key_type;
OEMCrypto_SignatureHashAlgorithm algorithm;
Properties::Init();
RequestedSecurityLevel requestedSecurityLevel =
mFdp.ConsumeBool() ? kLevelDefault : kLevel3;
cryptoSession->Open(requestedSecurityLevel);
RequestedSecurityLevel requested_security_level =
fdp_.ConsumeBool() ? kLevelDefault : kLevel3;
crypto_session->Open(requested_security_level);
while (mFdp.remaining_bytes()) {
auto invokeCryptoSessionAPI = mFdp.PickValueInArray<
while (fdp_.remaining_bytes()) {
auto invoke_crypto_session_API = fdp_.PickValueInArray<
const std::function<void()>>({
[&]() {
std::string token = mFdp.ConsumeRandomLengthString(kStringLength);
std::string additionalToken =
mFdp.ConsumeRandomLengthString(kStringLength);
cryptoSession->GetProvisioningToken(
mFdp.ConsumeBool() ? &token : nullptr,
mFdp.ConsumeBool() ? &additionalToken : nullptr);
std::string token = fdp_.ConsumeRandomLengthString(kStringLength);
std::string additional_token =
fdp_.ConsumeRandomLengthString(kStringLength);
crypto_session->GetProvisioningToken(
fdp_.ConsumeBool() ? &token : nullptr,
fdp_.ConsumeBool() ? &additional_token : nullptr);
},
[&]() {
cryptoSession->SetSystemId(
mFdp.ConsumeIntegral<uint32_t>() /*system_id*/);
crypto_session->SetSystemId(
fdp_.ConsumeIntegral<uint32_t>() /*system_id*/);
},
[&]() {
std::string provisioningId;
cryptoSession->GetProvisioningId(&provisioningId);
cryptoSession->GetExternalDeviceUniqueId(&provisioningId);
std::string provisioning_id;
crypto_session->GetProvisioningId(&provisioning_id);
crypto_session->GetExternalDeviceUniqueId(&provisioning_id);
},
[&]() {
cryptoSession->LoadLicense(
mFdp.ConsumeRandomLengthString(kStringLength) /*signed_message*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*coreMessage*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*signature*/,
keyType);
crypto_session->LoadLicense(
fdp_.ConsumeRandomLengthString(kStringLength) /*signed_message*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*core_message*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*signature*/,
key_type);
},
[&]() {
std::string coreMessage =
mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature = mFdp.ConsumeRandomLengthString(kStringLength);
cryptoSession->PrepareAndSignRenewalRequest(
mFdp.ConsumeRandomLengthString(kStringLength) /*message*/,
mFdp.ConsumeBool() ? &coreMessage : nullptr,
mFdp.ConsumeBool() ? &signature : nullptr);
std::string core_message =
fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature = fdp_.ConsumeRandomLengthString(kStringLength);
crypto_session->PrepareAndSignRenewalRequest(
fdp_.ConsumeRandomLengthString(kStringLength) /*message*/,
fdp_.ConsumeBool() ? &core_message : nullptr,
fdp_.ConsumeBool() ? &signature : nullptr);
},
[&]() {
cryptoSession->LoadRenewal(
mFdp.ConsumeRandomLengthString(kStringLength) /*signed_message*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*coreMessage*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*signature*/);
crypto_session->LoadRenewal(
fdp_.ConsumeRandomLengthString(kStringLength) /*signed_message*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*core_message*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*signature*/);
},
[&]() {
const std::string& message =
mFdp.ConsumeRandomLengthString(kStringLength);
std::string coreMessage =
mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature = mFdp.ConsumeRandomLengthString(kStringLength);
fdp_.ConsumeRandomLengthString(kStringLength);
std::string core_message =
fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature = fdp_.ConsumeRandomLengthString(kStringLength);
OEMCrypto_SignatureHashAlgorithm algorithm;
bool shouldSpecifyAlgorithm = mFdp.ConsumeBool();
cryptoSession->PrepareAndSignProvisioningRequest(
message, mFdp.ConsumeBool() ? &coreMessage : nullptr,
mFdp.ConsumeBool() ? &signature : nullptr, shouldSpecifyAlgorithm,
bool should_specify_algorithm = fdp_.ConsumeBool();
crypto_session->PrepareAndSignProvisioningRequest(
message, fdp_.ConsumeBool() ? &core_message : nullptr,
fdp_.ConsumeBool() ? &signature : nullptr, should_specify_algorithm,
algorithm);
},
[&]() {
if (mFdp.ConsumeBool()) {
const CryptoWrappedKey privateKey;
cryptoSession->LoadCertificatePrivateKey(privateKey);
if (fdp_.ConsumeBool()) {
const CryptoWrappedKey private_key;
crypto_session->LoadCertificatePrivateKey(private_key);
} else {
CryptoWrappedKey::Type type =
(CryptoWrappedKey::Type)mFdp.ConsumeIntegral<int32_t>();
std::string key = mFdp.ConsumeRandomLengthString(kStringLength);
const CryptoWrappedKey privateKey(type, key);
cryptoSession->LoadCertificatePrivateKey(privateKey);
(CryptoWrappedKey::Type)fdp_.ConsumeIntegral<int32_t>();
std::string key = fdp_.ConsumeRandomLengthString(kStringLength);
const CryptoWrappedKey private_key(type, key);
crypto_session->LoadCertificatePrivateKey(private_key);
}
},
[&]() {
std::string publicKey;
std::string publicKeySignature;
std::string wrappedPrivateKey;
CryptoWrappedKey::Type keyType;
cryptoSession->GenerateCertificateKeyPair(
&publicKey, &publicKeySignature, &wrappedPrivateKey, &keyType);
std::string public_key;
std::string public_key_signature;
std::string wrapped_private_key;
CryptoWrappedKey::Type key_type;
crypto_session->GenerateCertificateKeyPair(
&public_key, &public_key_signature, &wrapped_private_key, &key_type);
},
[&]() {
if (mFdp.ConsumeBool()) {
const CryptoWrappedKey privateKey;
cryptoSession->LoadOemCertificatePrivateKey(privateKey);
if (fdp_.ConsumeBool()) {
const CryptoWrappedKey private_key;
crypto_session->LoadOemCertificatePrivateKey(private_key);
} else {
CryptoWrappedKey::Type type =
(CryptoWrappedKey::Type)mFdp.ConsumeIntegral<int32_t>();
std::string key = mFdp.ConsumeRandomLengthString(kStringLength);
const CryptoWrappedKey privateKey(type, key);
cryptoSession->LoadOemCertificatePrivateKey(privateKey);
(CryptoWrappedKey::Type)fdp_.ConsumeIntegral<int32_t>();
std::string key = fdp_.ConsumeRandomLengthString(kStringLength);
const CryptoWrappedKey private_key(type, key);
crypto_session->LoadOemCertificatePrivateKey(private_key);
}
},
[&]() {
size_t out;
RequestedSecurityLevel security_level =
(RequestedSecurityLevel)mFdp.ConsumeIntegral<int32_t>();
cryptoSession->GetNumberOfOpenSessions(security_level, &out);
(RequestedSecurityLevel)fdp_.ConsumeIntegral<int32_t>();
crypto_session->GetNumberOfOpenSessions(security_level, &out);
},
[&]() {
std::string info = mFdp.ConsumeRandomLengthString(kStringLength);
cryptoSession->GetBuildInformation(&info);
std::string info = fdp_.ConsumeRandomLengthString(kStringLength);
crypto_session->GetBuildInformation(&info);
},
[&]() {
CdmWatermarkingSupport support =
(CdmWatermarkingSupport)mFdp.ConsumeIntegral<int32_t>();
cryptoSession->GetWatermarkingSupport(&support);
(CdmWatermarkingSupport)fdp_.ConsumeIntegral<int32_t>();
crypto_session->GetWatermarkingSupport(&support);
},
[&]() {
CdmProductionReadiness readiness =
(CdmProductionReadiness)mFdp.ConsumeIntegral<int32_t>();
cryptoSession->GetProductionReadiness(&readiness);
(CdmProductionReadiness)fdp_.ConsumeIntegral<int32_t>();
crypto_session->GetProductionReadiness(&readiness);
},
[&]() {
RequestedSecurityLevel security_level =
(RequestedSecurityLevel)mFdp.ConsumeIntegral<int32_t>();
size_t number_of_entries = mFdp.ConsumeIntegral<size_t>();
cryptoSession->GetMaximumUsageTableEntries(security_level,
(RequestedSecurityLevel)fdp_.ConsumeIntegral<int32_t>();
size_t number_of_entries = fdp_.ConsumeIntegral<size_t>();
crypto_session->GetMaximumUsageTableEntries(security_level,
&number_of_entries);
},
[&]() {
RequestedSecurityLevel security_level =
(RequestedSecurityLevel)mFdp.ConsumeIntegral<int32_t>();
uint32_t decrypt_hash_support = mFdp.ConsumeIntegral<uint32_t>();
cryptoSession->GetDecryptHashSupport(security_level,
(RequestedSecurityLevel)fdp_.ConsumeIntegral<int32_t>();
uint32_t decrypt_hash_support = fdp_.ConsumeIntegral<uint32_t>();
crypto_session->GetDecryptHashSupport(security_level,
&decrypt_hash_support);
},
[&]() {
bool hasSupport = mFdp.ConsumeBool();
cryptoSession->HasUsageTableSupport(&hasSupport);
bool has_support = fdp_.ConsumeBool();
crypto_session->HasUsageTableSupport(&has_support);
},
[&]() {
cryptoSession->DeactivateUsageInformation(
mFdp.ConsumeRandomLengthString(
crypto_session->DeactivateUsageInformation(
fdp_.ConsumeRandomLengthString(
kStringLength) /*provider_session_token*/);
},
[&]() {
std::string usageReport =
mFdp.ConsumeRandomLengthString(kStringLength);
CryptoSession::UsageDurationStatus usageDurationStatus;
int64_t secondsSinceStarted = mFdp.ConsumeIntegral<int64_t>();
int64_t secondsSinceLastPlayed = mFdp.ConsumeIntegral<int64_t>();
cryptoSession->GenerateUsageReport(
mFdp.ConsumeRandomLengthString(
std::string usage_report =
fdp_.ConsumeRandomLengthString(kStringLength);
CryptoSession::UsageDurationStatus usage_duration_status;
int64_t seconds_since_started = fdp_.ConsumeIntegral<int64_t>();
int64_t seconds_since_last_played = fdp_.ConsumeIntegral<int64_t>();
crypto_session->GenerateUsageReport(
fdp_.ConsumeRandomLengthString(
kStringLength) /*provider_session_token*/,
&usageReport, &usageDurationStatus, &secondsSinceStarted,
&secondsSinceLastPlayed);
&usage_report, &usage_duration_status, &seconds_since_started,
&seconds_since_last_played);
},
[&]() {
uint32_t nonce = mFdp.ConsumeIntegral<uint32_t>();
cryptoSession->GenerateNonce(&nonce);
uint32_t nonce = fdp_.ConsumeIntegral<uint32_t>();
crypto_session->GenerateNonce(&nonce);
},
[&]() {
std::string signedMessage, coreMessage, signature;
std::string wrappedPrivateKey;
cryptoSession->LoadProvisioning(
signedMessage, coreMessage, signature,
mFdp.ConsumeBool() ? &wrappedPrivateKey : nullptr);
std::string signed_message, core_message, signature;
std::string wrapped_private_key;
crypto_session->LoadProvisioning(
signed_message, core_message, signature,
fdp_.ConsumeBool() ? &wrapped_private_key : nullptr);
},
[&]() {
cryptoSession->SetDecryptHash(
mFdp.ConsumeIntegral<int16_t>() /*frame_number*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*hash*/);
crypto_session->SetDecryptHash(
fdp_.ConsumeIntegral<int16_t>() /*frame_number*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*hash*/);
},
[&]() {
CdmEncryptionAlgorithm algorithm;
std::string outBuffer;
cryptoSession->GenericDecrypt(
mFdp.ConsumeRandomLengthString(kStringLength) /*in_buffer*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*key_id*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*iv*/, algorithm,
&outBuffer);
std::string out_buffer;
crypto_session->GenericDecrypt(
fdp_.ConsumeRandomLengthString(kStringLength) /*in_buffer*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*key_id*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*iv*/, algorithm,
&out_buffer);
},
[&]() {
CdmSigningAlgorithm algorithm = mFdp.ConsumeBool()
CdmSigningAlgorithm algorithm = fdp_.ConsumeBool()
? kSigningAlgorithmHmacSha256
: kSigningAlgorithmUnknown;
std::string signature;
cryptoSession->GenericSign(
mFdp.ConsumeRandomLengthString(kStringLength) /*message*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*key_id*/,
crypto_session->GenericSign(
fdp_.ConsumeRandomLengthString(kStringLength) /*message*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*key_id*/,
algorithm, &signature);
},
[&]() {
CdmSigningAlgorithm algorithm = kSigningAlgorithmHmacSha256;
const std::string signature;
cryptoSession->GenericVerify(
mFdp.ConsumeRandomLengthString(kStringLength) /*message*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*key_id*/,
crypto_session->GenericVerify(
fdp_.ConsumeRandomLengthString(kStringLength) /*message*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*key_id*/,
algorithm, signature);
},
[&]() {
UsageTableHeader usageTableHeader;
cryptoSession->CreateUsageTableHeader(requestedSecurityLevel,
&usageTableHeader);
UsageTableHeader usage_table_header;
crypto_session->CreateUsageTableHeader(requested_security_level,
&usage_table_header);
cryptoSession->LoadUsageTableHeader(requestedSecurityLevel,
usageTableHeader);
uint32_t newEntryCount;
cryptoSession->ShrinkUsageTableHeader(
requestedSecurityLevel, newEntryCount, &usageTableHeader);
crypto_session->LoadUsageTableHeader(requested_security_level,
usage_table_header);
uint32_t new_entry_count;
crypto_session->ShrinkUsageTableHeader(
requested_security_level, new_entry_count, &usage_table_header);
},
[&]() {
const UsageTableHeader usageTableHeader;
cryptoSession->LoadUsageTableHeader(requestedSecurityLevel,
usageTableHeader);
const UsageTableHeader usage_table_header;
crypto_session->LoadUsageTableHeader(requested_security_level,
usage_table_header);
},
[&]() {
uint32_t entryNumber;
cryptoSession->CreateUsageEntry(&entryNumber);
cryptoSession->MoveUsageEntry(entryNumber);
uint32_t entry_number;
crypto_session->CreateUsageEntry(&entry_number);
crypto_session->MoveUsageEntry(entry_number);
},
[&]() {
const UsageEntry usageEntry;
cryptoSession->LoadUsageEntry(
mFdp.ConsumeIntegral<uint32_t>() /*entry_number*/, usageEntry);
const UsageEntry usage_entry;
crypto_session->LoadUsageEntry(
fdp_.ConsumeIntegral<uint32_t>() /*entry_number*/, usage_entry);
},
[&]() {
UsageTableHeader usageTableHeader;
UsageEntry usageEntry;
cryptoSession->UpdateUsageEntry(&usageTableHeader, &usageEntry);
UsageTableHeader usage_table_header;
UsageEntry usage_entry;
crypto_session->UpdateUsageEntry(&usage_table_header, &usage_entry);
},
[&]() {
bool canSupportOutput = mFdp.ConsumeBool();
bool canDisableOutput = mFdp.ConsumeBool();
bool canSupportCgmsA = mFdp.ConsumeBool();
cryptoSession->GetAnalogOutputCapabilities(
&canSupportOutput, &canDisableOutput, &canSupportCgmsA);
bool can_support_output = fdp_.ConsumeBool();
bool can_disable_output = fdp_.ConsumeBool();
bool can_support_cgmsa = fdp_.ConsumeBool();
crypto_session->GetAnalogOutputCapabilities(
&can_support_output, &can_disable_output, &can_support_cgmsa);
},
[&]() {
cryptoSession->SetDebugIgnoreKeyboxCount(
mFdp.ConsumeIntegral<uint32_t>() /*count*/);
crypto_session->SetDebugIgnoreKeyboxCount(
fdp_.ConsumeIntegral<uint32_t>() /*count*/);
},
[&]() { cryptoSession->GetOkpFallbackPolicy(); },
[&]() { crypto_session->GetOkpFallbackPolicy(); },
[&]() {
std::string request = mFdp.ConsumeRandomLengthString(kStringLength);
cryptoSession->PrepareOtaProvisioningRequest(
mFdp.ConsumeBool() /*use_test_key*/, &request);
std::string request = fdp_.ConsumeRandomLengthString(kStringLength);
crypto_session->PrepareOtaProvisioningRequest(
fdp_.ConsumeBool() /*use_test_key*/, &request);
},
[&]() {
cryptoSession->LoadOtaProvisioning(
mFdp.ConsumeBool() /*use_test_key*/,
mFdp.ConsumeRandomLengthString(kStringLength) /*response*/);
crypto_session->LoadOtaProvisioning(
fdp_.ConsumeBool() /*use_test_key*/,
fdp_.ConsumeRandomLengthString(kStringLength) /*response*/);
},
[&]() {
uint32_t tier = mFdp.ConsumeIntegral<uint32_t>();
cryptoSession->GetResourceRatingTier(&tier);
uint32_t tier = fdp_.ConsumeIntegral<uint32_t>();
crypto_session->GetResourceRatingTier(&tier);
},
[&]() {
size_t max;
cryptoSession->GetMaxNumberOfSessions(requestedSecurityLevel, &max);
crypto_session->GetMaxNumberOfSessions(requested_security_level, &max);
},
[&]() {
std::string keyData = mFdp.ConsumeRandomLengthString(kStringLength);
cryptoSession->GetTokenFromKeybox(requestedSecurityLevel, &keyData);
std::string key_data = fdp_.ConsumeRandomLengthString(kStringLength);
crypto_session->GetTokenFromKeybox(requested_security_level, &key_data);
},
[&]() {
std::string bcc = mFdp.ConsumeRandomLengthString(kStringLength);
std::string additionalSignature =
mFdp.ConsumeRandomLengthString(kStringLength);
cryptoSession->GetBootCertificateChain(&bcc, &additionalSignature);
std::string bcc = fdp_.ConsumeRandomLengthString(kStringLength);
std::string additional_signature =
fdp_.ConsumeRandomLengthString(kStringLength);
crypto_session->GetBootCertificateChain(&bcc, &additional_signature);
},
[&]() {
cryptoSession->GenerateDerivedKeys(
mFdp.ConsumeRandomLengthString(kStringLength) /*message*/);
crypto_session->GenerateDerivedKeys(
fdp_.ConsumeRandomLengthString(kStringLength) /*message*/);
},
[&]() {
CdmDecryptionParametersV16 params2;
cryptoSession->Decrypt(params2);
CdmDecryptionParametersV16 params_2;
crypto_session->Decrypt(params_2);
},
[&]() {
const std::string& message =
mFdp.ConsumeRandomLengthString(kStringLength);
std::string coreMessage, signature;
bool shouldSpecifyAlgorithm;
fdp_.ConsumeRandomLengthString(kStringLength);
std::string core_message, signature;
bool should_specify_algorithm;
OEMCrypto_SignatureHashAlgorithm algorithm;
cryptoSession->PrepareAndSignProvisioningRequest(
message, &coreMessage, &signature, shouldSpecifyAlgorithm,
crypto_session->PrepareAndSignProvisioningRequest(
message, &core_message, &signature, should_specify_algorithm,
algorithm);
cryptoSession->PrepareAndSignLicenseRequest(
message, &coreMessage, &signature, shouldSpecifyAlgorithm,
crypto_session->PrepareAndSignLicenseRequest(
message, &core_message, &signature, should_specify_algorithm,
algorithm);
},
[&]() {
std::string keyId = mFdp.ConsumeRandomLengthString(kStringLength);
std::string message = mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature, coreMessage;
setUp(cryptoSession.get(), keyId, message, signature, coreMessage);
std::string key_id = fdp_.ConsumeRandomLengthString(kStringLength);
std::string message = fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature, core_message;
SetUp(crypto_session.get(), key_id, message, signature, core_message);
std::vector<uint8_t> inVector;
std::vector<uint8_t> ivVector;
std::string inBuffer;
std::vector<uint8_t> in_vector;
std::vector<uint8_t> iv_vector;
std::string in_buffer;
std::string iv;
CdmEncryptionAlgorithm algorithmEncrypt =
CdmEncryptionAlgorithm algorithm_encrypt =
kEncryptionAlgorithmAesCbc128;
std::string outBuffer;
initializeStripeBuffer(&inVector, CONTENT_KEY_SIZE * 15);
inBuffer = std::string(inVector.begin(), inVector.end());
initializeStripeBuffer(&ivVector, KEY_IV_SIZE);
iv = std::string(ivVector.begin(), ivVector.end());
std::string out_buffer;
InitializeStripeBuffer(&in_vector, CONTENT_KEY_SIZE * 15);
in_buffer = std::string(in_vector.begin(), in_vector.end());
InitializeStripeBuffer(&iv_vector, KEY_IV_SIZE);
iv = std::string(iv_vector.begin(), iv_vector.end());
cryptoSession->GenericEncrypt(inBuffer, keyId, iv, algorithmEncrypt,
&outBuffer);
crypto_session->GenericEncrypt(in_buffer, key_id, iv, algorithm_encrypt,
&out_buffer);
},
[&]() {
std::string keyId = mFdp.ConsumeRandomLengthString(kStringLength);
std::string message = mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature, coreMessage;
setUp(cryptoSession.get(), keyId, message, signature, coreMessage);
std::string key_id = fdp_.ConsumeRandomLengthString(kStringLength);
std::string message = fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature, core_message;
SetUp(crypto_session.get(), key_id, message, signature, core_message);
std::vector<uint8_t> inVector;
std::vector<uint8_t> ivVector;
std::string inBuffer;
std::vector<uint8_t> in_vector;
std::vector<uint8_t> iv_vector;
std::string in_buffer;
std::string iv;
CdmEncryptionAlgorithm algorithmEncrypt =
CdmEncryptionAlgorithm algorithm_encrypt =
kEncryptionAlgorithmAesCbc128;
std::string outBuffer;
initializeStripeBuffer(&inVector, CONTENT_KEY_SIZE * 15);
inBuffer = std::string(inVector.begin(), inVector.end());
initializeStripeBuffer(&ivVector, KEY_IV_SIZE);
iv = std::string(ivVector.begin(), ivVector.end());
std::string out_buffer;
InitializeStripeBuffer(&in_vector, CONTENT_KEY_SIZE * 15);
in_buffer = std::string(in_vector.begin(), in_vector.end());
InitializeStripeBuffer(&iv_vector, KEY_IV_SIZE);
iv = std::string(iv_vector.begin(), iv_vector.end());
cryptoSession->GenericDecrypt(inBuffer, keyId, iv, algorithmEncrypt,
&outBuffer);
crypto_session->GenericDecrypt(in_buffer, key_id, iv, algorithm_encrypt,
&out_buffer);
},
[&]() {
std::string keyId = mFdp.ConsumeRandomLengthString(kStringLength);
std::string message = mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature, coreMessage;
setUp(cryptoSession.get(), keyId, message, signature, coreMessage);
std::string key_id = fdp_.ConsumeRandomLengthString(kStringLength);
std::string message = fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature, core_message;
SetUp(crypto_session.get(), key_id, message, signature, core_message);
CdmSigningAlgorithm algorithm2 = kSigningAlgorithmHmacSha256;
cryptoSession->GenericSign(message, keyId, algorithm2, &signature);
CdmSigningAlgorithm algorithm_2 = kSigningAlgorithmHmacSha256;
crypto_session->GenericSign(message, key_id, algorithm_2, &signature);
},
[&]() {
std::string keyId = mFdp.ConsumeRandomLengthString(kStringLength);
std::string message = mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature, coreMessage;
setUp(cryptoSession.get(), keyId, message, signature, coreMessage);
std::string key_id = fdp_.ConsumeRandomLengthString(kStringLength);
std::string message = fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature, core_message;
SetUp(crypto_session.get(), key_id, message, signature, core_message);
CdmSigningAlgorithm algorithm2 = kSigningAlgorithmHmacSha256;
cryptoSession->GenericVerify(message, keyId, algorithm2, signature);
CdmSigningAlgorithm algorithm_2 = kSigningAlgorithmHmacSha256;
crypto_session->GenericVerify(message, key_id, algorithm_2, signature);
},
[&]() {
const std::string keyId =
mFdp.ConsumeRandomLengthString(kStringLength);
std::string message = mFdp.ConsumeRandomLengthString(kStringLength);
std::string signature, coreMessage;
setUp(cryptoSession.get(), keyId, message, signature, coreMessage);
CdmDecryptionParametersV16 params(keyId);
const std::string key_id =
fdp_.ConsumeRandomLengthString(kStringLength);
std::string message = fdp_.ConsumeRandomLengthString(kStringLength);
std::string signature, core_message;
SetUp(crypto_session.get(), key_id, message, signature, core_message);
CdmDecryptionParametersV16 params(key_id);
CryptoSessionFuzzer::FillDecryptParams(params);
cryptoSession->Decrypt(params);
crypto_session->Decrypt(params);
},
});
invokeCryptoSessionAPI();
invoke_crypto_session_API();
}
cryptoSession->Close();
crypto_session->Close();
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
CryptoSessionFuzzer cryptoSessionFuzzer(data, size);
cryptoSessionFuzzer.process();
CryptoSessionFuzzer crypto_session_fuzzer(data, size);
crypto_session_fuzzer.Process();
return 0;
}