Files
ce_cdm/core/test/provisioning_holder.h
Googler 6d36a0c93d Source release 19.6.0
GitOrigin-RevId: 13a33e34413c19da1bfe76abcc66be519c9ac9d1
2025-06-09 23:44:53 -07:00

105 lines
3.9 KiB
C++

// Copyright 2023 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine License
// Agreement.
#ifndef WVCDM_CORE_TEST_PROVISIONING_HOLDER_H_
#define WVCDM_CORE_TEST_PROVISIONING_HOLDER_H_
#include "test_base.h"
#include <string>
namespace wvcdm {
class ProvisioningHolder {
public:
ProvisioningHolder(TestCdmEngine* cdm_engine, const ConfigTestEnv& config)
: cdm_engine_(cdm_engine),
config_(config),
provisioning_server_url_(config.provisioning_server()),
provisioning_service_certificate_(
config.provisioning_service_certificate()) {}
// Generates requests, fetches response, and loads response.
void Provision(CdmCertificateType cert_type, bool binary_provisioning);
void Provision(bool binary_provisioning) {
Provision(kCertificateWidevine, binary_provisioning);
}
// Generates a provisioning request from the |cdm_engine_|.
// If successful, the request the stored in |request_|.
// The result of |request_| should always be the URL-Safe-Base64
// encoded value of the request.
void GenerateRequest(CdmCertificateType cert_type, bool binary_provisioning);
void GenerateRequest(bool binary_provisioning) {
GenerateRequest(kCertificateWidevine, binary_provisioning);
}
// Fetch the provisioning response from the server.
// Uses |request_| as the source of the request, and stores
// JSON message of the response to |response_|.
void FetchResponse();
// Loads the response into the |cdm_engine_|, expecting success.
void LoadResponse(bool binary_provisioning);
// Loads the response into the |cdm_engine_|, returning the
// result from CDM.
CdmResponseType LoadResponseReturnStatus(bool binary_provisioning);
const std::string& request() const { return request_; }
// Sets the request to be used on next call to FetchResponse().
// The provided |request| must be a URL-Safe-Base64 encoding
// of the provisioning request.
void set_request(const std::string& request) { request_ = request; }
const std::string& response() const { return response_; }
const std::string& certificate() const { return certificate_; }
const std::string& wrapped_key() const { return wrapped_key_; }
void ClearProvisioningData() {
cert_type_ = kCertificateWidevine;
request_.clear();
response_.clear();
certificate_.clear();
wrapped_key_.clear();
}
void set_log_core_message(bool log_core_message) {
log_core_message_ = log_core_message;
}
protected:
TestCdmEngine* cdm_engine_;
// Config variables.
const ConfigTestEnv& config_;
std::string provisioning_server_url_;
std::string provisioning_service_certificate_;
// Request variables.
CdmCertificateType cert_type_;
std::string request_; // URL-Safe-Base64 encoding of request.
// Response variables.
std::string response_; // JSON message containing response.
// Post-provisioning variables.
std::string certificate_;
std::string wrapped_key_;
// Locate the portion of the server's provisioning response message that is
// between the strings jason_start_substr and json_end_substr. Returns the
// string through *result. If the start substring match fails, assume the
// entire string represents a serialized protobuf mesaage and return true with
// the entire string. If the end_substring match fails, return false with an
// empty *result.
static bool ExtractSignedMessage(const std::string& response,
std::string* result);
// Dump request and response information for use in a debug or failure log.
std::string DumpProvAttempt(const std::string& request,
const std::string& response,
CdmCertificateType cert_type) const;
private:
bool log_core_message_ = false;
};
} // namespace wvcdm
#endif // WVCDM_CORE_TEST_PROVISIONING_HOLDER_H_