Exemple #1
0
        public void ProgressiveAssetDeliveryPolicyTestAttach()
        {
            var asset = _mediaContext.Assets.Create("Asset for EnvelopeAssetDeliveryPolicyTestAttach", AssetCreationOptions.None);


            IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("", AssetDeliveryPolicyType.NoDynamicEncryption, AssetDeliveryProtocol.ProgressiveDownload, null);


            asset.DeliveryPolicies.Add(policy);

            asset = _mediaContext.Assets.Where(a => a.Id == asset.Id).Single();
            var check = asset.DeliveryPolicies[0];

            // Assert.AreEqual(policy.Id, check.Id);
            Assert.AreEqual(1, asset.DeliveryPolicies.Count);

            List <IAssetDeliveryPolicy> policies = asset.DeliveryPolicies.ToList();

            foreach (IAssetDeliveryPolicy current in policies)
            {
                asset.DeliveryPolicies.Remove(current);
                current.Delete();
            }

            asset.Delete();
        }
        public static IAssetDeliveryPolicy CreateAssetDeliveryPolicy(CloudMediaContext objCloudMediaContext, IContentKey objIContentKey)
        {
            Uri keyAcquisitionUri = objIContentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);

            string envelopeEncryptionIV = Convert.ToBase64String(CryptoUtils.GenerateCryptographicallyStrongRandomBytes(16));

            // The following policy configuration specifies:
            //   key url that will have KID=<Guid> appended to the envelope and
            //   the Initialization Vector (IV) to use for the envelope encryption.
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> assetDeliveryPolicyConfiguration = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeKeyAcquisitionUrl, keyAcquisitionUri.ToString() },
                { AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, envelopeEncryptionIV }
            };

            IAssetDeliveryPolicy objIAssetDeliveryPolicy = objCloudMediaContext.AssetDeliveryPolicies.Create(
                "SmoothHLSDynamicEncryptionAssetDeliveryPolicy",
                AssetDeliveryPolicyType.DynamicEnvelopeEncryption,
                AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash,
                assetDeliveryPolicyConfiguration);

            // Add AssetDelivery Policy to the asset
            //objIAsset.DeliveryPolicies.Add(objIAssetDeliveryPolicy);
            Console.WriteLine();
            Console.WriteLine("Adding Asset Delivery Policy: " + objIAssetDeliveryPolicy.AssetDeliveryPolicyType);
            Console.WriteLine("Key Delivery URL = {0}", keyAcquisitionUri.ToString());

            return(objIAssetDeliveryPolicy);
        }
Exemple #3
0
        static public void CreateAssetDeliveryPolicy(IAsset asset, IContentKey key)
        {
            Uri keyAcquisitionUri = key.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);

            string envelopeEncryptionIV = Convert.ToBase64String(GetRandomBuffer(16));

            // The following policy configuration specifies:
            //   key url that will have KID=<Guid> appended to the envelope and
            //   the Initialization Vector (IV) to use for the envelope encryption.
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> assetDeliveryPolicyConfiguration =
                new Dictionary <AssetDeliveryPolicyConfigurationKey, string>
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeKeyAcquisitionUrl, keyAcquisitionUri.ToString() }
            };

            IAssetDeliveryPolicy assetDeliveryPolicy =
                _context.AssetDeliveryPolicies.Create(
                    "AssetDeliveryPolicy",
                    AssetDeliveryPolicyType.DynamicEnvelopeEncryption,
                    AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.Dash,
                    assetDeliveryPolicyConfiguration);

            // Add AssetDelivery Policy to the asset
            asset.DeliveryPolicies.Add(assetDeliveryPolicy);
            Console.WriteLine();
            Console.WriteLine("Adding Asset Delivery Policy: " +
                              assetDeliveryPolicy.AssetDeliveryPolicyType);
        }
        private void buttonExistingDelPol_Click(object sender, EventArgs e)
        {
            AssetDeliveryPolicyType poltype = AssetDeliveryPolicyType.None;

            if (_form1.GetContentKeyType == ContentKeyType.CommonEncryption)
            {
                poltype = AssetDeliveryPolicyType.DynamicCommonEncryption;
            }
            else if (_form1.GetContentKeyType == ContentKeyType.CommonEncryptionCbcs)
            {
                poltype = AssetDeliveryPolicyType.DynamicCommonEncryptionCbcs;
            }
            else if (_form1.GetContentKeyType == ContentKeyType.EnvelopeEncryption)
            {
                poltype = AssetDeliveryPolicyType.DynamicEnvelopeEncryption;
            }

            var form = new SelectDeliveryPolicy(_context, poltype);

            if (form.ShowDialog() == DialogResult.OK)
            {
                var pol = form.SelectedPolicy;
                if (pol != null)
                {
                    _existingDeliveryPolicy = pol;
                    textBoxDelPolId.Text    = string.Format("{0} ({1})", pol.Name, pol.Id);
                    ValidateButtonOk();
                }
            }
        }
Exemple #5
0
        public void PlayReadyAssetDeliveryPolicyTestAttach()
        {
            var asset = _mediaContext.Assets.Create("Asset for PlayReadyAssetDeliveryPolicyTestAttach", AssetCreationOptions.None);

            var contentKey = _mediaContext.ContentKeys.Create(Guid.NewGuid(), GetRandomData(16), "Content Key for PlayReadyAssetDeliveryPolicyTestAttach", ContentKeyType.CommonEncryption);

            asset.ContentKeys.Add(contentKey);

            IAssetDeliveryPolicy policy = CreatePlayReadyPolicy("Policy for PlayReadyAssetDeliveryPolicyTestAttach");

            asset.DeliveryPolicies.Add(policy);

            asset = _mediaContext.Assets.Where(a => a.Id == asset.Id).Single();
            var check = asset.DeliveryPolicies[0];

            Assert.AreEqual(policy.Id, check.Id);
            Assert.AreEqual(1, asset.DeliveryPolicies.Count);

            List <IAssetDeliveryPolicy> policies = asset.DeliveryPolicies.ToList();

            foreach (IAssetDeliveryPolicy current in policies)
            {
                asset.DeliveryPolicies.Remove(current);
                current.Delete();
            }

            asset.Delete();
        }
