Commit 93114a11 authored by Jason Williams's avatar Jason Williams
Browse files

Code review feedback

parent 9bf97dc8
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@ namespace SampleWdpClient
        /// </summary>
        private DevicePortal portal;

        /// <summary>
        /// An SSL thumbprint that we'll accept.
        /// </summary>
        private string thumbprint;

        /// <summary>
        /// The main page constructor.
        /// </summary>
@@ -469,8 +474,31 @@ namespace SampleWdpClient
        /// <returns>whether the cert passes validation</returns>
        private bool DoCertValidation(DevicePortal sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            // TODO: Allow the user to accept this certificate (trust once, trust always). (Issue #154)
            X509Certificate2 cert = new X509Certificate2(certificate);

            // If we have previously said to accept this cert, don't prompt again for this session.
            if (!string.IsNullOrEmpty(this.thumbprint) && this.thumbprint.Equals(cert.Thumbprint, StringComparison.OrdinalIgnoreCase))
            {
                return true;
            }

            // We could alternatively ask the user if they wanted to always trust
            // this device and we could persist the thumbprint in some way (registry, database, filesystem, etc).
            MessageBoxResult result = MessageBox.Show(string.Format(
                                "Do you want to accept the following certificate?\n\nThumbprint:\n  {0}\nIssuer:\n  {1}", 
                                cert.Thumbprint,
                                cert.Issuer),
                            "Untrusted Certificate Detected", 
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Question,
                            MessageBoxResult.No);

            if (result == MessageBoxResult.Yes)
            {
                thumbprint = cert.Thumbprint;
                return true;
            }
            return false;
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ namespace Microsoft.Tools.WindowsDevicePortal
        /// Gets the root certificate from the device.
        /// </summary>
        /// <returns>The device certificate.</returns>
        public async Task<X509Certificate2> GetDeviceCertificate()
        public async Task<X509Certificate2> GetRootDeviceCertificate()
        {
            X509Certificate2 certificate = null;