Esempio n. 1
0
        public static IContentKey AddAuthorizationPolicyToContentKey(CloudMediaContext objCloudMediaContext, IContentKey objIContentKey, string keyId)
        {
            // Create ContentKeyAuthorizationPolicy with restrictions and create authorization policy
            IContentKeyAuthorizationPolicy policy = objCloudMediaContext.ContentKeyAuthorizationPolicies.CreateAsync(keyId).Result;

            List <ContentKeyAuthorizationPolicyRestriction> restrictions = new List <ContentKeyAuthorizationPolicyRestriction>();

            //ContentKeyAuthorizationPolicyRestriction restriction = new ContentKeyAuthorizationPolicyRestriction
            //                                                                            {
            //                                                                                Name = "Open Authorization Policy",
            //                                                                                KeyRestrictionType = (int)ContentKeyRestrictionType.Open,
            //                                                                                Requirements = null // no requirements
            //                                                                            };
            //ContentKeyAuthorizationPolicyRestriction restriction = new ContentKeyAuthorizationPolicyRestriction
            //{
            //    Name = "Authorization Policy with SWT Token Restriction",
            //    KeyRestrictionType = (int)ContentKeyRestrictionType.TokenRestricted,
            //    Requirements = ContentKeyAuthorizationHelper.CreateRestrictionRequirements()
            //};
            ContentKeyAuthorizationPolicyRestriction restriction = new ContentKeyAuthorizationPolicyRestriction
            {
                Name = "JWTContentKeyAuthorizationPolicyRestriction",
                KeyRestrictionType = (int)ContentKeyRestrictionType.TokenRestricted,
                Requirements       = ContentKeyAuthorizationHelper.CreateRestrictionRequirementsForJWT()
            };

            restrictions.Add(restriction);

            IContentKeyAuthorizationPolicyOption policyOption = objCloudMediaContext.ContentKeyAuthorizationPolicyOptions.Create(
                keyId,
                ContentKeyDeliveryType.BaselineHttp,
                restrictions,
                "");

            policy.Options.Add(policyOption);

            // Add ContentKeyAutorizationPolicy to ContentKey
            objIContentKey.AuthorizationPolicyId = policy.Id;
            IContentKey IContentKeyUpdated = objIContentKey.UpdateAsync().Result;

            return(IContentKeyUpdated);
        }
Esempio n. 2
0
        public static IContentKey ConfigureKeyDeliveryService(CloudMediaContext objCloudMediaContext, Guid keyId, string contentKeyB64, string assetId)
        {
            //check if the keyId exists
            var keys = objCloudMediaContext.ContentKeys.Where(k => k.Id == "nb:kid:UUID:" + keyId.ToString());

            if (keys.Count() > 0)
            {
                Console.WriteLine("Key Delivery for Key ID = {0} exists.", string.Format("nb:kid:UUID:{0}", keyId.ToString()));
                return(null);
            }

            byte[] keyValue = Convert.FromBase64String(contentKeyB64);

            var contentKey = objCloudMediaContext.ContentKeys.Create(keyId, keyValue, string.Format("KID_{0}", keyId.ToString()), ContentKeyType.CommonEncryption);

            var restrictions = new List <ContentKeyAuthorizationPolicyRestriction>
            {
                //ContentKeyRestrictionType.Open
                //new ContentKeyAuthorizationPolicyRestriction { Requirements = null,
                //                                               Name = "Open",
                //                                               KeyRestrictionType = (int) ContentKeyRestrictionType.Open
                //                                             }

                //ContentKeyRestrictionType.IPRestricted,    sample asset: http://willzhanmediaservice.origin.mediaservices.windows.net/394ade06-2d0b-4d5d-9fcc-dca67f9116ae/Anna.ism/Manifest
                //new ContentKeyAuthorizationPolicyRestriction { Requirements = string.Format("<Allowed addressType=\"IPv4\"><AddressRange start=\"{0}\" end=\"{0}\" /></Allowed>", "67.186.67.74"),
                //                                               Name = "IPRestricted",
                //                                               KeyRestrictionType = (int) ContentKeyRestrictionType.IPRestricted
                //                                             }

                //ContentKeyRestrictionType.TokenRestricted, sample asset: http://willzhanmediaservice.origin.mediaservices.windows.net/0bd8e2fd-e508-4eac-b5b8-f10d95cbe9de/BigBuckBunny.ism/manifest
                //new ContentKeyAuthorizationPolicyRestriction { Requirements = ContentKeyAuthorizationHelper.CreateRestrictionRequirements(),  //(ContentKeyAuthorizationHelper.AccessPolicyTemplateKeyClaim),
                //                                               Name = "TokenRestricted",
                //                                               KeyRestrictionType = (int) ContentKeyRestrictionType.TokenRestricted
                //                                             }

                new ContentKeyAuthorizationPolicyRestriction {
                    Requirements       = ContentKeyAuthorizationHelper.CreateRestrictionRequirementsForJWT(),                                           //(ContentKeyAuthorizationHelper.AccessPolicyTemplateKeyClaim),
                    Name               = "JWTContentKeyAuthorizationPolicyRestriction",
                    KeyRestrictionType = (int)ContentKeyRestrictionType.TokenRestricted
                }
            };

            //Name IContentKeyAuthorizationPolicy as IAsset.Id so that it is easy to be cleaned up
            IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = objCloudMediaContext.ContentKeyAuthorizationPolicies.CreateAsync(assetId).Result;

            //Use License Template API
            string newLicenseTemplate = CreatePRLicenseResponseTemplate();

            //Name IContentKeyAuthorizationPolicyOption as IAsset.Id so that it is easy to be cleaned up
            IContentKeyAuthorizationPolicyOption policyOption = objCloudMediaContext.ContentKeyAuthorizationPolicyOptions.Create(assetId, ContentKeyDeliveryType.PlayReadyLicense, restrictions, newLicenseTemplate);

            contentKeyAuthorizationPolicy.Options.Add(policyOption);

            // Associate the content key authorization policy with the content key
            contentKey.AuthorizationPolicyId = contentKeyAuthorizationPolicy.Id;   //or contentKey.AuthorizationPolicy = policy;
            contentKey = contentKey.UpdateAsync().Result;


            // Update the MediaEncryptor_PlayReadyProtection.xml file with the key and URL info.
            Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.PlayReadyLicense);

            Console.WriteLine(string.Format("LAURL = {0}", keyDeliveryServiceUri.OriginalString));

            return(contentKey);
        }