Exemple #6
0
        private void DoMenuRenamePolicy()
        {
            var policies = ReturnSelectedDeliveryPolicies();

            if (policies.Count == 1)
            {
                IAssetDeliveryPolicy DelPol = policies.FirstOrDefault();

                string value = DelPol.Name;

                if (Program.InputBox("Policy rename", string.Format("Enter the new name for policy '{0}' :", DelPol.Name), ref value) == DialogResult.OK)
                {
                    try
                    {
                        DelPol.Name = value;
                        DelPol.Update();
                        ListPolicies();
                    }
                    catch
                    {
                        MessageBox.Show("There is a problem when renaming the policy.");
                        return;
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            VerifyCerts();

            var credentials = new MediaServicesCredentials(_wamsAccount, _wamsAccountKey)
            {
                AcsBaseAddress = _wamsAcsBaseAddress,
                Scope          = _wamsAcsScope
            };

            _mediaContext = new CloudMediaContext(_wamsEndpoint, credentials);

            IAsset asset = CreateAsset();

            IContentKey key = CreateKeyWithPolicy(asset);

            IAssetDeliveryPolicy assetDeliveryPolicy = CreateAssetDeliveryPolicy(asset, key);

            asset.DeliveryPolicies.Add(assetDeliveryPolicy);

            Console.WriteLine("Asset Delivery Policy Added");

            ILocator streamingLocator = CreateLocator(asset);

            IStreamingEndpoint origin = GetOrigin(recreate: false);

            Uri uri = GetManifestUrl(origin, asset, streamingLocator);

            string keyDeliveryUrl = key.GetKeyDeliveryUrl(ContentKeyDeliveryType.FairPlay).ToString();

            Console.WriteLine("ism: {0}\nkey delivery: {1}", uri, keyDeliveryUrl);

            Console.ReadKey();
        }
Exemple #8
0
        public string[] GetProtectionTypes(IAsset asset)
        {
            List <string>        protectionTypes = new List <string>();
            IAssetDeliveryPolicy deliveryPolicy  = asset.DeliveryPolicies.Where(p => p.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicEnvelopeEncryption).SingleOrDefault();

            if (deliveryPolicy != null)
            {
                protectionTypes.Add(MediaProtection.AES.ToString());
            }
            deliveryPolicy = asset.DeliveryPolicies.Where(p => p.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicCommonEncryption).SingleOrDefault();
            if (deliveryPolicy != null)
            {
                IContentKey contentKey = asset.ContentKeys.Where(k => k.ContentKeyType == ContentKeyType.CommonEncryption).SingleOrDefault();
                if (contentKey != null)
                {
                    IContentKeyAuthorizationPolicy authPolicy = GetEntityById(MediaEntity.ContentKeyAuthPolicy, contentKey.AuthorizationPolicyId) as IContentKeyAuthorizationPolicy;
                    if (authPolicy != null)
                    {
                        IContentKeyAuthorizationPolicyOption policyOption = authPolicy.Options.Where(o => o.KeyDeliveryType == ContentKeyDeliveryType.PlayReadyLicense).SingleOrDefault();
                        if (policyOption != null)
                        {
                            protectionTypes.Add(MediaProtection.PlayReady.ToString());
                        }
                        policyOption = authPolicy.Options.Where(o => o.KeyDeliveryType == ContentKeyDeliveryType.Widevine).SingleOrDefault();
                        if (policyOption != null)
                        {
                            protectionTypes.Add(MediaProtection.Widevine.ToString());
                        }
                    }
                }
            }
            return(protectionTypes.ToArray());
        }
Exemple #9
0
        static public IAssetDeliveryPolicy CreateAssetDeliveryPolicyAES(IAsset asset, IContentKey key, AssetDeliveryProtocol assetdeliveryprotocol, string name, CloudMediaContext _context, Uri keyAcquisitionUri)
        {
            // if user does not specify a custom LA URL, let's use the AES key server from Azure Media Services
            if (keyAcquisitionUri == null)
            {
                keyAcquisitionUri = key.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);
            }

            string envelopeEncryptionIV = Convert.ToBase64String(GetRandomBuffer(16));

            // The following policy configuration specifies:
            //   key url that will have KID=<Guid> appended to the envelope and
            //   the Initialization Vector (IV) to use for the envelope encryption.
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> assetDeliveryPolicyConfiguration =
                new Dictionary <AssetDeliveryPolicyConfigurationKey, string>
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeKeyAcquisitionUrl, keyAcquisitionUri.ToString() },
                { AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, envelopeEncryptionIV }
            };

            IAssetDeliveryPolicy assetDeliveryPolicy =
                _context.AssetDeliveryPolicies.Create(
                    name,
                    AssetDeliveryPolicyType.DynamicEnvelopeEncryption,
                    assetdeliveryprotocol,
                    assetDeliveryPolicyConfiguration);

            // Add AssetDelivery Policy to the asset
            asset.DeliveryPolicies.Add(assetDeliveryPolicy);
            return(assetDeliveryPolicy);
        }
Exemple #10
0
        public void TestGetEncryptionState()
        {
            IAsset asset = JobTests.CreateSmoothAsset(_mediaContext, _filePaths, AssetCreationOptions.None);
            AssetDeliveryProtocol protocolsToSet = AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.Dash;
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> configuration = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>()
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeBaseKeyAcquisitionUrl, "https://www.test.com/" },
                { AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, Convert.ToBase64String(ContentKeyTests.GetRandomBuffer(16)) }
            };
            IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("Test Policy", AssetDeliveryPolicyType.DynamicEnvelopeEncryption, protocolsToSet, configuration);
            IContentKey          key    = _mediaContext.ContentKeys.Create(Guid.NewGuid(), ContentKeyTests.GetRandomBuffer(16), "Test key", ContentKeyType.EnvelopeEncryption);

            asset.ContentKeys.Add(key);
            asset.DeliveryPolicies.Add(policy);

            AssetEncryptionState state = asset.GetEncryptionState(protocolsToSet);

            Assert.AreEqual(AssetEncryptionState.DynamicEnvelopeEncryption, state);

            state = asset.GetEncryptionState(AssetDeliveryProtocol.Dash | AssetDeliveryProtocol.Hds);
            Assert.AreEqual(AssetEncryptionState.NoSinglePolicyApplies, state);

            state = asset.GetEncryptionState(AssetDeliveryProtocol.Hds);
            Assert.AreEqual(AssetEncryptionState.BlockedByPolicy, state);

            CleanupAsset(asset);
        }
