public function testCreateContentKeyAuthorizationPolicyOptionForWidevine() { // Setup Token $widevine = new WidevineMessage(); $widevine->allowed_track_types = AllowedTrackTypes::SD_HD; $contentKeySpecs = new ContentKeySpecs(); $contentKeySpecs->required_output_protection = new RequiredOutputProtection(); $contentKeySpecs->required_output_protection->hdcp = Hdcp::HDCP_NONE; $contentKeySpecs->security_level = 1; $contentKeySpecs->track_type = 'SD'; $widevine->content_key_specs = array($contentKeySpecs); $policyOverrides = new \stdClass(); $policyOverrides->can_play = true; $policyOverrides->can_persist = true; $policyOverrides->can_renew = false; $widevine->policy_overrides = $policyOverrides; $jsonWidevine = WidevineMessageSerializer::serialize($widevine); $template = new TokenRestrictionTemplate(TokenType::SWT); $template->setPrimaryVerificationKey(new SymmetricVerificationKey()); $template->setAlternateVerificationKeys(array(new SymmetricVerificationKey())); $template->setAudience('http://sampleaudience/'); $template->setIssuer('http://sampleissuerurl/'); $claims = array(); $claims[] = new TokenClaim(TokenClaim::CONTENT_KEY_ID_CLAIM_TYPE); $claims[] = new TokenClaim('Rental', 'true'); $template->setRequiredClaims($claims); $serializedTemplate = TokenRestrictionTemplateSerializer::serialize($template); // Setup Options $name = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_OPTIONS_NAME . $this->createSuffix(); $restrictionName = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_POLICY_RESTRICTION_NAME . $this->createSuffix(); $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName($restrictionName); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::TOKEN_RESTRICTED); $restriction->setRequirements($serializedTemplate); $restrictions = array($restriction); $options = new ContentKeyAuthorizationPolicyOption(); $options->setName($name); $options->setKeyDeliveryType(ContentKeyDeliveryType::WIDEVINE); $options->setKeyDeliveryConfiguration($jsonWidevine); $options->setRestrictions($restrictions); // Test $result = $this->createContentKeyAuthorizationPolicyOption($options); // Retrieve the CKAPO again. $result = $this->restProxy->getContentKeyAuthorizationPolicyOption($result->getId()); // Assert Options $this->assertEquals($options->getName(), $result->getName()); $this->assertEquals($options->getKeyDeliveryType(), $result->getKeyDeliveryType()); $this->assertJsonStringEqualsJsonString($jsonWidevine, $result->getKeyDeliveryConfiguration()); $actualWidevine = WidevineMessageSerializer::deserialize($result->getKeyDeliveryConfiguration()); $this->assertEqualsWidevineMessage($widevine, $actualWidevine); return $result->getId(); }
/** * @covers WindowsAzure\MediaServices\Models\ContentKeyAuthorizationPolicyRestriction::getRequirements * @covers WindowsAzure\MediaServices\Models\ContentKeyAuthorizationPolicyRestriction::setRequirements */ public function testGetSetRequirements() { // Setup $testNameForContentKeyAuthorizationRestriction = 'test requirements'; $contentKeyAuthorizationRestriction = new ContentKeyAuthorizationPolicyRestriction(); // Test $contentKeyAuthorizationRestriction->setRequirements($testNameForContentKeyAuthorizationRestriction); $result = $contentKeyAuthorizationRestriction->getRequirements(); // Assert $this->assertEquals($testNameForContentKeyAuthorizationRestriction, $result); }
/** * Fill ContentKeyAuthorizationPolicyOption from array * * @param array $options Array containing values for object properties * * @return void */ public function fromArray($options) { if (isset($options['Id'])) { Validate::isString($options['Id'], 'options[Id]'); $this->_id = $options['Id']; } if (isset($options['Name'])) { Validate::isString($options['Name'], 'options[Name]'); $this->_name = $options['Name']; } if (isset($options['KeyDeliveryType'])) { Validate::isInteger($options['KeyDeliveryType'], 'options[KeyDeliveryType]'); $this->_keyDeliveryType = $options['KeyDeliveryType']; } if (isset($options['KeyDeliveryConfiguration'])) { Validate::isString($options['KeyDeliveryConfiguration'], 'options[KeyDeliveryConfiguration]'); $this->_keyDeliveryConfiguration = $options['KeyDeliveryConfiguration']; } if (!empty($options['Restrictions'])) { Validate::isArray($options['Restrictions'], 'options[Restrictions]'); foreach ($options['Restrictions'] as $restriction) { $this->_restrictions[] = ContentKeyAuthorizationPolicyRestriction::createFromOptions($restriction); } } }
function addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType, $fairPlayASK, $fairPlayPfxPassword, $fairPlayPfxFile, $fairPlayIV) { // 4.1 Create ContentKeyAuthorizationPolicyRestriction (Token Restricted) $tokenRestriction = generateTokenRequirements($tokenType); $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName('ContentKey Authorization Policy Restriction'); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::TOKEN_RESTRICTED); $restriction->setRequirements($tokenRestriction); // 4.2 Configure FairPlay license options. $fairPlayConfiguration = configureFairPlayPolicyOptions($restProxy, $fairPlayASK, $fairPlayPfxPassword, $fairPlayPfxFile, $fairPlayIV); // 4.3 Create ContentKeyAuthorizationPolicyOption (FairPlay) $fairPlayOption = new ContentKeyAuthorizationPolicyOption(); $fairPlayOption->setName('Deliver Common CBC Content Key with token restrictions'); $fairPlayOption->setKeyDeliveryType(ContentKeyDeliveryType::FAIRPLAY); $fairPlayOption->setRestrictions(array($restriction)); $fairPlayOption->setKeyDeliveryConfiguration($fairPlayConfiguration); $fairPlayOption = $restProxy->createContentKeyAuthorizationPolicyOption($fairPlayOption); // 4.4 Create ContentKeyAuthorizationPolicy $ckapolicy = new ContentKeyAuthorizationPolicy(); $ckapolicy->setName('ContentKey Authorization Policy'); $ckapolicy = $restProxy->createContentKeyAuthorizationPolicy($ckapolicy); // 4.5 Link the ContentKeyAuthorizationPolicyOption to the ContentKeyAuthorizationPolicy $restProxy->linkOptionToContentKeyAuthorizationPolicy($fairPlayOption, $ckapolicy); // 4.6 Associate the ContentKeyAuthorizationPolicy with the ContentKey $contentKey->setAuthorizationPolicyId($ckapolicy->getId()); $restProxy->updateContentKey($contentKey); echo "Added Content Key Authorization Policy: name={$ckapolicy->getName()} id={$ckapolicy->getId()}" . PHP_EOL; return $tokenRestriction; }
function addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType) { // 4.1 Create ContentKeyAuthorizationPolicyRestriction (Token Restricted) $tokenRestriction = generateTokenRequirements($tokenType); $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName('ContentKey Authorization Policy Restriction'); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::TOKEN_RESTRICTED); $restriction->setRequirements($tokenRestriction); // 4.2 Create ContentKeyAuthorizationPolicyOption (AES) $option = new ContentKeyAuthorizationPolicyOption(); $option->setName('ContentKey Authorization Policy Option'); $option->setKeyDeliveryType(ContentKeyDeliveryType::BASELINE_HTTP); $option->setRestrictions(array($restriction)); $option = $restProxy->createContentKeyAuthorizationPolicyOption($option); // 4.3 Create ContentKeyAuthorizationPolicy $ckapolicy = new ContentKeyAuthorizationPolicy(); $ckapolicy->setName('ContentKey Authorization Policy'); $ckapolicy = $restProxy->createContentKeyAuthorizationPolicy($ckapolicy); // 4.4 Link the ContentKeyAuthorizationPolicyOption to the ContentKeyAuthorizationPolicy $restProxy->linkOptionToContentKeyAuthorizationPolicy($option, $ckapolicy); // 4.7 Associate the ContentKeyAuthorizationPolicy with the ContentKey $contentKey->setAuthorizationPolicyId($ckapolicy->getId()); $restProxy->updateContentKey($contentKey); print "Added Content Key Authorization Policy: name={$ckapolicy->getName()} id={$ckapolicy->getId()}\r\n"; return $tokenRestriction; }
// 3.2 Get the protection key id for ContentKey $protectionKeyId = $restProxy->getProtectionKeyId(ContentKeyTypes::ENVELOPE_ENCRYPTION); $protectionKey = $restProxy->getProtectionKey($protectionKeyId); $contentKey = new ContentKey(); $contentKey->setContentKey($aesKey, $protectionKey); $contentKey->setProtectionKeyId($protectionKeyId); $contentKey->setProtectionKeyType(ProtectionKeyTypes::X509_CERTIFICATE_THUMBPRINT); $contentKey->setContentKeyType(ContentKeyTypes::ENVELOPE_ENCRYPTION); // 3.3 Create the ContentKey $contentKey = $restProxy->createContentKey($contentKey); print "Content Key id={$contentKey->getId()}\r\n"; // 3.4 Associate the ContentKey with the Asset $restProxy->linkContentKeyToAsset($encodedAsset, $contentKey); // Phase 4 - Create the ContentKey Authorization Policy // 4.1 Create ContentKeyAuthorizationPolicyRestriction (Open) $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName('ContentKey Authorization Policy Restriction'); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::OPEN); // 4.2 Create ContentKeyAuthorizationPolicyOption (AES) $option = new ContentKeyAuthorizationPolicyOption(); $option->setName('ContentKey Authorization Policy Option'); $option->setKeyDeliveryType(ContentKeyDeliveryType::BASELINE_HTTP); $option->setRestrictions(array($restriction)); $option = $restProxy->createContentKeyAuthorizationPolicyOption($option); // 4.3 Create ContentKeyAuthorizationPolicy $ckapolicy = new ContentKeyAuthorizationPolicy(); $ckapolicy->setName('ContentKey Authorization Policy'); $ckapolicy = $restProxy->createContentKeyAuthorizationPolicy($ckapolicy); // 4.4 Link the ContentKeyAuthorizationPolicyOption to the ContentKeyAuthorizationPolicy $restProxy->linkOptionsToContentKeyAuthorizationPolicy($option, $ckapolicy); // 4.5 Associate the ContentKeyAuthorizationPolicy with the ContentKey
function addTokenRestrictedAuthorizationPolicy($restProxy, $contentKey, $tokenType) { // 4.1 Create ContentKeyAuthorizationPolicyRestriction (Token Restricted) $tokenRestriction = generateTokenRequirements($tokenType); $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName('ContentKey Authorization Policy Restriction'); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::TOKEN_RESTRICTED); $restriction->setRequirements($tokenRestriction); // 4.2 Configure PlayReady and Widevine license templates. $playReadyLicenseTemplate = configurePlayReadyLicenseTemplate(); $widevineLicenseTemplate = configureWidevineLicenseTemplate(); // 4.3 Create ContentKeyAuthorizationPolicyOption (PlayReady) $playReadyOption = new ContentKeyAuthorizationPolicyOption(); $playReadyOption->setName('PlayReady Authorization Policy Option'); $playReadyOption->setKeyDeliveryType(ContentKeyDeliveryType::PLAYREADY_LICENSE); $playReadyOption->setRestrictions(array($restriction)); $playReadyOption->setKeyDeliveryConfiguration($playReadyLicenseTemplate); $playReadyOption = $restProxy->createContentKeyAuthorizationPolicyOption($playReadyOption); // 4.4 Create ContentKeyAuthorizationPolicyOption (Widevine) $widevineOption = new ContentKeyAuthorizationPolicyOption(); $widevineOption->setName('Widevine Authorization Policy Option'); $widevineOption->setKeyDeliveryType(ContentKeyDeliveryType::WIDEVINE); $widevineOption->setRestrictions(array($restriction)); $widevineOption->setKeyDeliveryConfiguration($widevineLicenseTemplate); $widevineOption = $restProxy->createContentKeyAuthorizationPolicyOption($widevineOption); // 4.5 Create ContentKeyAuthorizationPolicy $ckapolicy = new ContentKeyAuthorizationPolicy(); $ckapolicy->setName('ContentKey Authorization Policy'); $ckapolicy = $restProxy->createContentKeyAuthorizationPolicy($ckapolicy); // 4.6 Link the ContentKeyAuthorizationPolicyOption to the ContentKeyAuthorizationPolicy $restProxy->linkOptionToContentKeyAuthorizationPolicy($playReadyOption, $ckapolicy); $restProxy->linkOptionToContentKeyAuthorizationPolicy($widevineOption, $ckapolicy); // 4.7 Associate the ContentKeyAuthorizationPolicy with the ContentKey $contentKey->setAuthorizationPolicyId($ckapolicy->getId()); $restProxy->updateContentKey($contentKey); print "Added Content Key Authorization Policy: name={$ckapolicy->getName()} id={$ckapolicy->getId()}\r\n"; return $tokenRestriction; }
/** * @covers WindowsAzure\MediaServices\Models\ContentKeyAuthorizationPolicyOption::getRestrictions * @covers WindowsAzure\MediaServices\Models\ContentKeyAuthorizationPolicyOption::setRestrictions */ public function testGetSetRestrictions() { // Setup $name = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_OPTIONS_NAME; $restrictionName = TestResources::MEDIA_SERVICES_CONTENT_KEY_AUTHORIZATION_POLICY_RESTRICTION_NAME; $restriction = new ContentKeyAuthorizationPolicyRestriction(); $restriction->setName($restrictionName); $restriction->setKeyRestrictionType(ContentKeyRestrictionType::OPEN); $restrictions = array($restriction); $options = new ContentKeyAuthorizationPolicyOption(); $options->setName($name); $options->setKeyDeliveryType(ContentKeyDeliveryType::BASELINE_HTTP); $options->setRestrictions($restrictions); // Test $result = $options->getRestrictions(); // Assert $this->assertEquals($result, $restrictions); }
/** * Create ContentKeyAuthorizationPolicyRestriction from array * * @param array $options Array containing values for object properties * * @return ContentKeyAuthorizationPolicyRestriction */ public static function createFromOptions($options) { $contentKeyAuthorizationPolicyRestriction = new ContentKeyAuthorizationPolicyRestriction(); $contentKeyAuthorizationPolicyRestriction->fromArray($options); return $contentKeyAuthorizationPolicyRestriction; }