// Copyright 2018 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_INTERFACE_H #define OEMCRYPTO_INTERFACE_H #include #include #include #include "OEMCryptoCENC.h" namespace wvcas { // InputStreamParams mirrors the parameters in OEMCrypto API. The // purpose is to allow OEMCrypto_Descramble to be mocked. OEMCrypto_Descramble // takes 11 parameters as of API V15. GoogleMock allows a maximum of 10. struct InputStreamParams { const uint8_t* data_addr; size_t data_length; bool is_encrypted; InputStreamParams() {}; InputStreamParams(const uint8_t* data_addr, size_t data_length, bool is_encrypted) : data_addr(data_addr), data_length(data_length), is_encrypted(is_encrypted) {} }; // Calls to oemcrypto are called via this object. The purpose of this object is // to allow OEMCrypto to be mocked. The implementation of this object only wraps // OEMCrypto methods adding limited additional functionality. Added // functionality is limited to adapt the input parameters to the oemcrypto api. // Method signatures in this class can only have a maximum of 10 parameters to // maintain compatibility with googlemock. class OEMCryptoInterface { public: OEMCryptoInterface(); virtual ~OEMCryptoInterface(); virtual OEMCryptoResult OEMCrypto_Initialize(void); virtual OEMCryptoResult OEMCrypto_Terminate(void); virtual OEMCryptoResult OEMCrypto_OpenSession( OEMCrypto_SESSION* session) const; virtual OEMCryptoResult OEMCrypto_CloseSession( OEMCrypto_SESSION session) const; virtual OEMCrypto_ProvisioningMethod OEMCrypto_GetProvisioningMethod() const; virtual OEMCryptoResult OEMCrypto_GetKeyData(uint8_t* keyData, size_t* keyDataLength) const; virtual uint32_t OEMCrypto_SupportedCertificates() const; virtual OEMCryptoResult OEMCrypto_GenerateNonce(OEMCrypto_SESSION session, uint32_t* nonce) const; virtual OEMCryptoResult OEMCrypto_GenerateDerivedKeys( OEMCrypto_SESSION session, const uint8_t* mac_key_context, uint32_t mac_key_context_length, const uint8_t* enc_key_context, uint32_t enc_key_context_length) const; virtual OEMCryptoResult OEMCrypto_PrepAndSignLicenseRequest( OEMCrypto_SESSION session, uint8_t* message, size_t message_length, size_t* core_message_size, uint8_t* signature, size_t* signature_length) const; virtual OEMCryptoResult OEMCrypto_PrepAndSignRenewalRequest( OEMCrypto_SESSION session, uint8_t* message, size_t message_length, size_t* core_message_size, uint8_t* signature, size_t* signature_length) const; virtual OEMCryptoResult OEMCrypto_PrepAndSignProvisioningRequest( OEMCrypto_SESSION session, uint8_t* message, size_t message_length, size_t* core_message_size, uint8_t* signature, size_t* signature_length) const; virtual OEMCryptoResult OEMCrypto_LoadProvisioning( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, size_t core_message_length, const uint8_t* signature, size_t signature_length, uint8_t* wrapped_private_key, size_t* wrapped_private_key_length) const; virtual OEMCryptoResult OEMCrypto_GetOEMPublicCertificate( OEMCrypto_SESSION session, uint8_t* public_cert, size_t* public_cert_length) const; virtual OEMCryptoResult OEMCrypto_LoadDRMPrivateKey( OEMCrypto_SESSION session, OEMCrypto_PrivateKeyType key_type, const uint8_t* wrapped_rsa_key, size_t wrapped_rsa_key_length) const; virtual OEMCryptoResult OEMCrypto_GenerateRSASignature( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, uint8_t* signature, size_t* signature_length, RSA_Padding_Scheme padding_scheme) const; virtual OEMCryptoResult OEMCrypto_DeriveKeysFromSessionKey( OEMCrypto_SESSION session, const uint8_t* enc_session_key, size_t enc_session_key_length, const uint8_t* mac_key_context, size_t mac_key_context_length, const uint8_t* enc_key_context, size_t enc_key_context_length) const; virtual OEMCryptoResult OEMCrypto_LoadLicense(OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, size_t core_message_length, const uint8_t* signature, size_t signature_length) const; virtual OEMCryptoResult OEMCrypto_LoadRenewal(OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, size_t core_message_length, const uint8_t* signature, size_t signature_length) const; virtual OEMCryptoResult OEMCrypto_LoadCasECMKeys( OEMCrypto_SESSION session, const uint8_t* message, size_t message_length, const OEMCrypto_EntitledContentKeyObject* even_key, const OEMCrypto_EntitledContentKeyObject* odd_key) const; virtual OEMCryptoResult OEMCrypto_GetHDCPCapability( OEMCrypto_HDCP_Capability* current, OEMCrypto_HDCP_Capability* max) const; virtual OEMCryptoResult OEMCrypto_GetDeviceID(uint8_t* deviceID, size_t* idLength) const; virtual OEMCryptoResult OEMCrypto_LoadTestKeybox(const uint8_t* buffer, size_t length) const; virtual const char* OEMCrypto_SecurityLevel() const; virtual OEMCryptoResult OEMCrypto_CreateEntitledKeySession( OEMCrypto_SESSION oec_session, OEMCrypto_SESSION* key_session) const; virtual OEMCryptoResult OEMCrypto_RemoveEntitledKeySession( OEMCrypto_SESSION key_session) const; virtual OEMCryptoResult OEMCrypto_ReassociateEntitledKeySession( OEMCrypto_SESSION key_session, OEMCrypto_SESSION oec_session) const; virtual uint32_t OEMCrypto_APIVersion() const; virtual OEMCryptoResult OEMCrypto_GetOEMKeyToken( OEMCrypto_SESSION key_session, uint8_t* key_token, size_t* key_token_length) const; virtual OEMCryptoResult OEMCrypto_GetSignatureHashAlgorithm( OEMCrypto_SESSION session, OEMCrypto_SignatureHashAlgorithm* algorithm) const; virtual OEMCryptoResult OEMCrypto_GetBootCertificateChain( uint8_t* bcc, size_t* bcc_length, uint8_t* additional_signature, size_t* additional_signature_length); virtual OEMCryptoResult OEMCrypto_GenerateCertificateKeyPair( OEMCrypto_SESSION session, uint8_t* public_key, size_t* public_key_length, uint8_t* public_key_signature, size_t* public_key_signature_length, uint8_t* wrapped_private_key, size_t* wrapped_private_key_length, OEMCrypto_PrivateKeyType* key_type); virtual OEMCryptoResult OEMCrypto_InstallOemPrivateKey( OEMCrypto_SESSION session, OEMCrypto_PrivateKeyType key_type, const uint8_t* wrapped_private_key, size_t wrapped_private_key_length); virtual uint8_t OEMCrypto_Security_Patch_Level(); virtual OEMCryptoResult OEMCrypto_BuildInformation(char* buffer, size_t* buffer_length); OEMCryptoInterface(const OEMCryptoInterface&) = delete; OEMCryptoInterface& operator=(const OEMCryptoInterface&) = delete; private: class Impl; std::unique_ptr impl_; }; } // namespace wvcas #endif // OEMCRYPTO_INTERFACE_H