Update includes and BUILD

This commit is contained in:
Lu Chen
2020-02-05 11:21:51 -08:00
parent 5c42bf9b7f
commit ac564bb46f
50 changed files with 510 additions and 377 deletions

View File

@@ -60,7 +60,6 @@ cc_library(
deps = [
":wv_cas_types",
"//base",
"@abseil_repo//absl/base:core_headers",
"@abseil_repo//absl/strings",
"//common:status",
"//common:string_util",
@@ -77,7 +76,6 @@ cc_test(
srcs = ["wv_cas_ca_descriptor_test.cc"],
deps = [
":wv_cas_ca_descriptor",
":wv_cas_types",
"//testing:gunit_main",
"//protos/public:media_cas_cc_proto",
],
@@ -113,7 +111,6 @@ cc_test(
srcs = ["wv_cas_ecm_test.cc"],
deps = [
":wv_cas_ecm",
":wv_cas_types",
"//testing:gunit_main",
"@abseil_repo//absl/strings",
"//media_cas_packager_sdk/internal:mpeg2ts",
@@ -131,10 +128,9 @@ cc_library(
deps = [
"//base",
"//external:protobuf",
"@abseil_repo//absl/base:core_headers",
"@abseil_repo//absl/flags:flag",
"@abseil_repo//absl/strings",
"@curl_repo//:curl",
"//util:error_space",
"//common:signature_util",
"//common:status",
"//media_cas_packager_sdk/internal:key_fetcher",
@@ -153,7 +149,9 @@ cc_test(
"//base",
"//external:protobuf",
"//testing:gunit_main",
"@abseil_repo//absl/flags:flag",
"@abseil_repo//absl/strings",
"//common:status",
"//protos/public:media_cas_encryption_cc_proto",
],
)
@@ -189,8 +187,8 @@ cc_binary(
deps = [
":wv_cas_types",
"//base",
"@abseil_repo//absl/base:core_headers",
"@abseil_repo//absl/strings",
"@abseil_repo//absl/flags:flag",
"@abseil_repo//absl/flags:parse",
"//media_cas_packager_sdk/internal:ecmg_client_handler",
],
)
@@ -200,6 +198,8 @@ cc_binary(
srcs = ["wv_emmg.cc"],
deps = [
"//base",
"@abseil_repo//absl/flags:flag",
"@abseil_repo//absl/flags:parse",
"//media_cas_packager_sdk/internal:emmg",
],
)

View File

@@ -14,7 +14,6 @@
#include "absl/strings/str_cat.h"
#include "common/status.h"
#include "common/string_util.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
#include "protos/public/media_cas.pb.h"
namespace widevine {

View File

@@ -10,8 +10,10 @@
#define MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_CA_DESCRIPTOR_H_
#include <stddef.h>
#include <string>
#include <cstdint>
#include "media_cas_packager_sdk/public/wv_cas_types.h"
namespace widevine {

View File

@@ -8,10 +8,7 @@
#include "media_cas_packager_sdk/public/wv_cas_ca_descriptor.h"
#include <string>
#include "testing/gunit.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
#include "protos/public/media_cas.pb.h"
using ::testing::Test;

View File

@@ -8,13 +8,15 @@
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <memory>
#include <utility>
#include <vector>
#include "glog/logging.h"
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "common/crypto_util.h"
#include "common/status.h"
#include "example/constants.h"
@@ -22,7 +24,6 @@
#include "media_cas_packager_sdk/internal/fixed_key_fetcher.h"
#include "media_cas_packager_sdk/internal/mpeg2ts.h"
#include "media_cas_packager_sdk/internal/util.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
namespace widevine {
namespace cas {

View File

@@ -9,13 +9,9 @@
#ifndef MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_ECM_H_
#define MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_ECM_H_
#include <cstddef>
#include <list>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <cstdint>
#include "media_cas_packager_sdk/public/wv_cas_types.h"
namespace widevine {

View File

@@ -8,11 +8,11 @@
#include "media_cas_packager_sdk/public/wv_cas_ecm.h"
#include <string.h>
#include "testing/gunit.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "media_cas_packager_sdk/internal/mpeg2ts.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
using ::testing::Test;

View File

@@ -10,32 +10,32 @@
#include <stddef.h>
#include <string.h>
#include <string>
#include "gflags/gflags.h"
#include <cstdint>
#include "glog/logging.h"
#include "google/protobuf/util/json_util.h"
#include "absl/flags/flag.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "curl/curl.h"
#include "curl/easy.h"
#include "common/signature_util.h"
#include "common/status.h"
#include "protos/public/media_cas_encryption.pb.h"
using google::protobuf::util::JsonPrintOptions;
using google::protobuf::util::JsonStringToMessage;
using google::protobuf::util::MessageToJsonString;
DEFINE_string(
license_server, "",
"HTTP URL to the license server for making CAS encryption request");
DEFINE_string(signing_provider, "",
"Name of the provider signing the CAS encryption request");
DEFINE_string(signing_key, "",
"AES key (in hex) for signing the CAS encryption request");
DEFINE_string(signing_iv, "",
"AES iv (in hex) for signing the CAS encryption request");
ABSL_FLAG(std::string, license_server, "",
"HTTP URL to the license server for making CAS encryption request.");
ABSL_FLAG(std::string, signing_provider, "",
"Name of the provider signing the CAS encryption request.");
ABSL_FLAG(std::string, signing_key, "",
"AES key (in hex) for signing the CAS encryption request.");
ABSL_FLAG(std::string, signing_iv, "",
"AES iv (in hex) for signing the CAS encryption request.");
namespace widevine {
namespace cas {
@@ -43,8 +43,9 @@ namespace cas {
Status WvCasKeyFetcher::RequestEntitlementKey(
const std::string& request_string,
std::string* signed_response_string) const {
if (FLAGS_signing_provider.empty() || FLAGS_signing_key.empty() ||
FLAGS_signing_iv.empty()) {
if (absl::GetFlag(FLAGS_signing_provider).empty() ||
absl::GetFlag(FLAGS_signing_key).empty() ||
absl::GetFlag(FLAGS_signing_iv).empty()) {
return Status(
error::INVALID_ARGUMENT,
"Flag 'signing_provider', 'signing_key' or 'signing_iv' is empty");
@@ -73,13 +74,14 @@ Status WvCasKeyFetcher::RequestEntitlementKey(
signed_request.set_request(request_json);
std::string signature;
if (!signature_util::GenerateAesSignature(
request_json, absl::HexStringToBytes(FLAGS_signing_key),
absl::HexStringToBytes(FLAGS_signing_iv), &signature)
request_json,
absl::HexStringToBytes(absl::GetFlag(FLAGS_signing_key)),
absl::HexStringToBytes(absl::GetFlag(FLAGS_signing_iv)), &signature)
.ok()) {
return Status(error::INTERNAL, "Failed to sign the request.");
}
signed_request.set_signature(signature);
signed_request.set_signer(FLAGS_signing_provider);
signed_request.set_signer(absl::GetFlag(FLAGS_signing_provider));
std::string signed_request_json;
// NOTE: MessageToJsonString will automatically converts the 'request' and
// 'signature' fields in SignedCasEncryptionRequest to base64, because they
@@ -126,14 +128,15 @@ size_t AppendToString(void* ptr, size_t size, size_t count,
Status WvCasKeyFetcher::MakeHttpRequest(const std::string& signed_request_json,
std::string* http_response_json) const {
CHECK(http_response_json);
if (FLAGS_license_server.empty()) {
if (absl::GetFlag(FLAGS_license_server).empty()) {
return Status(error::INVALID_ARGUMENT, "Flag 'license_server' is empty");
}
CURL* curl;
CURLcode curl_code;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, FLAGS_license_server.c_str());
curl_easy_setopt(curl, CURLOPT_URL,
absl::GetFlag(FLAGS_license_server).c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, signed_request_json.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, http_response_json);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &AppendToString);

View File

@@ -11,14 +11,10 @@
#include <string>
#include "gflags/gflags.h"
#include "absl/flags/declare.h"
#include "common/status.h"
#include "media_cas_packager_sdk/internal/key_fetcher.h"
DECLARE_string(license_server);
DECLARE_string(signing_provider);
DECLARE_string(signing_key);
DECLARE_string(signing_iv);
namespace widevine {
namespace cas {
@@ -55,4 +51,10 @@ class WvCasKeyFetcher : public KeyFetcher {
} // namespace cas
} // namespace widevine
// Exposed for testing and example.
ABSL_DECLARE_FLAG(std::string, license_server);
ABSL_DECLARE_FLAG(std::string, signing_provider);
ABSL_DECLARE_FLAG(std::string, signing_key);
ABSL_DECLARE_FLAG(std::string, signing_iv);
#endif // MEDIA_CAS_PACKAGER_SDK_PUBLIC_WV_CAS_KEY_FETCHER_H_

View File

@@ -8,12 +8,13 @@
#include "media_cas_packager_sdk/public/wv_cas_key_fetcher.h"
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "google/protobuf/text_format.h"
#include "testing/gmock.h"
#include "testing/gunit.h"
#include "absl/flags/flag.h"
#include "absl/strings/escaping.h"
#include "common/status.h"
#include "protos/public/media_cas_encryption.pb.h"
using testing::_;
@@ -63,9 +64,9 @@ class WvCasKeyFetcherTest : public ::testing::Test {
public:
WvCasKeyFetcherTest() {}
void SetUp() override {
FLAGS_signing_provider = kSigningProvider;
FLAGS_signing_key = kSingingKey;
FLAGS_signing_iv = kSingingIv;
absl::SetFlag(&FLAGS_signing_provider, kSigningProvider);
absl::SetFlag(&FLAGS_signing_key, kSingingKey);
absl::SetFlag(&FLAGS_signing_iv, kSingingIv);
CHECK(
google::protobuf::TextFormat::ParseFromString(kCasEncryptionRequest, &request_));

View File

@@ -8,7 +8,6 @@
#include "media_cas_packager_sdk/public/wv_cas_types.h"
#include "testing/gmock.h"
#include "testing/gunit.h"
namespace widevine {

View File

@@ -9,6 +9,7 @@
// Widevine MediaCAS ECMG server.
#include <netinet/in.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
@@ -19,54 +20,37 @@
#include <iostream>
#include <string>
#include "gflags/gflags.h"
#include <cstdint>
#include "glog/logging.h"
#include "absl/strings/str_cat.h"
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "media_cas_packager_sdk/internal/ecmg_client_handler.h"
#include "media_cas_packager_sdk/public/wv_cas_types.h"
static constexpr int32_t kDefaultDelayStart = 200;
static constexpr int32_t kDefaultDelayStop = 200;
static constexpr int32_t kDefaultEcmRepPeriod = 100;
static constexpr int32_t kDefaultMaxCompTime = 100;
static constexpr int32_t kAccessCriteriaTransferMode = 0;
static constexpr int32_t kNumberOfContentKeys = 2;
static constexpr char kDefaultCryptoMode[] = "AesCtr";
static constexpr bool kDefaultUseFixedFetcher = false;
DEFINE_int32(port, 0, "Server port number");
ABSL_FLAG(int32_t, port, 1234, "Server port number.");
// ECMG related flags.
// TODO(user): Consider adding flags 'ac_delay_start', 'ac_delay_stop',
// 'transition_delay_start', 'transition_delay_stop'.
DEFINE_int32(
delay_start, kDefaultDelayStart,
"This flag sets the DVB SimulCrypt delay_start parameter, in milliseconds");
DEFINE_int32(
delay_stop, kDefaultDelayStop,
"This flag sets the DVB SimulCrypt delay_stop parameter, in milliseconds");
DEFINE_int32(
ecm_rep_period, kDefaultEcmRepPeriod,
"It sets the DVB SimulCrypt parameter ECM_rep_period, in milliseconds");
DEFINE_int32(
max_comp_time, kDefaultMaxCompTime,
"It sets the DVB SimulCrypt parameter max_comp_time, in milliseconds.");
DEFINE_int32(
access_criteria_transfer_mode, kAccessCriteriaTransferMode,
ABSL_FLAG(int32_t, delay_start, 200, "delay_start, in milliseconds.");
ABSL_FLAG(int32_t, delay_stop, 200, "delay_stop, in milliseconds.");
ABSL_FLAG(int32_t, ecm_rep_period, 100, "ECM_rep_period, in milliseconds.");
ABSL_FLAG(int32_t, max_comp_time, 100, "max_comp_time, in milliseconds.");
ABSL_FLAG(
int32_t, access_criteria_transfer_mode, 0,
"If it equals 0, it indicates that the access_criteria parameter is "
"required in the CW_provision message only when the contents of this "
"parameter change. If it equals 1, it indicates that the ECMG requires the "
"access_criteria parameter be present in each CW_provision message.");
DEFINE_int32(number_of_content_keys, kNumberOfContentKeys,
"It sets the number of content keys (CwPerMsg). Must be 1 (single "
"key) or 2 (key rotation enabled). It also sets LeadCw as "
"number_of_content_keys - 1.");
DEFINE_string(crypto_mode, kDefaultCryptoMode,
"Encryption mode. Choices are \"AesCtr\", \"AesCbc\", "
"\"DvbCsa2\", \"DvbCsa3\", \"AesOfb\", \"AesScte\".");
DEFINE_bool(use_fixed_fetcher, kDefaultUseFixedFetcher,
"Use fixed fetcher to fetch mocked entitlement licenses for "
"testing purposes.");
ABSL_FLAG(int32_t, number_of_content_keys, 2,
"It sets the number of content keys (CwPerMsg). Must be 1 (single "
"key) or 2 (key rotation enabled). It also sets LeadCw as "
"number_of_content_keys - 1.");
ABSL_FLAG(std::string, crypto_mode, "AesCtr",
"Encryption mode. Choices are \"AesCtr\", \"AesCbc\", "
"\"DvbCsa2\", \"DvbCsa3\", \"AesOfb\", \"AesScte\".");
ABSL_FLAG(bool, use_fixed_fetcher, false,
"If set, use fixed fetcher to fetch mocked entitlement licenses when "
"needed for testing purposes.");
#define LISTEN_QUEUE_SIZE (20)
#define BUFFER_SIZE (1024)
@@ -76,15 +60,20 @@ using widevine::cas::EcmgConfig;
void BuildEcmgConfig(EcmgConfig* config) {
DCHECK(config);
config->delay_start = FLAGS_delay_start;
config->delay_stop = FLAGS_delay_stop;
config->ecm_rep_period = FLAGS_ecm_rep_period;
config->max_comp_time = FLAGS_max_comp_time;
config->access_criteria_transfer_mode = FLAGS_access_criteria_transfer_mode;
config->number_of_content_keys = FLAGS_number_of_content_keys;
CHECK(StringToCryptoMode(FLAGS_crypto_mode, &config->crypto_mode))
config->delay_start = absl::GetFlag(FLAGS_delay_start);
config->delay_stop = absl::GetFlag(FLAGS_delay_stop);
config->ecm_rep_period = absl::GetFlag(FLAGS_ecm_rep_period);
config->max_comp_time = absl::GetFlag(FLAGS_max_comp_time);
config->access_criteria_transfer_mode =
absl::GetFlag(FLAGS_access_criteria_transfer_mode);
CHECK(absl::GetFlag(FLAGS_number_of_content_keys) == 1 ||
absl::GetFlag(FLAGS_number_of_content_keys) == 2)
<< "--number_of_content_keys must be 1 or 2.";
config->number_of_content_keys = absl::GetFlag(FLAGS_number_of_content_keys);
CHECK(StringToCryptoMode(absl::GetFlag(FLAGS_crypto_mode),
&config->crypto_mode))
<< "Unknown crypto mode.";
config->use_fixed_fetcher = FLAGS_use_fixed_fetcher;
config->use_fixed_fetcher = absl::GetFlag(FLAGS_use_fixed_fetcher);
}
void PrintMessage(const std::string& description, const char* const message,
@@ -126,11 +115,7 @@ void ServeClient(int socket_fd, EcmgClientHandler* ecmg) {
}
int main(int argc, char** argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
CHECK(FLAGS_port != 0) << "need --port";
CHECK(FLAGS_number_of_content_keys == 1 || FLAGS_number_of_content_keys == 2)
<< "--number_of_content_keys must be 1 or 2.";
absl::ParseCommandLine(argc, argv);
EcmgConfig ecmg_config;
BuildEcmgConfig(&ecmg_config);
@@ -139,7 +124,7 @@ int main(int argc, char** argv) {
bzero(reinterpret_cast<char*>(&server_address), sizeof(server_address));
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl(INADDR_ANY);
server_address.sin_port = htons(FLAGS_port);
server_address.sin_port = htons(absl::GetFlag(FLAGS_port));
// Create a listening socket.
int listen_socket_fd = socket(AF_INET, SOCK_STREAM, /* protocol= */ 0);

View File

@@ -12,54 +12,69 @@
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cstring>
#include "gflags/gflags.h"
#include <cstring>
#include <string>
#include <cstdint>
#include "glog/logging.h"
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "media_cas_packager_sdk/internal/emmg.h"
DEFINE_string(mux_address, "", "Mux server address");
DEFINE_int32(mux_port, 0, "Mux server port number");
// EMMG specfic configs.
DEFINE_int32(client_id, 0, "EMMG client_id");
DEFINE_int32(section_tspkt_flag, 1, "EMMG section_tspkt_flag");
DEFINE_int32(data_channel_id, 0, "EMMG data_channel_id");
DEFINE_int32(data_stream_id, 0, "EMMG data_stream_id");
DEFINE_int32(data_id, 0, "EMMG data_id");
ABSL_FLAG(std::string, mux_address, "", "Mux server address.");
ABSL_FLAG(int32_t, mux_port, 0, "Mux server port number.");
// EMMG specific configs.
// To facilitate uniqueness of client_id, the following rules apply:
// in the case of EMMs or other CA related data, the two first bytes of the
// client_id should be equal to the two bytes of the corresponding CA_system_id.
ABSL_FLAG(int32_t, client_id, 0x4AD40000, "EMMG client_id.");
// TODO(user): Currently it can only support section_tspkt_flag = 1.
ABSL_FLAG(int32_t, section_tspkt_flag, 1,
"EMMG section_tspkt_flag. Currently it can only be set to 1.");
ABSL_FLAG(int32_t, data_channel_id, 0, "EMMG data_channel_id.");
ABSL_FLAG(int32_t, data_stream_id, 0, "EMMG data_stream_id.");
ABSL_FLAG(int32_t, data_id, 0, "EMMG data_id.");
// data_type: type of data carried in the datagram in the stream:
// 0x00: EMM;
// 0x01: private data;
// 0x02: DVB reserved (ECM);
// other values: DVB reserved.
DEFINE_int32(data_type, 0, "EMMG data_type");
ABSL_FLAG(int32_t, data_type, 1, "EMMG data_type");
ABSL_FLAG(std::string, content_provider, "", "Content provider");
ABSL_FLAG(std::string, content_id, "", "Content id");
#define BUFFER_SIZE (1024)
void BuildEmmgConfig(widevine::cas::EmmgConfig *config) {
CHECK(config);
config->client_id = FLAGS_client_id;
config->section_tspkt_flag = FLAGS_section_tspkt_flag;
config->data_channel_id = FLAGS_data_channel_id;
config->data_stream_id = FLAGS_data_stream_id;
config->data_id = FLAGS_data_id;
config->data_type = FLAGS_data_type;
config->client_id = absl::GetFlag(FLAGS_client_id);
config->section_tspkt_flag = absl::GetFlag(FLAGS_section_tspkt_flag);
config->data_channel_id = absl::GetFlag(FLAGS_data_channel_id);
config->data_stream_id = absl::GetFlag(FLAGS_data_stream_id);
config->data_id = absl::GetFlag(FLAGS_data_id);
config->data_type = absl::GetFlag(FLAGS_data_type);
config->content_provider = absl::GetFlag(FLAGS_content_provider);
config->content_id = absl::GetFlag(FLAGS_content_id);
}
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
CHECK(!FLAGS_mux_address.empty()) << "flag --mux_address is required";
CHECK(FLAGS_mux_port != 0) << "flag --mux_port is required";
absl::ParseCommandLine(argc, argv);
CHECK(!absl::GetFlag(FLAGS_mux_address).empty())
<< "flag --mux_address is required";
CHECK(absl::GetFlag(FLAGS_mux_port) != 0) << "flag --mux_port is required";
// Create server address.
struct hostent ret;
struct hostent *server;
char buffer[BUFFER_SIZE];
int h_errnop = 0;
int return_val = gethostbyname_r(FLAGS_mux_address.c_str(), &ret, buffer,
sizeof(buffer), &server, &h_errnop);
int return_val =
gethostbyname_r(absl::GetFlag(FLAGS_mux_address).c_str(), &ret, buffer,
sizeof(buffer), &server, &h_errnop);
if (return_val != 0 || server == nullptr) {
LOG(FATAL) << "gethostbyname_r failed for " << FLAGS_mux_address;
LOG(FATAL) << "gethostbyname_r failed for "
<< absl::GetFlag(FLAGS_mux_address);
}
struct sockaddr_in server_address;
bzero(reinterpret_cast<char *>(&server_address), sizeof(server_address));
@@ -67,7 +82,7 @@ int main(int argc, char **argv) {
bcopy(server->h_addr,
reinterpret_cast<char *>(&server_address.sin_addr.s_addr),
server->h_length);
server_address.sin_port = htons(FLAGS_mux_port);
server_address.sin_port = htons(absl::GetFlag(FLAGS_mux_port));
// Connect to server.
int server_socket_fd = socket(AF_INET, SOCK_STREAM, 0);