Exemple #11
0
        public void FailToAttachPolicyIfRequiredEnvelopeKeyNotPresent()
        {
            var asset = _mediaContext.Assets.Create("Asset for FailToAttachPolicyIfRequiredEnvelopeKeyNotPresent", AssetCreationOptions.None);

            // Do not create or attach a content key

            IAssetDeliveryPolicy policy = CreateEnvelopePolicy("Policy for FailToAttachPolicyIfRequiredEnvelopeKeyNotPresent");

            try
            {
                asset.DeliveryPolicies.Add(policy);
                Assert.Fail("Expected DataServiceRequestException didn't occur.");
            }
            catch (DataServiceRequestException e)
            {
                Assert.IsTrue(e.ToString().Contains("Cannot set an AssetDeliveryPolicy specifying AssetDeliveryPolicyType.DynamicEnvelopeEncryption when no ContentKey with ContentKeyType.EnvelopeEncryption is linked to it"));

                throw;
            }
            finally
            {
                asset.Delete();
                policy.Delete();
            }
        }
 private void AddTestDeliveryPolicies(IAsset asset, AssetDeliveryProtocol protocol, AssetDeliveryPolicyType deliveryType)
 {
     if (deliveryType != AssetDeliveryPolicyType.None)
     {
         IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("Test Asset Delivery Policy", deliveryType, protocol, null);
         asset.DeliveryPolicies.Add(policy);
     }
 }
Exemple #13
0
        private void DeleteDeliveryPolicyAndVerify(IAssetDeliveryPolicy policy)
        {
            string id = policy.Id;

            policy.Delete();

            IAssetDeliveryPolicy policyToCheck = _mediaContext.AssetDeliveryPolicies.Where(p => p.Id == id).FirstOrDefault();

            Assert.IsNull(policyToCheck);
        }
Exemple #14
0
        private IAssetDeliveryPolicy GetDeliveryPolicy(AssetDeliveryPolicyType policyType, Dictionary <AssetDeliveryPolicyConfigurationKey,
                                                                                                       string> policyConfig, string policyName, ContentKeyDeliveryType deliveryType)
        {
            IAssetDeliveryPolicy deliveryPolicy = GetEntityByName(MediaEntity.DeliveryPolicy, policyName, true) as IAssetDeliveryPolicy;

            if (deliveryPolicy == null)
            {
                AssetDeliveryProtocol policyProtocols = GetDeliveryProtocols(deliveryType);
                deliveryPolicy = _media.AssetDeliveryPolicies.Create(policyName, policyType, policyProtocols, policyConfig);
            }
            return(deliveryPolicy);
        }
