Commit 210c9de3 authored by Jason Williams's avatar Jason Williams Committed by GitHub
Browse files

Merge pull request #140 from WilliamsJason/master

Allow specifying a cert to use when connecting 
parents 69c20b8a 0a6cc307
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -155,6 +155,15 @@ namespace XboxWdpDriver
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether or not we are allowing cert override which may specify a proxy instead of the web management service.
        /// </summary>
        public bool AllowCertOverride
        {
            get;
            set;
        }

        /// <summary>
        /// Returns certificate data
        /// </summary>
@@ -169,6 +178,8 @@ namespace XboxWdpDriver
        /// </summary>
        /// <param name="certificate">The device's root certificate.</param>
        public void SetDeviceCertificate(X509Certificate2 certificate)
        {
            if (!this.AllowCertOverride)
            {
                if (!certificate.IssuerName.Name.Contains(DevicePortalCertificateIssuer))
                {
@@ -178,6 +189,7 @@ namespace XboxWdpDriver
                        null,
                        "Failed to download device certificate");
                }
            }

            this.deviceCertificate = certificate;
        }
+2 −2
Original line number Diff line number Diff line
@@ -5,10 +5,10 @@
//----------------------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;
using System.Threading;

namespace XboxWdpDriver
{
+2 −2
Original line number Diff line number Diff line
@@ -5,10 +5,10 @@
//----------------------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Tools.WindowsDevicePortal;
using static Microsoft.Tools.WindowsDevicePortal.DevicePortal;
using System.Threading;

namespace XboxWdpDriver
{
+5 −0
Original line number Diff line number Diff line
@@ -54,6 +54,11 @@ namespace XboxWdpDriver
        /// </summary>
        public static readonly string Listen = "listen";

        /// <summary>
        /// Optional manual Cert file identifier string.
        /// </summary>
        public static readonly string Cert = "certfile";

        /// <summary>
        /// List for storing parsed command line parameters as key value pairs.
        /// </summary>
+21 −2
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
@@ -205,7 +206,24 @@ namespace XboxWdpDriver

                DevicePortal portal = new DevicePortal(connection);

                Task connectTask = portal.Connect(updateConnection: false);
                byte[] rawCert = null;

                if (parameters.HasParameter(ParameterHelper.Cert))
                {
                    string certFile = parameters.GetParameterValue(ParameterHelper.Cert);

                    try
                    {
                        rawCert = File.ReadAllBytes(certFile);
                        connection.AllowCertOverride = true;
                    }
                    catch (Exception e)
                    {
                        throw new Exception(string.Format("Failed to read manual cert file {0}, {1}", certFile, e.Message), e);
                    }
                }

                Task connectTask = portal.Connect(updateConnection: false, rawManualCertificate: rawCert);
                connectTask.Wait();

                if (portal.ConnectionHttpStatusCode != HttpStatusCode.OK)
@@ -252,6 +270,7 @@ namespace XboxWdpDriver
                            {
                                Console.WriteLine("Connected to Default console: {0}", targetConsole);
                            }

                            break;

                        case OperationType.FiddlerOperation:
Loading