Skip to content

Commit

Permalink
Improvements in SSL accept handler
Browse files Browse the repository at this point in the history
- 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 <jose.simoes@eclo.solutions>
  • Loading branch information
josesimoes committed Nov 12, 2019
1 parent f3122ac commit 7a5a4e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace System.Net
/// </remarks>
public class HttpListener
{
private readonly object lockObj = new object();
private readonly object lockObj;

/// <summary>
/// Indicates whether the listener is waiting on an http or https
Expand Down Expand Up @@ -122,6 +122,8 @@ public SslProtocols SslProtocols
/// class has no arguments.</remarks>
public HttpListener(string prefix)
{
lockObj = new object();

InitListener(prefix, -1);
}

Expand All @@ -137,6 +139,8 @@ public HttpListener(string prefix)
/// class has no arguments.</remarks>
public HttpListener(string prefix, int port)
{
lockObj = new object();

InitListener(prefix, port);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -591,7 +597,7 @@ public void Stop()
/// </example>
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();
Expand Down Expand Up @@ -666,8 +672,7 @@ public int MaximumResponseHeadersLength

#pragma warning disable S2292 // Trivial properties should be auto-implemented
/// <summary>
/// The certificate used if <b>HttpListener</b> implements an https
/// server.
/// The certificate used if <see cref="HttpListener"/> implements an https server.
/// </summary>
public X509Certificate HttpsCert
#pragma warning restore S2292 // Trivial properties should be auto-implemented
Expand Down
2 changes: 1 addition & 1 deletion source/version.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down

0 comments on commit 7a5a4e4

Please sign in to comment.