//////////////////////////////////////////////////////////////////////////////// // Copyright 2018 Google LLC. // // This software is licensed under the terms defined in the Widevine Master // License Agreement. For a copy of this agreement, please contact // widevine-licensing@google.com. //////////////////////////////////////////////////////////////////////////////// #include #include #include "gflags/gflags.h" #include "glog/logging.h" #include "common/status.h" #include "media_cas_packager_sdk/public/wv_cas_key_fetcher.h" #include "protos/public/media_cas_encryption.pb.h" DEFINE_string(content_id, "21140844", "Content ID"); DEFINE_bool(key_rotation, true, "Whether key rotation is enabled"); DEFINE_string(track_type, "SD", "Provider name"); int main(int argc, char **argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); CHECK(!FLAGS_content_id.empty() && !FLAGS_track_type.empty()) << "Flags 'content_id' and 'track_type' are required"; // Required flags in key fetcher. CHECK(!FLAGS_license_server.empty() && !FLAGS_signing_provider.empty() && !FLAGS_signing_key.empty() && !FLAGS_signing_iv.empty()) << "Flags 'license_server', 'signing_provider', 'signing_key' " "and 'signing_iv' are required"; std::string request_str; widevine::CasEncryptionRequest request; request.set_provider(FLAGS_signing_provider); request.set_content_id(FLAGS_content_id); request.set_key_rotation(FLAGS_key_rotation); // Only 1 track in this example. request.add_track_types(FLAGS_track_type); LOG(INFO) << "Request: " << request.ShortDebugString(); if (!request.SerializeToString(&request_str)) { LOG(ERROR) << "Failed to serialize request"; return -1; } std::string signed_response_str; widevine::cas::WvCasKeyFetcher key_fetcher; widevine::Status status = key_fetcher.RequestEntitlementKey(request_str, &signed_response_str); if (!status.ok()) { LOG(ERROR) << "Failed to request entitlement key"; return -1; } widevine::SignedCasEncryptionResponse signed_response; if (!signed_response.ParseFromString(signed_response_str)) { LOG(ERROR) << "Failed to deserialize signed response"; return -1; } LOG(INFO) << "Signed response: " << signed_response.ShortDebugString(); widevine::CasEncryptionResponse response; if (!response.ParseFromString(signed_response.response())) { LOG(ERROR) << "Failed to deserialize response"; return -1; } LOG(INFO) << "Response: " << response.ShortDebugString(); return 0; }