From 7a5a4e45266bf9534d9b78409f53fba740ef5cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 12 Nov 2019 17:13:23 +0000 Subject: [PATCH] Improvements in SSL accept handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace sslProtocols collection with parameter. - Replace call to AuthenticateAsServer to remove requirement for client certificate. - Lock object is now initialized in constructor. - Correct typos in comments. - Bump version to 1.2.2-preview. Signed-off-by: José Simões --- .../Http/System.Net.HttpListener.cs | 19 ++++++++++++------- source/version.json | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/nanoFramework.System.Net.Http/Http/System.Net.HttpListener.cs b/source/nanoFramework.System.Net.Http/Http/System.Net.HttpListener.cs index bbf5889b..9da40ad0 100644 --- a/source/nanoFramework.System.Net.Http/Http/System.Net.HttpListener.cs +++ b/source/nanoFramework.System.Net.Http/Http/System.Net.HttpListener.cs @@ -22,7 +22,7 @@ namespace System.Net /// public class HttpListener { - private readonly object lockObj = new object(); + private readonly object lockObj; /// /// Indicates whether the listener is waiting on an http or https @@ -122,6 +122,8 @@ public SslProtocols SslProtocols /// class has no arguments. public HttpListener(string prefix) { + lockObj = new object(); + InitListener(prefix, -1); } @@ -137,6 +139,8 @@ public HttpListener(string prefix) /// class has no arguments. public HttpListener(string prefix, int port) { + lockObj = new object(); + InitListener(prefix, port); } @@ -405,11 +409,13 @@ private void AcceptThreadFunc() else { // This is the case of https. - // Once connection estiblished need to create secure stream and authenticate server. + // Once connection established need to create secure stream and authenticate server. netStream = new SslStream(clientSock); - // Throws exception if fails. - ((SslStream)netStream).AuthenticateAsServer(m_httpsCert, m_sslProtocols); + // Throws exception if this fails + // pass the server certificate + // do not require client certificate + ((SslStream)netStream).AuthenticateAsServer(m_httpsCert, false, m_sslProtocols); netStream.ReadTimeout = 10000; } @@ -591,7 +597,7 @@ public void Stop() /// public HttpListenerContext GetContext() { - // Protects access for simulteneous call for GetContext and Close or Stop. + // Protects access for simultaneous call for GetContext and Close or Stop. lock (lockObj) { if (m_Closed) throw new ObjectDisposedException(); @@ -666,8 +672,7 @@ public int MaximumResponseHeadersLength #pragma warning disable S2292 // Trivial properties should be auto-implemented /// - /// The certificate used if HttpListener implements an https - /// server. + /// The certificate used if implements an https server. /// public X509Certificate HttpsCert #pragma warning restore S2292 // Trivial properties should be auto-implemented diff --git a/source/version.json b/source/version.json index c4c9f96a..7e65fe36 100644 --- a/source/version.json +++ b/source/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.2.1-preview.{height}", + "version": "1.2.2-preview.{height}", "assemblyVersion": { "precision": "revision" },