Fix for default cert folder path

This commit is contained in:
sta 2014-05-08 16:35:35 +09:00
parent 470a254a19
commit 53f44a0e0e
2 changed files with 27 additions and 11 deletions

View File

@ -51,6 +51,13 @@ namespace WebSocketSharp.Net
{ {
internal sealed class EndPointListener internal sealed class EndPointListener
{ {
#region Private Static Fields
private static readonly string _defaultCertFolderPath =
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData);
#endregion
#region Private Fields #region Private Fields
private List<ListenerPrefix> _all; // host = '+' private List<ListenerPrefix> _all; // host = '+'
@ -154,6 +161,9 @@ namespace WebSocketSharp.Net
private static X509Certificate2 getCertificate ( private static X509Certificate2 getCertificate (
int port, string certFolderPath, X509Certificate2 defaultCert) int port, string certFolderPath, X509Certificate2 defaultCert)
{ {
if (certFolderPath == null || certFolderPath.Length == 0)
certFolderPath = _defaultCertFolderPath;
try { try {
var cer = Path.Combine (certFolderPath, String.Format ("{0}.cer", port)); var cer = Path.Combine (certFolderPath, String.Format ("{0}.cer", port));
var key = Path.Combine (certFolderPath, String.Format ("{0}.key", 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) 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 cer = Path.Combine (certFolderPath, String.Format ("{0}.cer", port));
var key = Path.Combine (certFolderPath, String.Format ("{0}.key", port)); var key = Path.Combine (certFolderPath, String.Format ("{0}.key", port));

View File

@ -161,15 +161,21 @@ namespace WebSocketSharp.Net
/// authenticate the server on the secure connection. /// authenticate the server on the secure connection.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This property represents the path to the folder in which stores the certificate files /// <para>
/// associated with each port number of added URI prefixes. A set of the certificate files /// This property represents the path to the folder in which stores the certificate files
/// is a pair of the <c>'port number'.cer</c> (DER) and <c>'port number'.key</c> /// associated with each port number of added URI prefixes. A set of the certificate files
/// (DER, RSA Private Key). /// is a pair of the <c>'port number'.cer</c> (DER) and <c>'port number'.key</c>
/// (DER, RSA Private Key).
/// </para>
/// <para>
/// If this property is <see langword="null"/> or empty, the result of
/// <c>System.Environment.GetFolderPath
/// (<see cref="Environment.SpecialFolder.ApplicationData"/>)</c> is used as the default path.
/// </para>
/// </remarks> /// </remarks>
/// <value> /// <value>
/// A <see cref="string"/> that represents the path to the folder in which stores the /// A <see cref="string"/> that represents the path to the folder in which stores
/// certificate files. The default value is result of <c>System.Environment.GetFolderPath /// the certificate files. The default value is <see langword="null"/>.
/// (<see cref="Environment.SpecialFolder.ApplicationData"/>)</c>.
/// </value> /// </value>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// This listener has been closed. /// This listener has been closed.
@ -177,10 +183,7 @@ namespace WebSocketSharp.Net
public string CertificateFolderPath { public string CertificateFolderPath {
get { get {
CheckDisposed (); CheckDisposed ();
return _certFolderPath == null || _certFolderPath.Length == 0 return _certFolderPath;
? (_certFolderPath =
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData))
: _certFolderPath;
} }
set { set {