/** * getAccessAction * input: flavor ids, drmProvider * Get Access Action * @action getAccess * @param string $entryId * @param string $flavorIds * @param string $referrer * @return KalturaDrmLicenseAccessDetails **/ public function getAccessAction($entryId, $flavorIds, $referrer) { $response = new KalturaDrmLicenseAccessDetails(); $response->policy = ""; $response->duration = 0; $response->absolute_duration = 0; $flavorIdsArr = explode(",", $flavorIds); $entry = entryPeer::retrieveByPK($entryId); if (isset($entry)) { try { $drmLU = new DrmLicenseUtils($entry, $referrer); if ($this->validateFlavorAssetssAllowed($drmLU, $flavorIdsArr) == true) { $policyId = $drmLU->getPolicyId(); KalturaLog::info("policy_id is '{$policyId}'"); $dbPolicy = DrmPolicyPeer::retrieveByPK($policyId); if (isset($dbPolicy)) { $expirationDate = DrmLicenseUtils::calculateExpirationDate($dbPolicy, $entry); $response->policy = $dbPolicy->getName(); $response->duration = $expirationDate; $response->absolute_duration = $expirationDate; KalturaLog::info("response is '" . print_r($response, true) . "' "); } else { KalturaLog::err("Could not get DRM policy from DB"); } } } catch (Exception $e) { KalturaLog::err("Could not validate license access, returned with message '" . $e->getMessage() . "'"); } } else { KalturaLog::err("Entry '{$entryId}' not found"); } return $response; }
/** * Get Play Ready policy and dates for license creation * * @action getLicenseDetails * @param string $keyId * @param string $deviceId * @param int $deviceType * @param string $entryId * @param string $referrer 64base encoded * @return KalturaPlayReadyLicenseDetails $response * * @throws KalturaErrors::MISSING_MANDATORY_PARAMETER * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws KalturaPlayReadyErrors::ENTRY_NOT_FOUND_BY_KEY_ID * @throws KalturaPlayReadyErrors::PLAYREADY_POLICY_NOT_FOUND */ public function getLicenseDetailsAction($keyId, $deviceId, $deviceType, $entryId = null, $referrer = null) { KalturaLog::debug('Get Play Ready license details for keyID: ' . $keyId); $entry = $this->getLicenseRequestEntry($keyId, $entryId); $referrerDecoded = base64_decode(str_replace(" ", "+", $referrer)); if (!is_string($referrerDecoded)) { $referrerDecoded = ""; } // base64_decode can return binary data $drmLU = new DrmLicenseUtils($entry, $referrerDecoded); $policyId = $drmLU->getPolicyId(); if (!isset($policyId)) { throw new KalturaAPIException(KalturaPlayReadyErrors::PLAYREADY_POLICY_NOT_FOUND, $entry->getId()); } $dbPolicy = DrmPolicyPeer::retrieveByPK($policyId); if (!$dbPolicy) { throw new KalturaAPIException(KalturaPlayReadyErrors::PLAYREADY_POLICY_OBJECT_NOT_FOUND, $policyId); } list($beginDate, $expirationDate, $removalDate) = $this->calculateLicenseDates($dbPolicy, $entry); $policy = new KalturaPlayReadyPolicy(); $policy->fromObject($dbPolicy, $this->getResponseProfile()); $this->registerDevice($deviceId, $deviceType); $response = new KalturaPlayReadyLicenseDetails(); $response->policy = $policy; $response->beginDate = $beginDate; $response->expirationDate = $expirationDate; $response->removalDate = $removalDate; return $response; }
/** * Mark the KalturaDrmPolicy object as deleted * * @action delete * @param int $drmPolicyId * @return KalturaDrmPolicy * * @throws KalturaErrors::INVALID_OBJECT_ID */ public function deleteAction($drmPolicyId) { $dbDrmPolicy = DrmPolicyPeer::retrieveByPK($drmPolicyId); if (!$dbDrmPolicy) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $drmPolicyId); } $dbDrmPolicy->setStatus(DrmPolicyStatus::DELETED); $dbDrmPolicy->save(); $drmPolicy = KalturaDrmPolicy::getInstanceByType($dbDrmPolicy->getProvider()); $drmPolicy->fromObject($dbDrmPolicy, $this->getResponseProfile()); return $drmPolicy; }
<?php ini_set("memory_limit", "1024M"); if ($argc < 3) { die('DRM Policy ID and signing key required.\\n'); } chdir(__DIR__ . '/../'); require_once __DIR__ . '/../bootstrap.php'; $drmPolicyId = $argv[1]; $signingKey = $argv[2]; shout("Adding signing key [" . $signingKey . "] to drm policy [" . $drmPolicyId . "]", true); $drmDbPolicy = DrmPolicyPeer::retrieveByPK($drmPolicyId); if (is_null($drmDbPolicy)) { throw new kCoreException("DRM Policy Id is invalid"); } $drmDbPolicy->putInCustomData(DrmProfile::CUSTOM_DATA_SIGNING_KEY, $signingKey); $drmDbPolicy->save(); shout("Finished adding signingkey to drm policy", true); //write to log function function shout($str, $newLine = false) { echo "[" . date('H:i:s') . "] " . $str . ($newLine ? "\n" : ""); }