/// <summary>
        /// Asynchronously creates an <see cref="IContentKeyAuthorizationPolicyOption"/> with the provided name and permissions, valid for the provided duration.
        /// </summary>
        /// <param name="name">Specifies a friendly name for the PolicyOption.</param>
        /// <param name="deliveryType">Delivery method of the content key to the client.</param>
        /// <param name="restrictions">Authorization restrictions.</param>
        /// <param name="keyDeliveryConfiguration">Xml data, specific to the key delivery type that defines how the key is delivered to the client.</param>
        /// <returns>A function delegate that returns the future result to be available through the Task&lt;IContentKeyAuthorizationPolicyOption&gt;.</returns>
        public Task <IContentKeyAuthorizationPolicyOption> CreateAsync(
            string name,
            ContentKeyDeliveryType deliveryType,
            List <ContentKeyAuthorizationPolicyRestriction> restrictions,
            string keyDeliveryConfiguration)
        {
            IMediaDataServiceContext dataContext = this.MediaContext.MediaServicesClassFactory.CreateDataServiceContext();
            var policyOption = new ContentKeyAuthorizationPolicyOptionData
            {
                Name                     = name,
                Restrictions             = restrictions,
                KeyDeliveryConfiguration = keyDeliveryConfiguration
            };

            ((IContentKeyAuthorizationPolicyOption)policyOption).KeyDeliveryType = deliveryType;

            policyOption.SetMediaContext(this.MediaContext);
            dataContext.AddObject(ContentKeyAuthorizationPolicyOptionSet, policyOption);

            MediaRetryPolicy retryPolicy = this.MediaContext.MediaServicesClassFactory.GetSaveChangesRetryPolicy(dataContext as IRetryPolicyAdapter);

            return(retryPolicy.ExecuteAsync <IMediaDataServiceResponse>(() => dataContext.SaveChangesAsync(policyOption))
                   .ContinueWith <IContentKeyAuthorizationPolicyOption>(
                       t =>
            {
                t.ThrowIfFaulted();

                return (ContentKeyAuthorizationPolicyOptionData)t.Result.AsyncState;
            },
                       TaskContinuationOptions.ExecuteSynchronously));
        }
