From 767adb8a0ffbd639ec8944fe89f470bdd0a7be0b Mon Sep 17 00:00:00 2001 From: Haoming Wu Date: Fri, 16 Dec 2022 01:15:44 +0000 Subject: [PATCH] DRM VTS Vendor module for castkey Bug: 253168737 Test: none Change-Id: I3024434946be8186535ed61f907f45c9fc67ed1f --- .../mediadrm/vts/vendor_module/Android.bp | 42 +++++ .../mediadrm/vts/vendor_module/factory.cpp | 10 ++ .../mediadrm/vts/vendor_module/vts_module.cpp | 156 ++++++++++++++++++ .../mediadrm/vts/vendor_module/vts_module.h | 44 +++++ 4 files changed, 252 insertions(+) create mode 100644 cast_auth/mediadrm/vts/vendor_module/Android.bp create mode 100644 cast_auth/mediadrm/vts/vendor_module/factory.cpp create mode 100644 cast_auth/mediadrm/vts/vendor_module/vts_module.cpp create mode 100644 cast_auth/mediadrm/vts/vendor_module/vts_module.h diff --git a/cast_auth/mediadrm/vts/vendor_module/Android.bp b/cast_auth/mediadrm/vts/vendor_module/Android.bp new file mode 100644 index 0000000..774e527 --- /dev/null +++ b/cast_auth/mediadrm/vts/vendor_module/Android.bp @@ -0,0 +1,42 @@ +// Builds libvtscastauth.so + +cc_library_shared { + name: "libvtscastauth", + + include_dirs: [ + "hardware/interfaces/drm/1.0/vts/functional", + "vendor/widevine/libwvdrmengine/cdm/include", + "vendor/widevine/libwvdrmengine/cdm/core/include", + "vendor/widevine/libwvdrmengine/cdm/core/test", + "vendor/widevine/libwvdrmengine/cdm/util/include", + "system/libbase/include", + "system/libvintf/include", + + ], + + srcs: [ + "factory.cpp", + "vts_module.cpp", + ":vts_cdm_core_test_srcs", + ], + + static_libs: [ + "libgtest", + "libcdm", + "libcdm_utils", + ], + + shared_libs: [ + "libbase", + "libbinder_ndk", + "libcrypto", + "liblog", + "libssl", + "libutils", + ], + + relative_install_path: "drm-vts-test-libs", + + proprietary: true, + +} diff --git a/cast_auth/mediadrm/vts/vendor_module/factory.cpp b/cast_auth/mediadrm/vts/vendor_module/factory.cpp new file mode 100644 index 0000000..d58ff09 --- /dev/null +++ b/cast_auth/mediadrm/vts/vendor_module/factory.cpp @@ -0,0 +1,10 @@ +#include "drm_hal_vendor_module_api.h" +#include "vts_module.h" + +namespace castkey_vts { + extern "C" { + DrmHalVTSVendorModule *vendorModuleFactory() { + return new CastkeyVTSVendorModule_V1(); + } + }; +}; // namespace castkey_vts diff --git a/cast_auth/mediadrm/vts/vendor_module/vts_module.cpp b/cast_auth/mediadrm/vts/vendor_module/vts_module.cpp new file mode 100644 index 0000000..f556f68 --- /dev/null +++ b/cast_auth/mediadrm/vts/vendor_module/vts_module.cpp @@ -0,0 +1,156 @@ +#include "gtest/gtest.h" +#include "license_request.h" +#include "string_conversions.h" +#include "url_request.h" +#include "utils/Log.h" +#include "vts_module.h" + +using std::array; +using std::map; +using std::string; +using std::vector; +using wvutil::a2b_hex; +using wvutil::b2a_hex; +using wvcdm::LicenseRequest; +using wvcdm::UrlRequest; + +namespace castkey_vts { + + const int kHttpOk = 200; + + vector CastkeyVTSVendorModule_V1::getUUID() const { + uint8_t uuid[16] = { + 0xBC, 0xB4, 0x81, 0xCB, 0xA1, 0xD5, 0x42, 0xAF, + 0xB1, 0xE3, 0x7B, 0xFF, 0x14, 0x73, 0xEB, 0x85 + }; + return vector(uuid, uuid + sizeof(uuid)); + } + + void LogResponseError(const string& message, int http_status_code) { + ALOGD("HTTP Status code = %d", http_status_code); + ALOGD("HTTP response(%zd): %s", message.size(), b2a_hex(message).c_str()); + } + + vector CastkeyVTSVendorModule_V1::handleProvisioningRequest( + const vector& provisioning_request, + const string& server_url) { + + // Use secure connection and chunk transfer coding. + UrlRequest url_request(server_url); + EXPECT_TRUE(url_request.is_connected()) << "Fail to connect to " + << server_url; + url_request.PostCertRequestInQueryString(toString(provisioning_request)); + string reply; + EXPECT_TRUE(url_request.GetResponse(&reply)); + + int http_status_code = url_request.GetStatusCode(reply); + if (kHttpOk != http_status_code) { + LogResponseError(reply, http_status_code); + } + EXPECT_EQ(kHttpOk, http_status_code); + vector result(reply.begin(), reply.end()); + return vector(result); + } + + vector CastkeyVTSVendorModule_V1::handleKeyRequest( + const vector&key_request, const string& server_url) { + + // Use secure connection and chunk transfer coding. + UrlRequest url_request(server_url); + EXPECT_TRUE(url_request.is_connected()) << "Fail to connect to " + << server_url; + url_request.PostRequest(toString(key_request)); + string reply; + EXPECT_TRUE(url_request.GetResponse(&reply)); + + int httpStatusCode = url_request.GetStatusCode(reply); + if (httpStatusCode != kHttpOk) { + LogResponseError(reply, httpStatusCode); + } + EXPECT_EQ(httpStatusCode, kHttpOk); + + string drm_msg; + if (kHttpOk == httpStatusCode) { + LicenseRequest lic_request; + lic_request.GetDrmMessage(reply, drm_msg); + ALOGV("HTTP response body: (%zd bytes)", drm_msg.size()); + } + vector result(drm_msg.begin(), drm_msg.end()); + return result; + } + + vector + CastkeyVTSVendorModule_V1::getContentConfigurations() const { + + vector configurations; + { + const string serverUrl = "https://proxy.uat.widevine.com/proxy"; + const vector initData = a2b_hex( + "00000042" // blob size + "70737368" // "pssh" + "00000000" // flags + "edef8ba979d64acea3c827dcd51d21ed" // Widevine system id + "00000022" // pssh data size + "08011a0d7769646576696e655f746573" // pssh data... + "74220f73747265616d696e675f636c69" + "7031"); + const vector keyId = a2b_hex("371EA35E1A985D75D198A7F41020DC23"); + const vector keyValue = a2b_hex("371EA35E1A985D75D198A7F41020DC23"); + const vector keys = { + { + .isSecure = false, + .keyId = keyId, + .clearContentKey = keyValue + } + }; + + ContentConfiguration config = { + .name = "streaming_clip1", + .serverUrl = serverUrl, + .initData = initData, + .mimeType = "cenc", + .optionalParameters = map(), + .policy.allowOffline = false, + .keys = keys + }; + configurations.push_back(config); + } + + // Content Configuration #2 - Allows offline playback + { + const string serverUrl = "https://proxy.uat.widevine.com/proxy"; + const vector initData = a2b_hex( + "00000042" // blob size + "70737368" // "pssh" + "00000000" // flags + "edef8ba979d64acea3c827dcd51d21ed" // Widevine system id + "00000020" // pssh data size + "08011a0d7769646576696e655f746573" // pssh data... + "74220d6f66666c696e655f636c697033" + "7031"); + const vector keyId = a2b_hex("3260f39e12ccf653529990168a3583ff"); + const vector keyValue = a2b_hex("8040c019929b2cc116a2e8dac739eafa"); + const vector keys = { + { + .isSecure = false, + .keyId = keyId, + .clearContentKey = keyValue + } + }; + + ContentConfiguration config = { + .name = "offline_clip3", + .serverUrl = serverUrl, + .initData = initData, + .mimeType = "cenc", + .optionalParameters = map(), + .policy.allowOffline = true, + .keys = keys + }; + configurations.push_back(config); + }; + + return configurations; + } + +}; // namespace castkey_vts diff --git a/cast_auth/mediadrm/vts/vendor_module/vts_module.h b/cast_auth/mediadrm/vts/vendor_module/vts_module.h new file mode 100644 index 0000000..6483b14 --- /dev/null +++ b/cast_auth/mediadrm/vts/vendor_module/vts_module.h @@ -0,0 +1,44 @@ +#ifndef CASTKEY_VENDOR_VTS_MODULE +#define CASTKEY_VENDOR_VTS_MODULE + +#include + +#include "drm_hal_vendor_module_api.h" + +using std::vector; + +/** + * Define the DrmHalVTSVendorModule_V1 for Castkey. Refer to + * drm_hal_vendor_module_api.h for more details. + */ +namespace castkey_vts { + + class CastkeyVTSVendorModule_V1 : public DrmHalVTSVendorModule_V1 { + public: + CastkeyVTSVendorModule_V1() {} + virtual ~CastkeyVTSVendorModule_V1() {} + + virtual vector getUUID() const; + + virtual vector handleProvisioningRequest(const vector& + provisioningRequest, const std::string& url); + + virtual vector handleKeyRequest(const vector& + keyRequest, const std::string& serverUrl); + + virtual std::vector + getContentConfigurations() const; + + virtual std::string getServiceName() const {return "castkey";} + + private: + CastkeyVTSVendorModule_V1(const CastkeyVTSVendorModule_V1&) = delete; + void operator=(const CastkeyVTSVendorModule_V1&) = delete; + + std::string toString(std::vector vector) { + return std::string(vector.begin(), vector.end()); + } + }; +}; // namespace castkey_vts + +#endif //CASTKEY_VENDOR_VTS_MODULE