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