25 #include <uuid/uuid.h>
35 #define KEYID_TAG_START "<KID>"
36 #define KEYID_TAG_END "</KID>"
37 #define PLAYREADY_VERSION "4.0.0.0"
41 const std::string AampPlayReadyHelper::PLAYREADY_OCDM_ID =
"com.microsoft.playready";
45 return PLAYREADY_OCDM_ID;
50 initData = this->mInitData;
61 std::string retVal =
"";
62 int first = data.find(start);
63 if ((first != std::string::npos))
65 std::string subStr = data.substr(first + start.size());
66 int last = subStr.find(end);
67 if ((last != std::string::npos))
69 retVal = subStr.substr (0,last);
80 #define PLAYREADY_VERSION_4_0_KID_START "<KID>"
81 #define PLAYREADY_VERSION_4_X_KID_START "<KID"
82 #define PLAYREADY_KID_END "</KID>"
84 #define PLAYREADY_VERSION_4_0 "4.0.0.0"
85 #define PLAYREADY_VERSION_4_1 "4.1.0.0"
86 #define PLAYREADY_VERSION_4_2 "4.2.0.0"
87 #define PLAYREADY_VERSION_4_3 "4.3.0.0"
88 std::string AampPlayReadyHelper::extrackKeyID()
90 std::string propValueEnd =
"\"";
92 std::string keyId =
"";
94 AAMPLOG_WARN (
"PlayReady Version [%s]", version.c_str());
110 keyId =
findSubstr(keyTag,
"VALUE=\"", propValueEnd);
124 std::string kids =
findSubstr(protectInfo,
"<KIDS>",
"</KIDS>");
127 keyId =
findSubstr(keyTag,
"VALUE=\"", propValueEnd);
141 std::string kids =
findSubstr(protectInfo,
"<KIDS>",
"</KIDS>");
144 keyId =
findSubstr(keyTag,
"VALUE=\"", propValueEnd);
148 AAMPLOG_WARN (
"Unsupported PSSH version MPD[%s]", version.c_str());
151 AAMPLOG_INFO(
"Extracted Key ID: %s", keyId.c_str());
173 if (initData != NULL && initDataLen > 0)
175 this->mInitData.assign(initData, initData + initDataLen);
176 std::string keyData =
"";
177 char* cleanedPssh = (
char*) malloc(initDataLen+1);
180 int cleanedPsshLen = 0;
181 for(
int itr = 0; itr < initDataLen; itr++)
183 if(initData[itr] != 0)
186 cleanedPssh[cleanedPsshLen++] = initData[itr];
189 cleanedPssh[cleanedPsshLen] = 0;
197 keyData = extrackKeyID();
200 if (!keyData.empty())
202 size_t decodedDataLen = 0;
203 unsigned char* decodedKeydata =
base64_Decode(keyData.c_str(), &decodedDataLen, keyData.size());
205 if (decodedDataLen != PLAYREADY_DECODED_KEY_ID_LEN)
207 AAMPLOG_ERR(
"Invalid key size found while extracting PR Decoded-KeyID-Length: %d (PR KeyID: %s KeyID-Length: %d)", decodedDataLen, keyData.c_str(), keyIdLen);
211 unsigned char swappedKeydata[PLAYREADY_DECODED_KEY_ID_LEN] = {0};
213 unsigned char keyId[PLAYREADY_KEY_ID_LEN] = {0};
214 uuid_t *keyiduuid = (uuid_t*)swappedKeydata;
215 uuid_unparse_lower(*keyiduuid,
reinterpret_cast<char*
>(keyId));
216 AAMPLOG_INFO(
"Extracted Key ID is %s", keyId);
217 mKeyID.assign(keyId, keyId + (PLAYREADY_KEY_ID_LEN-1));
221 free(decodedKeydata);
225 AAMPLOG_WARN(
"Bad DRM init data with Empty KeyID has received : %s!!",
friendlyName().c_str());
234 AAMPLOG_ERR(
"Invalid PSSH Data Recieved : NULL");
242 if (mContentMetaData.empty())
244 mContentMetaData = metaData;
250 keyID = this->mKeyID;
257 if (licenseRequest.url.empty())
259 licenseRequest.url = challengeInfo.
url;
262 licenseRequest.headers = {{
"Content-Type:", {
"text/xml; charset=utf-8"}}};
264 if (!mContentMetaData.empty())
266 std::vector<uint8_t> challengeData(
reinterpret_cast<const char*
>(challengeInfo.
data->getData().c_str()),
reinterpret_cast<const char*
>(challengeInfo.
data->getData().c_str()) + challengeInfo.
data->getDataLength());
269 comChallengeObj.
add(
"keySystem",
"playReady");
270 comChallengeObj.
add(
"mediaUsage",
"stream");
274 if ((!challengeInfo.
accessToken.empty()) && !licenseRequest.licenseAnonymousRequest)
279 licenseRequest.payload = comChallengeObj.
print();
281 else if (challengeInfo.
data)
283 licenseRequest.payload = challengeInfo.
data->getData();
289 return (((drmInfo.
systemUUID == PLAYREADY_UUID) || (drmInfo.
keyFormat == AampPlayReadyHelper::PLAYREADY_OCDM_ID))
298 return std::make_shared<AampPlayReadyHelper>(drmInfo,logObj);
305 systemIds.push_back(PLAYREADY_UUID);