RDK Documentation (Open Sourced RDK Components)
AampVgdrmHelper.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2020 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file AampVgdrmHelper.cpp
22  * @brief Handles operations for Vg DRM
23  */
24 
25 
26 #include <memory>
27 #include <iostream>
28 
29 #include "AampVgdrmHelper.h"
30 #include "AampJsonObject.h"
31 #include "AampConfig.h"
32 
33 static AampVgdrmHelperFactory vgdrm_helper_factory;
34 
35 const std::string AampVgdrmHelper::VGDRM_OCDM_ID = "net.vgdrm";
36 
37 const std::string& AampVgdrmHelper::ocdmSystemId() const
38 {
39  return VGDRM_OCDM_ID;
40 }
41 
42 void AampVgdrmHelper::createInitData(std::vector<uint8_t>& initData) const
43 {
44  AampJsonObject jsonInitDataObj;
45 
46  if (jsonInitDataObj.add(std::string("initData"), mDrmInfo.initData) &&
47  jsonInitDataObj.add(std::string("uri"), mDrmInfo.keyURI) &&
48  (mPsshStr.empty() || jsonInitDataObj.add(std::string("pssh"), mPsshStr)))
49  {
50  // Note: PSSH may be empty, all other strings are expected to be present
51  jsonInitDataObj.print(initData);
52  }
53 }
54 
55 bool AampVgdrmHelper::parsePssh(const uint8_t* initData, uint32_t initDataLen)
56 {
57  //TODO
58  return true;
59 }
60 
61 void AampVgdrmHelper::getKey(std::vector<uint8_t>& keyID) const
62 {
63  if ((mDrmInfo.keyURI.length() != 40) && (mDrmInfo.keyURI.length() != 48))
64  {
65  AAMPLOG_ERR("Invalid key URI: %s", mDrmInfo.keyURI);
66  return;
67  }
68 
69  /* Each byte is represented as 2 characters in the URI */
70  int keyLen = std::stoi(mDrmInfo.keyURI.substr(KEY_ID_OFFSET, 2), 0, BASE_16); /* no CRC32 */
71 
72  if ((KEY_PAYLOAD_OFFSET + (2 * keyLen)) > mDrmInfo.keyURI.length())
73  {
74  AAMPLOG_ERR("Invalid key length extracted from URI: %d", keyLen);
75  return;
76  }
77 
78  keyID.clear();
79  keyID.reserve(keyLen);
80  for (int i = 0; i < keyLen; i++)
81  {
82  keyID.push_back(std::stoi(mDrmInfo.keyURI.substr(KEY_PAYLOAD_OFFSET + (2 * i), 2), 0, BASE_16));
83  }
84 }
85 
86 void AampVgdrmHelper::generateLicenseRequest(const AampChallengeInfo& challengeInfo, AampLicenseRequest& licenseRequest) const
87 {
88  licenseRequest.method = AampLicenseRequest::DRM_RETRIEVE;
89  licenseRequest.url = "";
90  licenseRequest.payload = "";
91 }
92 
93 bool AampVgdrmHelperFactory::isDRM(const struct DrmInfo& drmInfo) const
94 {
95  // VGDRM only supports HLS for now
96  if (drmInfo.mediaFormat != eMEDIAFORMAT_HLS) return false;
97 
98  if (VGDRM_UUID == drmInfo.keyFormat) return true;
99  if (AampVgdrmHelper::VGDRM_OCDM_ID == drmInfo.keyFormat) return true;
100 
101  /* For legacy DMR */
102  if (((drmInfo.keyURI.length() == 40) ||
103  (drmInfo.keyURI.length() == 48)) &&
104  (drmInfo.keyURI.find_first_not_of("0123456789abcdefABCDEF") == std::string::npos))
105  {
106  if (VGDRM_URI_START.count(drmInfo.keyURI.substr(0,14)) != 0) return true;
107  }
108 
109  return false;
110 }
111 
112 std::shared_ptr<AampDrmHelper> AampVgdrmHelperFactory::createHelper(const struct DrmInfo& drmInfo, AampLogManager *logObj) const
113 {
114  if (isDRM(drmInfo))
115  {
116  return std::make_shared<AampVgdrmHelper>(drmInfo, logObj);
117  }
118  return NULL;
119 }
120 
121 void AampVgdrmHelperFactory::appendSystemId(std::vector<std::string>& systemIds) const
122 {
123  systemIds.push_back(VGDRM_UUID);
124 }
125 
DrmInfo::keyURI
std::string keyURI
Definition: AampDrmInfo.h:87
AampVgdrmHelper::getKey
void getKey(std::vector< uint8_t > &keyID) const
Get the key ID.
Definition: AampVgdrmHelper.cpp:61
AampVgdrmHelper::parsePssh
bool parsePssh(const uint8_t *initData, uint32_t initDataLen)
Parse the optional PSSH data.
Definition: AampVgdrmHelper.cpp:55
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampVgdrmHelperFactory
Helps to operate Vg DRM.
Definition: AampVgdrmHelper.h:93
AampLicenseRequest::DRM_RETRIEVE
@ DRM_RETRIEVE
Definition: AampDrmHelper.h:63
AampLicenseRequest
Holds the data to get the License.
Definition: AampDrmHelper.h:57
AampVgdrmHelper::generateLicenseRequest
void generateLicenseRequest(const AampChallengeInfo &challengeInfo, AampLicenseRequest &licenseRequest) const
Generate the request details for the DRM license.
Definition: AampVgdrmHelper.cpp:86
DrmInfo::initData
std::string initData
Definition: AampDrmInfo.h:90
DrmInfo
DRM information required to decrypt.
Definition: AampDrmInfo.h:47
AampJsonObject.h
File to handle Json format.
AampVgdrmHelper::ocdmSystemId
virtual const std::string & ocdmSystemId() const
Returns the OCDM system ID of the helper.
Definition: AampVgdrmHelper.cpp:37
AampVgdrmHelperFactory::isDRM
bool isDRM(const struct DrmInfo &drmInfo) const
Determines if a helper class provides the identified DRM.
Definition: AampVgdrmHelper.cpp:93
DrmInfo::keyFormat
std::string keyFormat
Definition: AampDrmInfo.h:88
AampJsonObject::print
std::string print()
Print the constructed JSON to a string.
Definition: AampJsonObject.cpp:365
AampConfig.h
Configurations for AAMP.
AampVgdrmHelper::createInitData
void createInitData(std::vector< uint8_t > &initData) const
Definition: AampVgdrmHelper.cpp:42
eMEDIAFORMAT_HLS
@ eMEDIAFORMAT_HLS
Definition: AampDrmMediaFormat.h:34
AampJsonObject::add
bool add(const std::string &name, const std::string &value, const ENCODING encoding=ENCODING_STRING)
Add a string value.
Definition: AampJsonObject.cpp:69
AampVgdrmHelperFactory::appendSystemId
void appendSystemId(std::vector< std::string > &systemIds) const
Adds the system IDs supported by the DRM to a vector Used by the GStreamer plugins to advertise the D...
Definition: AampVgdrmHelper.cpp:121
AampChallengeInfo
Aamp challenge info to get the License.
Definition: AampDrmHelper.h:44
DrmInfo::mediaFormat
MediaFormat mediaFormat
Definition: AampDrmInfo.h:80
AampVgdrmHelperFactory::createHelper
std::shared_ptr< AampDrmHelper > createHelper(const struct DrmInfo &drmInfo, AampLogManager *logObj=NULL) const
Build a helper class to support the identified DRM.
Definition: AampVgdrmHelper.cpp:112
AampJsonObject
Utility class to construct a JSON string.
Definition: AampJsonObject.h:37