public void DigitalVideoOnlyContentRestrictionAndAllowPassingVideoContentToUnknownOutputMutuallyExclusive()
        {
            string serializedTemplate = null;
            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();
            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            // Part 1: Make sure we cannot set DigitalVideoOnlyContentRestriction to true if
            //         UnknownOutputPassingOption.Allowed is set
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.Allowed;
            licenseTemplate.PlayRight.DigitalVideoOnlyContentRestriction = true;

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.DigitalVideoOnlyMutuallyExclusiveWithPassingToUnknownOutputError, ae.Message);
            }

            // Part 2: Make sure we cannot set UnknownOutputPassingOption.AllowedWithVideoConstriction
            //         if DigitalVideoOnlyContentRestriction is true
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.AllowedWithVideoConstriction;

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.DigitalVideoOnlyMutuallyExclusiveWithPassingToUnknownOutputError, ae.Message);
            }

            // Part 3: Make sure we can set DigitalVideoOnlyContentRestriction to true if
            //         UnknownOutputPassingOption.NotAllowed is set
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.NotAllowed;
            licenseTemplate.PlayRight.DigitalVideoOnlyContentRestriction = true;

            serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
            Assert.IsNotNull(serializedTemplate);

            Assert.IsNotNull(MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate));
        }
コード例 #2
0
ファイル: DynamicEncryption.cs プロジェクト: zhshen/HuaweiAMS
        /// <summary>
        /// Configures authorization policy. 
        /// Creates a content key. 
        /// Updates the PlayReady configuration XML file.
        /// </summary>
        /// <returns>The content key.</returns>
        public static IContentKey ConfigureKeyDeliveryServiceForPlayReady(CloudMediaContext _context, Guid keyId, byte[] keyValue, PlayReadyLicenseTemplate licenseTemplate,
            ContentKeyRestrictionType PlayReadyKeyRestriction, string PlayReadyPolicyName)
        {

            var contentKey = _context.ContentKeys.Create(keyId, keyValue, "key test", ContentKeyType.CommonEncryption);

            var restrictions = new List<ContentKeyAuthorizationPolicyRestriction>
                {
                    new ContentKeyAuthorizationPolicyRestriction {
                        Requirements = null, Name = Enum.GetName(typeof(ContentKeyRestrictionType),PlayReadyKeyRestriction),
                        KeyRestrictionType = (int)PlayReadyKeyRestriction }
                };

            IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = _context.
                        ContentKeyAuthorizationPolicies.
                        CreateAsync("Deliver Common Content Key with no restrictions").
                        Result;

            // Configure PlayReady license template.

            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            string newLicenseTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);

            IContentKeyAuthorizationPolicyOption policyOption =
                _context.ContentKeyAuthorizationPolicyOptions.Create(
                PlayReadyPolicyName,
                    ContentKeyDeliveryType.PlayReadyLicense,
                        restrictions, newLicenseTemplate);

            contentKeyAuthorizationPolicy.Options.Add(policyOption);

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

            return contentKey;
        }
        public void ValidateNonPersistentLicenseConstraints()
        {
            string serializedTemplate = null;
            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();
            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            // Part 1: Make sure we cannot set GracePeriod on a NonPersistent license
            licenseTemplate.LicenseType = PlayReadyLicenseType.Nonpersistent;
            licenseTemplate.GracePeriod = TimeSpan.FromDays(1);

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.GracePeriodCannotBeSetOnNonPersistentLicense, ae.Message);
            }

            // Part 2: Make sure we cannot set a FirstPlayExpiration on a NonPersistent license.
            licenseTemplate.GracePeriod = null;
            licenseTemplate.PlayRight.FirstPlayExpiration = TimeSpan.FromDays(1);

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.FirstPlayExpirationCannotBeSetOnNonPersistentLicense, ae.Message);
            }

            // Part 3: Make sure we cannot set a BeginDate on a NonPersistent license.
            licenseTemplate.PlayRight.FirstPlayExpiration = null;
            licenseTemplate.BeginDate = DateTime.UtcNow;

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.BeginDateCannotBeSetOnNonPersistentLicense, ae.Message);
            }

            // Part 4: Make sure we cannot set an ExpirationDate on a NonPersistent license.
            licenseTemplate.BeginDate = null;
            licenseTemplate.ExpirationDate = DateTime.UtcNow;

            try
            {
                serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail("Expected ArgumentException");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual(ErrorMessages.ExpirationCannotBeSetOnNonPersistentLicense, ae.Message);
            }
        }
        public void RoundTripTest()
        {
            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            responseTemplate.ResponseCustomData = "This is my response custom data";
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();
            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            licenseTemplate.LicenseType = PlayReadyLicenseType.Persistent;
            licenseTemplate.BeginDate = DateTime.Now.AddHours(-1);
            licenseTemplate.ExpirationDate = DateTime.Now.AddDays(30).ToUniversalTime();

            licenseTemplate.PlayRight.CompressedDigitalAudioOpl = 300;
            licenseTemplate.PlayRight.CompressedDigitalVideoOpl = 400;
            licenseTemplate.PlayRight.UncompressedDigitalAudioOpl = 250;
            licenseTemplate.PlayRight.UncompressedDigitalVideoOpl = 270;
            licenseTemplate.PlayRight.AnalogVideoOpl = 100;
            licenseTemplate.PlayRight.AgcAndColorStripeRestriction = new AgcAndColorStripeRestriction(1);
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.Allowed;
            licenseTemplate.PlayRight.ExplicitAnalogTelevisionOutputRestriction = new ExplicitAnalogTelevisionRestriction(0, true);
            licenseTemplate.PlayRight.ImageConstraintForAnalogComponentVideoRestriction = true;
            licenseTemplate.PlayRight.ImageConstraintForAnalogComputerMonitorRestriction = true;
            licenseTemplate.PlayRight.ScmsRestriction = new ScmsRestriction(2);

            string serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
            Assert.IsFalse(String.IsNullOrWhiteSpace(serializedTemplate));

            PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate);
            Assert.IsNotNull(responseTemplate2);
        }
