aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs9
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs56
-rw-r--r--Emby.Server.Implementations/Cryptography/CertificateGenerator.cs42
-rw-r--r--Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs20
-rw-r--r--Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs10
-rw-r--r--Emby.Server.Implementations/Library/UserManager.cs6
-rw-r--r--Emby.Server.Implementations/Logging/SimpleLogManager.cs4
-rw-r--r--Emby.Server.Implementations/Net/SocketFactory.cs23
-rw-r--r--Emby.Server.Implementations/ServerApplicationPaths.cs4
9 files changed, 114 insertions, 60 deletions
diff --git a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
index 54d1d5302..1e63aa1a6 100644
--- a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
+++ b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
@@ -13,15 +13,12 @@ namespace Emby.Server.Implementations.AppBase
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
/// </summary>
- protected BaseApplicationPaths(string programDataPath, string appFolderPath, Action<string> createDirectoryFn)
+ protected BaseApplicationPaths(string programDataPath, string appFolderPath)
{
ProgramDataPath = programDataPath;
ProgramSystemPath = appFolderPath;
- CreateDirectoryFn = createDirectoryFn;
}
- protected Action<string> CreateDirectoryFn;
-
public string ProgramDataPath { get; private set; }
/// <summary>
@@ -45,7 +42,7 @@ namespace Emby.Server.Implementations.AppBase
{
_dataDirectory = Path.Combine(ProgramDataPath, "data");
- CreateDirectoryFn(_dataDirectory);
+ Directory.CreateDirectory(_dataDirectory);
}
return _dataDirectory;
@@ -152,7 +149,7 @@ namespace Emby.Server.Implementations.AppBase
{
_cachePath = Path.Combine(ProgramDataPath, "cache");
- CreateDirectoryFn(_cachePath);
+ Directory.CreateDirectory(_cachePath);
}
return _cachePath;
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 3ad8fe7df..bc88d652c 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -111,6 +111,7 @@ using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using Emby.Server.Core.Cryptography;
using Emby.Server.Implementations.Archiving;
using Emby.Server.Implementations.Cryptography;
using Emby.Server.Implementations.Diagnostics;
@@ -368,8 +369,6 @@ namespace Emby.Server.Implementations
internal IPowerManagement PowerManagement { get; private set; }
internal IImageEncoder ImageEncoder { get; private set; }
- private readonly Action<string, string, string> _certificateGenerator;
- private readonly Func<string> _defaultUserNameFactory;
protected IProcessFactory ProcessFactory { get; private set; }
protected ITimerFactory TimerFactory { get; private set; }
protected ICryptoProvider CryptographyProvider = new CryptographyProvider();
@@ -394,10 +393,7 @@ namespace Emby.Server.Implementations
IEnvironmentInfo environmentInfo,
IImageEncoder imageEncoder,
ISystemEvents systemEvents,
- IMemoryStreamFactory memoryStreamFactory,
- INetworkManager networkManager,
- Action<string, string, string> certificateGenerator,
- Func<string> defaultUsernameFactory)
+ INetworkManager networkManager)
{
// hack alert, until common can target .net core
BaseExtensions.CryptographyProvider = CryptographyProvider;
@@ -407,7 +403,7 @@ namespace Emby.Server.Implementations
NetworkManager = networkManager;
EnvironmentInfo = environmentInfo;
SystemEvents = systemEvents;
- MemoryStreamFactory = memoryStreamFactory;
+ MemoryStreamFactory = new MemoryStreamProvider();
FailedAssemblies = new List<string>();
@@ -421,9 +417,7 @@ namespace Emby.Server.Implementations
Logger = LogManager.GetLogger("App");
StartupOptions = options;
- _certificateGenerator = certificateGenerator;
_releaseAssetFilename = releaseAssetFilename;
- _defaultUserNameFactory = defaultUsernameFactory;
PowerManagement = powerManagement;
ImageEncoder = imageEncoder;
@@ -917,7 +911,7 @@ namespace Emby.Server.Implementations
AuthenticationRepository = GetAuthenticationRepository();
RegisterSingleInstance(AuthenticationRepository);
- UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, CryptographyProvider, _defaultUserNameFactory());
+ UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, CryptographyProvider);
RegisterSingleInstance(UserManager);
LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager);
@@ -1257,7 +1251,7 @@ namespace Emby.Server.Implementations
case MediaBrowser.Model.System.Architecture.X64:
return new[]
{
- "https://embydata.com/downloads/ffmpeg/osx/ffmpeg-x64-20170308.7z"
+ "https://embydata.com/downloads/ffmpeg/osx/ffmpeg-x64-20170308.7z"
};
}
@@ -1271,12 +1265,12 @@ namespace Emby.Server.Implementations
case MediaBrowser.Model.System.Architecture.X64:
return new[]
{
- "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win64.7z"
+ "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win64.7z"
};
case MediaBrowser.Model.System.Architecture.X86:
return new[]
{
- "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win32.7z"
+ "https://embydata.com/downloads/ffmpeg/windows/ffmpeg-20170308-win32.7z"
};
}
@@ -1290,12 +1284,12 @@ namespace Emby.Server.Implementations
case MediaBrowser.Model.System.Architecture.X64:
return new[]
{
- "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-64bit-static.7z"
+ "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-64bit-static.7z"
};
case MediaBrowser.Model.System.Architecture.X86:
return new[]
{
- "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-32bit-static.7z"
+ "https://embydata.com/downloads/ffmpeg/linux/ffmpeg-git-20170301-32bit-static.7z"
};
}
@@ -1442,17 +1436,17 @@ namespace Emby.Server.Implementations
StartServer();
LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
- GetExports<IVirtualFolderCreator>(),
- GetExports<IItemResolver>(),
- GetExports<IIntroProvider>(),
- GetExports<IBaseItemComparer>(),
- GetExports<ILibraryPostScanTask>());
+ GetExports<IVirtualFolderCreator>(),
+ GetExports<IItemResolver>(),
+ GetExports<IIntroProvider>(),
+ GetExports<IBaseItemComparer>(),
+ GetExports<ILibraryPostScanTask>());
ProviderManager.AddParts(GetExports<IImageProvider>(),
- GetExports<IMetadataService>(),
- GetExports<IMetadataProvider>(),
- GetExports<IMetadataSaver>(),
- GetExports<IExternalId>());
+ GetExports<IMetadataService>(),
+ GetExports<IMetadataProvider>(),
+ GetExports<IMetadataSaver>(),
+ GetExports<IExternalId>());
ImageProcessor.AddParts(GetExports<IImageEnhancer>());
@@ -1652,7 +1646,7 @@ namespace Emby.Server.Implementations
try
{
- _certificateGenerator(certPath, certHost, password);
+ CertificateGenerator.CreateSelfSignCertificatePfx(certPath, certHost, password, Logger);
}
catch (Exception ex)
{
@@ -2158,7 +2152,7 @@ namespace Emby.Server.Implementations
list.Remove(plugin);
Plugins = list.ToArray();
}
-
+
/// <summary>
/// Checks for update.
/// </summary>
@@ -2176,7 +2170,7 @@ namespace Emby.Server.Implementations
}
var result = await new GithubUpdater(HttpClient, JsonSerializer).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename,
- "MBServer", "Mbserver.zip", cacheLength, cancellationToken).ConfigureAwait(false);
+ "MBServer", "Mbserver.zip", cacheLength, cancellationToken).ConfigureAwait(false);
HasUpdateAvailable = result.IsUpdateAvailable;
@@ -2314,12 +2308,18 @@ namespace Emby.Server.Implementations
NotifyPendingRestart();
}
+ private bool _disposed;
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
- Dispose(true);
+ if (!_disposed)
+ {
+ _disposed = true;
+
+ Dispose(true);
+ }
}
/// <summary>
diff --git a/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs b/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs
index 2600d7470..b4c84a600 100644
--- a/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs
+++ b/Emby.Server.Implementations/Cryptography/CertificateGenerator.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Security.Cryptography;
+using System.Xml;
namespace Emby.Server.Core.Cryptography
{
@@ -27,7 +28,11 @@ namespace Emby.Server.Core.Cryptography
DateTime notAfter = DateTime.Now.AddYears(10);
RSA issuerKey = RSA.Create();
+#if NET46
issuerKey.FromXmlString(MonoTestRootAgency);
+#else
+ RSACryptoServiceProviderExtensions.FromXmlString(issuerKey, MonoTestRootAgency);
+#endif
RSA subjectKey = RSA.Create();
// serial number MUST be positive
@@ -44,7 +49,7 @@ namespace Emby.Server.Core.Cryptography
cb.NotAfter = notAfter;
cb.SubjectName = subject;
cb.SubjectPublicKey = subjectKey;
-
+
// signature
cb.Hash = "SHA256";
byte[] rawcert = cb.Sign(issuerKey);
@@ -66,4 +71,39 @@ namespace Emby.Server.Core.Cryptography
p12.SaveToFile(fileName);
}
}
+
+ public static class RSACryptoServiceProviderExtensions
+ {
+ public static void FromXmlString(RSA rsa, string xmlString)
+ {
+ RSAParameters parameters = new RSAParameters();
+
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml(xmlString);
+
+ if (xmlDoc.DocumentElement.Name.Equals("RSAKeyValue"))
+ {
+ foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
+ {
+ switch (node.Name)
+ {
+ case "Modulus": parameters.Modulus = Convert.FromBase64String(node.InnerText); break;
+ case "Exponent": parameters.Exponent = Convert.FromBase64String(node.InnerText); break;
+ case "P": parameters.P = Convert.FromBase64String(node.InnerText); break;
+ case "Q": parameters.Q = Convert.FromBase64String(node.InnerText); break;
+ case "DP": parameters.DP = Convert.FromBase64String(node.InnerText); break;
+ case "DQ": parameters.DQ = Convert.FromBase64String(node.InnerText); break;
+ case "InverseQ": parameters.InverseQ = Convert.FromBase64String(node.InnerText); break;
+ case "D": parameters.D = Convert.FromBase64String(node.InnerText); break;
+ }
+ }
+ }
+ else
+ {
+ throw new Exception("Invalid XML RSA key.");
+ }
+
+ rsa.ImportParameters(parameters);
+ }
+ }
}
diff --git a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs
index 0999fa141..f86279f37 100644
--- a/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs
+++ b/Emby.Server.Implementations/EnvironmentInfo/EnvironmentInfo.cs
@@ -6,16 +6,16 @@ namespace Emby.Server.Implementations.EnvironmentInfo
{
public class EnvironmentInfo : IEnvironmentInfo
{
- public Architecture? CustomArchitecture { get; set; }
- public MediaBrowser.Model.System.OperatingSystem? CustomOperatingSystem { get; set; }
+ private Architecture? _customArchitecture;
+ private MediaBrowser.Model.System.OperatingSystem? _customOperatingSystem;
public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem
{
get
{
- if (CustomOperatingSystem.HasValue)
+ if (_customOperatingSystem.HasValue)
{
- return CustomOperatingSystem.Value;
+ return _customOperatingSystem.Value;
}
switch (Environment.OSVersion.Platform)
@@ -30,6 +30,10 @@ namespace Emby.Server.Implementations.EnvironmentInfo
return MediaBrowser.Model.System.OperatingSystem.Windows;
}
+ set
+ {
+ _customOperatingSystem = value;
+ }
}
public string OperatingSystemName
@@ -60,13 +64,17 @@ namespace Emby.Server.Implementations.EnvironmentInfo
{
get
{
- if (CustomArchitecture.HasValue)
+ if (_customArchitecture.HasValue)
{
- return CustomArchitecture.Value;
+ return _customArchitecture.Value;
}
return Environment.Is64BitOperatingSystem ? MediaBrowser.Model.System.Architecture.X64 : MediaBrowser.Model.System.Architecture.X86;
}
+ set
+ {
+ _customArchitecture = value;
+ }
}
public string GetEnvironmentVariable(string name)
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
index 1017953ba..f512b723d 100644
--- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
@@ -66,8 +66,10 @@ namespace Emby.Server.Implementations.HttpClientManager
// http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
ServicePointManager.Expect100Continue = false;
- // Trakt requests sometimes fail without this
+#if NET46
+// Trakt requests sometimes fail without this
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
+#endif
}
/// <summary>
@@ -428,7 +430,7 @@ namespace Emby.Server.Implementations.HttpClientManager
try
{
var bytes = options.RequestContentBytes ??
- Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty);
+ Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty);
httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";
@@ -727,7 +729,7 @@ namespace Emby.Server.Implementations.HttpClientManager
}
var webException = ex as WebException
- ?? ex.InnerException as WebException;
+ ?? ex.InnerException as WebException;
if (webException != null)
{
@@ -762,7 +764,7 @@ namespace Emby.Server.Implementations.HttpClientManager
}
var operationCanceledException = ex as OperationCanceledException
- ?? ex.InnerException as OperationCanceledException;
+ ?? ex.InnerException as OperationCanceledException;
if (operationCanceledException != null)
{
diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs
index 019b8162a..211c54cee 100644
--- a/Emby.Server.Implementations/Library/UserManager.cs
+++ b/Emby.Server.Implementations/Library/UserManager.cs
@@ -71,9 +71,8 @@ namespace Emby.Server.Implementations.Library
private readonly IServerApplicationHost _appHost;
private readonly IFileSystem _fileSystem;
private readonly ICryptoProvider _cryptographyProvider;
- private readonly string _defaultUserName;
- public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func<IImageProcessor> imageProcessorFactory, Func<IDtoService> dtoServiceFactory, Func<IConnectManager> connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ICryptoProvider cryptographyProvider, string defaultUserName)
+ public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func<IImageProcessor> imageProcessorFactory, Func<IDtoService> dtoServiceFactory, Func<IConnectManager> connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, ICryptoProvider cryptographyProvider)
{
_logger = logger;
UserRepository = userRepository;
@@ -86,7 +85,6 @@ namespace Emby.Server.Implementations.Library
_jsonSerializer = jsonSerializer;
_fileSystem = fileSystem;
_cryptographyProvider = cryptographyProvider;
- _defaultUserName = defaultUserName;
ConfigurationManager = configurationManager;
Users = new List<User>();
@@ -381,7 +379,7 @@ namespace Emby.Server.Implementations.Library
// There always has to be at least one user.
if (users.Count == 0)
{
- var name = MakeValidUsername(_defaultUserName);
+ var name = MakeValidUsername(Environment.UserName);
var user = InstantiateNewUser(name);
diff --git a/Emby.Server.Implementations/Logging/SimpleLogManager.cs b/Emby.Server.Implementations/Logging/SimpleLogManager.cs
index 1a50f162a..5c83766fe 100644
--- a/Emby.Server.Implementations/Logging/SimpleLogManager.cs
+++ b/Emby.Server.Implementations/Logging/SimpleLogManager.cs
@@ -138,10 +138,10 @@ namespace Emby.Server.Implementations.Logging
foreach (var message in _queue.GetConsumingEnumerable())
{
- any = true;
-
var bytes = Encoding.UTF8.GetBytes(message + Environment.NewLine);
_fileStream.Write(bytes, 0, bytes.Length);
+
+ any = true;
}
if (any)
diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.cs
index ab3bd0b31..f78fbdfd7 100644
--- a/Emby.Server.Implementations/Net/SocketFactory.cs
+++ b/Emby.Server.Implementations/Net/SocketFactory.cs
@@ -69,8 +69,8 @@ namespace Emby.Server.Implementations.Net
if (remotePort < 0) throw new ArgumentException("remotePort cannot be less than zero.", "remotePort");
var addressFamily = remoteAddress.AddressFamily == IpAddressFamily.InterNetwork
- ? AddressFamily.InterNetwork
- : AddressFamily.InterNetworkV6;
+ ? AddressFamily.InterNetwork
+ : AddressFamily.InterNetworkV6;
var retVal = new Socket(addressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
@@ -82,7 +82,7 @@ namespace Emby.Server.Implementations.Net
{
// This is not supported on all operating systems (qnap)
}
-
+
try
{
return new UdpSocket(retVal, new IpEndPointInfo(remoteAddress, remotePort));
@@ -139,11 +139,11 @@ namespace Emby.Server.Implementations.Net
throw;
}
}
-
+
/// <summary>
- /// Creates a new UDP acceptSocket that is a member of the SSDP multicast local admin group and binds it to the specified local port.
- /// </summary>
- /// <returns>An implementation of the <see cref="ISocket"/> interface used by RSSDP components to perform acceptSocket operations.</returns>
+ /// Creates a new UDP acceptSocket that is a member of the SSDP multicast local admin group and binds it to the specified local port.
+ /// </summary>
+ /// <returns>An implementation of the <see cref="ISocket"/> interface used by RSSDP components to perform acceptSocket operations.</returns>
public ISocket CreateSsdpUdpSocket(IpAddressInfo localIpAddress, int localPort)
{
if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort");
@@ -186,7 +186,16 @@ namespace Emby.Server.Implementations.Net
try
{
+ // not supported on all platforms. throws on ubuntu with .net core 2.0
retVal.ExclusiveAddressUse = false;
+ }
+ catch (SocketException)
+ {
+
+ }
+
+ try
+ {
//retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive);
diff --git a/Emby.Server.Implementations/ServerApplicationPaths.cs b/Emby.Server.Implementations/ServerApplicationPaths.cs
index b4b2bb139..675b0d78c 100644
--- a/Emby.Server.Implementations/ServerApplicationPaths.cs
+++ b/Emby.Server.Implementations/ServerApplicationPaths.cs
@@ -13,8 +13,8 @@ namespace Emby.Server.Implementations
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class.
/// </summary>
- public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath, Action<string> createDirectoryFn)
- : base(programDataPath, appFolderPath, createDirectoryFn)
+ public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath)
+ : base(programDataPath, appFolderPath)
{
ApplicationResourcesPath = applicationResourcesPath;
}