Exemple #15
0
        private void DoDeleteDelPol()
        {
            if (listViewPolicies.SelectedIndices.Count > 0)
            {
                string question;
                int    nbError    = 0;
                string messagestr = "";

                if (listViewPolicies.SelectedIndices.Count == 1)
                {
                    question = "Are you sure that you want to DELETE this policy from the Azure Media Services account ?";
                }
                else
                {
                    question = string.Format("Are you sure that you want to DELETE these {0} policies from the Azure Media Services account ?", listViewPolicies.SelectedIndices.Count);
                }

                if (MessageBox.Show(question, "Delivery policy deletion", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    this.Cursor = Cursors.WaitCursor;
                    foreach (var ind in listViewPolicies.SelectedIndices)
                    {
                        IAssetDeliveryPolicy DelPol = delPolicies.Skip((int)ind).Take(1).FirstOrDefault();

                        if (DelPol != null)
                        {
                            try
                            {
                                DelPol.Delete();
                            }
                            catch (Exception e)
                            {
                                nbError++;
                                if (e.InnerException != null)
                                {
                                    messagestr = Program.GetErrorMessage(e);
                                }
                            }
                        }
                    }
                    this.Cursor = Cursors.Default;

                    if (nbError > 0)
                    {
                        messagestr = string.Format("Error when deleting {0} delivery policies.", nbError) + Constants.endline + messagestr;
                        MessageBox.Show(messagestr);
                    }

                    ListPolicies();
                }
            }
        }
Exemple #16
0
        /// <summary>
        /// Create an asset and configure asset delivery policies.
        /// </summary>
        /// <returns></returns>
        public static IAsset CreateAndConfigureAsset()
        {
            IAsset asset = _context.Assets.Create(AssetlName, AssetCreationOptions.None);

            IAssetDeliveryPolicy policy =
                _context.AssetDeliveryPolicies.Create("Clear Policy",
                                                      AssetDeliveryPolicyType.NoDynamicEncryption,
                                                      AssetDeliveryProtocol.HLS | AssetDeliveryProtocol.SmoothStreaming | AssetDeliveryProtocol.Dash, null);

            asset.DeliveryPolicies.Add(policy);

            return(asset);
        }
Exemple #17
0
        static public IAssetDeliveryPolicy CreateAssetDeliveryPolicyNoDynEnc(IAsset asset, AssetDeliveryProtocol assetdeliveryprotocol, CloudMediaContext _context)
        {
            IAssetDeliveryPolicy assetDeliveryPolicy =
                _context.AssetDeliveryPolicies.Create(
                    "AssetDeliveryPolicy NoDynEnc",
                    AssetDeliveryPolicyType.NoDynamicEncryption,
                    assetdeliveryprotocol,
                    null);         //  no dyn enc then no need for configuration

            // Add AssetDelivery Policy to the asset
            asset.DeliveryPolicies.Add(assetDeliveryPolicy);
            return(assetDeliveryPolicy);
        }
Exemple #18
0
        public void AssetDeliveryPolicyTestUpdate()
        {
            IAssetDeliveryPolicy policy = CreateEnvelopePolicy("AssetDeliveryPolicyTestUpdate");

            string newName = "somenewname";

            policy.Name = newName;
            policy.Update();

            var check = _mediaContext.AssetDeliveryPolicies.Where(p => p.Id == policy.Id).AsEnumerable().Single();

            Assert.AreEqual(newName, check.Name);

            DeleteDeliveryPolicyAndVerify(policy);
        }
Exemple #19
0
        private void SetupCommonPolicy(IAsset asset, AssetDeliveryProtocol protocol)
        {
            IContentKey key = _mediaContext.ContentKeys.Create(Guid.NewGuid(), ContentKeyTests.GetRandomBuffer(16), "Common Encryption Key", ContentKeyType.CommonEncryption);

            asset.ContentKeys.Add(key);

            Dictionary <AssetDeliveryPolicyConfigurationKey, string> config = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>()
            {
                { AssetDeliveryPolicyConfigurationKey.PlayReadyLicenseAcquisitionUrl, "https://fakeKeyDeliveryurl.com/PlayReady" }
            };

            IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("Clear Policy", AssetDeliveryPolicyType.DynamicCommonEncryption, protocol, config);

            asset.DeliveryPolicies.Add(policy);
        }
Exemple #20
0
        private List <IAssetDeliveryPolicy> ReturnSelectedDeliveryPolicies()
        {
            List <IAssetDeliveryPolicy> Selection = new List <IAssetDeliveryPolicy>();

            foreach (int selectedindex in listViewPolicies.SelectedIndices)
            {
                IAssetDeliveryPolicy DP = delPolicies.Where(pol => pol.Id == listViewPolicies.Items[selectedindex].SubItems[3].Text).FirstOrDefault();

                if (DP != null)
                {
                    Selection.Add(DP);
                }
            }
            return(Selection);
        }
Exemple #21
0
        private void SetupEnvelopePolicy(IAsset asset, AssetDeliveryProtocol protocol)
        {
            IContentKey key = _mediaContext.ContentKeys.Create(Guid.NewGuid(), ContentKeyTests.GetRandomBuffer(16), "Envelope Encryption Key", ContentKeyType.EnvelopeEncryption);

            asset.ContentKeys.Add(key);


            Dictionary <AssetDeliveryPolicyConfigurationKey, string> config = new Dictionary <AssetDeliveryPolicyConfigurationKey, string>()
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeBaseKeyAcquisitionUrl, "https://fakeKeyDeliveryurl.com/" },
                { AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, Convert.ToBase64String(Guid.NewGuid().ToByteArray()) } // TODO: Remove this once no IV is supported
            };

            IAssetDeliveryPolicy policy = _mediaContext.AssetDeliveryPolicies.Create("Clear Policy", AssetDeliveryPolicyType.DynamicEnvelopeEncryption, protocol, config);

            asset.DeliveryPolicies.Add(policy);
        }
        //Key Delivery URL = https://willzhanmediaservice.keydelivery.mediaservices.windows.net/?KID=7dfa376f-8a29-44f1-b546-3215492fe12f
        //You must publish AFTER you configure AES dynamic encryption. Segment manifest will contain encryption info.
        public static void DynamicAesEncryptionFlow(CloudMediaContext objCloudMediaContext, IAsset objIAsset)
        {
            //Create IContentKey
            IContentKey objIContentKey = CreateEnvelopeTypeContentKey(objCloudMediaContext);

            //add AuthorizationPolicy to IContentKey
            objIContentKey = AddAuthorizationPolicyToContentKey(objCloudMediaContext, objIContentKey, objIAsset.Id);

            //create asset delivery policy
            IAssetDeliveryPolicy objIAssetDeliveryPolicy = CreateAssetDeliveryPolicy(objCloudMediaContext, objIContentKey);

            //Associate IContentKey with IAsset
            objIAsset.ContentKeys.Add(objIContentKey);

            // Add AssetDelivery Policy to the asset
            objIAsset.DeliveryPolicies.Add(objIAssetDeliveryPolicy);
        }
Exemple #23
0
        public void TestAssetDeliveryPolicyCreateRetry()
        {
            var expected = new AssetDeliveryPolicyData {
                Name = "testData"
            };
            var fakeException   = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var dataContextMock = TestMediaServicesClassFactory.CreateSaveChangesMock(fakeException, 2, expected);

            dataContextMock.Setup((ctxt) => ctxt.AddObject("AssetDeliveryPolicies", It.IsAny <object>()));

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            var task = _mediaContext.AssetDeliveryPolicies.CreateAsync(expected.Name, AssetDeliveryPolicyType.None, AssetDeliveryProtocol.None, null);

            task.Wait();
            IAssetDeliveryPolicy actual = task.Result;

            Assert.AreEqual(expected.Name, actual.Name);
            dataContextMock.Verify((ctxt) => ctxt.SaveChangesAsync(It.IsAny <object>()), Times.Exactly(2));
        }
        static public IAssetDeliveryPolicy CreateAssetDeliveryPolicyAES(IAsset asset, IContentKey key, AssetDeliveryProtocol assetdeliveryprotocol, string name, CloudMediaContext _context, Uri keyAcquisitionUri)
        {
            // if user does not specify a custom LA URL, let's use the AES key server from Azure Media Services
            if (keyAcquisitionUri == null)
            {
                keyAcquisitionUri = key.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp);
            }

            // let's key the url with the key id parameter
            UriBuilder uriBuilder = new UriBuilder(keyAcquisitionUri);

            uriBuilder.Query  = String.Empty;
            keyAcquisitionUri = uriBuilder.Uri;

            // Removed in March 2016. In order to use EnvelopeBaseKeyAcquisitionUrl and reuse the same policy for several assets
            //string envelopeEncryptionIV = Convert.ToBase64String(GetRandomBuffer(16));

            // The following policy configuration specifies:
            //   key url that will have KID=<Guid> appended to the envelope and
            //   the Initialization Vector (IV) to use for the envelope encryption.
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> assetDeliveryPolicyConfiguration =
                new Dictionary <AssetDeliveryPolicyConfigurationKey, string>
            {
                { AssetDeliveryPolicyConfigurationKey.EnvelopeBaseKeyAcquisitionUrl, keyAcquisitionUri.ToString() }
                //{AssetDeliveryPolicyConfigurationKey.EnvelopeKeyAcquisitionUrl, keyAcquisitionUri.ToString()},
                //{AssetDeliveryPolicyConfigurationKey.EnvelopeEncryptionIVAsBase64, envelopeEncryptionIV}
            };

            IAssetDeliveryPolicy assetDeliveryPolicy =
                _context.AssetDeliveryPolicies.Create(
                    name,
                    AssetDeliveryPolicyType.DynamicEnvelopeEncryption,
                    assetdeliveryprotocol,
                    assetDeliveryPolicyConfiguration);

            // Add AssetDelivery Policy to the asset
            asset.DeliveryPolicies.Add(assetDeliveryPolicy);
            return(assetDeliveryPolicy);
        }
