74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine Master
|
|
// License Agreement.
|
|
#ifndef OEMCRYPTO_FUZZ_HELPER_H_
|
|
#define OEMCRYPTO_FUZZ_HELPER_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "OEMCryptoCAS.h"
|
|
#include "oec_device_features.h"
|
|
#include "oec_session_util.h"
|
|
#include "oemcrypto_corpus_generator_helper.h"
|
|
#include "oemcrypto_session_tests_helper.h"
|
|
namespace wvoec {
|
|
// Initial setup to create a valid OEMCrypto state such as initializing crypto
|
|
// firmware/hardware, installing golden key box etc. in order to fuzz
|
|
// OEMCrypto APIs.
|
|
class InitializeFuzz : public SessionUtil {
|
|
public:
|
|
InitializeFuzz() {
|
|
wvoec::global_features.Initialize();
|
|
OEMCrypto_SetSandbox(kTestSandbox, sizeof(kTestSandbox));
|
|
OEMCrypto_Initialize();
|
|
EnsureTestKeys();
|
|
}
|
|
|
|
~InitializeFuzz() { OEMCrypto_Terminate(); }
|
|
};
|
|
|
|
class OEMCryptoLicenseAPIFuzz : public InitializeFuzz {
|
|
public:
|
|
OEMCryptoLicenseAPIFuzz() : license_messages_(&session_) {
|
|
session_.open();
|
|
InstallTestRSAKey(&session_);
|
|
session_.GenerateNonce();
|
|
}
|
|
|
|
~OEMCryptoLicenseAPIFuzz() {
|
|
session_.close();
|
|
}
|
|
|
|
LicenseRoundTrip& license_messages() { return license_messages_; }
|
|
|
|
private:
|
|
Session session_;
|
|
LicenseRoundTrip license_messages_;
|
|
};
|
|
|
|
class OEMCryptoProvisioningAPIFuzz : public InitializeFuzz {
|
|
public:
|
|
OEMCryptoProvisioningAPIFuzz()
|
|
: provisioning_messages_(&session_, encoded_rsa_key_) {
|
|
// Opens a session and Generates Nonce.
|
|
provisioning_messages_.PrepareSession(keybox_);
|
|
}
|
|
|
|
~OEMCryptoProvisioningAPIFuzz() { session_.close(); }
|
|
|
|
ProvisioningRoundTrip& provisioning_messages() {
|
|
return provisioning_messages_;
|
|
}
|
|
|
|
private:
|
|
Session session_;
|
|
ProvisioningRoundTrip provisioning_messages_;
|
|
};
|
|
|
|
// Redirect printf and log statements from oemcrypto functions to a file to
|
|
// reduce noise
|
|
void RedirectStdoutToFile();
|
|
} // namespace wvoec
|
|
|
|
#endif // OEMCRYPTO_FUZZ_HELPER_H_
|