See Widevine Modular DRM Proxy Integration documentation.
        private string GetWidevineConfiguration(Uri keyDeliveryUrl)
        {
            if (radioButtonBasic.Checked)
            {
                return "{}";
            }
            else
            {
                var template = new WidevineMessage
                {
                    content_key_specs = new[]
                                                  {
                                            new ContentKeySpecs
                                            {
                                                required_output_protection = new RequiredOutputProtection { hdcp = (Hdcp)(Enum.Parse(typeof(Hdcp), (string)comboBoxReqOutputProtection.SelectedItem))},
                                                track_type = textBoxTrackType.Text
                                            }
                                        },
                    policy_overrides = new
                    {
                        can_play = checkBoxCanPlay.Checked,
                        can_persist = checkBoxCanPersist.Checked,
                        can_renew = checkBoxCanRenew.Checked
                    }
                };

                if (checkBoxAllowTrackType.Checked)
                {
                    template.allowed_track_types = (AllowedTrackTypes)(Enum.Parse(typeof(AllowedTrackTypes), (string)comboBoxAllowedTrackTypes.SelectedItem));
                }

                if (checkBoxSecLevel.Checked)
                {
                    template.content_key_specs.FirstOrDefault().security_level = (int)numericUpDownSecLevel.Value;
                }

                if (checkBoxCanRenew.Checked)
                {
                    template.policy_overrides = new
                    {
                        can_play = checkBoxCanPlay.Checked,
                        can_persist = checkBoxCanPersist.Checked,
                        can_renew = checkBoxCanRenew.Checked,
                        renewal_server_url = keyDeliveryUrl.ToString()
                    };
                }

                return JsonConvert.SerializeObject(template, Newtonsoft.Json.Formatting.Indented);
            }
        }
Example #2
0
        public static string CreateWidevineConfigSophisticated(Uri keyDeliveryUrl)
        {
            var template = new WidevineMessage
            {
                allowed_track_types = AllowedTrackTypes.SD_HD,
                content_key_specs = new[]
                {
                    new ContentKeySpecs
                    {
                        required_output_protection = new RequiredOutputProtection { hdcp = Hdcp.HDCP_NONE},
                        security_level = 1,
                        track_type = "SD"
                    }
                },
                policy_overrides = new
                {
                    can_play = true,
                    can_persist = true,
                    can_renew = true,
                    renewal_server_url = keyDeliveryUrl.ToString(),
                }
            };

            string configuration = JsonConvert.SerializeObject(template);
            return configuration;
        }
        public void GetWidevineKeyDeliveryUrlAndFetchLicenseWithPolicy()
        {
            IContentKey contentKey = null;
            IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = null;
            IContentKeyAuthorizationPolicyOption policyOption = null;

            try
            {
                byte[] expectedKey = null;
                contentKey = CreateTestKey(_mediaContext, ContentKeyType.CommonEncryption, out expectedKey);

                var template = new WidevineMessage
                {
                    allowed_track_types = AllowedTrackTypes.SD_HD,
                    content_key_specs = new[]
                    {
                        new ContentKeySpecs
                        {
                            key_id = contentKey.Id,
                            required_output_protection = new RequiredOutputProtection { hdcp = Hdcp.HDCP_NONE},
                            security_level = 1,
                            track_type = "SD"
                        }
                    },
                    policy_overrides = new
                    {
                        can_play = true,
                        can_persist = true,
                        can_renew = true,
                        license_duration_seconds = 10,
                        renewal_delay_seconds = 3,
                    }
                };

                string configuration = JsonConvert.SerializeObject(template);

                policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(
                    _mediaContext,
                    String.Empty,
                    ContentKeyDeliveryType.Widevine,
                    null,
                    configuration,
                    ContentKeyRestrictionType.Open);

                List<IContentKeyAuthorizationPolicyOption> options = new List<IContentKeyAuthorizationPolicyOption>
                {
                    policyOption
                };

                contentKeyAuthorizationPolicy = CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey);

                Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.Widevine);

                Assert.IsNotNull(keyDeliveryServiceUri);

                KeyDeliveryServiceClient keyClient = new KeyDeliveryServiceClient(RetryPolicy.DefaultFixed);
                string rawkey = EncryptionUtils.GetKeyIdAsGuid(contentKey.Id).ToString();

                string payload = "CAEShAEKTAgAEkgAAAACAAAQWPXbhtb/q43f3SfuC2VP3q0jeAECW3emQkWn2wXCYVOnvlWPDNqh8VVIB4GmsNA8eVVFigXkQWIGN0GlgMKjpUESLAoqChQIARIQJMPCzl2bViyMQEtyK/gtmRABGhAyNWY3ODMzMTcyMmJjM2EyGAEgv5iQkAUaIC3ON1zVgeV0rP7w2VmVLGorqClcMQO4BdbHPyk3GsnY";

                byte[] license = keyClient.AcquireWidevineLicenseWithBearerHeader(
                    keyDeliveryServiceUri,
                    TokenServiceClient.GetAuthTokenForKey(rawkey),
                    Convert.FromBase64String(payload));

                string expectedString = Convert.ToBase64String(license);
                Assert.AreEqual("CAIS", expectedString.Substring(0, 4));
            }
            finally
            {
                CleanupKeyAndPolicy(contentKey, contentKeyAuthorizationPolicy, policyOption);
            }
        }
        private static string ConfigureWidevineLicenseTemplate()
        {
            var template = new WidevineMessage
            {
                allowed_track_types = AllowedTrackTypes.SD_HD,
                content_key_specs = new[]
                {
                    new ContentKeySpecs
                    {
                        required_output_protection = new RequiredOutputProtection { hdcp = Hdcp.HDCP_NONE},
                        security_level = 1,
                        track_type = "SD"
                    }
                },
                policy_overrides = new
                {
                    can_play = true,
                    can_persist = true,
                    can_renew = false
                }
            };

            string configuration = JsonConvert.SerializeObject(template);
            return configuration;
        }