Skip to content

Commit 574b890

Browse files
Merge pull request #657 from rdkcentral/feature/VPLAY-11384_8.2
VPLAY-11384 Get access (session) token from auth service
2 parents 279d024 + dc76cf8 commit 574b890

7 files changed

Lines changed: 68 additions & 58 deletions

File tree

drm/AampDRMLicManager.cpp

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ KeyState AampDRMLicenseManager::acquireLicense(std::shared_ptr<DrmHelper> drmHel
254254
const char *sessionToken = NULL;
255255
if(!usingAppDefinedAuthToken)
256256
{ /* authToken not set externally by app */
257-
sessionToken = getAccessToken(tokenLen, tokenError , aampInstance->mConfig->IsConfigSet(eAAMPConfig_SslVerifyPeer));
257+
sessionToken = getAccessToken(tokenLen, tokenError);
258258
AAMPLOG_WARN("Access Token from AuthServer");
259259
}
260260
else
@@ -333,7 +333,7 @@ KeyState AampDRMLicenseManager::acquireLicense(std::shared_ptr<DrmHelper> drmHel
333333
}
334334
int tokenLen = 0;
335335
int tokenError = 0;
336-
const char *sessionToken = getAccessToken(tokenLen, tokenError,aampInstance->mConfig->IsConfigSet(eAAMPConfig_SslVerifyPeer));
336+
const char *sessionToken = getAccessToken(tokenLen, tokenError);
337337
if (NULL != sessionToken)
338338
{
339339
AAMPLOG_INFO("Requesting License with new access token");
@@ -589,76 +589,39 @@ string extractSubstring(string parentStr, string startStr, string endStr)
589589
/**
590590
* @brief Get the accessToken from authService.
591591
*/
592-
const char * AampDRMLicenseManager::getAccessToken(int &tokenLen, int &error_code , bool bSslPeerVerify)
592+
const char * AampDRMLicenseManager::getAccessToken(int &tokenLen, int &error_code)
593593
{
594594
if(accessToken == NULL)
595595
{
596-
DownloadResponsePtr respData = std::make_shared<DownloadResponse> ();
597-
// Initialize the Seesion Token Connector
598-
DownloadConfigPtr inpData = std::make_shared<DownloadConfig> ();
599-
inpData->bIgnoreResponseHeader = true;
600-
inpData->eRequestType = eCURL_GET;
601-
inpData->iStallTimeout = 0; // 2sec
602-
inpData->iStartTimeout = 0; // 2sec
603-
inpData->iDownloadTimeout = DEFAULT_CURL_TIMEOUT;
604-
inpData->bNeedDownloadMetrics = true;
605-
inpData->bSSLVerifyPeer = bSslPeerVerify;
606-
mAccessTokenConnector.Initialize(inpData);
607-
mAccessTokenConnector.Download(SESSION_TOKEN_URL, respData);
608-
609-
if( respData->curlRetValue == CURLE_OK )
610-
{
611-
if (respData->iHttpRetValue == 200 || respData->iHttpRetValue == 206)
612-
{
613-
string tokenReplyStr;
614-
mAccessTokenConnector.GetDataString(tokenReplyStr);
615-
string tokenStatusCode = extractSubstring(tokenReplyStr, "status\":", ",\"");
616-
if(tokenStatusCode.length() == 0)
617-
{
618-
//StatusCode could be last element in the json
619-
tokenStatusCode = extractSubstring(tokenReplyStr, "status\":", "}");
620-
}
621-
if(tokenStatusCode.length() == 1 && tokenStatusCode.c_str()[0] == '0')
596+
std::string token;
597+
if (ContentSecurityManager::GetInstance()->getSessionToken(token))
598+
{
599+
size_t len = token.length();
600+
if(len > 0)
601+
{
602+
accessToken = (char*)malloc(len+1);
603+
if(accessToken)
622604
{
623-
string token = extractSubstring(tokenReplyStr, "token\":\"", "\"");
624-
size_t len = token.length();
625-
if(len > 0)
626-
{
627-
accessToken = (char*)malloc(len+1);
628-
if(accessToken)
629-
{
630-
accessTokenLen = (int)len;
631-
memcpy( accessToken, token.c_str(), len );
632-
accessToken[len] = 0x00;
633-
AAMPLOG_WARN(" Received session token from auth service in [%f]",respData->downloadCompleteMetrics.total);
634-
}
635-
else
636-
{
637-
AAMPLOG_WARN("accessToken is null"); //CID:83536 - Null Returns
638-
}
639-
}
640-
else
641-
{
642-
AAMPLOG_WARN(" Could not get access token from session token reply");
643-
error_code = eAUTHTOKEN_TOKEN_PARSE_ERROR;
644-
}
605+
accessTokenLen = (int)len;
606+
memcpy( accessToken, token.c_str(), len );
607+
accessToken[len] = 0x00;
608+
AAMPLOG_WARN(" Received session token from auth service");
645609
}
646610
else
647611
{
648-
AAMPLOG_ERR(" Missing or invalid status code in session token reply");
649-
error_code = eAUTHTOKEN_INVALID_STATUS_CODE;
612+
AAMPLOG_WARN("accessToken is null"); //CID:83536 - Null Returns
650613
}
651614
}
652615
else
653616
{
654-
AAMPLOG_ERR(" Get Session token call failed with http error %d", respData->iHttpRetValue);
655-
error_code = respData->iHttpRetValue;
617+
AAMPLOG_WARN("Invalid access token from ContentSecurityManager");
618+
error_code = eAUTHTOKEN_TOKEN_PARSE_ERROR;
656619
}
657620
}
658621
else
659622
{
660-
AAMPLOG_ERR(" Get Session token call failed with curl error %d", respData->curlRetValue);
661-
error_code = respData->curlRetValue;
623+
AAMPLOG_ERR("ContentSecurityManager failed to get access token");
624+
error_code = eAUTHTOKEN_TOKEN_PARSE_ERROR;
662625
}
663626
}
664627

drm/AampDRMLicManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AampDRMLicenseManager
7171
* @note AccessToken memory is dynamically allocated, deallocation
7272
* should be handled at the caller side.
7373
*/
74-
const char* getAccessToken(int &tokenLength, int &error_code ,bool bSslPeerVerify);
74+
const char* getAccessToken(int &tokenLength, int &error_code);
7575
/**
7676
* @fn acquireLicense
7777
*/

middleware/externals/contentsecuritymanager/ContentSecurityManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ void ContentSecurityManager::DestroyInstance()
8888
}
8989
}
9090

91+
/**
92+
* @brief To acquire an access token from auth service
93+
*/
94+
bool ContentSecurityManager::getSessionToken(std::string &token)
95+
{
96+
return false;
97+
}
98+
9199
/**
92100
* @brief To indicate whether application support firebolt capability
93101
*/

middleware/externals/contentsecuritymanager/ContentSecurityManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ class ContentSecurityManager : public PlayerScheduler
131131
*/
132132
virtual void ReleaseSession(int64_t sessionId);
133133

134+
/**
135+
* @fn getSessionToken
136+
*
137+
* @param[out] token - access token
138+
*/
139+
virtual bool getSessionToken(std::string &token);
140+
134141
/**
135142
* @fn SendWatermarkSessionEvent_CB
136143
*/

middleware/externals/contentsecuritymanager/SecManagerThunder.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ SecManagerThunder::~SecManagerThunder()
104104
UnRegisterAllEvents();
105105
}
106106

107+
/**
108+
* @brief To acquire access token
109+
*/
110+
bool SecManagerThunder::getSessionToken(std::string &token)
111+
{
112+
ThunderAccessPlayer authService(AUTH_SERVICE_CALL_SIGN);
113+
JsonObject param;
114+
JsonObject response;
115+
116+
if (authService.InvokeJSONRPC("getSessionToken", param, response, 10000))
117+
{
118+
token = response["token"].String();
119+
return true;
120+
}
121+
return false;
122+
}
123+
107124
/**
108125
* @brief To acquire license from SecManager
109126
*/

middleware/externals/contentsecuritymanager/SecManagerThunder.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define SECMANAGER_CALL_SIGN "org.rdk.SecManager.1"
4141
#define WATERMARK_PLUGIN_CALLSIGN "org.rdk.Watermark.1"
4242
//#define RDKSHELL_CALLSIGN "org.rdk.RDKShell.1" //need to be used instead of WATERMARK_PLUGIN_CALLSIGN if RDK Shell is used for rendering watermark
43+
#define AUTH_SERVICE_CALL_SIGN "org.rdk.AuthService.1"
4344

4445
/**
4546
* @class SecManagerThunder
@@ -92,6 +93,12 @@ class SecManagerThunder : public ContentSecurityManager
9293
* @param sessionId Session context (optional)
9394
*/
9495
void ShowWatermark(bool show);
96+
/**
97+
* @brief Acquire access token
98+
* @param token Return token
99+
* @return true if command succeeded
100+
*/
101+
bool getSessionToken(std::string &token);
95102
/**
96103
* @fn setWindowSize
97104
*

test/utests/fakes/FakeContentSecurityManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ bool ContentSecurityManager::AcquireLicense( std::string clientId, std::string a
6666
return false;
6767
}
6868

69+
/**
70+
* @brief get session token
71+
*/
72+
bool ContentSecurityManager::getSessionToken(std::string &token)
73+
{
74+
return false;
75+
}
76+
6977
/**
7078
* @brief To update session state to SecManager
7179
*/

0 commit comments

Comments
 (0)