156 lines
8.2 KiB
C++
156 lines
8.2 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// 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.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "common/output_protection_util.h"
|
|
|
|
#include "testing/gmock.h"
|
|
#include "testing/gunit.h"
|
|
|
|
namespace widevine {
|
|
namespace op_util {
|
|
|
|
TEST(OutputProtectionUtilTest, AnalogOutputAllowed_DeviceWithoutAnalogOutput) {
|
|
License::KeyContainer::OutputProtection output_protection;
|
|
output_protection.set_disable_analog_output(false);
|
|
ClientIdentification::ClientCapabilities client_capabilities;
|
|
client_capabilities.set_analog_output_capabilities(
|
|
ClientIdentification::ClientCapabilities::ANALOG_OUTPUT_UNKNOWN);
|
|
bool should_disable_output_protection = true;
|
|
ASSERT_OK(VerifyDeviceCapabilities(client_capabilities, output_protection,
|
|
&should_disable_output_protection));
|
|
EXPECT_FALSE(should_disable_output_protection);
|
|
}
|
|
|
|
TEST(OutputProtectionUtilTest,
|
|
AnalogOutputNotAllowed_DeviceWithoutAnalogOutput) {
|
|
License::KeyContainer::OutputProtection output_protection;
|
|
output_protection.set_disable_analog_output(true);
|
|
ClientIdentification::ClientCapabilities client_capabilities;
|
|
client_capabilities.set_analog_output_capabilities(
|
|
ClientIdentification::ClientCapabilities::ANALOG_OUTPUT_NONE);
|
|
bool should_disable_output_protection = true;
|
|
ASSERT_OK(VerifyDeviceCapabilities(client_capabilities, output_protection,
|
|
&should_disable_output_protection));
|
|
EXPECT_FALSE(should_disable_output_protection);
|
|
}
|
|
|
|
TEST(OutputProtectionUtilTest, AnalogOutputNotAllowed_DeviceWithAnalogOutput) {
|
|
License::KeyContainer::OutputProtection output_protection;
|
|
output_protection.set_disable_analog_output(true);
|
|
ClientIdentification::ClientCapabilities client_capabilities;
|
|
client_capabilities.set_analog_output_capabilities(
|
|
ClientIdentification::ClientCapabilities::ANALOG_OUTPUT_SUPPORTED);
|
|
client_capabilities.set_can_disable_analog_output(false);
|
|
bool should_disable_output_protection = true;
|
|
ASSERT_EQ(error::PERMISSION_DENIED,
|
|
VerifyDeviceCapabilities(client_capabilities, output_protection,
|
|
&should_disable_output_protection)
|
|
.error_code());
|
|
EXPECT_FALSE(should_disable_output_protection);
|
|
// Client has the ability to disable it's analog output.
|
|
client_capabilities.set_can_disable_analog_output(true);
|
|
EXPECT_OK(VerifyDeviceCapabilities(client_capabilities, output_protection,
|
|
&should_disable_output_protection));
|
|
}
|
|
|
|
TEST(OutputProtectionUtilTest, CGMSRequired) {
|
|
License::KeyContainer::OutputProtection output_protection;
|
|
output_protection.set_disable_analog_output(false);
|
|
output_protection.set_cgms_flags(
|
|
License::KeyContainer::OutputProtection::COPY_NEVER);
|
|
ClientIdentification::ClientCapabilities client_capabilities;
|
|
client_capabilities.set_analog_output_capabilities(
|
|
ClientIdentification::ClientCapabilities::ANALOG_OUTPUT_SUPPORTED);
|
|
bool should_disable_output_protection = true;
|
|
EXPECT_EQ(error::PERMISSION_DENIED,
|
|
VerifyDeviceCapabilities(client_capabilities, output_protection,
|
|
&should_disable_output_protection)
|
|
.error_code());
|
|
client_capabilities.set_analog_output_capabilities(
|
|
ClientIdentification::ClientCapabilities::ANALOG_OUTPUT_SUPPORTS_CGMS_A);
|
|
ASSERT_OK(VerifyDeviceCapabilities(client_capabilities, output_protection,
|
|
&should_disable_output_protection));
|
|
EXPECT_FALSE(should_disable_output_protection);
|
|
}
|
|
// TODO(user): enable this test.
|
|
TEST(OutputProtectionUtilTest, DISABLED_VerifyDeviceHdcpCapabilities) {
|
|
ClientIdentification::ClientCapabilities device_capabilities;
|
|
License::KeyContainer::OutputProtection required;
|
|
|
|
// Device capabilities was not specified by the client.
|
|
device_capabilities.clear_max_hdcp_version();
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_NONE);
|
|
bool should_disable_output_protection;
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V1);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2_1);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2_2);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(
|
|
License::KeyContainer::OutputProtection::HDCP_NO_DIGITAL_OUTPUT);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
|
|
// Device capabilities are too low for any HDCP. Only fail if the required
|
|
// protection is HDCP_NO_DIGITAL_OUTPUT.
|
|
device_capabilities.set_max_hdcp_version(
|
|
ClientIdentification::ClientCapabilities::HDCP_NONE);
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_NONE);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V1);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(
|
|
License::KeyContainer::OutputProtection::HDCP_NO_DIGITAL_OUTPUT);
|
|
EXPECT_EQ(error::PERMISSION_DENIED,
|
|
VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection)
|
|
.error_code());
|
|
|
|
// Device does not have any digital output ports. In this case, the CDM
|
|
// cannot enforce this situation. For now, allow all HDCP requests, the KCB
|
|
// will enforce the HDCP settings.
|
|
device_capabilities.set_max_hdcp_version(
|
|
ClientIdentification::ClientCapabilities::HDCP_NO_DIGITAL_OUTPUT);
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_NONE);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V1);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2_1);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(License::KeyContainer::OutputProtection::HDCP_V2_2);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
required.set_hdcp(
|
|
License::KeyContainer::OutputProtection::HDCP_NO_DIGITAL_OUTPUT);
|
|
EXPECT_OK(VerifyDeviceCapabilities(device_capabilities, required,
|
|
&should_disable_output_protection));
|
|
}
|
|
|
|
} // namespace op_util
|
|
} // namespace widevine
|