Share via

using Window.Security.Cryptography.Cryptography.X509Certificates with UWP( UAP 10.0) for ssl pinning

Sandeep N 1 Reputation point
2021-12-16T17:49:55.797+00:00

I want to perform ssl pinning on my UWP app. My app runs on Visual Studio 2015 update 3. I need to validate server certificates agains our root CA. I am not able to get reference of System.Security.Cryptography.X509Certificates but not available. Please let me know the alternatives here.

I have tried the below:

  1. Used Window.Security.Cryptography. The https request is invoked using rootCertificate = caCertificateString; filter.CacheControl.ReadBehavior = HttpCacheReadBehavior.NoCache; filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName); filter.ServerCustomValidationRequested += FilterOnServerCustomValidationRequested;
                         //filter.ClientCertificate = await this.getClientCertiifcate(posCertificateString, password);
                         var httpClient = new Windows.Web.Http.HttpClient(filter);
                         var httpContent = new Windows.Web.Http.HttpStringContent(requestObj, Windows.Storage.Streams.UnicodeEncoding.Utf8);
    
                         httpContent.Headers.ContentType = Windows.Web.Http.Headers.HttpMediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
                         var response = await httpClient.PostAsync(new Uri(URL), httpContent);
    
    
                         string content = await response.Content.ReadAsStringAsync();
                         JsonObject statusObject = new JsonObject();
                         statusObject.Add("response", JsonValue.CreateStringValue(content));
                         return content;
    
  2. How do we get the root CA details from the server certificate of args.ServerCertificate
  3. What are the next steps here to be done. Which methods of Certificate class should we use further for validation

Please find my code here:

private void FilterOnServerCustomValidationRequested(HttpBaseProtocolFilter sender, HttpServerCustomValidationRequestedEventArgs args)
        {
           try
            {
                byte[] bytes = System.Convert.FromBase64String(this.rootCertificate); // Our root CA. Need to validate against args.ServerCertificate





            }
            catch(Exception e)
            {
                args.Reject();
            }
        }
Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.