Exemple #25
0
        private void UpdateTestCasesForAddedPolicy(List <TestCase> testCases, IList <IAssetDeliveryPolicy> policies)
        {
            foreach (TestCase testCase in testCases)
            {
                IAssetDeliveryPolicy policy = policies.Where(p => p.AssetDeliveryProtocol.HasFlag(testCase.ProtocolsToTest)).SingleOrDefault();

                if (policy == null)
                {
                    testCase.ExpectedState = DecideBetweenBlockedOrMultiplePolicies(testCase.ProtocolsToTest, policies);
                }
                else
                {
                    switch (policy.AssetDeliveryPolicyType)
                    {
                    case AssetDeliveryPolicyType.Blocked:
                        testCase.ExpectedState = AssetEncryptionState.BlockedByPolicy;
                        break;

                    case AssetDeliveryPolicyType.DynamicCommonEncryption:
                        testCase.ExpectedState = AssetEncryptionState.DynamicCommonEncryption;
                        break;

                    case AssetDeliveryPolicyType.DynamicEnvelopeEncryption:
                        testCase.ExpectedState = AssetEncryptionState.DynamicEnvelopeEncryption;
                        break;

                    case AssetDeliveryPolicyType.NoDynamicEncryption:
                        testCase.ExpectedState = AssetEncryptionState.NoDynamicEncryption;
                        break;

                    default:
                        throw new Exception("Unexpected policy type");
                    }
                }
            }
        }
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info($"AMS v2 Function - CreateAssetDeliveryPolicy was triggered!");

            string jsonContent = await req.Content.ReadAsStringAsync();

            dynamic data = JsonConvert.DeserializeObject(jsonContent);

            // Validate input objects
            if (data.assetDeliveryPolicyName == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetDeliveryPolicyName in the input object" }));
            }
            if (data.assetDeliveryPolicyType == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetDeliveryPolicyType in the input object" }));
            }
            if (data.assetDeliveryPolicyProtocol == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetDeliveryPolicyProtocol in the input object" }));
            }
            string assetDeliveryPolicyName = data.assetDeliveryPolicyName;
            string assetDeliveryPolicyType = data.assetDeliveryPolicyType;

            if (!MediaServicesHelper.AMSAssetDeliveryPolicyType.ContainsKey(assetDeliveryPolicyType))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid assetDeliveryPolicyType in the input object" }));
            }
            List <string> assetDeliveryPolicyProtocol = ((JArray)data.assetDeliveryPolicyProtocol).ToObject <List <string> >();

            foreach (var p in assetDeliveryPolicyProtocol)
            {
                if (!MediaServicesHelper.AMSAssetDeliveryProtocol.ContainsKey(p))
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid assetDeliveryPolicyProtocol in the input object" }));
                }
            }
            List <string> assetDeliveryPolicyContentProtectionNames = null;
            string        fairPlayPolicyId = null;

            if (data.assetDeliveryPolicyContentProtection != null)
            {
                assetDeliveryPolicyContentProtectionNames = ((JArray)data.assetDeliveryPolicyContentProtection).ToObject <List <string> >();
                foreach (var p in assetDeliveryPolicyContentProtectionNames)
                {
                    if (!MediaServicesHelper.AMSAssetDeliveryContentProtection.ContainsKey(p))
                    {
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid assetDeliveryPolicyContentProtection in the input object" }));
                    }
                    if (MediaServicesHelper.AMSAssetDeliveryContentProtection[p] == MediaServicesHelper.AssetDeliveryContentProtection.FairPlay)
                    {
                        if (fairPlayPolicyId == null)
                        {
                            return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass fairPlayContentKeyAuthorizationPolicyOptionId in the input object" }));
                        }
                        fairPlayPolicyId = data.fairPlayContentKeyAuthorizationPolicyOptionId;
                    }
                }
            }


            MediaServicesCredentials amsCredentials = new MediaServicesCredentials();
            IAssetDeliveryPolicy     policy         = null;

            try
            {
                // Load AMS account context
                log.Info($"Using AMS v2 REST API Endpoint : {amsCredentials.AmsRestApiEndpoint.ToString()}");

                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(amsCredentials.AmsAadTenantDomain,
                                                                                       new AzureAdClientSymmetricKey(amsCredentials.AmsClientId, amsCredentials.AmsClientSecret),
                                                                                       AzureEnvironments.AzureCloudEnvironment);
                AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);
                _context = new CloudMediaContext(amsCredentials.AmsRestApiEndpoint, tokenProvider);

                AssetDeliveryPolicyType assetDeliveryPolicyTypeValue     = MediaServicesHelper.AMSAssetDeliveryPolicyType[assetDeliveryPolicyType];
                AssetDeliveryProtocol   assetDeliveryPolicyProtocolValue = AssetDeliveryProtocol.None;
                foreach (var p in assetDeliveryPolicyProtocol)
                {
                    assetDeliveryPolicyProtocolValue |= MediaServicesHelper.AMSAssetDeliveryProtocol[p];
                }
                Dictionary <Asset​Delivery​Policy​Configuration​Key, String> assetDeliveryPolicyConfigurationValue = null;
                if (assetDeliveryPolicyContentProtectionNames != null)
                {
                    IContentKeyAuthorizationPolicyOption fairplayPolicyOpiton = null;
                    if (fairPlayPolicyId != null)
                    {
                        fairplayPolicyOpiton = _context.ContentKeyAuthorizationPolicyOptions.Where(p => p.Id == fairPlayPolicyId).Single();
                        if (fairplayPolicyOpiton == null)
                        {
                            return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "FairPlay ContentKeyAuthorizationPolicyOption not found" }));
                        }
                    }
                    assetDeliveryPolicyConfigurationValue = CreateDeliveryPolicyConfiguration(assetDeliveryPolicyContentProtectionNames, fairplayPolicyOpiton);
                }
                policy = _context.AssetDeliveryPolicies.Create(assetDeliveryPolicyName,
                                                               assetDeliveryPolicyTypeValue, assetDeliveryPolicyProtocolValue, assetDeliveryPolicyConfigurationValue);
            }
            catch (Exception e)
            {
                log.Info($"ERROR: Exception {e}");
                return(req.CreateResponse(HttpStatusCode.BadRequest));
            }

            return(req.CreateResponse(HttpStatusCode.OK, new
            {
                assetDeliveryPolicyId = policy.Id
            }));
        }
