Commit da412532 authored by David Kline's avatar David Kline
Browse files

fixed Get() in the UWP library. moved SetCertificate() to the IDevicePortalImplementation

parent a698d7a1
Loading
Loading
Loading
Loading
+7 −24
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ using Windows.Foundation;
using Windows.Security.Cryptography.Certificates;
using Windows.Storage.Streams;
using Windows.Web.Http;
using Windows.Web.Http.Filters;

namespace Microsoft.Tools.WindowsDevicePortal
{
@@ -46,7 +47,11 @@ namespace Microsoft.Tools.WindowsDevicePortal

                try
                {
                    using (HttpClient client = new HttpClient())
                    HttpBaseProtocolFilter requestSettings = new HttpBaseProtocolFilter();
                    requestSettings.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
                    requestSettings.AllowUI = false;

                    using (HttpClient client = new HttpClient(requestSettings))
                    {
                        IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> responseOperation = client.GetAsync(uri);
                        TaskAwaiter<HttpResponseMessage> responseAwaiter = responseOperation.GetAwaiter();
@@ -65,7 +70,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
                                }

                                certificate = new Certificate(bufferOperation.GetResults());
                                if (!certificate.Issuer.StartsWith(DevicePortalCertificateIssuer))
                                if (!certificate.Issuer.Contains(DevicePortalCertificateIssuer))
                                {
                                    certificate = null;
                                    throw new DevicePortalException(
@@ -94,27 +99,5 @@ namespace Microsoft.Tools.WindowsDevicePortal
            }
        }
#pragma warning restore 1998

        /// <summary>
        /// Sets the device's root certificate in the certificate store. 
        /// </summary>
        /// <param name="certificate">The device's root certificate.</param>
        private void SetDeviceCertificate(Certificate certificate)
        {
            // Verify that the certificate is one we recognize.
            if (!certificate.Issuer.StartsWith(DevicePortalCertificateIssuer))
            {
                certificate = null;
                throw new DevicePortalException(
                    (HttpStatusCode)0,
                    "Invalid certificate issuer",
                    null,
                    "Failed to set the device certificate");
            }

            // Install the certificate.
            CertificateStore trustedStore = CertificateStores.TrustedRootCertificationAuthorities;
            trustedStore.Add(certificate);
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Security.Credentials;
@@ -68,7 +69,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
                }
            }

            return null;
            return (dataBuffer != null) ? dataBuffer.AsStream() : null;
        }
#pragma warning restore 1998
    }