Tools release: 1.2.0
This commit is contained in:
@@ -103,65 +103,29 @@ maven_install(
|
||||
)
|
||||
|
||||
# GRPC
|
||||
git_repository(
|
||||
http_archive(
|
||||
name = "io_grpc_grpc_java",
|
||||
remote = "https://github.com/grpc/grpc-java.git",
|
||||
tag = "v1.23.0",
|
||||
strip_prefix = "grpc-java-1.36.0",
|
||||
url = "https://github.com/grpc/grpc-java/archive/v1.36.0.zip",
|
||||
)
|
||||
|
||||
# GRPC Core
|
||||
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS")
|
||||
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS")
|
||||
|
||||
maven_install(
|
||||
name = "grpc_core",
|
||||
artifacts = ["io.grpc:grpc-core:1.23.0"],
|
||||
artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS,
|
||||
generate_compat_repositories = True,
|
||||
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
"https://repo.maven.apache.org/maven2/",
|
||||
],
|
||||
)
|
||||
|
||||
# GRPC Netty
|
||||
maven_install(
|
||||
name = "grpc_netty",
|
||||
artifacts = ["io.grpc:grpc-netty:1.23.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
load("@maven//:compat.bzl", "compat_repositories")
|
||||
compat_repositories()
|
||||
|
||||
maven_install(
|
||||
name = "grpc_netty_all",
|
||||
artifacts = ["io.netty:netty-all:4.1.41.Final"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
# GRPC Stub
|
||||
maven_install(
|
||||
name = "grpc_stub",
|
||||
artifacts = ["io.grpc:grpc-stub:1.23.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
# GRPC Contenxt
|
||||
maven_install(
|
||||
name = "grpc_context",
|
||||
artifacts = ["io.grpc:grpc-context:1.18.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
|
||||
grpc_java_repositories()
|
||||
|
||||
# GSON
|
||||
maven_install(
|
||||
@@ -174,80 +138,6 @@ maven_install(
|
||||
],
|
||||
)
|
||||
|
||||
# Netty TcNative (for GRPC)
|
||||
maven_install(
|
||||
name = "netty_tcnative",
|
||||
artifacts = ["io.netty:netty-tcnative:2.0.25.Final"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
# Netty BoringSSL
|
||||
maven_install(
|
||||
name = "netty_boringssl",
|
||||
artifacts = ["io.netty:netty-tcnative-boringssl-static:2.0.25.Final"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
# Open Census (for GRPC)
|
||||
maven_install(
|
||||
name = "open_census_api",
|
||||
artifacts = ["io.opencensus:opencensus-api:0.24.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
maven_install(
|
||||
name = "open_census",
|
||||
artifacts = ["io.opencensus:opencensus-contrib-http-jetty-client:0.19.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
maven_install(
|
||||
name = "open_census_util",
|
||||
artifacts = ["io.opencensus:opencensus-contrib-http-util:0.19.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
maven_install(
|
||||
name = "open_census_grpc_metrics",
|
||||
artifacts = ["io.opencensus:opencensus-contrib-grpc-metrics:0.24.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
# Perfmark (GRPC)
|
||||
maven_install(
|
||||
name = "io_perfmark_api",
|
||||
artifacts = ["io.perfmark:perfmark-api:0.17.0"],
|
||||
repositories = [
|
||||
"https://jcenter.bintray.com",
|
||||
"https://maven.google.com",
|
||||
"https://repo1.maven.org/maven2",
|
||||
],
|
||||
)
|
||||
|
||||
# Google Protobuf Protos
|
||||
PROTOBUF_BUILD_FILE = """
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
@@ -361,9 +251,5 @@ bind(
|
||||
actual = "@com_google_protobuf//:protobuf_java",
|
||||
)
|
||||
|
||||
# Loads necessary bazel rules for later consumption.
|
||||
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
|
||||
grpc_java_repositories()
|
||||
|
||||
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
|
||||
protobuf_deps()
|
||||
|
||||
@@ -28,7 +28,6 @@ proto_library(
|
||||
java_proto_library(
|
||||
name = "published_devices_java_proto",
|
||||
deps = [":published_devices_proto"],
|
||||
|
||||
)
|
||||
|
||||
java_grpc_library(
|
||||
@@ -38,3 +37,8 @@ java_grpc_library(
|
||||
":published_devices_java_proto",
|
||||
],
|
||||
)
|
||||
|
||||
java_proto_library(
|
||||
name = "device_security_profiles_java_proto",
|
||||
deps = [":device_security_profiles_proto"],
|
||||
)
|
||||
|
||||
@@ -91,4 +91,6 @@ enum HashAlgorithm {
|
||||
HASH_ALGORITHM_SHA_1 = 1;
|
||||
// Secure Hash Algorithm 2 256 bits (SHA-256).
|
||||
HASH_ALGORITHM_SHA_256 = 2;
|
||||
// Secure Hash Algorithm 2 384 bits (SHA-384).
|
||||
HASH_ALGORITHM_SHA_384 = 3;
|
||||
}
|
||||
|
||||
0
tools/source/published_devices_client/google/chrome/widevine/contentpartners/v1beta1/published_devices.proto
Executable file → Normal file
0
tools/source/published_devices_client/google/chrome/widevine/contentpartners/v1beta1/published_devices.proto
Executable file → Normal file
@@ -10,6 +10,7 @@ java_library(
|
||||
name = "interfaces",
|
||||
srcs = glob(["*.java"]),
|
||||
deps = [
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:device_security_profiles_java_proto",
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_java_proto",
|
||||
"@com_google_protobuf//:protobuf_java",
|
||||
"@apache_httpcore//:org_apache_httpcomponents_httpcore",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2020 Google LLC. All rights reserved.
|
||||
package com.google.video.widevine.jts.interfaces;
|
||||
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.SignedDeviceSecurityProfiles;
|
||||
|
||||
/** DeviceSecurityProfile defines APIs for getting Signed Device Security Profile list. */
|
||||
public interface DeviceSecurityProfile {
|
||||
|
||||
/**
|
||||
* Get the latest {@code SignedDeviceSecurityProfiles} containing Device Security Profile list
|
||||
* data.
|
||||
*
|
||||
* @return {@code SignedDeviceSecurityProfiles} containing Device Security Profile list data.
|
||||
*/
|
||||
public SignedDeviceSecurityProfiles getSignedDeviceSecurityProfiles() throws Exception;
|
||||
}
|
||||
@@ -9,29 +9,24 @@ package(
|
||||
java_library(
|
||||
name = "providers",
|
||||
srcs = glob(["*.java"]),
|
||||
runtime_deps = [
|
||||
"@grpc_context//:io_grpc_grpc_context",
|
||||
"@grpc_netty_all//:io_netty_netty_all",
|
||||
"@io_perfmark_api//:io_perfmark_perfmark_api",
|
||||
"@netty_boringssl//:io_netty_netty_tcnative_boringssl_static",
|
||||
"@open_census//:io_opencensus_opencensus_contrib_http_jetty_client",
|
||||
"@open_census_api//:io_opencensus_opencensus_api",
|
||||
"@open_census_grpc_metrics//:io_opencensus_opencensus_contrib_grpc_metrics",
|
||||
"@open_census_util//:io_opencensus_opencensus_contrib_http_util",
|
||||
],
|
||||
deps = [
|
||||
":libwvpl_cas_proxy_sdk_lib.jar",
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:device_security_profiles_java_proto",
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_grpc",
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_java_proto",
|
||||
"//httpclient",
|
||||
"//interfaces",
|
||||
"@google_guice//:com_google_inject_guice",
|
||||
"@json//:org_json_json",
|
||||
"@jsr305_annotations//:com_google_code_findbugs_jsr305",
|
||||
"@com_google_protobuf//:protobuf_java",
|
||||
"@google_guava//:com_google_guava_guava",
|
||||
"@grpc_core//:io_grpc_grpc_core",
|
||||
"@grpc_netty//:io_grpc_grpc_netty",
|
||||
"@grpc_stub//:io_grpc_grpc_stub",
|
||||
"@io_grpc_grpc_java//api",
|
||||
"@io_grpc_grpc_java//netty",
|
||||
"@io_grpc_grpc_java//protobuf",
|
||||
"@io_grpc_grpc_java//stub",
|
||||
"@maven//:com_google_api_grpc_proto_google_common_protos",
|
||||
"@maven//:com_google_code_findbugs_jsr305",
|
||||
"@maven//:com_google_code_gson_gson",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
package com.google.video.widevine.jts.providers;
|
||||
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.DeviceSecurityProfileCriteria;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.ListDeviceSecurityProfilesRequest;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevices;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevicesRequest;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevicesServiceGrpc;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.SignedDeviceSecurityProfiles;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.protobuf.ExtensionRegistry;
|
||||
import com.google.protobuf.TextFormat;
|
||||
import com.google.video.widevine.jts.httpclient.Credentials;
|
||||
import com.google.video.widevine.jts.interfaces.DeviceCertificate;
|
||||
import com.google.video.widevine.jts.interfaces.DeviceSecurityProfile;
|
||||
import com.google.video.widevine.sdk.wvpl.WvPLBaseEnvironment;
|
||||
import com.google.video.widevine.sdk.wvpl.WvPLStatusException;
|
||||
import io.grpc.ManagedChannel;
|
||||
@@ -19,18 +24,22 @@ import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Provides the latest {@code PublishedDevices} data from the Widevine Published Devices Service.
|
||||
* Provides the latest {@code PublishedDevices} or {@code SignedDeviceSecurityProfiles} data from
|
||||
* the Widevine Published Devices Service.
|
||||
*
|
||||
* This implementation uses the Widevine Published Devices API, and support a gRPC method for
|
||||
* retrieving PublishedDevices with an embedded Published Devices list.
|
||||
* <p>This implementation uses the Widevine Published Devices API, and support a gRPC method for
|
||||
* retrieving PublishedDevices with an embedded Published Devices list, or Device Security Profiles
|
||||
* list.
|
||||
*/
|
||||
public class PublishedDevicesProvider implements DeviceCertificate {
|
||||
public class PublishedDevicesProvider implements DeviceCertificate, DeviceSecurityProfile {
|
||||
private static final Logger logger = Logger.getLogger(PublishedDevicesProvider.class.getName());
|
||||
private WvPLBaseEnvironment<?> environment = null;
|
||||
private String apiServicePath = null;
|
||||
private Credentials credentials = null;
|
||||
private String provider = null;
|
||||
|
||||
/**
|
||||
* PublishedDevicesProvider constructor.
|
||||
@@ -38,15 +47,21 @@ public class PublishedDevicesProvider implements DeviceCertificate {
|
||||
* @param environment A WvPLBaseEnvironment object initialized with a Service Certificate.
|
||||
* @param serviceAccountPath Path to a GCP Service Account json file, used in OAUTH.
|
||||
* @param apiServicePath Path to a Widevine Published Devices API service.
|
||||
* @param provider Provider name, necessary for creating ListDSP request. It could be null if it
|
||||
* is not used by dsps.
|
||||
* @throws IOException upon failure creating OAUTH credentials.
|
||||
*/
|
||||
@Inject
|
||||
public PublishedDevicesProvider(
|
||||
WvPLBaseEnvironment<?> environment, String serviceAccountPath, String apiServicePath)
|
||||
WvPLBaseEnvironment<?> environment,
|
||||
String serviceAccountPath,
|
||||
String apiServicePath,
|
||||
@Nullable String provider)
|
||||
throws IOException {
|
||||
this.environment = environment;
|
||||
this.apiServicePath = apiServicePath;
|
||||
credentials = new Credentials(serviceAccountPath);
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +72,7 @@ public class PublishedDevicesProvider implements DeviceCertificate {
|
||||
* @throws WvPLStatusException upon WvPLBaseEnvironment errors.
|
||||
*/
|
||||
@Override
|
||||
public PublishedDevices getPublishedDevices() throws InterruptedException, WvPLStatusException{
|
||||
public PublishedDevices getPublishedDevices() throws InterruptedException, WvPLStatusException {
|
||||
ManagedChannel channel = null;
|
||||
PublishedDevices devicesResponse = null;
|
||||
|
||||
@@ -70,10 +85,20 @@ public class PublishedDevicesProvider implements DeviceCertificate {
|
||||
PublishedDevicesServiceGrpc.PublishedDevicesServiceBlockingStub blockingStub =
|
||||
PublishedDevicesServiceGrpc.newBlockingStub(channel)
|
||||
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata));
|
||||
devicesResponse = blockingStub.getPublishedDevices(PublishedDevicesRequest.parseFrom(
|
||||
environment.generateDeviceStatusListRequest()));
|
||||
logger.log(Level.INFO, "GRPC Call to PublishedDevicesService.GetSignedList returned:\n %s"
|
||||
+ TextFormat.printer().printToString(devicesResponse));
|
||||
devicesResponse =
|
||||
blockingStub.getPublishedDevices(
|
||||
PublishedDevicesRequest.parseFrom(
|
||||
environment.generateDeviceStatusListRequest(),
|
||||
ExtensionRegistry.getEmptyRegistry()));
|
||||
String truncatedLogString = TextFormat.printer().printToString(devicesResponse);
|
||||
int tenLines = 800;
|
||||
if (truncatedLogString.length() > tenLines) {
|
||||
truncatedLogString = truncatedLogString.substring(0, tenLines) + "...";
|
||||
}
|
||||
logger.log(
|
||||
Level.INFO,
|
||||
"GRPC Call to PublishedDevicesService.GetPublishedDevices returned:\n %s"
|
||||
+ truncatedLogString);
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.INFO, "IOException encountered trying to retrieve the signed list: " + e);
|
||||
} finally {
|
||||
@@ -85,6 +110,50 @@ public class PublishedDevicesProvider implements DeviceCertificate {
|
||||
return devicesResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignedDeviceSecurityProfiles getSignedDeviceSecurityProfiles()
|
||||
throws InterruptedException, WvPLStatusException {
|
||||
// Generate list dsp request.
|
||||
ListDeviceSecurityProfilesRequest listDspRequest =
|
||||
ListDeviceSecurityProfilesRequest.newBuilder()
|
||||
.setDeviceSecurityProfileCriteria(
|
||||
DeviceSecurityProfileCriteria.newBuilder()
|
||||
.setContentProvider(this.provider)
|
||||
.build())
|
||||
.build();
|
||||
|
||||
ManagedChannel channel = null;
|
||||
SignedDeviceSecurityProfiles signedMessageInResponse = null;
|
||||
|
||||
logger.log(Level.INFO, "Getting DeviceSecurityProfilesList...");
|
||||
try {
|
||||
channel = createRpcChannel(apiServicePath);
|
||||
Metadata metadata = new Metadata();
|
||||
String token = "Bearer " + credentials.getAccessToken();
|
||||
metadata.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), token);
|
||||
|
||||
PublishedDevicesServiceGrpc.PublishedDevicesServiceBlockingStub blockingStub =
|
||||
PublishedDevicesServiceGrpc.newBlockingStub(channel)
|
||||
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata));
|
||||
|
||||
signedMessageInResponse =
|
||||
blockingStub.listDeviceSecurityProfiles(listDspRequest).getSignedDeviceSecurityProfiles();
|
||||
logger.log(
|
||||
Level.INFO,
|
||||
"GRPC Call to PublishedDevicesService.ListDeviceSecurityProfiles returned:\n %s"
|
||||
+ TextFormat.printer().printToString(signedMessageInResponse));
|
||||
} catch (IOException e) {
|
||||
logger.log(
|
||||
Level.INFO, "IOException encountered trying to retrieve the signed dsp list: " + e);
|
||||
} finally {
|
||||
if (channel != null) {
|
||||
channel.shutdown();
|
||||
channel.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
return signedMessageInResponse;
|
||||
}
|
||||
|
||||
private static ManagedChannel createRpcChannel(String host) {
|
||||
return NettyChannelBuilder.forTarget(host).build();
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -9,18 +9,8 @@ java_library(
|
||||
srcs = [
|
||||
"PublishedDevicesCli.java",
|
||||
],
|
||||
runtime_deps = [
|
||||
"@grpc_context//:io_grpc_grpc_context",
|
||||
"@grpc_netty_all//:io_netty_netty_all",
|
||||
"@io_perfmark_api//:io_perfmark_perfmark_api",
|
||||
"@netty_boringssl//:io_netty_netty_tcnative_boringssl_static",
|
||||
"@netty_tcnative//:io_netty_netty_tcnative",
|
||||
"@open_census//:io_opencensus_opencensus_contrib_http_jetty_client",
|
||||
"@open_census_api//:io_opencensus_opencensus_api",
|
||||
"@open_census_grpc_metrics//:io_opencensus_opencensus_contrib_grpc_metrics",
|
||||
"@open_census_util//:io_opencensus_opencensus_contrib_http_util",
|
||||
],
|
||||
deps = [
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:device_security_profiles_java_proto",
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_grpc",
|
||||
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_java_proto",
|
||||
"//providers",
|
||||
|
||||
@@ -7,6 +7,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import com.beust.jcommander.JCommander;
|
||||
import com.beust.jcommander.Parameter;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevices;
|
||||
import com.google.chrome.widevine.contentpartners.v1beta1.SignedDeviceSecurityProfiles;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.video.widevine.jts.providers.PublishedDevicesProvider;
|
||||
import com.google.video.widevine.sdk.wvpl.WvPLCASProxyEnvironment;
|
||||
@@ -18,25 +20,28 @@ import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Published Devices Command Line Interface.
|
||||
* Published Devices Client command line tool.
|
||||
*
|
||||
* Provides a command line interface to get the latest {@code PublishedDevices} data from the
|
||||
* Widevine Published Devices Service.
|
||||
* <p>Provides a command line interface to get the latest {@code PublishedDevices} and {@code
|
||||
* SignedDeviceSecurityProfiles} data from the Widevine Published Devices Service.
|
||||
*
|
||||
* Default Widevine Service API path: widevine.googleapis.com.
|
||||
* <p>Default Widevine Service API path: widevine.googleapis.com.
|
||||
*
|
||||
* To build:
|
||||
* Bazel build java/com/google/video/widevine/jts/tools:published_devices_client_deploy.jar
|
||||
* <p>To build: bazel build
|
||||
* java/com/google/video/widevine/jts/tools:published_devices_cli_deploy.jar
|
||||
*
|
||||
* To run:
|
||||
* java -Djava.library.path=./path/to/license/sdk.so \
|
||||
* -jar /path/to/published_devices_client_deploy.jar \
|
||||
* -service_cert_path /path/to/cert_file.der \
|
||||
* -service_private_key_path /path/to/private_key.der \
|
||||
* -service_private_key_passphrase theprivatekeypassphrase
|
||||
* -service_account_path /path/to/service-account.json \
|
||||
* <p>To run: java -Djava.library.path=./path/to/license/sdk.so \ -jar
|
||||
* /path/to/published_devices_cli_deploy.jar \ -data_type PUBLISHED_DEVICESOrDSPInString \
|
||||
* -service_cert_path /path/to/cert_file.der \ -service_private_key_path /path/to/private_key.der \
|
||||
* -service_private_key_passphrase theprivatekeypassphrase \ -service_account_path
|
||||
* /path/to/service-account.json \ -provider_name providerNameInString
|
||||
*/
|
||||
public final class PublishedDevicesCli {
|
||||
private static final String PUBLISHED_DEVICES = "PUBLISHED_DEVICES";
|
||||
private static final String DSP = "DSP";
|
||||
private static final ImmutableList<String> DATA_TYPE_LIST =
|
||||
ImmutableList.of(PUBLISHED_DEVICES, DSP);
|
||||
|
||||
private WvPLCASProxyEnvironment environment = null;
|
||||
private PublishedDevicesProvider publishedDevices = null;
|
||||
private String serviceCertPath = null;
|
||||
@@ -44,42 +49,68 @@ public final class PublishedDevicesCli {
|
||||
private String privateKeyPassphrase = null;
|
||||
|
||||
/** Command Line Flags. */
|
||||
static class Flags{
|
||||
private Flags() {}
|
||||
static class Flags {
|
||||
private Flags() {}
|
||||
|
||||
@Parameter(names = "-service_cert_path", description = "Path to service certificate")
|
||||
private String serviceCertPath = "";
|
||||
@Parameter(
|
||||
names = "-data_type",
|
||||
description =
|
||||
"Set retrieved data type. Must be \"PUBLISHED_DEVICES\" or \"DSP\". Default is"
|
||||
+ " \"PUBLISHED_DEVICES\".")
|
||||
private String dataType = "PUBLISHED_DEVICES";
|
||||
|
||||
@Parameter(names = "-service_private_key_path",
|
||||
description = "Path to private key file needed to decrypt service certificate")
|
||||
private String servicePrivateKeyPath = "";
|
||||
@Parameter(names = "-service_cert_path", description = "Path to service certificate")
|
||||
private String serviceCertPath = "";
|
||||
|
||||
@Parameter(names = "-service_private_key_passphrase",
|
||||
description = "Passphrase needed to decrypt the private key")
|
||||
private String servicePrivateKeyPassphrase = "";
|
||||
@Parameter(
|
||||
names = "-service_private_key_path",
|
||||
description = "Path to private key file needed to decrypt service certificate")
|
||||
private String servicePrivateKeyPath = "";
|
||||
|
||||
@Parameter(names = "-service_account_path",
|
||||
description = "Path to a GCP Service Account json file")
|
||||
private String serviceAccountPath = "";
|
||||
@Parameter(
|
||||
names = "-service_private_key_passphrase",
|
||||
description = "Passphrase needed to decrypt the private key")
|
||||
private String servicePrivateKeyPassphrase = "";
|
||||
|
||||
@Parameter(names = "-api_service_path",
|
||||
description = "Optional. Path to a Widevine API service.")
|
||||
private String apiServicePath = "widevine.googleapis.com";
|
||||
@Parameter(
|
||||
names = "-service_account_path",
|
||||
description = "Path to a GCP Service Account json file")
|
||||
private String serviceAccountPath = "";
|
||||
|
||||
@Parameter(names = "-s",
|
||||
description = "Save PublishedDevices file path.")
|
||||
private String saveFilePath = null;
|
||||
@Parameter(
|
||||
names = "-api_service_path",
|
||||
description = "Optional. Path to a Widevine API service.")
|
||||
private String apiServicePath = "widevine.googleapis.com";
|
||||
|
||||
@Parameter(
|
||||
names = "-provider_name",
|
||||
description =
|
||||
"Set provider name. Must provide when obtaining DSPs. Optional for obtaining"
|
||||
+ " PUBLISHED_DEVICES.")
|
||||
private String provider = "";
|
||||
|
||||
@Parameter(names = "-s", description = "Save retrieved file path.")
|
||||
private String saveFilePath = null;
|
||||
}
|
||||
|
||||
public PublishedDevicesCli(String serviceCertPath, String privateKeyPath,
|
||||
String privateKeyPassphrase, String serviceAccountPath, String apiServicePath)
|
||||
public PublishedDevicesCli(
|
||||
String dataType,
|
||||
String serviceCertPath,
|
||||
String privateKeyPath,
|
||||
String privateKeyPassphrase,
|
||||
String serviceAccountPath,
|
||||
String apiServicePath,
|
||||
String provider)
|
||||
throws Exception {
|
||||
this.serviceCertPath = serviceCertPath;
|
||||
this.privateKeyPath = privateKeyPath;
|
||||
this.privateKeyPassphrase = privateKeyPassphrase;
|
||||
initializeWvplEnvironment();
|
||||
publishedDevices = new PublishedDevicesProvider(
|
||||
environment, serviceAccountPath, apiServicePath);
|
||||
// Construct PublishedDevicesProvider to obtain PUBLISHED_DEVICES or DSPs.
|
||||
if (dataType.equals(PUBLISHED_DEVICES)) {
|
||||
initializeWvplEnvironment();
|
||||
}
|
||||
publishedDevices =
|
||||
new PublishedDevicesProvider(environment, serviceAccountPath, apiServicePath, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,30 +125,61 @@ public final class PublishedDevicesCli {
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves PublishedDevices proto data to a file.
|
||||
* Get the latest {@code SignedDeviceSecurityProfiles} from the Widevine Published Devices
|
||||
* Service.
|
||||
*
|
||||
* @return The latest SignedDeviceSecurityProfiles data.
|
||||
*/
|
||||
public SignedDeviceSecurityProfiles getSignedDeviceSecurityProfiles()
|
||||
throws InterruptedException, WvPLStatusException {
|
||||
return publishedDevices.getSignedDeviceSecurityProfiles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves byte array to a file.
|
||||
*
|
||||
* @param saveFilePath The path to the save file.
|
||||
* @param publishedDevices A PublishedDevices proto.
|
||||
* @param byteArray a byte array transformed from proto.
|
||||
*/
|
||||
public static void savePublishedDevicesDataToFile(String saveFilePath,
|
||||
PublishedDevices publishedDevices) throws IOException {
|
||||
public static void saveByteArrayToFile(String saveFilePath, byte[] byteArray) throws IOException {
|
||||
Files.write(
|
||||
Paths.get(saveFilePath),
|
||||
BaseEncoding.base64Url().encode(publishedDevices.toByteArray()).getBytes(UTF_8));
|
||||
Paths.get(saveFilePath), BaseEncoding.base64Url().encode(byteArray).getBytes(UTF_8));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Flags flags = new Flags();
|
||||
new JCommander(flags, args);
|
||||
PublishedDevicesCli devices = new PublishedDevicesCli(
|
||||
flags.serviceCertPath,
|
||||
flags.servicePrivateKeyPath,
|
||||
flags.servicePrivateKeyPassphrase,
|
||||
flags.serviceAccountPath,
|
||||
flags.apiServicePath);
|
||||
PublishedDevices publishedDevices = devices.getPublishedDevices();
|
||||
if (flags.saveFilePath != null) {
|
||||
savePublishedDevicesDataToFile(flags.saveFilePath, publishedDevices);
|
||||
// Check flags.
|
||||
if (!DATA_TYPE_LIST.contains(flags.dataType)) {
|
||||
System.out.println("Data type should be selected from:" + DATA_TYPE_LIST);
|
||||
System.err.println("Error selecting data type. Exit");
|
||||
System.exit(-1);
|
||||
}
|
||||
if (flags.dataType.equals(DSP) && flags.provider.isEmpty()) {
|
||||
System.err.println("Failed to provide the provider name for obtaining DSP list. Exit");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
PublishedDevicesCli devices =
|
||||
new PublishedDevicesCli(
|
||||
flags.dataType,
|
||||
flags.serviceCertPath,
|
||||
flags.servicePrivateKeyPath,
|
||||
flags.servicePrivateKeyPassphrase,
|
||||
flags.serviceAccountPath,
|
||||
flags.apiServicePath,
|
||||
flags.provider);
|
||||
if (flags.dataType.equals(PUBLISHED_DEVICES)) {
|
||||
PublishedDevices publishedDevices = devices.getPublishedDevices();
|
||||
if (flags.saveFilePath != null) {
|
||||
saveByteArrayToFile(flags.saveFilePath, publishedDevices.toByteArray());
|
||||
}
|
||||
} else {
|
||||
SignedDeviceSecurityProfiles signedDeviceSecurityProfiles =
|
||||
devices.getSignedDeviceSecurityProfiles();
|
||||
if (flags.saveFilePath != null) {
|
||||
saveByteArrayToFile(flags.saveFilePath, signedDeviceSecurityProfiles.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user