Exemple #27
0
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info($"AMS v2 Function - Add Dynamic Encryption was triggered!");

            string jsonContent = await req.Content.ReadAsStringAsync();

            dynamic data = JsonConvert.DeserializeObject(jsonContent);

            // Validate input objects
            if (data.assetId == null && data.programId == null && data.channelName == null && data.programName == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetId or programID or channelName/programName in the input object" }));
            }

            if (data.contentKeyAuthorizationPolicyId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass contentKeyAuthorizationPolicyId in the input object" }));
            }

            if (data.assetDeliveryPolicyId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetDeliveryPolicyId in the input object" }));
            }

            if (data.contentKeyType == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass contentKeyType in the input object" }));
            }

            string assetId     = data.assetId;
            string programId   = data.programId;
            string channelName = data.channelName;
            string programName = data.programName;
            string contentKeyAuthorizationPolicyId = data.contentKeyAuthorizationPolicyId;
            string assetDeliveryPolicyId           = data.assetDeliveryPolicyId;
            string contentKeyTypeName = data.contentKeyType;
            string contentKeyId       = data.keyId;
            string contentKeySecret   = data.contentKey;

            if (!MediaServicesHelper.AMSContentKeyType.ContainsKey(contentKeyTypeName))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid contentKeyType in the input object" }));
            }


            ContentKeyType contentKeyType = MediaServicesHelper.AMSContentKeyType[contentKeyTypeName];

            if (contentKeyType != ContentKeyType.CommonEncryption && contentKeyType != ContentKeyType.CommonEncryptionCbcs && contentKeyType != ContentKeyType.EnvelopeEncryption)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid contentKeyType in the input object" }));
            }


            string contentKeyName = null;

            if (data.contentKeyName != null)
            {
                contentKeyName = data.contentKeyName;
            }

            MediaServicesCredentials amsCredentials = new MediaServicesCredentials();
            IAsset asset = null;
            IContentKeyAuthorizationPolicy ckaPolicy = null;
            IAssetDeliveryPolicy           adPolicy  = null;
            IContentKey contentKey = null;

            try
            {
                // Load AMS account context
                log.Info($"Using AMS v2 REST API Endpoint : {amsCredentials.AmsRestApiEndpoint.ToString()}");

                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(amsCredentials.AmsAadTenantDomain,
                                                                                       new AzureAdClientSymmetricKey(amsCredentials.AmsClientId, amsCredentials.AmsClientSecret),
                                                                                       AzureEnvironments.AzureCloudEnvironment);
                AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);
                _context = new CloudMediaContext(amsCredentials.AmsRestApiEndpoint, tokenProvider);

                // Let's get the asset
                if (assetId != null)
                {
                    // Get the Asset, ContentKeyAuthorizationPolicy, AssetDeliveryPolicy
                    asset = _context.Assets.Where(a => a.Id == assetId).FirstOrDefault();
                    if (asset == null)
                    {
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Asset not found" }));
                    }
                }
                else if (programId != null)
                {
                    var program = _context.Programs.Where(p => p.Id == programId).FirstOrDefault();
                    if (program == null)
                    {
                        log.Info("Program not found");
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new
                        {
                            error = "Program not found"
                        }));
                    }
                    asset = program.Asset;
                }
                else // with channelName and programName
                {
                    // find the Channel, Program and Asset
                    var channel = _context.Channels.Where(c => c.Name == channelName).FirstOrDefault();
                    if (channel == null)
                    {
                        log.Info("Channel not found");
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new
                        {
                            error = "Channel not found"
                        }));
                    }

                    var program = channel.Programs.Where(p => p.Name == programName).FirstOrDefault();
                    if (program == null)
                    {
                        log.Info("Program not found");
                        return(req.CreateResponse(HttpStatusCode.BadRequest, new
                        {
                            error = "Program not found"
                        }));
                    }
                    asset = program.Asset;
                }

                log.Info($"Using asset Id : {asset.Id}");

                ckaPolicy = _context.ContentKeyAuthorizationPolicies.Where(p => p.Id == contentKeyAuthorizationPolicyId).Single();
                if (ckaPolicy == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "ContentKeyAuthorizationPolicy not found" }));
                }
                adPolicy = _context.AssetDeliveryPolicies.Where(p => p.Id == assetDeliveryPolicyId).Single();
                if (adPolicy == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "AssetDeliveryPolicy not found" }));
                }

                if (contentKeyId != null)
                {
                    string keyiddwitprefix = "";

                    if (contentKeyId.StartsWith("nb:kid:UUID:"))
                    {
                        keyiddwitprefix = contentKeyId;
                        contentKeyId    = contentKeyId.Substring(12);
                    }
                    else
                    {
                        keyiddwitprefix = "nb:kid:UUID:" + contentKeyId;
                    }

                    // let's retrieve the key if it exists already
                    contentKey = _context.ContentKeys.Where(k => k.Id == keyiddwitprefix).FirstOrDefault();
                }

                if (contentKey == null) // let's create it as it was not found or delivered to the function
                {
                    switch (contentKeyType)
                    {
                    case ContentKeyType.CommonEncryption:
                        if (contentKeyName == null)
                        {
                            contentKeyName = "Common Encryption ContentKey";
                        }
                        contentKey = MediaServicesHelper.CreateContentKey(_context, contentKeyName, ContentKeyType.CommonEncryption, contentKeyId, contentKeySecret);
                        break;

                    case ContentKeyType.CommonEncryptionCbcs:
                        if (contentKeyName == null)
                        {
                            contentKeyName = "Common Encryption CBCS ContentKey";
                        }
                        contentKey = MediaServicesHelper.CreateContentKey(_context, contentKeyName, ContentKeyType.CommonEncryptionCbcs, contentKeyId, contentKeySecret);
                        break;

                    case ContentKeyType.EnvelopeEncryption:
                        if (contentKeyName == null)
                        {
                            contentKeyName = "Envelope Encryption ContentKey";
                        }
                        contentKey = MediaServicesHelper.CreateContentKey(_context, contentKeyName, ContentKeyType.EnvelopeEncryption, contentKeyId, contentKeySecret);
                        break;
                    }
                }

                asset.ContentKeys.Add(contentKey);
                contentKey.AuthorizationPolicyId = ckaPolicy.Id;
                contentKey = contentKey.UpdateAsync().Result;
                asset.DeliveryPolicies.Add(adPolicy);
            }
            catch (Exception ex)
            {
                string message = ex.Message + ((ex.InnerException != null) ? Environment.NewLine + MediaServicesHelper.GetErrorMessage(ex) : "");
                log.Info($"ERROR: Exception {message}");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, new { error = message }));
            }

            return(req.CreateResponse(HttpStatusCode.OK, new
            {
                contentKeyId = contentKey.Id,
                assetId = asset.Id
            }));
        }
        public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info($"AMS v2 Function - CreateContentKeyAuthorizationPolicy was triggered!");

            string jsonContent = await req.Content.ReadAsStringAsync();

            dynamic data = JsonConvert.DeserializeObject(jsonContent);

            // Validate input objects
            if (data.assetId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetId in the input object" }));
            }
            if (data.contentKeyAuthorizationPolicyId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass contentKeyAuthorizationPolicyId in the input object" }));
            }
            if (data.assetDeliveryPolicyId == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass assetDeliveryPolicyId in the input object" }));
            }
            if (data.contentKeyType == null)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass contentKeyType in the input object" }));
            }
            string assetId = data.assetId;
            string contentKeyAuthorizationPolicyId = data.contentKeyAuthorizationPolicyId;
            string assetDeliveryPolicyId           = data.assetDeliveryPolicyId;
            string contentKeyTypeName = data.contentKeyType;

            if (!MediaServicesHelper.AMSContentKeyType.ContainsKey(contentKeyTypeName))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid contentKeyType in the input object" }));
            }
            ContentKeyType contentKeyType = MediaServicesHelper.AMSContentKeyType[contentKeyTypeName];

            if (contentKeyType != ContentKeyType.CommonEncryption && contentKeyType != ContentKeyType.CommonEncryptionCbcs && contentKeyType != ContentKeyType.EnvelopeEncryption)
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Please pass a valid contentKeyType in the input object" }));
            }
            string contentKeyName = null;

            if (data.contentKeyName != null)
            {
                contentKeyName = data.contentKeyName;
            }

            MediaServicesCredentials amsCredentials = new MediaServicesCredentials();
            IAsset asset = null;
            IContentKeyAuthorizationPolicy ckaPolicy = null;
            IAssetDeliveryPolicy           adPolicy  = null;
            IContentKey contentKey = null;

            try
            {
                // Load AMS account context
                log.Info($"Using AMS v2 REST API Endpoint : {amsCredentials.AmsRestApiEndpoint.ToString()}");

                AzureAdTokenCredentials tokenCredentials = new AzureAdTokenCredentials(amsCredentials.AmsAadTenantDomain,
                                                                                       new AzureAdClientSymmetricKey(amsCredentials.AmsClientId, amsCredentials.AmsClientSecret),
                                                                                       AzureEnvironments.AzureCloudEnvironment);
                AzureAdTokenProvider tokenProvider = new AzureAdTokenProvider(tokenCredentials);
                _context = new CloudMediaContext(amsCredentials.AmsRestApiEndpoint, tokenProvider);

                // Get the Asset, ContentKeyAuthorizationPolicy, AssetDeliveryPolicy
                asset = _context.Assets.Where(a => a.Id == assetId).FirstOrDefault();
                if (asset == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "Asset not found" }));
                }
                ckaPolicy = _context.ContentKeyAuthorizationPolicies.Where(p => p.Id == contentKeyAuthorizationPolicyId).Single();
                if (ckaPolicy == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "ContentKeyAuthorizationPolicy not found" }));
                }
                adPolicy = _context.AssetDeliveryPolicies.Where(p => p.Id == assetDeliveryPolicyId).Single();
                if (adPolicy == null)
                {
                    return(req.CreateResponse(HttpStatusCode.BadRequest, new { error = "AssetDeliveryPolicy not found" }));
                }
                switch (contentKeyType)
                {
                case ContentKeyType.CommonEncryption:
                    if (contentKeyName == null)
                    {
                        contentKeyName = "Common Encryption ContentKey";
                    }
                    contentKey = MediaServicesHelper.CreateContentKey(_context, contentKeyName, ContentKeyType.CommonEncryption);
                    break;

                case ContentKeyType.CommonEncryptionCbcs:
                    if (contentKeyName == null)
                    {
                        contentKeyName = "Common Encryption CBCS ContentKey";
                    }
                    contentKey = MediaServicesHelper.CreateContentKey(_context, contentKeyName, ContentKeyType.CommonEncryptionCbcs);
                    break;

                case ContentKeyType.EnvelopeEncryption:
                    if (contentKeyName == null)
                    {
                        contentKeyName = "Envelope Encryption ContentKey";
                    }
                    contentKey = MediaServicesHelper.CreateContentKey(_context, contentKeyName, ContentKeyType.EnvelopeEncryption);
                    break;
                }
                asset.ContentKeys.Add(contentKey);
                contentKey.AuthorizationPolicyId = ckaPolicy.Id;
                contentKey = contentKey.UpdateAsync().Result;
                asset.DeliveryPolicies.Add(adPolicy);
            }
            catch (Exception e)
            {
                log.Info($"ERROR: Exception {e}");
                return(req.CreateResponse(HttpStatusCode.BadRequest));
            }

            return(req.CreateResponse(HttpStatusCode.OK, new
            {
                contentKeyId = contentKey.Id
            }));
        }