コード例 #2
0
        /// <summary>
        /// Gets the Key Delivery Uri
        /// </summary>
        public Uri GetKeyDeliveryUrl(ContentKeyDeliveryType contentKeyDeliveryType)
        {
            try
            {
                Task <Uri> task = this.GetKeyDeliveryUrlAsync(contentKeyDeliveryType);

                return(task.Result);
            }
            catch (AggregateException exception)
            {
                throw exception.Flatten().InnerException;
            }
        }
        public static IContentKeyAuthorizationPolicyOption CreateOption(CloudMediaContext dataContext, string optionName, ContentKeyDeliveryType deliveryType, string requirements, string configuration, ContentKeyRestrictionType restrictionType)
        {
            var restrictions = new List<ContentKeyAuthorizationPolicyRestriction>
                {
                    new ContentKeyAuthorizationPolicyRestriction { Requirements = requirements, Name = "somename" }
                };

            restrictions[0].SetKeyRestrictionTypeValue(restrictionType);

            IContentKeyAuthorizationPolicyOption option = dataContext.ContentKeyAuthorizationPolicyOptions.Create(
                optionName,
                deliveryType,
                restrictions,
                configuration);

            return option;
        }
        /// <summary>
        /// Creates an PolicyOption with the provided name and permissions, valid for the provided duration.
        /// </summary>
        /// <param name="name">Specifies a friendly name for the PolicyOption.</param>
        /// <param name="deliveryType">Delivery method of the content key to the client.</param>
        /// <param name="restrictions">Authorization restrictions.</param>
        /// <param name="keyDeliveryConfiguration">Xml data, specific to the key delivery type that defines how the key is delivered to the client.</param>
        /// <returns>An <see cref="IContentKeyAuthorizationPolicyOption"/>.</returns>
        public IContentKeyAuthorizationPolicyOption Create(
            string name,
            ContentKeyDeliveryType deliveryType,
            List <ContentKeyAuthorizationPolicyRestriction> restrictions,
            string keyDeliveryConfiguration)
        {
            try
            {
                Task <IContentKeyAuthorizationPolicyOption> task = this.CreateAsync(name, deliveryType, restrictions, keyDeliveryConfiguration);
                task.Wait();

                return(task.Result);
            }
            catch (AggregateException exception)
            {
                throw exception.Flatten().InnerException;
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets the Key Delivery Uri Asynchronously
        /// </summary>
        public Task <Uri> GetKeyDeliveryUrlAsync(ContentKeyDeliveryType contentKeyDeliveryType)
        {
            return(Task.Factory.StartNew <Uri>(() =>
            {
                Uri returnValue = null;
                if (this.GetMediaContext() != null)
                {
                    IMediaDataServiceContext dataContext = this.GetMediaContext().MediaServicesClassFactory.CreateDataServiceContext();

                    MediaRetryPolicy retryPolicy = this.GetMediaContext().MediaServicesClassFactory.GetQueryRetryPolicy(dataContext as IRetryPolicyAdapter);

                    Uri uriGetKeyDeliveryUrl = new Uri(string.Format(CultureInfo.InvariantCulture, "/ContentKeys('{0}')/GetKeyDeliveryUrl", this.Id), UriKind.Relative);

                    BodyOperationParameter keyDeliveryTypeParameter = new BodyOperationParameter("keyDeliveryType", (int)contentKeyDeliveryType);

                    try
                    {
                        IEnumerable <string> results = retryPolicy.ExecuteAction <IEnumerable <string> >(() => dataContext.ExecuteAsync(uriGetKeyDeliveryUrl, "POST", true, keyDeliveryTypeParameter).Result);

                        if (results != null)
                        {
                            // We specified only one result above so take the first result
                            string uriString = results.FirstOrDefault();

                            if (uriString != null)
                            {
                                returnValue = new Uri(uriString);
                            }
                        }
                    }
                    catch (AggregateException exception)
                    {
                        throw exception.Flatten().InnerException;
                    }
                }

                return returnValue;
            }));
        }
コード例 #6
0
        public static IContentKeyAuthorizationPolicyOption AddOpenAuthorizationPolicyOption(IContentKey contentKey, ContentKeyDeliveryType contentkeydeliverytype, string keydeliveryconfig, CloudMediaContext _context)
        {
            // Create ContentKeyAuthorizationPolicy with Open restrictions
            // and create authorization policy
            List<ContentKeyAuthorizationPolicyRestriction> restrictions = new List<ContentKeyAuthorizationPolicyRestriction>
            {
            new ContentKeyAuthorizationPolicyRestriction
            {
            Name = "Open Authorization Policy",
            KeyRestrictionType = (int)ContentKeyRestrictionType.Open,
            Requirements = null
            }
            };

            IContentKeyAuthorizationPolicyOption policyOption =
                _context.ContentKeyAuthorizationPolicyOptions.Create(
                "Open option",
                contentkeydeliverytype,
                restrictions,
                keydeliveryconfig);

            return policyOption;
        }
コード例 #7
0
        public static IContentKeyAuthorizationPolicyOption CreateOption(CloudMediaContext dataContext, string optionName, ContentKeyDeliveryType deliveryType, string requirements, string configuration, ContentKeyRestrictionType restrictionType)
        {
            var restrictions = new List <ContentKeyAuthorizationPolicyRestriction>
            {
                new ContentKeyAuthorizationPolicyRestriction {
                    Requirements = requirements, Name = "somename"
                }
            };

            restrictions[0].SetKeyRestrictionTypeValue(restrictionType);

            IContentKeyAuthorizationPolicyOption option = dataContext.ContentKeyAuthorizationPolicyOptions.Create(
                optionName,
                deliveryType,
                restrictions,
                configuration);

            return(option);
        }
コード例 #8
0
        static public IContentKeyAuthorizationPolicy AddOpenAuthorizationPolicy(IContentKey contentKey, ContentKeyDeliveryType contentkeydeliverytype, string keydeliveryconfig, CloudMediaContext _context)
        {
            // Create ContentKeyAuthorizationPolicy with Open restrictions
            // and create authorization policy
            List <ContentKeyAuthorizationPolicyRestriction> restrictions = new List <ContentKeyAuthorizationPolicyRestriction>
            {
                new ContentKeyAuthorizationPolicyRestriction
                {
                    Name = "Open",
                    KeyRestrictionType = (int)ContentKeyRestrictionType.Open,
                    Requirements       = null
                }
            };

            IContentKeyAuthorizationPolicyOption policyOption =
                _context.ContentKeyAuthorizationPolicyOptions.Create(
                    "policy",
                    contentkeydeliverytype,
                    restrictions,
                    keydeliveryconfig);

            IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = _context.
                                                                           ContentKeyAuthorizationPolicies.
                                                                           CreateAsync("Open Authorization Policy").Result;

            contentKeyAuthorizationPolicy.Options.Add(policyOption);

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

            return(contentKeyAuthorizationPolicy);
        }
コード例 #9
0
        private IAssetDeliveryPolicy[] GetDeliveryPolicies(ContentProtection contentProtection)
        {
            List <IAssetDeliveryPolicy> deliveryPolicies = new List <IAssetDeliveryPolicy>();
            AssetDeliveryPolicyType     policyType       = AssetDeliveryPolicyType.NoDynamicEncryption;
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> policyConfig = null;
            string policyName = Constant.Media.DeliveryPolicy.DecryptionStorage;

            if (contentProtection.Aes)
            {
                policyType = AssetDeliveryPolicyType.DynamicEnvelopeEncryption;
                policyName = Constant.Media.DeliveryPolicy.EncryptionAes;
                ContentKeyType keyType        = ContentKeyType.EnvelopeEncryption;
                string         keyName        = Constant.Media.ContentProtection.ContentKeyNameAes;
                IContentKey    contentKey     = GetContentKey(keyType, keyName, contentProtection);
                Uri            keyDeliveryUrl = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);
                byte[]         encryptionIV   = CreateEncryptionKey();
                policyConfig = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>();
                policyConfig.Add(AssetDeliveryPolicyConfigurationKey.EnvelopeKeyAcquisitionUrl, keyDeliveryUrl.ToString());
                policyConfig.Add(AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, Convert.ToBase64String(encryptionIV));
                ContentKeyDeliveryType[] deliveryTypes  = new ContentKeyDeliveryType[] { ContentKeyDeliveryType.BaselineHttp };
                IAssetDeliveryPolicy     deliveryPolicy = GetDeliveryPolicy(policyName, policyType, policyConfig, deliveryTypes);
                deliveryPolicies.Add(deliveryPolicy);
            }
            if (contentProtection.DrmPlayReady && contentProtection.DrmWidevine)
            {
                policyType = AssetDeliveryPolicyType.DynamicCommonEncryption;
                policyName = Constant.Media.DeliveryPolicy.EncryptionDrmPlayReadyWidevine;
                ContentKeyType keyType    = ContentKeyType.CommonEncryption;
                string         keyName    = Constant.Media.ContentProtection.ContentKeyNameDrmPlayReadyWidevine;
                IContentKey    contentKey = GetContentKey(keyType, keyName, contentProtection);
                policyConfig = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>();
                Uri keyDeliveryUrl = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.PlayReadyLicense);
                policyConfig.Add(AssetDeliveryPolicyConfigurationKey.PlayReadyLicenseAcquisitionUrl, keyDeliveryUrl.ToString());
                keyDeliveryUrl = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.Widevine);
                policyConfig.Add(AssetDeliveryPolicyConfigurationKey.WidevineLicenseAcquisitionUrl, keyDeliveryUrl.ToString());
                ContentKeyDeliveryType[] deliveryTypes  = new ContentKeyDeliveryType[] { ContentKeyDeliveryType.PlayReadyLicense, ContentKeyDeliveryType.Widevine };
                IAssetDeliveryPolicy     deliveryPolicy = GetDeliveryPolicy(policyName, policyType, policyConfig, deliveryTypes);
                deliveryPolicies.Add(deliveryPolicy);
            }
            else if (contentProtection.DrmPlayReady)
            {
                policyType = AssetDeliveryPolicyType.DynamicCommonEncryption;
                policyName = Constant.Media.DeliveryPolicy.EncryptionDrmPlayReady;
                ContentKeyType keyType        = ContentKeyType.CommonEncryption;
                string         keyName        = Constant.Media.ContentProtection.ContentKeyNameDrmPlayReady;
                IContentKey    contentKey     = GetContentKey(keyType, keyName, contentProtection);
                Uri            keyDeliveryUrl = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.PlayReadyLicense);
                policyConfig = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>();
                policyConfig.Add(AssetDeliveryPolicyConfigurationKey.PlayReadyLicenseAcquisitionUrl, keyDeliveryUrl.ToString());
                ContentKeyDeliveryType[] deliveryTypes  = new ContentKeyDeliveryType[] { ContentKeyDeliveryType.PlayReadyLicense };
                IAssetDeliveryPolicy     deliveryPolicy = GetDeliveryPolicy(policyName, policyType, policyConfig, deliveryTypes);
                deliveryPolicies.Add(deliveryPolicy);
            }
            else if (contentProtection.DrmWidevine)
            {
                policyType = AssetDeliveryPolicyType.DynamicCommonEncryption;
                policyName = Constant.Media.DeliveryPolicy.EncryptionDrmWidevine;
                ContentKeyType keyType        = ContentKeyType.CommonEncryption;
                string         keyName        = Constant.Media.ContentProtection.ContentKeyNameDrmWidevine;
                IContentKey    contentKey     = GetContentKey(keyType, keyName, contentProtection);
                Uri            keyDeliveryUrl = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.Widevine);
                policyConfig = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>();
                policyConfig.Add(AssetDeliveryPolicyConfigurationKey.WidevineLicenseAcquisitionUrl, keyDeliveryUrl.ToString());
                ContentKeyDeliveryType[] deliveryTypes  = new ContentKeyDeliveryType[] { ContentKeyDeliveryType.Widevine };
                IAssetDeliveryPolicy     deliveryPolicy = GetDeliveryPolicy(policyName, policyType, policyConfig, deliveryTypes);
                deliveryPolicies.Add(deliveryPolicy);
            }
            return(deliveryPolicies.ToArray());
        }
