Merge pull request #969 from jabbera/ssl2
Ssl in mediabrowser against new listener.
This commit is contained in:
commit
bb02d68ceb
|
@ -36,6 +36,28 @@ namespace MediaBrowser.Controller
|
||||||
/// <value>The HTTP server port.</value>
|
/// <value>The HTTP server port.</value>
|
||||||
int HttpServerPort { get; }
|
int HttpServerPort { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the HTTPS server port.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The HTTPS server port.</value>
|
||||||
|
int HttpsServerPort { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value indiciating if an https port should be hosted.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The value indiciating if an https port should be hosted.
|
||||||
|
/// </value>
|
||||||
|
bool UseHttps { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value pointing to the file system where the ssl certiifcate is located.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The value pointing to the file system where the ssl certiifcate is located.
|
||||||
|
/// </value>
|
||||||
|
string CertificatePath { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this instance has update available.
|
/// Gets a value indicating whether this instance has update available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -19,7 +19,9 @@ namespace MediaBrowser.Controller.Net
|
||||||
/// Starts the specified server name.
|
/// Starts the specified server name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="urlPrefixes">The URL prefixes.</param>
|
/// <param name="urlPrefixes">The URL prefixes.</param>
|
||||||
void StartServer(IEnumerable<string> urlPrefixes);
|
/// <param name="certificatePath">If an https prefix is specified,
|
||||||
|
/// the ssl certificate localtion on the file system.</param>
|
||||||
|
void StartServer(IEnumerable<string> urlPrefixes, string certificatePath);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the local end points.
|
/// Gets the local end points.
|
||||||
|
|
|
@ -15,7 +15,9 @@ namespace MediaBrowser.Controller.Net
|
||||||
/// Starts this instance.
|
/// Starts this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="urlPrefixes">The URL prefixes.</param>
|
/// <param name="urlPrefixes">The URL prefixes.</param>
|
||||||
void Start(IEnumerable<string> urlPrefixes);
|
/// <param name="certificatePath">If an https prefix is specified,
|
||||||
|
/// the ssl certificate localtion on the file system.</param>
|
||||||
|
void Start(IEnumerable<string> urlPrefixes, string certificatePath);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a message to all clients currently connected via a web socket
|
/// Sends a message to all clients currently connected via a web socket
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using MediaBrowser.Model.Dto;
|
using System.Xml.Schema;
|
||||||
|
using MediaBrowser.Model.Dto;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Configuration
|
namespace MediaBrowser.Model.Configuration
|
||||||
|
@ -32,6 +33,17 @@ namespace MediaBrowser.Model.Configuration
|
||||||
/// <value>The HTTPS server port number.</value>
|
/// <value>The HTTPS server port number.</value>
|
||||||
public int HttpsPortNumber { get; set; }
|
public int HttpsPortNumber { get; set; }
|
||||||
|
|
||||||
|
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The value pointing to the file system where the ssl certiifcate is located.</value>
|
||||||
|
public bool UseHttps { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located..
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The value pointing to the file system where the ssl certiifcate is located..</value>
|
||||||
|
public string CertificatePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether [enable internet providers].
|
/// Gets or sets a value indicating whether [enable internet providers].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -187,6 +199,7 @@ namespace MediaBrowser.Model.Configuration
|
||||||
public string[] InsecureApps8 { get; set; }
|
public string[] InsecureApps8 { get; set; }
|
||||||
|
|
||||||
public bool SaveMetadataHidden { get; set; }
|
public bool SaveMetadataHidden { get; set; }
|
||||||
|
|
||||||
public bool EnableWin8HttpListener { get; set; }
|
public bool EnableWin8HttpListener { get; set; }
|
||||||
|
|
||||||
public NameValuePair[] ContentTypes { get; set; }
|
public NameValuePair[] ContentTypes { get; set; }
|
||||||
|
@ -204,6 +217,8 @@ namespace MediaBrowser.Model.Configuration
|
||||||
PublicPort = 8096;
|
PublicPort = 8096;
|
||||||
HttpServerPortNumber = 8096;
|
HttpServerPortNumber = 8096;
|
||||||
HttpsPortNumber = 8920;
|
HttpsPortNumber = 8920;
|
||||||
|
UseHttps = false;
|
||||||
|
CertificatePath = null;
|
||||||
EnableDashboardResponseCaching = true;
|
EnableDashboardResponseCaching = true;
|
||||||
|
|
||||||
EnableAutomaticRestart = true;
|
EnableAutomaticRestart = true;
|
||||||
|
|
|
@ -122,6 +122,24 @@ namespace MediaBrowser.Model.System
|
||||||
/// <value>The HTTP server port number.</value>
|
/// <value>The HTTP server port number.</value>
|
||||||
public int HttpServerPortNumber { get; set; }
|
public int HttpServerPortNumber { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The value pointing to the file system where the ssl certiifcate is located.</value>
|
||||||
|
public bool UseHttps { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located..
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The value pointing to the file system where the ssl certiifcate is located..</value>
|
||||||
|
public string CertificatePath { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the HTTPS server port number.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The HTTPS server port number.</value>
|
||||||
|
public int HttpsPortNumber { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether this instance has update available.
|
/// Gets or sets a value indicating whether this instance has update available.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -44,6 +44,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||||
|
|
||||||
private readonly bool _supportsNativeWebSocket;
|
private readonly bool _supportsNativeWebSocket;
|
||||||
|
|
||||||
|
private string _certificatePath;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the local end points.
|
/// Gets the local end points.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -217,10 +219,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||||
{
|
{
|
||||||
if (_supportsNativeWebSocket && NativeWebSocket.IsSupported)
|
if (_supportsNativeWebSocket && NativeWebSocket.IsSupported)
|
||||||
{
|
{
|
||||||
|
// Certificate location is ignored here. You need to use netsh
|
||||||
|
// to assign the certificate to the proper port.
|
||||||
return new HttpListenerServer(_logger, OnRequestReceived);
|
return new HttpListenerServer(_logger, OnRequestReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WebSocketSharpListener(_logger, OnRequestReceived);
|
return new WebSocketSharpListener(_logger, OnRequestReceived, _certificatePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WebSocketHandler(WebSocketConnectEventArgs args)
|
private void WebSocketHandler(WebSocketConnectEventArgs args)
|
||||||
|
@ -425,8 +429,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartServer(IEnumerable<string> urlPrefixes)
|
public void StartServer(IEnumerable<string> urlPrefixes, string certificatePath)
|
||||||
{
|
{
|
||||||
|
_certificatePath = certificatePath;
|
||||||
UrlPrefixes = urlPrefixes.ToList();
|
UrlPrefixes = urlPrefixes.ToList();
|
||||||
Start(UrlPrefixes.First());
|
Start(UrlPrefixes.First());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly Action<string> _endpointListener;
|
private readonly Action<string> _endpointListener;
|
||||||
|
private readonly string _certificatePath ;
|
||||||
|
|
||||||
public WebSocketSharpListener(ILogger logger, Action<string> endpointListener)
|
public WebSocketSharpListener(ILogger logger, Action<string> endpointListener,
|
||||||
|
string certificatePath)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_endpointListener = endpointListener;
|
_endpointListener = endpointListener;
|
||||||
|
_certificatePath = certificatePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action<Exception, IRequest> ErrorHandler { get; set; }
|
public Action<Exception, IRequest> ErrorHandler { get; set; }
|
||||||
|
@ -34,7 +37,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
|
||||||
public void Start(IEnumerable<string> urlPrefixes)
|
public void Start(IEnumerable<string> urlPrefixes)
|
||||||
{
|
{
|
||||||
if (_listener == null)
|
if (_listener == null)
|
||||||
_listener = new HttpListener(new PatternsLogger(_logger), null);
|
_listener = new HttpListener(new PatternsLogger(_logger), _certificatePath);
|
||||||
|
|
||||||
foreach (var prefix in urlPrefixes)
|
foreach (var prefix in urlPrefixes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -508,6 +508,14 @@
|
||||||
"LabelLocalHttpServerPortNumberHelp": "The tcp port number that Media Browser's http server should bind to.",
|
"LabelLocalHttpServerPortNumberHelp": "The tcp port number that Media Browser's http server should bind to.",
|
||||||
"LabelPublicPort": "Public port number:",
|
"LabelPublicPort": "Public port number:",
|
||||||
"LabelPublicPortHelp": "The public port number that should be mapped to the local port.",
|
"LabelPublicPortHelp": "The public port number that should be mapped to the local port.",
|
||||||
|
|
||||||
|
"LabelUseHttps": "Enable SSL",
|
||||||
|
"LabelUseHttpsHelp": "Check to enable SSL hosting.",
|
||||||
|
"LabelHttpsPort": "Local http port:",
|
||||||
|
"LabelHttpsPortHelp": "The tcp port number that Media Browser's https server should bind to.",
|
||||||
|
"LabelCertificatePath": "SSL Certificate path:",
|
||||||
|
"LabelCertificatePathHelp": "The path on the filesystem to the ssl certificate pfx file.",
|
||||||
|
|
||||||
"LabelWebSocketPortNumber": "Web socket port number:",
|
"LabelWebSocketPortNumber": "Web socket port number:",
|
||||||
"LabelEnableAutomaticPortMap": "Enable automatic port mapping",
|
"LabelEnableAutomaticPortMap": "Enable automatic port mapping",
|
||||||
"LabelEnableAutomaticPortMapHelp": "Attempt to automatically map the public port to the local port via UPnP. This may not work with some router models.",
|
"LabelEnableAutomaticPortMapHelp": "Attempt to automatically map the public port to the local port via UPnP. This may not work with some router models.",
|
||||||
|
|
|
@ -99,22 +99,22 @@ namespace MediaBrowser.Server.Implementations.ServerManager
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts this instance.
|
/// Starts this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start(IEnumerable<string> urlPrefixes)
|
public void Start(IEnumerable<string> urlPrefixes, string certificatePath)
|
||||||
{
|
{
|
||||||
ReloadHttpServer(urlPrefixes);
|
ReloadHttpServer(urlPrefixes, certificatePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restarts the Http Server, or starts it if not currently running
|
/// Restarts the Http Server, or starts it if not currently running
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ReloadHttpServer(IEnumerable<string> urlPrefixes)
|
private void ReloadHttpServer(IEnumerable<string> urlPrefixes, string certificatePath)
|
||||||
{
|
{
|
||||||
_logger.Info("Loading Http Server");
|
_logger.Info("Loading Http Server");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HttpServer = _applicationHost.Resolve<IHttpServer>();
|
HttpServer = _applicationHost.Resolve<IHttpServer>();
|
||||||
HttpServer.StartServer(urlPrefixes);
|
HttpServer.StartServer(urlPrefixes, certificatePath);
|
||||||
}
|
}
|
||||||
catch (SocketException ex)
|
catch (SocketException ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -133,6 +133,11 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
"http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/"
|
"http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (ServerConfigurationManager.Configuration.UseHttps)
|
||||||
|
{
|
||||||
|
list.Add("https://+:" + ServerConfigurationManager.Configuration.HttpsPortNumber + "/" + WebApplicationName + "/");
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -805,7 +810,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ServerManager.Start(HttpServerUrlPrefixes);
|
ServerManager.Start(HttpServerUrlPrefixes, CertificatePath);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -972,6 +977,8 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
CachePath = ApplicationPaths.CachePath,
|
CachePath = ApplicationPaths.CachePath,
|
||||||
MacAddress = GetMacAddress(),
|
MacAddress = GetMacAddress(),
|
||||||
HttpServerPortNumber = HttpServerPort,
|
HttpServerPortNumber = HttpServerPort,
|
||||||
|
UseHttps = UseHttps,
|
||||||
|
CertificatePath = CertificatePath,
|
||||||
OperatingSystem = OperatingSystemDisplayName,
|
OperatingSystem = OperatingSystemDisplayName,
|
||||||
CanSelfRestart = CanSelfRestart,
|
CanSelfRestart = CanSelfRestart,
|
||||||
CanSelfUpdate = CanSelfUpdate,
|
CanSelfUpdate = CanSelfUpdate,
|
||||||
|
@ -1046,6 +1053,21 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
get { return ServerConfigurationManager.Configuration.HttpServerPortNumber; }
|
get { return ServerConfigurationManager.Configuration.HttpServerPortNumber; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool UseHttps
|
||||||
|
{
|
||||||
|
get { return this.ServerConfigurationManager.Configuration.UseHttps; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string CertificatePath
|
||||||
|
{
|
||||||
|
get { return this.ServerConfigurationManager.Configuration.CertificatePath; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int HttpsServerPort
|
||||||
|
{
|
||||||
|
get { return ServerConfigurationManager.Configuration.HttpsPortNumber; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mac address.
|
/// Gets the mac address.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user