Specify widevine/media_cas_packager_sdk/presubmit in media_cas_packager_sdk METADATA file.
------------- Moves ecm_generator to media_cas_packager_sdk/internal. ------------- Add a simple TCP server listening on a port. My intention is to use this server to support the Simulcrypt APIs (TODO). Also add a simple TCP client binary for testing the server and also demo how to call the Simulcrypt APIs (TODO). ------------- If only a single key is in the ECM, it is the EVEN key. To make the code matches this understanding, change a parameter from 'false' to 'true'. But this change has NO impact on the produced ECM, regardless this parameter is 'false' or 'true' (i.e., whether using push_front or push_back), only a single key is in the ECM. ------------- Add classes that process Simulcrypt ECMG messages 1) Stream_set-up 2) CW_provision ------------- Renames server and client binaries. ------------- Make ecmg call ecm_generator to generate ecm. The return of the ecm to Simulcrypt caller will be implemented in the next CL. For now, using the 'key' (control word) in CW_provision message also as the 'key_id'. ------------- Move common folder ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217358698
This commit is contained in:
39
example/BUILD
Normal file
39
example/BUILD
Normal file
@@ -0,0 +1,39 @@
|
||||
################################################################################
|
||||
# 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.
|
||||
################################################################################
|
||||
|
||||
# Build file for the example code.
|
||||
|
||||
package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
|
||||
filegroup(
|
||||
name = "binary_release_files",
|
||||
srcs = [
|
||||
"simulcrypt_client.cc",
|
||||
"test_simulcrypt_messages.h",
|
||||
":simulcrypt_client",
|
||||
],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "simulcrypt_client",
|
||||
srcs = ["simulcrypt_client.cc"],
|
||||
deps = [
|
||||
"//base",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "test_simulcrypt_messages",
|
||||
hdrs = ["test_simulcrypt_messages.h"],
|
||||
deps = [
|
||||
"//base",
|
||||
],
|
||||
)
|
||||
80
example/simulcrypt_client.cc
Normal file
80
example/simulcrypt_client.cc
Normal file
@@ -0,0 +1,80 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Example client that talks to server_main.
|
||||
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "gflags/gflags.h"
|
||||
#include "glog/logging.h"
|
||||
|
||||
DEFINE_string(server, "", "Server host name");
|
||||
DEFINE_int32(port, 0, "Server port number");
|
||||
|
||||
constexpr uint32_t kBufferSize = 256;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
CHECK(!FLAGS_server.empty()) << "need --server";
|
||||
CHECK(FLAGS_port != 0) << "need --port";
|
||||
|
||||
struct hostent server;
|
||||
{
|
||||
int buflen = 1024;
|
||||
char buf[1024];
|
||||
struct hostent *result;
|
||||
int h_errnop;
|
||||
gethostbyname_r(/* __name= */ FLAGS_server.c_str(),
|
||||
/* __result_buf= */ &server, /* __buf= */ buf,
|
||||
/* __buflen= */ buflen,
|
||||
/* __result= */ &result, /* __h_errnop= */ &h_errnop);
|
||||
}
|
||||
|
||||
struct sockaddr_in server_addr;
|
||||
bzero(reinterpret_cast<char *>(&server_addr), sizeof(server_addr));
|
||||
server_addr.sin_family = AF_INET;
|
||||
// TODO(user): Consider using inet_pton() to populate server_addr.sin_addr.
|
||||
bcopy(server.h_addr, reinterpret_cast<char *>(&server_addr.sin_addr.s_addr),
|
||||
server.h_length);
|
||||
server_addr.sin_port = htons(FLAGS_port);
|
||||
|
||||
int socket_fd = socket(AF_INET, SOCK_STREAM, /* protocol= */ 0);
|
||||
CHECK(socket_fd >= 0) << "failed to opening socket";
|
||||
CHECK(connect(socket_fd, (struct sockaddr *)&server_addr,
|
||||
sizeof(server_addr)) >= 0)
|
||||
<< "failed to connect to socket";
|
||||
|
||||
printf("Please enter the message: ");
|
||||
char buffer[kBufferSize];
|
||||
bzero(buffer, kBufferSize);
|
||||
fgets(buffer, kBufferSize - 1, stdin);
|
||||
int total_bytes_written = 0;
|
||||
while (total_bytes_written != strlen(buffer)) {
|
||||
int num_bytes_written = write(socket_fd, buffer, strlen(buffer));
|
||||
if (num_bytes_written < 0) {
|
||||
LOG(FATAL) << "ERROR writing to socket: " << strerror(errno);
|
||||
}
|
||||
total_bytes_written += num_bytes_written;
|
||||
}
|
||||
bzero(buffer, kBufferSize);
|
||||
if (read(socket_fd, buffer, kBufferSize - 1) < 0) {
|
||||
LOG(FATAL) << "ERROR reading from socket: " << strerror(errno);
|
||||
}
|
||||
printf("Read from buffer: %s\n", buffer);
|
||||
|
||||
close(socket_fd);
|
||||
return 0;
|
||||
}
|
||||
166
example/test_simulcrypt_messages.h
Normal file
166
example/test_simulcrypt_messages.h
Normal file
@@ -0,0 +1,166 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Example Simulcrypt messages used in unit tests and example client.
|
||||
|
||||
#ifndef MEDIA_CAS_PACKAGER_SDK_EXAMPLE_TEST_SIMULCRYPT_MESSAGES_H_
|
||||
#define MEDIA_CAS_PACKAGER_SDK_EXAMPLE_TEST_SIMULCRYPT_MESSAGES_H_
|
||||
|
||||
namespace widevine {
|
||||
namespace cas {
|
||||
|
||||
const char kTestEcmgStreamSetupMessage[] = { // protocol_version
|
||||
'\x01',
|
||||
// message_type - Stream_set-up
|
||||
'\x01', '\x01',
|
||||
// message_length
|
||||
// 18 bytes below, 3 parameters 6 bytes each
|
||||
'\x00', '\x12',
|
||||
// parameter_type - ECM_channel_id
|
||||
'\x00', '\x0e',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x01',
|
||||
// parameter_type - ECM_stream_id
|
||||
'\x00', '\x0f',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x02',
|
||||
// parameter_type - nominal_CP_duration
|
||||
'\x00', '\x10',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x03'};
|
||||
|
||||
const char kTestEcmgCwProvisionMessageWithOneCw[] = {
|
||||
// protocol_version
|
||||
'\x01',
|
||||
// message_type - CW_provision
|
||||
'\x02', '\x01',
|
||||
// message_length
|
||||
// 64 bytes below, 3 * 6 + 8 + 10 + 1 * 22 + 6
|
||||
'\x00', '\x40',
|
||||
// parameter_type - ECM_channel_id
|
||||
'\x00', '\x0e',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x01',
|
||||
// parameter_type - ECM_stream_id
|
||||
'\x00', '\x0f',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x02',
|
||||
// parameter_type - CP_number
|
||||
'\x00', '\x12',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\xa1',
|
||||
// parameter_type - access_criteria
|
||||
'\x00', '\x0d',
|
||||
// parameter_length
|
||||
'\x00', '\x04',
|
||||
// parameter_value
|
||||
'\x00', '\x00', '\x00', '\x00',
|
||||
// parameter_type - CW_encryption
|
||||
'\x00', '\x18',
|
||||
// parameter_length
|
||||
'\x00', '\x06',
|
||||
// parameter_value
|
||||
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
|
||||
// parameter_type - CP_CW_combination
|
||||
'\x00', '\x14',
|
||||
// parameter_length - 2 + 16
|
||||
'\x00', '\x12',
|
||||
// parameter_value - CP then CW
|
||||
// CP
|
||||
'\x00', '\xa1',
|
||||
// CW (16 bytes)
|
||||
'\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11',
|
||||
'\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11',
|
||||
// parameter_type - CP_duration
|
||||
'\x00', '\x13',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x0a'};
|
||||
|
||||
const char kTestEcmgCwProvisionMessageWithTwoCw[] = {
|
||||
// protocol_version
|
||||
'\x01',
|
||||
// message_type - CW_provision
|
||||
'\x02', '\x01',
|
||||
// message_length
|
||||
// 86 bytes below, 3 * 6 + 8 + 10 + 2 * 22 + 6
|
||||
'\x00', '\x56',
|
||||
// parameter_type - ECM_channel_id
|
||||
'\x00', '\x0e',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x01',
|
||||
// parameter_type - ECM_stream_id
|
||||
'\x00', '\x0f',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x02',
|
||||
// parameter_type - CP_number
|
||||
'\x00', '\x12',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\xa1',
|
||||
// parameter_type - access_criteria
|
||||
'\x00', '\x0d',
|
||||
// parameter_length
|
||||
'\x00', '\x04',
|
||||
// parameter_value
|
||||
'\x00', '\x00', '\x00', '\x00',
|
||||
// parameter_type - CW_encryption
|
||||
'\x00', '\x18',
|
||||
// parameter_length
|
||||
'\x00', '\x06',
|
||||
// parameter_value
|
||||
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
|
||||
// parameter_type - CP_CW_combination
|
||||
'\x00', '\x14',
|
||||
// parameter_length - 2 + 16
|
||||
'\x00', '\x12',
|
||||
// parameter_value - CP then CW
|
||||
// CP
|
||||
'\x00', '\xa1',
|
||||
// CW (16 bytes)
|
||||
'\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11',
|
||||
'\x11', '\x11', '\x11', '\x11', '\x11', '\x11', '\x11',
|
||||
// parameter_type - CP_CW_combination
|
||||
'\x00', '\x14',
|
||||
// parameter_length - 2 + 16
|
||||
'\x00', '\x12',
|
||||
// parameter_value - CP then CW
|
||||
// CP
|
||||
'\x00', '\xa2',
|
||||
// CW (16 bytes)
|
||||
'\x22', '\x22', '\x22', '\x22', '\x22', '\x22', '\x22', '\x22', '\x22',
|
||||
'\x22', '\x22', '\x22', '\x22', '\x22', '\x22', '\x22',
|
||||
// parameter_type - CP_duration
|
||||
'\x00', '\x13',
|
||||
// parameter_length
|
||||
'\x00', '\x02',
|
||||
// parameter_value
|
||||
'\x00', '\x0a'};
|
||||
|
||||
} // namespace cas
|
||||
} // namespace widevine
|
||||
|
||||
#endif // MEDIA_CAS_PACKAGER_SDK_EXAMPLE_TEST_SIMULCRYPT_MESSAGES_H_
|
||||
Reference in New Issue
Block a user