Exemple #29
0
        private IAssetDeliveryPolicy[] GetDeliveryPolicies(ContentProtection contentProtection)
        {
            List <IAssetDeliveryPolicy> deliveryPolicies = new List <IAssetDeliveryPolicy>();
            AssetDeliveryPolicyType     policyType       = AssetDeliveryPolicyType.NoDynamicEncryption;
            Dictionary <AssetDeliveryPolicyConfigurationKey, string> policyConfig = null;
            string policyName = Constants.Media.DeliveryPolicy.DecryptionStorage;

            if (contentProtection.AES)
            {
                policyType = AssetDeliveryPolicyType.DynamicEnvelopeEncryption;
                policyName = Constants.Media.DeliveryPolicy.EncryptionAes;
                ContentKeyType keyType        = ContentKeyType.EnvelopeEncryption;
                string         keyName        = Constants.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));
                IAssetDeliveryPolicy deliveryPolicy = GetDeliveryPolicy(policyType, policyConfig, policyName, ContentKeyDeliveryType.BaselineHttp);
                deliveryPolicies.Add(deliveryPolicy);
            }
            if (contentProtection.DRMPlayReady && contentProtection.DRMWidevine)
            {
                policyType = AssetDeliveryPolicyType.DynamicCommonEncryption;
                policyName = Constants.Media.DeliveryPolicy.EncryptionDrmPlayReadyWidevine;
                ContentKeyType keyType    = ContentKeyType.CommonEncryption;
                string         keyName    = Constants.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());
                IAssetDeliveryPolicy deliveryPolicy = GetDeliveryPolicy(policyType, policyConfig, policyName, ContentKeyDeliveryType.PlayReadyLicense);
                deliveryPolicies.Add(deliveryPolicy);
                deliveryPolicy = GetDeliveryPolicy(policyType, policyConfig, policyName, ContentKeyDeliveryType.Widevine);
                deliveryPolicies.Add(deliveryPolicy);
            }
            else if (contentProtection.DRMPlayReady)
            {
                policyType = AssetDeliveryPolicyType.DynamicCommonEncryption;
                policyName = Constants.Media.DeliveryPolicy.EncryptionDrmPlayReady;
                ContentKeyType keyType        = ContentKeyType.CommonEncryption;
                string         keyName        = Constants.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());
                IAssetDeliveryPolicy deliveryPolicy = GetDeliveryPolicy(policyType, policyConfig, policyName, ContentKeyDeliveryType.PlayReadyLicense);
                deliveryPolicies.Add(deliveryPolicy);
            }
            else if (contentProtection.DRMWidevine)
            {
                policyType = AssetDeliveryPolicyType.DynamicCommonEncryption;
                policyName = Constants.Media.DeliveryPolicy.EncryptionDrmWidevine;
                ContentKeyType keyType        = ContentKeyType.CommonEncryption;
                string         keyName        = Constants.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());
                IAssetDeliveryPolicy deliveryPolicy = GetDeliveryPolicy(policyType, policyConfig, policyName, ContentKeyDeliveryType.Widevine);
                deliveryPolicies.Add(deliveryPolicy);
            }
            return(deliveryPolicies.ToArray());
        }
        private void DeleteDeliveryPolicyAndVerify(IAssetDeliveryPolicy policy)
        {
            string id = policy.Id;

            policy.Delete();

            IAssetDeliveryPolicy policyToCheck = _mediaContext.AssetDeliveryPolicies.Where(p => p.Id == id).FirstOrDefault();
            Assert.IsNull(policyToCheck);
        }
