From 53f44a0e0e7826207ddd24ba2d1a6c6c3ce8574a Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 8 May 2014 16:35:35 +0900 Subject: [PATCH] Fix for default cert folder path --- websocket-sharp/Net/EndPointListener.cs | 13 +++++++++++++ websocket-sharp/Net/HttpListener.cs | 25 ++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/websocket-sharp/Net/EndPointListener.cs b/websocket-sharp/Net/EndPointListener.cs index 5de0fe1b..3a8ec428 100644 --- a/websocket-sharp/Net/EndPointListener.cs +++ b/websocket-sharp/Net/EndPointListener.cs @@ -51,6 +51,13 @@ namespace WebSocketSharp.Net { internal sealed class EndPointListener { + #region Private Static Fields + + private static readonly string _defaultCertFolderPath = + Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData); + + #endregion + #region Private Fields private List _all; // host = '+' @@ -154,6 +161,9 @@ namespace WebSocketSharp.Net private static X509Certificate2 getCertificate ( int port, string certFolderPath, X509Certificate2 defaultCert) { + if (certFolderPath == null || certFolderPath.Length == 0) + certFolderPath = _defaultCertFolderPath; + try { var cer = Path.Combine (certFolderPath, String.Format ("{0}.cer", port)); var key = Path.Combine (certFolderPath, String.Format ("{0}.key", port)); @@ -310,6 +320,9 @@ namespace WebSocketSharp.Net internal static bool CertificateExists (int port, string certFolderPath) { + if (certFolderPath == null || certFolderPath.Length == 0) + certFolderPath = _defaultCertFolderPath; + var cer = Path.Combine (certFolderPath, String.Format ("{0}.cer", port)); var key = Path.Combine (certFolderPath, String.Format ("{0}.key", port)); diff --git a/websocket-sharp/Net/HttpListener.cs b/websocket-sharp/Net/HttpListener.cs index 589d1dbc..bdc622b7 100644 --- a/websocket-sharp/Net/HttpListener.cs +++ b/websocket-sharp/Net/HttpListener.cs @@ -161,15 +161,21 @@ namespace WebSocketSharp.Net /// authenticate the server on the secure connection. /// /// - /// This property represents the path to the folder in which stores the certificate files - /// associated with each port number of added URI prefixes. A set of the certificate files - /// is a pair of the 'port number'.cer (DER) and 'port number'.key - /// (DER, RSA Private Key). + /// + /// This property represents the path to the folder in which stores the certificate files + /// associated with each port number of added URI prefixes. A set of the certificate files + /// is a pair of the 'port number'.cer (DER) and 'port number'.key + /// (DER, RSA Private Key). + /// + /// + /// If this property is or empty, the result of + /// System.Environment.GetFolderPath + /// () is used as the default path. + /// /// /// - /// A that represents the path to the folder in which stores the - /// certificate files. The default value is result of System.Environment.GetFolderPath - /// (). + /// A that represents the path to the folder in which stores + /// the certificate files. The default value is . /// /// /// This listener has been closed. @@ -177,10 +183,7 @@ namespace WebSocketSharp.Net public string CertificateFolderPath { get { CheckDisposed (); - return _certFolderPath == null || _certFolderPath.Length == 0 - ? (_certFolderPath = - Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData)) - : _certFolderPath; + return _certFolderPath; } set {