Support for group license

Content keys in ECM v3 can now additionally be encrypted by group
entitlement keys.
This commit is contained in:
Lu Chen
2021-03-04 14:35:08 -08:00
parent 79e39b482d
commit 62777d7d3b
66 changed files with 1275 additions and 954 deletions

View File

@@ -9,12 +9,14 @@
// Example of Simulcrypt ECMG with custom entitlement key fetcher.
#include <netinet/in.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iostream>
@@ -76,7 +78,6 @@ void ServeClient(int socket_fd, WvCasEcmgClientHandler* ecmg) {
char response[kBufferSizeBytes];
while (true) {
bzero(request, kBufferSizeBytes);
bzero(response, kBufferSizeBytes);
size_t response_length = 0;
size_t request_length = recv(socket_fd, request, kBufferSizeBytes, 0);
if (request_length == 0) {
@@ -88,12 +89,23 @@ void ServeClient(int socket_fd, WvCasEcmgClientHandler* ecmg) {
return;
}
PrintMessage("Request", request, request_length);
ecmg->HandleRequest(kBufferSizeBytes, request, kBufferSizeBytes, response,
&response_length);
PrintMessage("Response", response, response_length);
if (send(socket_fd, response, response_length, 0) < 0) {
std::cerr << "Failed to send response to client." << std::endl;
return;
size_t processed_total_length = 0;
while (processed_total_length < request_length) {
bzero(response, kBufferSizeBytes);
size_t processed_length = 0;
ecmg->HandleRequest(kBufferSizeBytes - processed_total_length,
request + processed_total_length, kBufferSizeBytes,
response, response_length, processed_length);
if (processed_length == 0) {
std::cerr << "Failed to process the request" << std::endl;
return;
}
processed_total_length += processed_length;
PrintMessage("Response", response, response_length);
if (send(socket_fd, response, response_length, 0) < 0) {
std::cerr << "Failed to send response to client" << std::endl;
return;
}
}
}
}
@@ -118,10 +130,10 @@ std::vector<EntitlementKeyInfo> MyEntitlementKeyFetcherFun(uint16_t channel_id,
constexpr char entitlement_key_id_odd[] = "fake_key_id2....";
constexpr char entitlement_key_value_odd[] =
"fakefakefakefakefakefakefake2...";
return {{track_types_hd, /*is_even_key=*/true, entitlement_key_id_even,
entitlement_key_value_even},
{track_types_hd, /*is_even_key=*/false, entitlement_key_id_odd,
entitlement_key_value_odd}};
return {{track_types_hd, /*group_id=*/"", /*is_even_key=*/true,
entitlement_key_id_even, entitlement_key_value_even},
{track_types_hd, /*group_id=*/"", /*is_even_key=*/false,
entitlement_key_id_odd, entitlement_key_value_odd}};
}
int create_listen_socket_fd() {
@@ -181,6 +193,9 @@ int main(int argc, char** argv) {
break;
}
// Ignoring SIGCHLD signal to prevent Zombie processes.
signal(SIGCHLD, SIG_IGN);
// While loop to serve different client connections.
while (true) {
struct sockaddr_in client_address;
@@ -190,7 +205,7 @@ int main(int argc, char** argv) {
&client_address_size);
std::cout << "\nTCP connection " << client_socket_fd << " start"
<< std::endl;
if (client_socket_fd < 0) {
if (client_socket_fd < 0 && errno != EINTR) {
std::cerr << "Failed to accept connection request from client"
<< std::endl;
} else {