Exemple #31
0
        AssetEncryptionState IAsset.GetEncryptionState(AssetDeliveryProtocol protocolsToCheck)
        {
            IAsset asset = (IAsset)this;

            AssetEncryptionState returnValue = AssetEncryptionState.Unsupported;

            if (asset.IsStreamable)
            {
                if (asset.DeliveryPolicies.Count == 0)
                {
                    if ((asset.Options == AssetCreationOptions.EnvelopeEncryptionProtected) &&
                        (asset.AssetType == AssetType.MediaServicesHLS))
                    {
                        returnValue = AssetEncryptionState.StaticEnvelopeEncryption;
                    }
                    else if (asset.Options == AssetCreationOptions.CommonEncryptionProtected &&
                             (asset.AssetType == AssetType.MediaServicesHLS || asset.AssetType == AssetType.SmoothStreaming))
                    {
                        returnValue = AssetEncryptionState.StaticCommonEncryption;
                    }
                    else if (asset.Options == AssetCreationOptions.None)
                    {
                        returnValue = AssetEncryptionState.ClearOutput;
                    }
                    else if (asset.Options == AssetCreationOptions.StorageEncrypted)
                    {
                        returnValue = AssetEncryptionState.StorageEncryptedWithNoDeliveryPolicy;
                    }
                }
                else
                {
                    IAssetDeliveryPolicy policy = asset.DeliveryPolicies.Where(p => p.AssetDeliveryProtocol.HasFlag(protocolsToCheck)).FirstOrDefault();

                    if (policy == null)
                    {
                        if (asset.DeliveryPolicies.Any(p => ((p.AssetDeliveryProtocol & protocolsToCheck) != 0)))
                        {
                            returnValue = AssetEncryptionState.NoSinglePolicyApplies;
                        }
                        else
                        {
                            returnValue = AssetEncryptionState.BlockedByPolicy;
                        }
                    }
                    else
                    {
                        if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.Blocked)
                        {
                            returnValue = AssetEncryptionState.BlockedByPolicy;
                        }
                        else if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.NoDynamicEncryption)
                        {
                            returnValue = AssetEncryptionState.NoDynamicEncryption;
                        }
                        else if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicCommonEncryption)
                        {
                            if (((asset.AssetType == AssetType.SmoothStreaming) || (asset.AssetType == AssetType.MultiBitrateMP4)) &&
                                ((asset.Options == AssetCreationOptions.StorageEncrypted) || (asset.Options == AssetCreationOptions.None)))
                            {
                                returnValue = AssetEncryptionState.DynamicCommonEncryption;
                            }
                        }
                        else if (policy.AssetDeliveryPolicyType == AssetDeliveryPolicyType.DynamicEnvelopeEncryption)
                        {
                            if (((asset.AssetType == AssetType.SmoothStreaming) || (asset.AssetType == AssetType.MultiBitrateMP4)) &&
                                ((asset.Options == AssetCreationOptions.StorageEncrypted) || (asset.Options == AssetCreationOptions.None)))
                            {
                                returnValue = AssetEncryptionState.DynamicEnvelopeEncryption;
                            }
                        }
                    }
                }
            }

            return(returnValue);
        }