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);
        }
Exemplo n.º 2
0
        static string CreatePRLicenseResponseTemplate()
        {
            PlayReadyLicenseResponseTemplate objPlayReadyLicenseResponseTemplate = new PlayReadyLicenseResponseTemplate();

            objPlayReadyLicenseResponseTemplate.ResponseCustomData = string.Format("WAMS-SecureKeyDelivery, Time = {0}", DateTime.UtcNow.ToString("MM-dd-yyyy HH:mm:ss"));
            PlayReadyLicenseTemplate objPlayReadyLicenseTemplate = new PlayReadyLicenseTemplate();

            objPlayReadyLicenseResponseTemplate.LicenseTemplates.Add(objPlayReadyLicenseTemplate);

            //objPlayReadyLicenseTemplate.BeginDate        = DateTime.Now.AddHours(-1).ToUniversalTime();
            //objPlayReadyLicenseTemplate.ExpirationDate   = DateTime.Now.AddHours(10.0).ToUniversalTime();
            objPlayReadyLicenseTemplate.LicenseType      = PlayReadyLicenseType.Nonpersistent;
            objPlayReadyLicenseTemplate.AllowTestDevices = true;  //MinmumSecurityLevel: 150 vs 2000

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

            string serializedPRLicenseResponseTemplate = MediaServicesLicenseTemplateSerializer.Serialize(objPlayReadyLicenseResponseTemplate);

            //PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedPRLicenseResponseTemplate);

            return(serializedPRLicenseResponseTemplate);
        }
Exemplo n.º 3
0
        static private 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));
        }
Exemplo n.º 4
0
        static public string ConfigurePlayReadyLicenseTemplate(PlayReadyLicenseTemplate licenseTemplate)
        {
            // The following code configures PlayReady License Template using .NET classes
            // and returns the XML string.

            PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            return(MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate));
        }
Exemplo n.º 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();

            licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.Allowed;
            licenseTemplate.AllowTestDevices = true;

            responseTemplate.LicenseTemplates.Add(licenseTemplate);

            return(MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate));
        }
        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));
        }
        private void value_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool Error = false;

            try
            {
                PlayReadyLicenseTemplate plt = this.GetLicenseTemplateFromControls;
            }
            catch (Exception ex)
            {
                labelWarning.Text = Program.GetErrorMessage(ex);
                Error             = true;
            }

            if (!Error)
            {
                labelWarning.Text = string.Empty;
            }
        }
Exemplo n.º 8
0
        public void RoundTripTestErrorWithRelativeBeginDateBeginDate()
        {
            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.RelativeBeginDate = TimeSpan.FromHours(1);
                licenseTemplate.BeginDate         = DateTime.Now.AddHours(-1);

                string serializedTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
            }
            catch (ArgumentException ae)
            {
                Assert.IsTrue(ae.Message.Contains(ErrorMessages.BeginDateAndRelativeBeginDateCannotbeSetSimultaneouslyError));
                throw;
            }
        }
        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);
            }
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        private IContentKeyAuthorizationPolicy CreateContentKeyAuthPolicy(string policyName, IContentKey contentKey, ContentProtection contentProtection)
        {
            IContentKeyAuthorizationPolicy authPolicy = _media.ContentKeyAuthorizationPolicies.CreateAsync(policyName).Result;
            List <ContentKeyAuthorizationPolicyRestriction> policyRestrictions = CreateContentKeyAuthPolicyRestrictions(policyName, contentProtection);

            switch (contentKey.ContentKeyType)
            {
            case ContentKeyType.EnvelopeEncryption:
                string policyOptionName = string.Concat(policyName, Constants.Media.ContentProtection.AuthPolicyOptionNameAes);
                IContentKeyAuthorizationPolicyOption policyOption = GetEntityByName(MediaEntity.ContentKeyAuthPolicyOption, policyOptionName, true) as IContentKeyAuthorizationPolicyOption;
                if (policyOption == null)
                {
                    ContentKeyDeliveryType deliveryType = ContentKeyDeliveryType.BaselineHttp;
                    string deliveryConfig = string.Empty;
                    policyOption = _media.ContentKeyAuthorizationPolicyOptions.Create(policyOptionName, deliveryType, policyRestrictions, deliveryConfig);
                }
                authPolicy.Options.Add(policyOption);
                break;

            case ContentKeyType.CommonEncryption:
                if (contentProtection.DRMPlayReady)
                {
                    policyOptionName = string.Concat(policyName, Constants.Media.ContentProtection.AuthPolicyOptionNameDrmPlayReady);
                    policyOption     = GetEntityByName(MediaEntity.ContentKeyAuthPolicyOption, policyOptionName, true) as IContentKeyAuthorizationPolicyOption;
                    if (policyOption == null)
                    {
                        PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate();
                        PlayReadyLicenseTemplate         licenseTemplate  = new PlayReadyLicenseTemplate();
                        licenseTemplate.PlayRight.AllowPassingVideoContentToUnknownOutput = UnknownOutputPassingOption.NotAllowed;
                        licenseTemplate.LicenseType      = PlayReadyLicenseType.Nonpersistent;
                        licenseTemplate.AllowTestDevices = true;
                        responseTemplate.LicenseTemplates.Add(licenseTemplate);

                        ContentKeyDeliveryType deliveryType = ContentKeyDeliveryType.PlayReadyLicense;
                        string deliveryConfig = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate);
                        policyOption = _media.ContentKeyAuthorizationPolicyOptions.Create(policyOptionName, deliveryType, policyRestrictions, deliveryConfig);
                    }
                    authPolicy.Options.Add(policyOption);
                }
                if (contentProtection.DRMWidevine)
                {
                    policyOptionName = string.Concat(policyName, Constants.Media.ContentProtection.AuthPolicyOptionNameDrmWidevine);
                    policyOption     = GetEntityByName(MediaEntity.ContentKeyAuthPolicyOption, policyOptionName, true) as IContentKeyAuthorizationPolicyOption;
                    if (policyOption == null)
                    {
                        ContentKeySpecs contentKeySpecs = new ContentKeySpecs();
                        contentKeySpecs.required_output_protection      = new RequiredOutputProtection();
                        contentKeySpecs.required_output_protection.hdcp = Hdcp.HDCP_NONE;
                        contentKeySpecs.security_level = 1;
                        contentKeySpecs.track_type     = "SD";

                        WidevineMessage widevineMessage = new WidevineMessage();
                        widevineMessage.allowed_track_types = AllowedTrackTypes.SD_HD;
                        widevineMessage.content_key_specs   = new ContentKeySpecs[] { contentKeySpecs };
                        widevineMessage.policy_overrides    = new
                        {
                            can_play    = true,
                            can_renew   = true,
                            can_persist = false
                        };

                        ContentKeyDeliveryType deliveryType = ContentKeyDeliveryType.Widevine;
                        string deliveryConfig = JsonConvert.SerializeObject(widevineMessage);
                        policyOption = _media.ContentKeyAuthorizationPolicyOptions.Create(policyOptionName, deliveryType, policyRestrictions, deliveryConfig);
                    }
                    authPolicy.Options.Add(policyOption);
                }
                break;
            }
            return(authPolicy);
        }