1) Change return type to WvCasStatus for functions in wv_cas_types.cc.
2) Add a binary wv_cas_types_example. 3) Surface wv_cas_key_fetcher *source code* to partner to serve as an example of how they would make a HTTP request to acquire an entitlement key from license server. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=229953562
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
|
||||
const char kTestChannelSetup[] = {
|
||||
const char kTestEcmgChannelSetup[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x00', '\x01', // message_type - Channel_setup
|
||||
'\x00', '\x0e', // message_length
|
||||
@@ -26,7 +26,7 @@ const char kTestChannelSetup[] = {
|
||||
'\x4a', '\xd4', '\x00', '\x00' // parameter_value
|
||||
};
|
||||
|
||||
const char kTestChannelStatus[] = {
|
||||
const char kTestEcmgChannelStatus[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x00', '\x03', // message_type - Channel_status
|
||||
'\x00', '\x39', // message_length
|
||||
@@ -62,7 +62,7 @@ const char kTestChannelStatus[] = {
|
||||
'\x00', '\x64' // parameter_value
|
||||
};
|
||||
|
||||
const char kTestStreamSetup[] = {
|
||||
const char kTestEcmgStreamSetup[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x01', '\x01', // message_type - Stream_setup
|
||||
'\x00', '\x18', // message_length
|
||||
@@ -80,7 +80,7 @@ const char kTestStreamSetup[] = {
|
||||
'\x00', '\x64' // parameter_value
|
||||
};
|
||||
|
||||
const char kTestStreamStatus[] = {
|
||||
const char kTestEcmgStreamStatus[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x01', '\x03', // message_type - Stream_status
|
||||
'\x00', '\x17', // message_length
|
||||
@@ -98,7 +98,7 @@ const char kTestStreamStatus[] = {
|
||||
'\x01' // parameter_value
|
||||
};
|
||||
|
||||
const char kTestCwProvision[] = {
|
||||
const char kTestEcmgCwProvision[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x02', '\x01', // message_type - CW_provision
|
||||
'\x00', '\x44', // message_length
|
||||
@@ -126,7 +126,7 @@ const char kTestCwProvision[] = {
|
||||
'\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f'};
|
||||
|
||||
// CW is encrypted using hardcoded fixed entitlement key.
|
||||
const char kTestEcmResponse[] = {
|
||||
const char kTestEcmgEcmResponse[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x02', '\x02', // message_type - ECM_response
|
||||
'\x00', '\xd2', // message_length
|
||||
@@ -164,7 +164,7 @@ const char kTestEcmResponse[] = {
|
||||
'\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff',
|
||||
'\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff', '\xff'};
|
||||
|
||||
const char kTestStreamCloseRequest[] = {
|
||||
const char kTestEcmgStreamCloseRequest[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x01', '\x04', // message_type - Stream_close_request
|
||||
'\x00', '\x0c', // message_length
|
||||
@@ -176,7 +176,7 @@ const char kTestStreamCloseRequest[] = {
|
||||
'\x00', '\x01' // parameter_value
|
||||
};
|
||||
|
||||
const char kTestStreamCloseResponse[] = {
|
||||
const char kTestEcmgStreamCloseResponse[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x01', '\x05', // message_type - Stream_close_response
|
||||
'\x00', '\x0c', // message_length
|
||||
@@ -188,7 +188,7 @@ const char kTestStreamCloseResponse[] = {
|
||||
'\x00', '\x01' // parameter_value
|
||||
};
|
||||
|
||||
const char kTestChannelClose[] = {
|
||||
const char kTestEcmgChannelClose[] = {
|
||||
'\x03', // protocol_version
|
||||
'\x00', '\x04', // message_type - Channel_close
|
||||
'\x00', '\x06', // message_length
|
||||
|
||||
Binary file not shown.
@@ -8,12 +8,23 @@
|
||||
|
||||
// Example of how to use the wv_cas_ecm library.
|
||||
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "gflags/gflags.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
DEFINE_int32(content_iv_size, 8, "Content IV size");
|
||||
DEFINE_bool(key_rotation, true, "Whether key rotation is enabled");
|
||||
DEFINE_string(crypto_mode, "CSA2", "Only CBC, CTR, or CSA2 is allowed");
|
||||
DEFINE_int32(ecm_pid, 149, "PID for the ECM packet");
|
||||
DEFINE_string(output_file, "",
|
||||
"If specified, generated ECM TS packet will be written to the "
|
||||
"specified output file path");
|
||||
|
||||
const char kCsaEvenKey[] = "even_key"; // 8 bytes
|
||||
const char kEvenContentIv8Bytes[] = "even_iv."; // 8 bytes
|
||||
const char kEvenEntitlementKeyId[] = "fake_key_id1...."; // 16 bytes
|
||||
@@ -24,26 +35,45 @@ const char kOddContentIv8Bytes[] = "odd_iv.."; // 8 bytes
|
||||
const char kOddEntitlementKeyId[] = "fake_key_id2...."; // 16 bytes
|
||||
const char kOddEntitlementKey[] =
|
||||
"fakefakefakefakefakefakefake2..."; // 32 bytes
|
||||
const size_t kTsPacketSize = 188;
|
||||
|
||||
widevine::cas::CryptoMode GetCryptoMode() {
|
||||
if (FLAGS_crypto_mode.compare("CBC") == 0) {
|
||||
return widevine::cas::CryptoMode::kAesCbc;
|
||||
}
|
||||
if (FLAGS_crypto_mode.compare("CTR") == 0) {
|
||||
return widevine::cas::CryptoMode::kAesCtr;
|
||||
}
|
||||
return widevine::cas::CryptoMode::kDvbCsa2;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
// Generate ECM.
|
||||
widevine::cas::WvCasEcm wv_cas_ecm;
|
||||
widevine::cas::WvCasStatus status = wv_cas_ecm.Initialize(
|
||||
/* content_iv_size= */ 8, /* key_rotation_enabled= */ true,
|
||||
widevine::cas::CryptoMode::kDvbCsa2);
|
||||
FLAGS_content_iv_size, FLAGS_key_rotation, GetCryptoMode());
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to initialize WV CAS ECM, error: "
|
||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
||||
<< std::endl;
|
||||
}
|
||||
std::string ecm;
|
||||
status = wv_cas_ecm.GenerateEcm(
|
||||
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
||||
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
||||
kOddEntitlementKeyId, kOddEntitlementKey, &ecm);
|
||||
if (FLAGS_key_rotation) {
|
||||
status = wv_cas_ecm.GenerateEcm(
|
||||
kCsaEvenKey, kEvenContentIv8Bytes, kEvenEntitlementKeyId,
|
||||
kEvenEntitlementKey, kCsaOddKey, kOddContentIv8Bytes,
|
||||
kOddEntitlementKeyId, kOddEntitlementKey, &ecm);
|
||||
} else {
|
||||
status = wv_cas_ecm.GenerateSingleKeyEcm(kCsaEvenKey, kEvenContentIv8Bytes,
|
||||
kEvenEntitlementKeyId,
|
||||
kEvenEntitlementKey, &ecm);
|
||||
}
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to generate WV CAS ECM, error: "
|
||||
<< widevine::cas::GetWvCasStatusMessage(status)
|
||||
<< std::endl;
|
||||
return -1;
|
||||
} else {
|
||||
std::cout << "ECM size: " << ecm.size() << std::endl;
|
||||
std::cout << "ECM bytes: ";
|
||||
@@ -52,6 +82,30 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
// Generate ECM TS Packet.
|
||||
uint8_t packet[kTsPacketSize];
|
||||
uint8_t continuity_counter; // not used.
|
||||
status = wv_cas_ecm.GenerateTsPacket(ecm, FLAGS_ecm_pid,
|
||||
/* table_id= */ 0x80,
|
||||
&continuity_counter, packet);
|
||||
if (status != widevine::cas::OK) {
|
||||
std::cerr << "Failed to create ECM TS packet" << std::endl;
|
||||
return -1;
|
||||
} else {
|
||||
std::cout << "TS packet bytes: ";
|
||||
for (size_t i = 0; i < kTsPacketSize; i++) {
|
||||
printf("'\\x%02x', ", static_cast<uint16_t>(packet[i]));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
// Write ECM TS Packet to a file.
|
||||
if (!FLAGS_output_file.empty()) {
|
||||
std::ofstream file;
|
||||
file.open(FLAGS_output_file.c_str(), std::ios_base::binary);
|
||||
assert(file.is_open());
|
||||
file.write(reinterpret_cast<char *>(packet), kTsPacketSize);
|
||||
file.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
example/wv_cas_types_example
Normal file
BIN
example/wv_cas_types_example
Normal file
Binary file not shown.
37
example/wv_cas_types_example.cc
Normal file
37
example/wv_cas_types_example.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2019 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.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Example of how to use types/functions in wv_cas_types.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gflags/gflags.h"
|
||||
#include "glog/logging.h"
|
||||
#include "media_cas_packager_sdk/public/wv_cas_types.h"
|
||||
|
||||
DEFINE_string(function_to_call, "CreateWvCasEncryptionRequestJson",
|
||||
"Function in wv_cas_types to exercise");
|
||||
|
||||
void CallCreateWvCasEncryptionRequestJson() {
|
||||
widevine::cas::WvCasEncryptionRequest request;
|
||||
request.content_id = "cont_id cont_id ";
|
||||
request.provider = "widevine_test";
|
||||
request.track_types = {"SD"};
|
||||
request.key_rotation = true;
|
||||
std::string request_json;
|
||||
widevine::cas::CreateWvCasEncryptionRequestJson(request, &request_json);
|
||||
LOG(INFO) << FLAGS_function_to_call << " returns " << request_json;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
if (FLAGS_function_to_call.compare("CreateWvCasEncryptionRequestJson") == 0) {
|
||||
CallCreateWvCasEncryptionRequestJson();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user