diff --git a/Example3/Program.cs b/Example3/Program.cs index 5dd638be..db139442 100644 --- a/Example3/Program.cs +++ b/Example3/Program.cs @@ -28,8 +28,8 @@ namespace Example3 #endif /* To provide the secure connection. var cert = ConfigurationManager.AppSettings["ServerCertFile"]; - var password = ConfigurationManager.AppSettings["CertFilePassword"]; - httpsv.Certificate = new X509Certificate2 (cert, password); + var passwd = ConfigurationManager.AppSettings["CertFilePassword"]; + httpsv.SslConfiguration.ServerCertificate = new X509Certificate2 (cert, passwd); */ /* To provide the HTTP Authentication (Basic/Digest). diff --git a/websocket-sharp/Net/EndPointManager.cs b/websocket-sharp/Net/EndPointManager.cs index 688856dc..30199f98 100644 --- a/websocket-sharp/Net/EndPointManager.cs +++ b/websocket-sharp/Net/EndPointManager.cs @@ -114,7 +114,7 @@ namespace WebSocketSharp.Net port, secure, httpListener.CertificateFolderPath, - httpListener.DefaultSslConfiguration, + httpListener.SslConfiguration, httpListener.ReuseAddress); eps[port] = epl; diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index a9081dc9..c3659b8e 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -71,13 +71,13 @@ namespace WebSocketSharp.Net private Dictionary _ctxRegistry; private object _ctxRegistrySync; private Func _credFinder; - private ServerSslAuthConfiguration _defaultSslConfig; private bool _disposed; private bool _ignoreWriteExceptions; private bool _listening; private HttpListenerPrefixCollection _prefixes; private string _realm; private bool _reuseAddress; + private ServerSslAuthConfiguration _sslConfig; private List _waitQueue; private object _waitQueueSync; @@ -219,29 +219,6 @@ namespace WebSocketSharp.Net } } - /// - /// Gets or sets the default SSL configuration used to authenticate the server and - /// optionally the client on the secure connection. - /// - /// - /// A that represents the SSL configuration used to - /// authenticate the server optionally the client. The default value is . - /// - /// - /// This listener has been closed. - /// - public ServerSslAuthConfiguration DefaultSslConfiguration { - get { - CheckDisposed (); - return _defaultSslConfig; - } - - set { - CheckDisposed (); - _defaultSslConfig = value; - } - } - /// /// Gets or sets a value indicating whether the listener returns exceptions that occur when /// sending the response to the client. @@ -329,6 +306,29 @@ namespace WebSocketSharp.Net } } + /// + /// Gets or sets the SSL configuration used to authenticate the server and optionally the client + /// for secure connection. + /// + /// + /// A that represents the configuration used to + /// authenticate the server and optionally the client for secure connection. + /// + /// + /// This listener has been closed. + /// + public ServerSslAuthConfiguration SslConfiguration { + get { + CheckDisposed (); + return _sslConfig ?? (_sslConfig = new ServerSslAuthConfiguration (null)); + } + + set { + CheckDisposed (); + _sslConfig = value; + } + } + /// /// Gets or sets a value indicating whether, when NTLM authentication is used, /// the authentication information of first request is used to authenticate diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index d000c1c6..0d2e24e5 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -336,15 +336,15 @@ namespace WebSocketSharp.Server /// /// Gets or sets the SSL configuration used to authenticate the server and optionally the client - /// on the secure connection. + /// for secure connection. /// /// - /// A that represents the SSL configuration used to - /// authenticate the server and optionally the client. + /// A that represents the configuration used to + /// authenticate the server and optionally the client for secure connection. /// public ServerSslAuthConfiguration SslConfiguration { get { - return _listener.DefaultSslConfiguration; + return _listener.SslConfiguration; } set { @@ -354,10 +354,7 @@ namespace WebSocketSharp.Server return; } - if (EndPointListener.CertificateExists (_port, _listener.CertificateFolderPath)) - _logger.Warn ("The server certificate associated with the port number already exists."); - - _listener.DefaultSslConfiguration = value; + _listener.SslConfiguration = value; } } @@ -508,10 +505,17 @@ namespace WebSocketSharp.Server private string checkIfCertificateExists () { - return _secure && - !EndPointListener.CertificateExists (_port, _listener.CertificateFolderPath) && - (_listener.DefaultSslConfiguration == null || - _listener.DefaultSslConfiguration.ServerCertificate == null) + if (!_secure) + return null; + + var usr = _listener.SslConfiguration.ServerCertificate != null; + var port = EndPointListener.CertificateExists (_port, _listener.CertificateFolderPath); + if (usr && port) { + _logger.Warn ("The server certificate associated with the port number already exists."); + return null; + } + + return !(usr || port) ? "The secure connection requires a server certificate." : null; }