none
SSL Certificate Implementation in Cordova Windows Universal App RRS feed

  • Question

  • I'm trying to implement SSL certificate in Cordova Universal Windows App(Windows Phone 10 devices)

    I'm using crt file for certification &  consuming webservices using ajax. Getting error as "Network Error" and readystate is 0.
    Please find the following code

    I have added a Certificate in Declaration tab of appxmanifest file.

    Step 1:

     jQuery.support.cors = true;

    function onDeviceReady()
    {
           
            SetRootCertification();
    }

    Step2

      public async static void SetRootCertification()
       {
           try
           {
               Uri certificateFile = new Uri("ms-appx:///certificate.crt");
               StorageFile cerfile = await StorageFile.GetFileFromApplicationUriAsync(certificateFile);

               IBuffer certBlob = await FileIO.ReadBufferAsync(cerfile);
               Windows.Security.Cryptography.Certificates.Certificate rootCert = new Windows.Security.Cryptography.Certificates.Certificate(certBlob);
               Windows.Security.Cryptography.Certificates.CertificateStore trustedStore = Windows.Security.Cryptography.Certificates.CertificateStores.TrustedRootCertificationAuthorities;
               trustedStore.Add(rootCert);
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }

       Step3

           $.ajax({

               url: pageUrl,
               headers: {
                   'x-token': authToken
               },
               type: 'POST',
               data: JSON.stringify(jsonRequest),
               dataType: 'json',
               async: false,
               crossDomain: true,
               xhrFields: { withCredentials: true },
               contentType: "application/json;charset=utf-8",
               timeout: 7000,
               success: function (msg) {
                   data = JSON.stringify(msg);
                   successCallback(data);
               },
               error: function (XMLHttpRequest, textStatus, errorThrown) {
                   data = XMLHttpRequest.responseText;
                   successCallback(null);
               }
           });


    Friday, August 4, 2017 4:42 AM