DNLA over HTTP only

This commit is contained in:
Greenback 2020-12-07 22:06:28 +00:00
parent f2c2beca0f
commit d69f2d7d7f
4 changed files with 28 additions and 9 deletions

View File

@ -9,6 +9,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Emby.Dlna.PlayTo; using Emby.Dlna.PlayTo;
using Emby.Dlna.Ssdp; using Emby.Dlna.Ssdp;
using Jellyfin.Networking.Configuration;
using Jellyfin.Networking.Manager; using Jellyfin.Networking.Manager;
using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
@ -52,6 +53,8 @@ namespace Emby.Dlna.Main
private readonly ISocketFactory _socketFactory; private readonly ISocketFactory _socketFactory;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly object _syncLock = new object(); private readonly object _syncLock = new object();
private readonly NetworkConfiguration _netConfig;
private readonly bool _disabled;
private PlayToManager _manager; private PlayToManager _manager;
private SsdpDevicePublisher _publisher; private SsdpDevicePublisher _publisher;
@ -122,6 +125,13 @@ namespace Emby.Dlna.Main
httpClientFactory, httpClientFactory,
config); config);
Current = this; Current = this;
_netConfig = config.GetConfiguration<NetworkConfiguration>("network");
_disabled = appHost.ListenWithHttps && _netConfig.RequireHttps;
if (_disabled)
{
_logger.LogError("The DLNA specification does not support HTTPS.");
}
} }
public static DlnaEntryPoint Current { get; private set; } public static DlnaEntryPoint Current { get; private set; }
@ -136,6 +146,12 @@ namespace Emby.Dlna.Main
{ {
await ((DlnaManager)_dlnaManager).InitProfilesAsync().ConfigureAwait(false); await ((DlnaManager)_dlnaManager).InitProfilesAsync().ConfigureAwait(false);
if (_disabled)
{
// No use starting as dlna won't work, as we're running purely on HTTPS.
return;
}
ReloadComponents(); ReloadComponents();
_config.NamedConfigurationUpdated += OnNamedConfigurationUpdated; _config.NamedConfigurationUpdated += OnNamedConfigurationUpdated;
@ -290,12 +306,15 @@ namespace Emby.Dlna.Main
_logger.LogInformation("Registering publisher for {0} on {1}", fullService, address); _logger.LogInformation("Registering publisher for {0} on {1}", fullService, address);
var uri = new Uri(_appHost.GetSmartApiUrl(address.Address) + descriptorUri); var uri = new UriBuilder(_appHost.GetSmartApiUrl(address.Address) + descriptorUri);
// DLNA will only work over http, so we must reset to http:// : {port}
uri.Scheme = "http://";
uri.Port = _netConfig.PublicPort;
var device = new SsdpRootDevice var device = new SsdpRootDevice
{ {
CacheLifetime = TimeSpan.FromSeconds(1800), // How long SSDP clients can cache this info. CacheLifetime = TimeSpan.FromSeconds(1800), // How long SSDP clients can cache this info.
Location = uri, // Must point to the URL that serves your devices UPnP description document. Location = uri.Uri, // Must point to the URL that serves your devices UPnP description document.
Address = address.Address, Address = address.Address,
PrefixLength = address.PrefixLength, PrefixLength = address.PrefixLength,
FriendlyName = "Jellyfin", FriendlyName = "Jellyfin",

View File

@ -496,7 +496,7 @@ namespace Emby.Server.Implementations
{ {
var networkConfiguration = ServerConfigurationManager.GetNetworkConfiguration(); var networkConfiguration = ServerConfigurationManager.GetNetworkConfiguration();
HttpPort = networkConfiguration.HttpServerPortNumber; HttpPort = networkConfiguration.HttpServerPortNumber;
HttpsPort = networkConfiguration.HttpsPortNumber; HttpsPort = networkConfiguration.HttpsServerPortNumber;
// Safeguard against invalid configuration // Safeguard against invalid configuration
if (HttpPort == HttpsPort) if (HttpPort == HttpsPort)
@ -714,7 +714,7 @@ namespace Emby.Server.Implementations
// Don't use an empty string password // Don't use an empty string password
var password = string.IsNullOrWhiteSpace(info.Password) ? null : info.Password; var password = string.IsNullOrWhiteSpace(info.Password) ? null : info.Password;
var localCert = new X509Certificate2(certificateLocation, password); var localCert = new X509Certificate2(certificateLocation, password, X509KeyStorageFlags.UserKeySet);
// localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA; // localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA;
if (!localCert.HasPrivateKey) if (!localCert.HasPrivateKey)
{ {
@ -919,7 +919,7 @@ namespace Emby.Server.Implementations
var networkConfiguration = ServerConfigurationManager.GetNetworkConfiguration(); var networkConfiguration = ServerConfigurationManager.GetNetworkConfiguration();
// Need to restart if ports have changed // Need to restart if ports have changed
if (networkConfiguration.HttpServerPortNumber != HttpPort || if (networkConfiguration.HttpServerPortNumber != HttpPort ||
networkConfiguration.HttpsPortNumber != HttpsPort) networkConfiguration.HttpsServerPortNumber != HttpsPort)
{ {
if (ServerConfigurationManager.Configuration.IsPortAuthorized) if (ServerConfigurationManager.Configuration.IsPortAuthorized)
{ {

View File

@ -16,7 +16,7 @@ namespace Jellyfin.Networking.Configuration
public const int DefaultHttpPort = 8096; public const int DefaultHttpPort = 8096;
/// <summary> /// <summary>
/// The default value for <see cref="PublicHttpsPort"/> and <see cref="HttpsPortNumber"/>. /// The default value for <see cref="PublicHttpsPort"/> and <see cref="HttpsServerPortNumber"/>.
/// </summary> /// </summary>
public const int DefaultHttpsPort = 8920; public const int DefaultHttpsPort = 8920;
@ -76,7 +76,7 @@ namespace Jellyfin.Networking.Configuration
/// Gets or sets the HTTPS server port number. /// Gets or sets the HTTPS server port number.
/// </summary> /// </summary>
/// <value>The HTTPS server port number.</value> /// <value>The HTTPS server port number.</value>
public int HttpsPortNumber { get; set; } = DefaultHttpsPort; public int HttpsServerPortNumber { get; set; } = DefaultHttpsPort;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether to use HTTPS. /// Gets or sets a value indicating whether to use HTTPS.
@ -88,7 +88,7 @@ namespace Jellyfin.Networking.Configuration
public bool EnableHttps { get; set; } public bool EnableHttps { get; set; }
/// <summary> /// <summary>
/// Gets or sets the public mapped port. /// Gets or sets the Upublic mapped port.
/// </summary> /// </summary>
/// <value>The public mapped port.</value> /// <value>The public mapped port.</value>
public int PublicPort { get; set; } = DefaultHttpPort; public int PublicPort { get; set; } = DefaultHttpPort;

View File

@ -784,7 +784,7 @@ namespace Jellyfin.Networking.Manager
} }
else else
{ {
_logger.LogDebug("Invalid or unknown network {Token}.", token); _logger.LogDebug("Invalid or unknown object {Token}.", token);
} }
} }