// Copyright 2020 Google LLC. All Rights Reserved. #ifndef WHITEBOX_API_LICENSE_BUILDER_H_ #define WHITEBOX_API_LICENSE_BUILDER_H_ #include #include #include #include "cdm/protos/license_protocol.pb.h" #include "crypto_utils/rsa_key.h" namespace widevine { struct License { std::vector request; std::vector message; std::vector signature; // |session_key_| encrypted using the public key. The white-box expects the // session key to be encrypted, so we use the name "session_key_" (even if it // is encrypted), we omit the term "encrypted" to match the naming in the API. std::vector session_key; }; class TestLicenseBuilder { public: enum class RemoteAttestation { kUnavailable, kVerified, kUnverified, }; enum class VerificationStatus { kUnavailable, kHardwareVerified, kOther, }; // Returns padding data the can be used as |padding| when calling // AddSigningKey() or AddContentKey(). static std::vector NoPadding(); static std::vector PKSC8Padding(); // Returns a default signing key that can be used with AddSigningKey(). static std::vector DefaultSigningKey(); TestLicenseBuilder(); void AddSigningKey(const std::vector& key, const std::vector& padding = NoPadding()); // Add a content key so that there is some key in the license. This should not // be used with AddContentKey(). void AddStubbedContentKey(); void AddContentKey(video_widevine::License_KeyContainer_SecurityLevel level, const std::vector& key_id, const std::vector& key, const std::vector& padding = NoPadding()); // The key id will matter as we will need to reference it, but the key won't // matter since we are only using it as a means to verify that a non-content // key can't be used as a content key. void AddOperatorSessionKey(const std::vector& key_id); void SetRemoteAttestation(RemoteAttestation setting); void SetVerificationStatus(VerificationStatus setting); // Gets the serialized license request and response (in components) that would // have been used in the license exchange. void Build(const RsaPublicKey& public_key, License* license) const; private: const std::string session_key_ = "0123456789ABCDEF"; video_widevine::LicenseRequest request_; video_widevine::License response_; std::string serialized_request_; std::string container_key_; }; } // namespace widevine #endif // WHITEBOX_API_LICENSE_BUILDER_H_