コード例 #10
0
ファイル: DynamicEncryption.cs プロジェクト: zhshen/HuaweiAMS
        public static IContentKeyAuthorizationPolicyOption AddTokenRestrictedAuthorizationPolicyCENC(string optionName, ContentKeyDeliveryType deliveryType, IContentKey contentKey, string Audience, string Issuer, IList<TokenClaim> tokenclaimslist, bool AddContentKeyIdentifierClaim, TokenType tokentype, ExplorerTokenType detailedtokentype, TokenVerificationKey mytokenverificationkey, CloudMediaContext _context, string newLicenseTemplate, string openIdDiscoveryPath = null)
        {
            string tokenTemplateString = GenerateTokenRequirements(tokentype, Audience, Issuer, tokenclaimslist, AddContentKeyIdentifierClaim, mytokenverificationkey, openIdDiscoveryPath);
            string tname = detailedtokentype.ToString();

            List<ContentKeyAuthorizationPolicyRestriction> restrictions = new List<ContentKeyAuthorizationPolicyRestriction>
                                                        {
                                                            new ContentKeyAuthorizationPolicyRestriction
                                                            {
                                                                Name = tname + " Token Authorization Policy",
                                                                KeyRestrictionType = (int)ContentKeyRestrictionType.TokenRestricted,
                                                                Requirements = tokenTemplateString,
                                                            }
                                                        };

            IContentKeyAuthorizationPolicyOption policyOption =
         _context.ContentKeyAuthorizationPolicyOptions.Create(optionName,
             deliveryType,
                 restrictions, newLicenseTemplate);


            return policyOption;
        }
コード例 #11
0
        static public IContentKeyAuthorizationPolicy AddOpenAuthorizationPolicy(IContentKey contentKey, ContentKeyDeliveryType contentkeydeliverytype, string keydeliveryconfig, CloudMediaContext _context)
        {
            // Create ContentKeyAuthorizationPolicy with Open restrictions
            // and create authorization policy
            IContentKeyAuthorizationPolicy policy = _context.
                                                    ContentKeyAuthorizationPolicies.
                                                    CreateAsync("Open Authorization Policy").Result;

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

            ContentKeyAuthorizationPolicyRestriction restriction =
                new ContentKeyAuthorizationPolicyRestriction
            {
                Name = "Open Authorization Policy",
                KeyRestrictionType = (int)ContentKeyRestrictionType.Open,
                Requirements       = null // no requirements needed
            };

            restrictions.Add(restriction);

            IContentKeyAuthorizationPolicyOption policyOption =
                _context.ContentKeyAuthorizationPolicyOptions.Create(
                    "policy",
                    contentkeydeliverytype,
                    restrictions,
                    keydeliveryconfig);

            policy.Options.Add(policyOption);

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

            return(policy);
        }