async public void AcquireLicenseReactively(PlayReadyLicenseAcquisitionServiceRequest licenseRequest) { Exception exception = null; try { _serviceRequest = licenseRequest; ConfigureServiceRequest(); if (RequestConfigData.ManualEnabling) { HttpHelper httpHelper = new HttpHelper(licenseRequest); await httpHelper.GenerateChallengeAndProcessResponse(); } else { await licenseRequest.BeginServiceRequest(); } } catch (Exception ex) { exception = ex; } finally { LAServiceRequestCompleted(licenseRequest, exception); } }
/// <summary> /// The application can proativly request a license by creating a license request and /// assigning a header which provides the specifics such as the KeyId of the license needed. /// </summary> static public void ProactiveLicenseAcquisition(PlayReadyContentHeader contentHeader, Action callback = null) { var laRequest = new PlayReadyLicenseAcquisitionServiceRequest(); laRequest.ContentHeader = contentHeader; ReactiveLicenseAcquisition(laRequest, null, callback); }
void HandleLicenseAcquisitionServiceRequest(PlayReadyLicenseAcquisitionServiceRequest serviceRequest) { _licenseAcquisition = new LAAndReportResult(new ReportResultDelegate(HandleServiceRequest_Finished)); _licenseAcquisition.LicenseRequestUri = LicenseRequestUri; _licenseAcquisition.RequestConfigData = RequestConfigData; _licenseAcquisition.AcquireLicenseReactively(serviceRequest); }
void ConfigureServiceRequest() { PlayReadyLicenseAcquisitionServiceRequest licenseRequest = _serviceRequest as PlayReadyLicenseAcquisitionServiceRequest; Debug.WriteLine(" "); Debug.WriteLine("Configure license request to these values:"); if (RequestConfigData.Uri != null) { Debug.WriteLine("LA URL :" + RequestConfigData.Uri.ToString()); licenseRequest.Uri = RequestConfigData.Uri; } if (RequestConfigData.CustomArtibutes != null && RequestConfigData.CustomArtibutes.Count >= 1) { customHeaders = RequestConfigData.CustomArtibutes; RequestConfigData.ManualEnabling = true; } if (RequestConfigData.ChallengeCustomData != null && RequestConfigData.ChallengeCustomData != String.Empty) { Debug.WriteLine("ChallengeCustomData:" + RequestConfigData.ChallengeCustomData); licenseRequest.ChallengeCustomData = RequestConfigData.ChallengeCustomData; } Debug.WriteLine(" "); }
private async void ProtectionManager_ServiceRequested(MediaProtectionManager sender, ServiceRequestedEventArgs e) { Log("ProtectionManager_ServiceRequested"); if (e.Request is PlayReadyIndividualizationServiceRequest) { Log("ProtectionManager_ServiceRequested: PlayReadyIndividualizationServiceRequest"); PlayReadyIndividualizationServiceRequest individualizationServiceRequest = (PlayReadyIndividualizationServiceRequest)e.Request; await individualizationServiceRequest.BeginServiceRequest(); Log("ProtectionManager_ServiceRequested: PlayReadyIndividualizationServiceRequest complete"); e.Completion.Complete(true); } else if (e.Request is PlayReadyLicenseAcquisitionServiceRequest) { Log("ProtectionManager_ServiceRequested: PlayReadyLicenseAcquisitionServiceRequest"); PlayReadyLicenseAcquisitionServiceRequest licenseAcquisitionRequest = (PlayReadyLicenseAcquisitionServiceRequest)e.Request; await licenseAcquisitionRequest.BeginServiceRequest(); Log("ProtectionManager_ServiceRequested: PlayReadyLicenseAcquisitionServiceRequest complete"); e.Completion.Complete(true); } }
async public void AcquireLicenseReactively(PlayReadyLicenseAcquisitionServiceRequest licenseRequest) { Exception exception = null; try { _serviceRequest = licenseRequest; ConfigureServiceRequest(); if( RequestConfigData.ManualEnabling ) { HttpHelper httpHelper = new HttpHelper( licenseRequest ); await httpHelper.GenerateChallengeAndProcessResponse(); } else { await licenseRequest.BeginServiceRequest(); } } catch( Exception ex ) { exception = ex; } finally { LAServiceRequestCompleted( licenseRequest, exception ); } }
void ConfigureServiceRequest() { PlayReadyLicenseAcquisitionServiceRequest licenseRequest = _serviceRequest as PlayReadyLicenseAcquisitionServiceRequest; licenseRequest.Uri = LicenseRequestUri; licenseRequest.ChallengeCustomData = "Custom Data"; }
public static async Task <bool> RequestLicenseManual(PlayReadyLicenseAcquisitionServiceRequest request) { Debug.WriteLine("ProtectionManager PlayReady Manual License Request in progress"); try { var r = request.GenerateManualEnablingChallenge(); var content = new ByteArrayContent(r.GetMessageBody()); foreach (var header in r.MessageHeaders.Where(x => x.Value != null)) { if (header.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { content.Headers.ContentType = MediaTypeHeaderValue.Parse(header.Value.ToString()); } else { content.Headers.Add(header.Key, header.Value.ToString()); } } var msg = new HttpRequestMessage(HttpMethod.Post, r.Uri) { Content = content }; Debug.WriteLine("Requesting license from {0} with custom data {1}", msg.RequestUri, await msg.Content.ReadAsStringAsync()); var client = new HttpClient(); var response = await client.SendAsync(msg); if (response.IsSuccessStatusCode) { request.ProcessManualEnablingResponse(await response.Content.ReadAsByteArrayAsync()); } else { Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + await response.Content.ReadAsStringAsync()); return(false); } } catch (Exception ex) { Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + ex.Message); return(false); } Debug.WriteLine("ProtectionManager PlayReady License Request successfull"); return(true); }
void HandleLicenseAcquisitionServiceRequest(PlayReadyLicenseAcquisitionServiceRequest serviceRequest) { TestLogger.LogMessage(" "); TestLogger.LogMessage("Enter RequestChain.HandleLicenseAcquisitionServiceRequest()"); _licenseAcquisition = new LAAndReportResult(new ReportResultDelegate(HandleServiceRequest_Finished)); _licenseAcquisition.RequestConfigData = _requestConfigData; _licenseAcquisition.AcquireLicenseReactively(serviceRequest); TestLogger.LogMessage("Leave RequestChain.HandleLicenseAcquisitionServiceRequest()"); }
void HandleLicenseAcquisitionServiceRequest(PlayReadyLicenseAcquisitionServiceRequest serviceRequest) { Debug.WriteLine(" "); Debug.WriteLine("Enter RequestChain.HandleLicenseAcquisitionServiceRequest()"); _licenseAcquisition = new LAAndReportResult(new ReportResultDelegate(HandleServiceRequest_Finished)); _licenseAcquisition.RequestConfigData = _requestConfigData; _licenseAcquisition.AcquireLicenseReactively(serviceRequest); //_licenseAcquisition.RequestLicenseManual(serviceRequest); Debug.WriteLine("Leave RequestChain.HandleLicenseAcquisitionServiceRequest()"); }
public static async Task<bool> RequestLicenseManual(PlayReadyLicenseAcquisitionServiceRequest request) { Debug.WriteLine("ProtectionManager PlayReady Manual License Request in progress"); try { var r = request.GenerateManualEnablingChallenge(); var content = new ByteArrayContent(r.GetMessageBody()); foreach (var header in r.MessageHeaders.Where(x => x.Value != null)) { if (header.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { content.Headers.ContentType = MediaTypeHeaderValue.Parse(header.Value.ToString()); } else { content.Headers.Add(header.Key, header.Value.ToString()); } } var msg = new HttpRequestMessage(HttpMethod.Post, r.Uri) { Content = content }; Debug.WriteLine("Requesting license from {0} with custom data {1}", msg.RequestUri, await msg.Content.ReadAsStringAsync()); var client = new HttpClient(); var response = await client.SendAsync(msg); if (response.IsSuccessStatusCode) { request.ProcessManualEnablingResponse(await response.Content.ReadAsByteArrayAsync()); } else { Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + await response.Content.ReadAsStringAsync()); return false; } } catch (Exception ex) { Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + ex.Message); return false; } Debug.WriteLine("ProtectionManager PlayReady License Request successfull"); return true; }
protected override void LAServiceRequestCompleted(PlayReadyLicenseAcquisitionServiceRequest sender, Exception hrCompletionStatus) { if (hrCompletionStatus == null) { _reportResult(true); } else { if (!PerformEnablingActionIfRequested(hrCompletionStatus) && !HandleExpectedError(hrCompletionStatus)) { _reportResult(false); } } }
public void AcquireLicenseProactively() { PlayReadyContentHeader contentHeader = new PlayReadyContentHeader( RequestConfigData.KeyId, RequestConfigData.KeyIdString, RequestConfigData.EncryptionAlgorithm, RequestConfigData.Uri, RequestConfigData.Uri, String.Empty, RequestConfigData.DomainServiceId); PlayReadyLicenseAcquisitionServiceRequest licenseRequest = new PlayReadyLicenseAcquisitionServiceRequest(); licenseRequest.ContentHeader = contentHeader; AcquireLicenseReactively(licenseRequest); }
public void AcquireLicenseProactively() { PlayReadyContentHeader contentHeader = new PlayReadyContentHeader( RequestConfigData.KeyId, RequestConfigData.KeyIdString, RequestConfigData.EncryptionAlgorithm, RequestConfigData.Uri, RequestConfigData.Uri, String.Empty, RequestConfigData.DomainServiceId); PlayReadyLicenseAcquisitionServiceRequest licenseRequest = new PlayReadyLicenseAcquisitionServiceRequest(); licenseRequest.ContentHeader = contentHeader; AcquireLicenseReactively( licenseRequest ); }
private async void ProtectionManager_ServiceRequested(MediaProtectionManager sender, ServiceRequestedEventArgs e) { log("Enter ProtectionManager_ServiceRequested"); if (e.Request is PlayReadyIndividualizationServiceRequest) { PlayReadyIndividualizationServiceRequest IndivRequest = e.Request as PlayReadyIndividualizationServiceRequest; bool bResultIndiv = await ReactiveIndivRequest(IndivRequest, e.Completion); } else if (e.Request is PlayReadyLicenseAcquisitionServiceRequest) { PlayReadyLicenseAcquisitionServiceRequest licenseRequest = e.Request as PlayReadyLicenseAcquisitionServiceRequest; LicenseAcquisitionRequest(licenseRequest, e.Completion, playReadyLicenseUrl, playReadyChallengeCustomData); } log("Leave ProtectionManager_ServiceRequested"); }
public void Test_ContentResolver(string strContentHeader, string strExpectServiceRequest, string strRootKid, string strLeafKid) { TestLogger.LogMessage("Enter Test_ContentResolver()"); TestLogger.LogMessage("Root Kid = " + strRootKid); TestLogger.LogMessage("Leaf Kid = " + strLeafKid); bool bTestActionResult = false; bool bExpectServiceRequest = ActionParamConvertToBool(strExpectServiceRequest); TestLogger.LogMessage(strContentHeader); PlayReadyContentHeader contentHeader = new PlayReadyContentHeader(new System.Text.UnicodeEncoding().GetBytes(strContentHeader)); LicenseAcquisition.DumpContentHeaderValues(contentHeader); TestLogger.LogMessage("Using PlayReadyContentResolver..."); IPlayReadyServiceRequest serviceRequest = PlayReadyContentResolver.ServiceRequest(contentHeader); if (serviceRequest == null && !bExpectServiceRequest) { TestLogger.LogMessage("ServiceRequest not needed!!!"); bTestActionResult = true; } else { TestLogger.LogMessage("Inspecting servicing request..."); PlayReadyLicenseAcquisitionServiceRequest licenseServiceRequest = serviceRequest as PlayReadyLicenseAcquisitionServiceRequest; if (licenseServiceRequest == null) { TestLogger.LogMessage("!!!!!!!!!!!!!!! servicing request is null !!!!!!!!!!"); } else { TestLogger.LogMessage("licenseServiceRequest.ContentHeader.KeyId = " + licenseServiceRequest.ContentHeader.KeyId.ToString()); if (licenseServiceRequest.ContentHeader.KeyId == new Guid(strRootKid)) { TestLogger.LogMessage("KeyId is equal to expired Root KeyId, as expected"); bTestActionResult = true; } } } TestActionFinished(bTestActionResult, null); TestLogger.LogMessage("Leave Test_ContentResolver()"); }
/// <summary>Request a license for playing a stream.</summary> /// <param name="request">The request.</param> /// <returns><c>True</c> if successfull, <c>false</c> otherwise.</returns> public static async Task<bool> RequestLicense(PlayReadyLicenseAcquisitionServiceRequest request) { Debug.WriteLine("ProtectionManager PlayReady License Request in progress"); try { Debug.WriteLine("Requesting license from {0} with custom data {1}", request.Uri, request.ChallengeCustomData); await request.BeginServiceRequest(); } catch (Exception ex) { Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + ex.Message); return false; } Debug.WriteLine("ProtectionManager PlayReady License Request successfull"); return true; }
/// <summary>Request a license for playing a stream.</summary> /// <param name="request">The request.</param> /// <returns><c>True</c> if successfull, <c>false</c> otherwise.</returns> public static async Task <bool> RequestLicense(PlayReadyLicenseAcquisitionServiceRequest request) { Debug.WriteLine("ProtectionManager PlayReady License Request in progress"); try { Debug.WriteLine("Requesting license from {0} with custom data {1}", request.Uri, request.ChallengeCustomData); await request.BeginServiceRequest(); } catch (Exception ex) { Debug.WriteLine("ProtectionManager PlayReady License Request failed: " + ex.Message); return(false); } Debug.WriteLine("ProtectionManager PlayReady License Request successfull"); return(true); }
void ConfigureServiceRequest() { PlayReadyLicenseAcquisitionServiceRequest licenseRequest = _serviceRequest as PlayReadyLicenseAcquisitionServiceRequest; TestLogger.LogMessage(" "); TestLogger.LogMessage("Configure license request to these values:"); if (RequestConfigData.Uri != null) { TestLogger.LogMessage("LA URL :" + RequestConfigData.Uri.ToString()); licenseRequest.Uri = RequestConfigData.Uri; } if (RequestConfigData.ChallengeCustomData != null && RequestConfigData.ChallengeCustomData != String.Empty) { TestLogger.LogMessage("ChallengeCustomData:" + RequestConfigData.ChallengeCustomData); licenseRequest.ChallengeCustomData = RequestConfigData.ChallengeCustomData; } TestLogger.LogMessage(" "); }
public void Test_CocktailContentResolver(string strContentHeader, string strLAURL, string strExpectServiceRequest) { TestLogger.LogMessage("Enter Test_CocktailContentResolver()"); bool bExpectServiceRequest = ActionParamConvertToBool(strExpectServiceRequest); Uri uri = ActionParamConvertToUri(strLAURL); TestLogger.LogMessage(strContentHeader); PlayReadyContentHeader contentHeader = new PlayReadyContentHeader( new System.Text.UnicodeEncoding().GetBytes(strContentHeader), uri, uri, String.Empty, Guid.Empty ); LicenseAcquisition.DumpContentHeaderValues(contentHeader); TestLogger.LogMessage("Using PlayReadyContentResolver..."); IPlayReadyServiceRequest serviceRequest = PlayReadyContentResolver.ServiceRequest(contentHeader); if (serviceRequest == null && !bExpectServiceRequest) { TestLogger.LogMessage("ServiceRequest not needed!!!"); TestActionFinished(true, null); } else { TestLogger.LogMessage("Servicing request..."); PlayReadyLicenseAcquisitionServiceRequest licenseServiceRequest = serviceRequest as PlayReadyLicenseAcquisitionServiceRequest; LAAndReportResult licenseAcquisition = new LAAndReportResult(new ReportResultDelegate(TestActionFinished), null); licenseAcquisition.AcquireLicenseReactively(serviceRequest as PlayReadyLicenseAcquisitionServiceRequest); } TestLogger.LogMessage("Leave Test_CocktailContentResolver()"); }
protected override void LAServiceRequestCompleted( PlayReadyLicenseAcquisitionServiceRequest sender, Exception hrCompletionStatus ) { if( hrCompletionStatus == null ) { _reportResult( true ); } else { if( !PerformEnablingActionIfRequested(hrCompletionStatus) && !HandleExpectedError(hrCompletionStatus) ) { _reportResult( false ); } } }
protected virtual void LAServiceRequestCompleted( PlayReadyLicenseAcquisitionServiceRequest sender, Exception hrCompletionStatus ) { }
/// <summary> /// Invoked to acquire the PlayReady License /// </summary> async void LicenseAcquisitionRequest(PlayReadyLicenseAcquisitionServiceRequest licenseRequest, MediaProtectionServiceCompletion CompletionNotifier, string Url, string ChallengeCustomData) { bool bResult = false; string ExceptionMessage = string.Empty; try { if (!string.IsNullOrEmpty(Url)) { log("ProtectionManager PlayReady Manual License Acquisition Service Request in progress - URL: " + Url); if (!string.IsNullOrEmpty(ChallengeCustomData)) { System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); byte[] b = encoding.GetBytes(ChallengeCustomData); licenseRequest.ChallengeCustomData = Convert.ToBase64String(b, 0, b.Length); } PlayReadySoapMessage soapMessage = licenseRequest.GenerateManualEnablingChallenge(); byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); else httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } CommonLicenseRequest licenseAcquision = new CommonLicenseRequest(); HttpContent responseHttpContent = await licenseAcquision.AcquireLicense(new Uri(Url), httpContent); if (responseHttpContent != null) { Exception exResult = licenseRequest.ProcessManualEnablingResponse(await responseHttpContent.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } bResult = true; } else ExceptionMessage = licenseAcquision.GetLastErrorMessage(); } else { log ("ProtectionManager PlayReady License Acquisition Service Request in progress - URL: " + licenseRequest.Uri.ToString()); await licenseRequest.BeginServiceRequest(); bResult = true; } } catch (Exception e) { ExceptionMessage = e.Message; } if (bResult == true) log(!string.IsNullOrEmpty(Url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request successful" : "ProtectionManager PlayReady License Acquisition Service Request successful"); else log(!string.IsNullOrEmpty(Url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request failed: " + ExceptionMessage : "ProtectionManager PlayReady License Acquisition Service Request failed: " + ExceptionMessage); CompletionNotifier.Complete(bResult); }
/// <summary> /// Invoked to acquire the PlayReady License /// </summary> async void LicenseAcquisitionRequest(PlayReadyLicenseAcquisitionServiceRequest licenseRequest, MediaProtectionServiceCompletion completionNotifier, string url, string challengeCustomData) { bool bResult = false; string ExceptionMessage = string.Empty; try { if (!string.IsNullOrEmpty(url)) { Log("ProtectionManager PlayReady Manual License Acquisition Service Request in progress - URL: " + url); if (!string.IsNullOrEmpty(challengeCustomData)) { var encoding = new UTF8Encoding(); byte[] b = encoding.GetBytes(challengeCustomData); licenseRequest.ChallengeCustomData = Convert.ToBase64String(b, 0, b.Length); } PlayReadySoapMessage soapMessage = licenseRequest.GenerateManualEnablingChallenge(); byte[] messageBytes = soapMessage.GetMessageBody(); HttpContent httpContent = new ByteArrayContent(messageBytes); IPropertySet propertySetHeaders = soapMessage.MessageHeaders; foreach (string strHeaderName in propertySetHeaders.Keys) { string strHeaderValue = propertySetHeaders[strHeaderName].ToString(); // The Add method throws an ArgumentException try to set protected headers like "Content-Type" // so set it via "ContentType" property if (strHeaderName.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)) { httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse(strHeaderValue); } else { httpContent.Headers.Add(strHeaderName.ToString(), strHeaderValue); } } var licenseAcquision = new CommonLicenseRequest(); HttpContent responseHttpContent = await licenseAcquision.AcquireLicenseAsync(new Uri(url), httpContent); if (responseHttpContent != null) { Exception exResult = licenseRequest.ProcessManualEnablingResponse(await responseHttpContent.ReadAsByteArrayAsync()); if (exResult != null) { throw exResult; } bResult = true; } else { ExceptionMessage = licenseAcquision.GetLastErrorMessage(); } } else { Log("ProtectionManager PlayReady License Acquisition Service Request in progress - URL: " + licenseRequest.Uri.ToString()); await licenseRequest.BeginServiceRequest(); bResult = true; } } catch (Exception e) { ExceptionMessage = e.Message; } if (bResult == true) { Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request successful" : "ProtectionManager PlayReady License Acquisition Service Request successful"); } else { Log(!string.IsNullOrEmpty(url) ? "ProtectionManager Manual PlayReady License Acquisition Service Request failed: " + ExceptionMessage : "ProtectionManager PlayReady License Acquisition Service Request failed: " + ExceptionMessage); } completionNotifier.Complete(bResult); }
protected virtual void LAServiceRequestCompleted(PlayReadyLicenseAcquisitionServiceRequest sender, Exception hrCompletionStatus) { }