public void GetPlayReadyLicenseDeliveryUrl() { IContentKey contentKey = null; IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = null; IContentKeyAuthorizationPolicyOption policyOption = null; try { contentKey = CreateTestKey(_mediaContext, ContentKeyType.CommonEncryption); PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate(); responseTemplate.LicenseTemplates.Add(new PlayReadyLicenseTemplate()); string licenseTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate); policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.PlayReadyLicense, null, licenseTemplate, ContentKeyRestrictionType.Open); List <IContentKeyAuthorizationPolicyOption> options = new List <IContentKeyAuthorizationPolicyOption> { policyOption }; contentKeyAuthorizationPolicy = CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey); Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.PlayReadyLicense); Assert.IsNotNull(keyDeliveryServiceUri); Assert.IsTrue(0 == String.Compare(keyDeliveryServiceUri.AbsolutePath, "/PlayReady/", StringComparison.OrdinalIgnoreCase)); } finally { CleanupKeyAndPolicy(contentKey, contentKeyAuthorizationPolicy, policyOption); } }
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); }
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); }
public void EnsureEnvelopeKeyDeliveryUrlForCommonKeyFails() { IContentKey contentKey = null; IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = null; IContentKeyAuthorizationPolicyOption policyOption = null; PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate(); responseTemplate.LicenseTemplates.Add(new PlayReadyLicenseTemplate()); string licenseTemplate = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate); try { contentKey = CreateTestKey(_mediaContext, ContentKeyType.CommonEncryption); policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.PlayReadyLicense, null, licenseTemplate, ContentKeyRestrictionType.Open); List <IContentKeyAuthorizationPolicyOption> options = new List <IContentKeyAuthorizationPolicyOption> { policyOption }; contentKeyAuthorizationPolicy = CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey); Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp); } finally { CleanupKeyAndPolicy(contentKey, contentKeyAuthorizationPolicy, policyOption); } }
public void KnownGoodInputMinimalLicenseTest() { string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates><PlayReadyLicenseTemplate><ContentKey i:type=\"ContentEncryptionKeyFromHeader\" /><PlayRight /></PlayReadyLicenseTemplate></LicenseTemplates></PlayReadyLicenseResponseTemplate>"; PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate); Assert.IsNotNull(responseTemplate2); }
public void KnownGoodInputTest() { string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates><PlayReadyLicenseTemplate><AllowTestDevices>false</AllowTestDevices><BeginDate i:nil=\"true\" /><ContentKey i:type=\"ContentEncryptionKeyFromHeader\" /><ContentType>Unspecified</ContentType><ExpirationDate i:nil=\"true\" /><LicenseType>Nonpersistent</LicenseType><PlayRight><AgcAndColorStripeRestriction><ConfigurationData>1</ConfigurationData></AgcAndColorStripeRestriction><AllowPassingVideoContentToUnknownOutput>Allowed</AllowPassingVideoContentToUnknownOutput><AnalogVideoOpl>100</AnalogVideoOpl><CompressedDigitalAudioOpl>300</CompressedDigitalAudioOpl><CompressedDigitalVideoOpl>400</CompressedDigitalVideoOpl><DigitalVideoOnlyContentRestriction>false</DigitalVideoOnlyContentRestriction><ExplicitAnalogTelevisionOutputRestriction><BestEffort>true</BestEffort><ConfigurationData>0</ConfigurationData></ExplicitAnalogTelevisionOutputRestriction><ImageConstraintForAnalogComponentVideoRestriction>true</ImageConstraintForAnalogComponentVideoRestriction><ImageConstraintForAnalogComputerMonitorRestriction>true</ImageConstraintForAnalogComputerMonitorRestriction><ScmsRestriction><ConfigurationData>2</ConfigurationData></ScmsRestriction><UncompressedDigitalAudioOpl>250</UncompressedDigitalAudioOpl><UncompressedDigitalVideoOpl>270</UncompressedDigitalVideoOpl></PlayRight></PlayReadyLicenseTemplate></LicenseTemplates><ResponseCustomData>This is my response custom data</ResponseCustomData></PlayReadyLicenseResponseTemplate>"; PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate); Assert.IsNotNull(responseTemplate2); }
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)); }
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)); }
public void InputMissingContentKeyShouldThrowArgumentException() { string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates><PlayReadyLicenseTemplate><PlayRight /></PlayReadyLicenseTemplate></LicenseTemplates></PlayReadyLicenseResponseTemplate>"; try { PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate); Assert.Fail("Should throw an ArgumentException"); } catch (SerializationException e) { e.Message.Contains("ContentKey"); } }
public void InputMissingLicenseTemplatesShouldThrowArgumentException() { string serializedTemplate = "<PlayReadyLicenseResponseTemplate xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/Azure/MediaServices/KeyDelivery/PlayReadyTemplate/v1\"><LicenseTemplates></LicenseTemplates></PlayReadyLicenseResponseTemplate>"; try { PlayReadyLicenseResponseTemplate responseTemplate2 = MediaServicesLicenseTemplateSerializer.Deserialize(serializedTemplate); Assert.Fail("Should throw an ArgumentException"); } catch (ArgumentException e) { Assert.IsTrue(e.Message.Contains(ErrorMessages.AtLeastOneLicenseTemplateRequired)); } }
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)); }
public void ContentKeyAuthorizationPolicyOptionTestEnumQuery() { var policyOptions = _mediaContext.ContentKeyAuthorizationPolicyOptions; PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate(); responseTemplate.LicenseTemplates.Add(new PlayReadyLicenseTemplate()); string optionName = "integrationtest-crud-746"; string requirements = null; string configuration = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate); ContentKeyRestrictionType restrictionType = ContentKeyRestrictionType.Open; IContentKeyAuthorizationPolicyOption option = CreateOption(_mediaContext, optionName, ContentKeyDeliveryType.PlayReadyLicense, requirements, configuration, restrictionType); var ok = policyOptions.Where(o => o.KeyDeliveryType == ContentKeyDeliveryType.PlayReadyLicense).AsEnumerable().Any(); Assert.IsTrue(ok, "Can not find option by DeliveryType"); }
public void SetupTest() { _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate(); responseTemplate.LicenseTemplates.Add(new PlayReadyLicenseTemplate()); TokenRestrictionTemplate tokenRestrictionTemplate = new TokenRestrictionTemplate(TokenType.JWT); tokenRestrictionTemplate.PrimaryVerificationKey = new SymmetricVerificationKey(); // the default constructor automatically generates a random key tokenRestrictionTemplate.Audience = "http://sampleIssuerUrl"; tokenRestrictionTemplate.Issuer = "http://sampleAudience"; string optionName = "integrationtest-crud-749"; string requirements = TokenRestrictionTemplateSerializer.Serialize(tokenRestrictionTemplate); string configuration = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate); ContentKeyRestrictionType restrictionType = ContentKeyRestrictionType.TokenRestricted; _testOption = CreateOption(_mediaContext, optionName, ContentKeyDeliveryType.PlayReadyLicense, requirements, configuration, restrictionType); }
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; } }
/// <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 AddingOptionsToCreatedPolicy() { string optionName = "AddingOptionsToCreatedPolicy Test Option"; PlayReadyLicenseResponseTemplate responseTemplate = new PlayReadyLicenseResponseTemplate(); responseTemplate.LicenseTemplates.Add(new PlayReadyLicenseTemplate()); TokenRestrictionTemplate tokenRestrictionTemplate = new TokenRestrictionTemplate(TokenType.JWT); tokenRestrictionTemplate.PrimaryVerificationKey = new SymmetricVerificationKey(); // the default constructor automatically generates a random key tokenRestrictionTemplate.Audience = "urn:someaudience"; tokenRestrictionTemplate.Issuer = "http://someissuerurl"; string requirements = TokenRestrictionTemplateSerializer.Serialize(tokenRestrictionTemplate); string configuration = MediaServicesLicenseTemplateSerializer.Serialize(responseTemplate); ContentKeyRestrictionType restrictionType = ContentKeyRestrictionType.TokenRestricted; IContentKeyAuthorizationPolicy policy = _mediaContext.ContentKeyAuthorizationPolicies.CreateAsync(testRun).Result; var option1 = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, optionName, ContentKeyDeliveryType.PlayReadyLicense, requirements, configuration, restrictionType); policy.Options.Add(option1); }
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); }
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); } }