Updated privacy_crypto_fuzzer

Implemented google c++ code style changes for privacy_crypto_fuzzer

exec/s: 3456
Test: ./privacy_crypto_fuzzer
Bug: 312374669

Change-Id: I1422956e873130e9f10b6b5612ea12397fbe3b08
This commit is contained in:
Onkar Shinde
2023-12-08 11:37:33 +00:00
committed by Aditya Wazir
parent 2b3de00a36
commit 44e768678b

View File

@@ -37,117 +37,117 @@ constexpr int32_t kMaxNumComponent = 10;
class PrivacyCryptoFuzzer {
public:
PrivacyCryptoFuzzer(const uint8_t *data, size_t size) : mFdp(data, size){};
void process();
std::string createOid() {
PrivacyCryptoFuzzer(const uint8_t *data, size_t size) : fdp_(data, size){};
void Process();
std::string CreateOid() {
std::string oid;
int32_t firstComponent = mFdp.ConsumeIntegralInRange<uint8_t>(
int32_t first_component = fdp_.ConsumeIntegralInRange<uint8_t>(
kMinFirstComponent, kMaxFirstComponent);
oid += std::to_string(firstComponent);
oid += std::to_string(first_component);
oid += '.';
uint32_t temp = 0;
if (firstComponent != 2) {
temp = mFdp.ConsumeIntegralInRange<uint32_t>(kMinSecondComponent,
if (first_component != 2) {
temp = fdp_.ConsumeIntegralInRange<uint32_t>(kMinSecondComponent,
kMaxSecondComponent);
} else {
temp = mFdp.ConsumeIntegral<uint32_t>();
temp = fdp_.ConsumeIntegral<uint32_t>();
}
oid += std::to_string(temp);
int32_t numComponent = mFdp.ConsumeIntegralInRange<int32_t>(
int32_t num_component = fdp_.ConsumeIntegralInRange<int32_t>(
kMinNumComponent, kMaxNumComponent);
for (int32_t i = 0; i < numComponent; ++i) {
for (int32_t i = 0; i < num_component; ++i) {
oid += '.';
oid += std::to_string(mFdp.ConsumeIntegral<uint32_t>());
oid += std::to_string(fdp_.ConsumeIntegral<uint32_t>());
}
return oid;
}
private:
FuzzedDataProvider mFdp;
FuzzedDataProvider fdp_;
};
void PrivacyCryptoFuzzer::process() {
AesCbcKey aesCbcKey;
RsaPublicKey rsaPubKey;
void PrivacyCryptoFuzzer::Process() {
AesCbcKey aes_cbc_key;
RsaPublicKey rsa_pub_key;
while (mFdp.remaining_bytes()) {
auto privacyCrptoApi = mFdp.PickValueInArray<const std::function<void()>>({
while (fdp_.remaining_bytes()) {
auto privacy_crypto_API = fdp_.PickValueInArray<const std::function<void()>>({
[&]() {
/**
* This Implementation is required to initialize RSA-public_key
* correctly.
*/
FuzzCdmClientPropertySet propertySet(&mFdp);
propertySet.enable_privacy_mode();
propertySet.set_service_certificate(kTestSignedCertificate);
FuzzCdmClientPropertySet property_set(&fdp_);
property_set.enable_privacy_mode();
property_set.set_service_certificate(kTestSignedCertificate);
PropertiesTestPeer::ForceReinit();
PropertiesTestPeer::AddSessionPropertySet(kTestSessionId1,
&propertySet);
std::string rawServiceCertificate;
&property_set);
std::string raw_service_certificate;
PropertiesTestPeer::GetServiceCertificate(kTestSessionId1,
&rawServiceCertificate);
SignedDrmCertificate signedRootCertificate;
std::string rootCertStr(
&raw_service_certificate);
SignedDrmCertificate signed_root_certificate;
std::string root_cert_str(
reinterpret_cast<const char *>(&kRootCertForProd[0]),
sizeof(kRootCertForProd));
signedRootCertificate.ParseFromString(rootCertStr);
DrmCertificate rootCert;
rootCert.ParseFromString(signedRootCertificate.drm_certificate());
rsaPubKey.Init(mFdp.ConsumeBool()
? rootCert.public_key()
: mFdp.ConsumeRandomLengthString(kMaxByte));
signed_root_certificate.ParseFromString(root_cert_str);
DrmCertificate root_cert;
root_cert.ParseFromString(signed_root_certificate.drm_certificate());
rsa_pub_key.Init(fdp_.ConsumeBool()
? root_cert.public_key()
: fdp_.ConsumeRandomLengthString(kMaxByte));
},
[&]() {
std::string cipherText;
std::string message = mFdp.ConsumeRandomLengthString(kMaxByte);
rsaPubKey.Encrypt(message, &cipherText);
std::string cipher_text;
std::string message = fdp_.ConsumeRandomLengthString(kMaxByte);
rsa_pub_key.Encrypt(message, &cipher_text);
},
[&]() {
rsaPubKey.VerifySignature(
mFdp.ConsumeRandomLengthString(kMaxByte) /* message */,
mFdp.ConsumeRandomLengthString(kMaxByte) /* signature */);
rsa_pub_key.VerifySignature(
fdp_.ConsumeRandomLengthString(kMaxByte) /* message */,
fdp_.ConsumeRandomLengthString(kMaxByte) /* signature */);
},
[&]() {
std::string key = mFdp.ConsumeRandomLengthString(SERVICE_KEY_SIZE);
if (mFdp.ConsumeBool()) {
std::string key = fdp_.ConsumeRandomLengthString(SERVICE_KEY_SIZE);
if (fdp_.ConsumeBool()) {
key.resize(SERVICE_KEY_SIZE, '0');
}
aesCbcKey.Init(key);
aes_cbc_key.Init(key);
},
[&]() {
std::string encId;
std::string iv = mFdp.ConsumeRandomLengthString(KEY_IV_SIZE);
if (mFdp.ConsumeBool()) {
std::string enc_id;
std::string iv = fdp_.ConsumeRandomLengthString(KEY_IV_SIZE);
if (fdp_.ConsumeBool()) {
iv.resize(KEY_IV_SIZE, '0');
}
aesCbcKey.Encrypt(mFdp.ConsumeRandomLengthString(kMaxByte),
mFdp.ConsumeBool() ? &encId : nullptr,
mFdp.ConsumeBool() ? &iv : nullptr);
aes_cbc_key.Encrypt(fdp_.ConsumeRandomLengthString(kMaxByte),
fdp_.ConsumeBool() ? &enc_id : nullptr,
fdp_.ConsumeBool() ? &iv : nullptr);
},
[&]() {
std::string data = mFdp.ConsumeRandomLengthString(kMaxByte);
std::string data = fdp_.ConsumeRandomLengthString(kMaxByte);
Md5Hash(data);
},
[&]() {
std::string data = mFdp.ConsumeRandomLengthString(kMaxByte);
std::string data = fdp_.ConsumeRandomLengthString(kMaxByte);
Sha256Hash(data);
},
[&]() {
size_t certIndex = mFdp.ConsumeBool() ? mFdp.ConsumeIntegral<size_t>()
size_t cert_index = fdp_.ConsumeBool() ? fdp_.ConsumeIntegral<size_t>()
: kOemCertSystemIdIndex;
uint32_t value = 0;
std::string oid = createOid();
std::string oid = CreateOid();
ExtractExtensionValueFromCertificate(
mFdp.ConsumeBool() ? kOemCertStr
: mFdp.ConsumeRandomLengthString(kMaxByte),
oid, certIndex, &value);
fdp_.ConsumeBool() ? kOemCertStr
: fdp_.ConsumeRandomLengthString(kMaxByte),
oid, cert_index, &value);
},
});
privacyCrptoApi();
privacy_crypto_API();
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
PrivacyCryptoFuzzer privacyCryptoFuzzer(data, size);
privacyCryptoFuzzer.process();
PrivacyCryptoFuzzer privacy_crypto_fuzzer(data, size);
privacy_crypto_fuzzer.Process();
return 0;
}