コード例 #5
0
        static private string ConfigurePlayReadyLicenseTemplate()
        {
            // The following code configures PlayReady License Template using .NET classes
            // and returns the XML string.

            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            return MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
        }
コード例 #6
0
        static private string ConfigurePlayReadyLicenseTemplate()
        {
            // The following code configures PlayReady License Template using .NET classes
            // and returns the XML string.

            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();
            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.Allowed;
            licenseTemplate.AllowTestDevices = true;

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            return MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
        }
        private static string ConfigurePlayReadyLicenseTemplate()
        {
            // The following code configures PlayReady License Template using .NET classes
            // and returns the XML string.

            //The PlayReadyLicenseResponseTemplate class represents the template for the response sent back to the end user.
            //It contains a field for a custom data string between the license server and the application
            //(may be useful for custom app logic) as well as a list of one or more license templates.
            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();

            // The PlayReadyLicenseTemplate class represents a license template for creating PlayReady licenses
            // to be returned to the end users.
            //It contains the data on the content key in the license and any rights or restrictions to be
            //enforced by the PlayReady DRM runtime when using the content key.
            PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();
            //Configure whether the license is persistent (saved in persistent storage on the client)
            //or non-persistent (only held in memory while the player is using the license).
            licenseTemplate.LicenseType = PlayReadyLicenseType.Nonpersistent;

            // AllowTestDevices controls whether test devices can use the license or not.
            // If true, the MinimumSecurityLevel property of the license
            // is set to 150.  If false (the default), the MinimumSecurityLevel property of the license is set to 2000.
            licenseTemplate.AllowTestDevices = true;

            // You can also configure the Play Right in the PlayReady license by using the PlayReadyPlayRight class.
            // It grants the user the ability to playback the content subject to the zero or more restrictions
            // configured in the license and on the PlayRight itself (for playback specific policy).
            // Much of the policy on the PlayRight has to do with output restrictions
            // which control the types of outputs that the content can be played over and
            // any restrictions that must be put in place when using a given output.
            // For example, if the DigitalVideoOnlyContentRestriction is enabled,
            //then the DRM runtime will only allow the video to be displayed over digital outputs
            //(analog video outputs won’t be allowed to pass the content).

            //IMPORTANT: These types of restrictions can be very powerful but can also affect the consumer experience.
            // If the output protections are configured too restrictive,
            // the content might be unplayable on some clients. For more information, see the PlayReady Compliance Rules document.

            // For example:
            //licenseTemplate.PlayRight.AgcAndColorStripeRestriction = new AgcAndColorStripeRestriction(1);

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            return MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
        }
        public void RoundTripTestErrorWithRelativeExpirationDateExpirationDate()
        {
            try
            {
                PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
                responseTemplate.ResponseCustomData = "This is my response custom data";
                PlayReadyLicenseTemplate licenseTemplate = new PlayReadyLicenseTemplate();
                responseTemplate.LicenseTemplates.Add(licenseTemplate);

                licenseTemplate.LicenseType = PlayReadyLicenseType.Persistent;
                licenseTemplate.RelativeExpirationDate = TimeSpan.FromHours(1);
                licenseTemplate.ExpirationDate = DateTime.Now.AddHours(1);

                string serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                Assert.Fail();
            }
            catch (ArgumentException ae)
            {
                Assert.IsTrue(ae.Message.Contains(ErrorMessages.ExpirationDateAndRelativeExpirationDateCannotbeSetSimultaneouslyError));
                throw;
            }
        }