public static void ClassInit(TestContext context) { //CreateCounters(); _mediaContext = WindowsAzureMediaServicesTestConfiguration.CreateCloudMediaContext(); IContentKeyAuthorizationPolicyOption policyOption = null; for (int i = 0; i < 10; i++) { byte[] expectedKey = null; IContentKey contentKey = GetKeyDeliveryUrlTests.CreateTestKey(_mediaContext, ContentKeyType.EnvelopeEncryption, out expectedKey); policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.BaselineHttp, null, null, ContentKeyRestrictionType.Open); List <IContentKeyAuthorizationPolicyOption> options = new List <IContentKeyAuthorizationPolicyOption> { policyOption }; GetKeyDeliveryUrlTests.CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey); Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp); Assert.IsNotNull(keyDeliveryServiceUri); string rawkey = EncryptionUtils.GetKeyIdAsGuid(contentKey.Id).ToString(); _testData.Add(new Tuple <Uri, string, string>(keyDeliveryServiceUri, TokenServiceClient.GetAuthTokenForKey(rawkey), GetKeyDeliveryUrlTests.GetString(expectedKey))); } }
public string Authenticate() { if (!AuthenticateTokenProvider.Current.IsExpired) { return(AuthenticateTokenProvider.Current.TokenKey); } var token = new TokenServiceClient(new WSHttpBinding(SecurityMode.None, true) { ReceiveTimeout = new TimeSpan(0, 0, 0, 0, _timeout) }, new EndpointAddress(_tokenUrl)); var authenticate = token.Authenticate(GenerateGuid(), Convert.ToInt32(_customerCode), _password); Audit("Authenticate" + authenticate); var body = authenticate.Element("MsgBody"); if (body == null) { AuthenticateTokenProvider.Current = new ErrorToken(authenticate.Element("MsgHeader").Element("Result").ToString()); } else { var expdate = body.Element("TokenConf").Element("ExpiryDate").Value; var key = body.Element("TokenConf").Element("TokenKey").Value; AuthenticateTokenProvider.Current = new SuccessToken(expdate, key); } return(AuthenticateTokenProvider.Current.TokenKey); }
public void authenticate_success() { var token = new TokenServiceClient(new WSHttpBinding(SecurityMode.None, true), new EndpointAddress(UriContext.Authenticate)); var authenticate = token.Authenticate(GenerateGuid(), 158, "Test@1234"); Assert.IsNotNull(authenticate.Element("MsgHeader")); }
private string GetToken() { var binding = new WSHttpBinding(SecurityMode.None, true); var token = new TokenServiceClient(binding, new EndpointAddress(UriContext.Authenticate)); var element = token.Authenticate(Guid.NewGuid().ToString(), 158, "Test@1234"); return(element.Element("MsgBody").Element("TokenConf").Element("TokenKey").Value); }
public void authenticate_fail() { var token = new TokenServiceClient(new WSHttpBinding(SecurityMode.None, true), new EndpointAddress(UriContext.Authenticate)); var authenticate = token.Authenticate(GenerateGuid(), 158, "Test@1235"); var o = authenticate.Element("MsgBody"); Assert.IsNull(o); }
public static void GetToken(EventHandler callback) { if (token != null) { callback(null, new TokenResultArgs { Result = token }); return; } callbacks.Add(callback); if (!inprogress) { inprogress = true; //get token var tokenservice = new TokenServiceClient(); tokenservice.GetTokenCompleted += (otokenservice, etokenservice) => { try { token = etokenservice.Result; IsolatedStorage.SaveData(token, ISOKey); foreach (EventHandler handler in callbacks) { handler(null, new TokenResultArgs { Result = token }); } inprogress = false; } catch (Exception) { //use last good token if available. token = IsolatedStorage.LoadStringData(ISOKey); if (token.Length > 0) { foreach (EventHandler handler in callbacks) { handler(null, new TokenResultArgs { Result = token }); } } //or else wait for next call to try again. inprogress = false; } }; tokenservice.GetTokenAsync(); } }
public void GetWidevineKeyDeliveryUrlAndFetchLicense() { IContentKey contentKey = null; IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = null; IContentKeyAuthorizationPolicyOption policyOption = null; try { byte[] expectedKey = null; contentKey = CreateTestKey(_mediaContext, ContentKeyType.CommonEncryption, out expectedKey); policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.Widevine, null, "{}", 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); } }
public void GetHlsKeyDeliveryUrlAndFetchKey() { IContentKey contentKey = null; IContentKeyAuthorizationPolicy contentKeyAuthorizationPolicy = null; IContentKeyAuthorizationPolicyOption policyOption = null; try { byte[] expectedKey = null; contentKey = CreateTestKey(_mediaContext, ContentKeyType.EnvelopeEncryption, out expectedKey); policyOption = ContentKeyAuthorizationPolicyOptionTests.CreateOption(_mediaContext, String.Empty, ContentKeyDeliveryType.BaselineHttp, null, null, ContentKeyRestrictionType.Open); List <IContentKeyAuthorizationPolicyOption> options = new List <IContentKeyAuthorizationPolicyOption> { policyOption }; contentKeyAuthorizationPolicy = CreateTestPolicy(_mediaContext, String.Empty, options, ref contentKey); Uri keyDeliveryServiceUri = contentKey.GetKeyDeliveryUrl(ContentKeyDeliveryType.BaselineHttp); Assert.IsNotNull(keyDeliveryServiceUri); // Enable once all accounts are enabled for per customer Key Delivery Urls //Assert.IsTrue(keyDeliveryServiceUri.Host.StartsWith(_mediaContext.Credentials.ClientId)); KeyDeliveryServiceClient keyClient = new KeyDeliveryServiceClient(RetryPolicy.DefaultFixed); string rawkey = EncryptionUtils.GetKeyIdAsGuid(contentKey.Id).ToString(); byte[] key = keyClient.AcquireHlsKey(keyDeliveryServiceUri, TokenServiceClient.GetAuthTokenForKey(rawkey)); string expectedString = GetString(expectedKey); string fetchedString = GetString(key); Assert.AreEqual(expectedString, fetchedString); } finally { CleanupKeyAndPolicy(contentKey, contentKeyAuthorizationPolicy, policyOption); } }
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); } }
public TokenInfo DoPayment(out string token) { RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(PrivateKey); byte[] signMain = rsa.SignData(Encoding.UTF8.GetBytes(Amount + Crn + Mid + ReturnUrl + Tid), new SHA1CryptoServiceProvider()); var signature = Convert.ToBase64String(signMain); RSACryptoServiceProvider cipher = new RSACryptoServiceProvider(); cipher.FromXmlString(PublicKey); byte[] data = Encoding.UTF8.GetBytes(Amount); byte[] cipherText = cipher.Encrypt(data, false); var enAmount = Convert.ToBase64String(cipherText); data = Encoding.UTF8.GetBytes(Mid); cipherText = cipher.Encrypt(data, false); var enMid = Convert.ToBase64String(cipherText); data = Encoding.UTF8.GetBytes(Crn); cipherText = cipher.Encrypt(data, false); var enCrn = Convert.ToBase64String(cipherText); data = Encoding.UTF8.GetBytes(ReturnUrl); cipherText = cipher.Encrypt(data, false); var enReferaladress = Convert.ToBase64String(cipherText); data = Encoding.UTF8.GetBytes(Tid); cipherText = cipher.Encrypt(data, false); var enTid = Convert.ToBase64String(cipherText); MabnaCardTokenService.TokenService services = new TokenServiceClient(); MabnaCardTokenService.tokenDTO tokenParm = new MabnaCardTokenService.tokenDTO { AMOUNT = enAmount, CRN = enCrn, MID = enMid, REFERALADRESS = enReferaladress, SIGNATURE = signature, TID = enTid }; var reservationRequest = new reservationRequest(tokenParm); var tokenResponse = services.reservation(reservationRequest); var result = new TokenInfo("-30000", GetDescription(1007, -30000), "", ""); token = ""; if ([email protected] == 0) { token = [email protected]; result.ActionType = "POST"; result.Action = PurchaseLink; result.Code = [email protected](); result.Result = GetDescription(1007, [email protected]); result.Tokenitems.Add(new TokenInfo.TokenItems("Token", [email protected])); } return(result); }