1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "[email protected]"
18 
19 #include <gtest/gtest.h>
20 #include "drm_hal_clearkey_module.h"
21 
22 namespace android {
23 namespace hardware {
24 namespace drm {
25 namespace V1_2 {
26 namespace vts {
27 
handleProvisioningRequest(const std::vector<uint8_t> &,const std::string &)28 std::vector<uint8_t> DrmHalVTSClearkeyModule::handleProvisioningRequest(
29         const std::vector<uint8_t>& /*provisioningRequest*/,
30         const std::string& /*url*/) {
31     EXPECT_TRUE(false) << "Clearkey doesn't support provisioning";
32     return {};
33 }
34 
35 std::vector<DrmHalVTSClearkeyModule::ContentConfiguration>
getContentConfigurations() const36         DrmHalVTSClearkeyModule::getContentConfigurations() const {
37     DrmHalVTSClearkeyModule::ContentConfiguration conf = {
38         .name = "DrmHalVTSClearkeyModule", // name
39         .serverUrl = "", // serverUrl
40         .initData = { // initData
41             // BMFF box header (4 bytes size + 'pssh')
42             0x00, 0x00, 0x00, 0x34, 0x70, 0x73, 0x73, 0x68,
43             // full box header (version = 1 flags = 0)
44             0x01, 0x00, 0x00, 0x00,
45             // system id
46             0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02, 0xac, 0xe3, 0x3c,
47             0x1e, 0x52, 0xe2, 0xfb, 0x4b,
48             // number of key ids
49             0x00, 0x00, 0x00, 0x01,
50             // key id
51             0x60, 0x06, 0x1e, 0x01, 0x7e, 0x47, 0x7e, 0x87, 0x7e, 0x57, 0xd0,
52             0x0d, 0x1e, 0xd0, 0x0d, 0x1e,
53             // size of data, must be zero
54             0x00, 0x00, 0x00, 0x00
55         },
56         .mimeType = "video/mp4", // mimeType
57         .optionalParameters = {}, // optionalParameters
58         .policy = { .allowOffline = true }, // allowOffline
59         .keys = { // keys
60             {
61                 .isSecure = false, // isSecure
62                 .keyId = { // keyId
63                     0x60, 0x06, 0x1e, 0x01, 0x7e, 0x47, 0x7e, 0x87,
64                     0x7e, 0x57, 0xd0, 0x0d, 0x1e, 0xd0, 0x0d, 0x1e
65                 },
66                 .clearContentKey = { // clearContentKey
67                     0x1a, 0x8a, 0x20, 0x95, 0xe4, 0xde, 0xb2, 0xd2,
68                     0x9e, 0xc8, 0x16, 0xac, 0x7b, 0xae, 0x20, 0x82
69                 }
70             }
71         }
72     };
73     return { conf };
74 }
75 
handleKeyRequest(const std::vector<uint8_t> & keyRequest,const std::string &)76 std::vector<uint8_t> DrmHalVTSClearkeyModule::handleKeyRequest(
77         const std::vector<uint8_t>& keyRequest,
78         const std::string& /*serverUrl*/) {
79 
80     // {"kids":["YAYeAX5Hfod-V9ANHtANHg"],"type":"temporary"}
81     std::vector<uint8_t> expectedKeyRequest = {
82         0x7b, 0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x59, 0x41, 0x59, 0x65,
83         0x41, 0x58, 0x35, 0x48, 0x66, 0x6f, 0x64, 0x2d, 0x56, 0x39, 0x41, 0x4e, 0x48, 0x74,
84         0x41, 0x4e, 0x48, 0x67, 0x22, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a,
85         0x22, 0x74, 0x65, 0x6d, 0x70, 0x6f, 0x72, 0x61, 0x72, 0x79, 0x22, 0x7d};
86 
87     // {"kids":["YAYeAX5Hfod-V9ANHtANHg"],"type":"persistent-license"}
88     std::vector<uint8_t> expectedKeyRequestPersistent = {
89         0x7b, 0x22, 0x6b, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x5b, 0x22, 0x59, 0x41, 0x59, 0x65,
90         0x41, 0x58, 0x35, 0x48, 0x66, 0x6f, 0x64, 0x2d, 0x56, 0x39, 0x41, 0x4e, 0x48, 0x74,
91         0x41, 0x4e, 0x48, 0x67, 0x22, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22, 0x3a,
92         0x22, 0x70, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x69,
93         0x63, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x7d};
94 
95     // {"keys":[{"kty":"oct","kid":"YAYeAX5Hfod-V9ANHtANHg","k":"GoogleTestKeyBase64ggg"}]}
96     std::vector<uint8_t> knownKeyResponse = {
97         0x7b, 0x22, 0x6b, 0x65, 0x79, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x6b, 0x74, 0x79, 0x22,
98         0x3a, 0x22, 0x6f, 0x63, 0x74, 0x22, 0x2c, 0x22, 0x6b, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x59,
99         0x41, 0x59, 0x65, 0x41, 0x58, 0x35, 0x48, 0x66, 0x6f, 0x64, 0x2d, 0x56, 0x39, 0x41, 0x4e,
100         0x48, 0x74, 0x41, 0x4e, 0x48, 0x67, 0x22, 0x2c, 0x22, 0x6b, 0x22, 0x3a, 0x22, 0x47, 0x6f,
101         0x6f, 0x67, 0x6c, 0x65, 0x54, 0x65, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x42, 0x61, 0x73, 0x65,
102         0x36, 0x34, 0x67, 0x67, 0x67, 0x22, 0x7d, 0x5d, 0x7d};
103 
104     // {"keys":[{"kty":"oct","kid":"YAYeAX5Hfod-V9ANHtANHg","k":"GoogleTestKeyBase64ggg"}],"type":"persistent-license"}
105     std::vector<uint8_t> knownKeyResponsePersistent = {
106         0x7b, 0x22, 0x6b, 0x65, 0x79, 0x73, 0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x6b, 0x74, 0x79, 0x22,
107         0x3a, 0x22, 0x6f, 0x63, 0x74, 0x22, 0x2c, 0x22, 0x6b, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x59,
108         0x41, 0x59, 0x65, 0x41, 0x58, 0x35, 0x48, 0x66, 0x6f, 0x64, 0x2d, 0x56, 0x39, 0x41, 0x4e,
109         0x48, 0x74, 0x41, 0x4e, 0x48, 0x67, 0x22, 0x2c, 0x22, 0x6b, 0x22, 0x3a, 0x22, 0x47, 0x6f,
110         0x6f, 0x67, 0x6c, 0x65, 0x54, 0x65, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x42, 0x61, 0x73, 0x65,
111         0x36, 0x34, 0x67, 0x67, 0x67, 0x22, 0x7d, 0x5d, 0x2c, 0x22, 0x74, 0x79, 0x70, 0x65, 0x22,
112         0x3a, 0x22, 0x70, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x6c, 0x69,
113         0x63, 0x65, 0x6e, 0x73, 0x65, 0x22, 0x7d};
114 
115     std::string req(keyRequest.begin(), keyRequest.end());
116     if (req.find("persistent-license") != std::string::npos) {
117         EXPECT_EQ(expectedKeyRequestPersistent, keyRequest);
118         return knownKeyResponsePersistent;
119     } else {
120         EXPECT_EQ(expectedKeyRequest, keyRequest);
121         return knownKeyResponse;
122     }
123 
124 }
125 
126 }  // namespace vts
127 }  // namespace V1_2
128 }  // namespace drm
129 }  // namespace hardware
130 }  // namespace android
131