move classes
This commit is contained in:
parent
6d250c4050
commit
67ffbed93e
|
@ -641,6 +641,16 @@ namespace Emby.Common.Implementations.IO
|
||||||
}).Where(i => i != null);
|
}).Where(i => i != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string[] ReadAllLines(string path)
|
||||||
|
{
|
||||||
|
return File.ReadAllLines(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteAllLines(string path, IEnumerable<string> lines)
|
||||||
|
{
|
||||||
|
File.WriteAllLines(path, lines);
|
||||||
|
}
|
||||||
|
|
||||||
public Stream OpenRead(string path)
|
public Stream OpenRead(string path)
|
||||||
{
|
{
|
||||||
return File.OpenRead(path);
|
return File.OpenRead(path);
|
||||||
|
|
|
@ -159,6 +159,9 @@
|
||||||
<Compile Include="ScheduledTasks\RefreshIntrosTask.cs" />
|
<Compile Include="ScheduledTasks\RefreshIntrosTask.cs" />
|
||||||
<Compile Include="ScheduledTasks\RefreshMediaLibraryTask.cs" />
|
<Compile Include="ScheduledTasks\RefreshMediaLibraryTask.cs" />
|
||||||
<Compile Include="ScheduledTasks\SystemUpdateTask.cs" />
|
<Compile Include="ScheduledTasks\SystemUpdateTask.cs" />
|
||||||
|
<Compile Include="Security\MBLicenseFile.cs" />
|
||||||
|
<Compile Include="Security\PluginSecurityManager.cs" />
|
||||||
|
<Compile Include="Security\RegRecord.cs" />
|
||||||
<Compile Include="ServerManager\ServerManager.cs" />
|
<Compile Include="ServerManager\ServerManager.cs" />
|
||||||
<Compile Include="ServerManager\WebSocketConnection.cs" />
|
<Compile Include="ServerManager\WebSocketConnection.cs" />
|
||||||
<Compile Include="Session\HttpSessionController.cs" />
|
<Compile Include="Session\HttpSessionController.cs" />
|
||||||
|
|
|
@ -4,15 +4,18 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
|
using MediaBrowser.Model.Cryptography;
|
||||||
|
using MediaBrowser.Model.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Security
|
namespace Emby.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
internal class MBLicenseFile
|
internal class MBLicenseFile
|
||||||
{
|
{
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
private readonly ICryptographyProvider _cryptographyProvider;
|
||||||
|
|
||||||
public string RegKey
|
public string RegKey
|
||||||
{
|
{
|
||||||
|
@ -40,9 +43,11 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
private readonly object _fileLock = new object();
|
private readonly object _fileLock = new object();
|
||||||
private string _regKey;
|
private string _regKey;
|
||||||
|
|
||||||
public MBLicenseFile(IApplicationPaths appPaths)
|
public MBLicenseFile(IApplicationPaths appPaths, IFileSystem fileSystem, ICryptographyProvider cryptographyProvider)
|
||||||
{
|
{
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_cryptographyProvider = cryptographyProvider;
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
@ -54,41 +59,30 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
|
|
||||||
public void AddRegCheck(string featureId)
|
public void AddRegCheck(string featureId)
|
||||||
{
|
{
|
||||||
using (var provider = new MD5CryptoServiceProvider())
|
var key = new Guid(_cryptographyProvider.GetMD5Bytes(Encoding.Unicode.GetBytes(featureId)));
|
||||||
{
|
var value = DateTime.UtcNow;
|
||||||
var key = new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId)));
|
|
||||||
var value = DateTime.UtcNow;
|
|
||||||
|
|
||||||
SetUpdateRecord(key, value);
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SetUpdateRecord(key, value);
|
||||||
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRegCheck(string featureId)
|
public void RemoveRegCheck(string featureId)
|
||||||
{
|
{
|
||||||
using (var provider = new MD5CryptoServiceProvider())
|
var key = new Guid(_cryptographyProvider.GetMD5Bytes(Encoding.Unicode.GetBytes(featureId)));
|
||||||
{
|
DateTime val;
|
||||||
var key = new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId)));
|
|
||||||
DateTime val;
|
|
||||||
|
|
||||||
_updateRecords.TryRemove(key, out val);
|
_updateRecords.TryRemove(key, out val);
|
||||||
|
|
||||||
Save();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime LastChecked(string featureId)
|
public DateTime LastChecked(string featureId)
|
||||||
{
|
{
|
||||||
using (var provider = new MD5CryptoServiceProvider())
|
DateTime last;
|
||||||
{
|
_updateRecords.TryGetValue(new Guid(_cryptographyProvider.GetMD5Bytes(Encoding.Unicode.GetBytes(featureId))), out last);
|
||||||
DateTime last;
|
|
||||||
_updateRecords.TryGetValue(new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId))), out last);
|
|
||||||
|
|
||||||
// guard agains people just putting a large number in the file
|
// guard agains people just putting a large number in the file
|
||||||
return last < DateTime.UtcNow ? last : DateTime.MinValue;
|
return last < DateTime.UtcNow ? last : DateTime.MinValue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Load()
|
private void Load()
|
||||||
|
@ -99,15 +93,21 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
contents = File.ReadAllLines(licenseFile);
|
contents = _fileSystem.ReadAllLines(licenseFile);
|
||||||
}
|
|
||||||
catch (DirectoryNotFoundException)
|
|
||||||
{
|
|
||||||
File.Create(licenseFile).Close();
|
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
catch (FileNotFoundException)
|
||||||
{
|
{
|
||||||
File.Create(licenseFile).Close();
|
lock (_fileLock)
|
||||||
|
{
|
||||||
|
_fileSystem.WriteAllBytes(licenseFile, new byte[] {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
lock (_fileLock)
|
||||||
|
{
|
||||||
|
_fileSystem.WriteAllBytes(licenseFile, new byte[] { });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contents != null && contents.Length > 0)
|
if (contents != null && contents.Length > 0)
|
||||||
|
@ -150,8 +150,11 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
}
|
}
|
||||||
|
|
||||||
var licenseFile = Filename;
|
var licenseFile = Filename;
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
||||||
lock (_fileLock) File.WriteAllLines(licenseFile, lines);
|
lock (_fileLock)
|
||||||
|
{
|
||||||
|
_fileSystem.WriteAllLines(licenseFile, lines);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,18 +5,18 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common;
|
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Common.Security;
|
using MediaBrowser.Common.Security;
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
|
using MediaBrowser.Model.Cryptography;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.Net;
|
using MediaBrowser.Model.Net;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Security
|
namespace Emby.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class PluginSecurityManager
|
/// Class PluginSecurityManager
|
||||||
|
@ -55,7 +55,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
private MBLicenseFile _licenseFile;
|
private MBLicenseFile _licenseFile;
|
||||||
private MBLicenseFile LicenseFile
|
private MBLicenseFile LicenseFile
|
||||||
{
|
{
|
||||||
get { return _licenseFile ?? (_licenseFile = new MBLicenseFile(_appPaths)); }
|
get { return _licenseFile ?? (_licenseFile = new MBLicenseFile(_appPaths, _fileSystem, _cryptographyProvider)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
|
@ -64,6 +64,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
private readonly ICryptographyProvider _cryptographyProvider;
|
||||||
|
|
||||||
private IEnumerable<IRequiresRegistration> _registeredEntities;
|
private IEnumerable<IRequiresRegistration> _registeredEntities;
|
||||||
protected IEnumerable<IRequiresRegistration> RegisteredEntities
|
protected IEnumerable<IRequiresRegistration> RegisteredEntities
|
||||||
|
@ -78,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
/// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
|
/// Initializes a new instance of the <see cref="PluginSecurityManager" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PluginSecurityManager(IServerApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer,
|
public PluginSecurityManager(IServerApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer,
|
||||||
IApplicationPaths appPaths, ILogManager logManager, IFileSystem fileSystem)
|
IApplicationPaths appPaths, ILogManager logManager, IFileSystem fileSystem, ICryptographyProvider cryptographyProvider)
|
||||||
{
|
{
|
||||||
if (httpClient == null)
|
if (httpClient == null)
|
||||||
{
|
{
|
||||||
|
@ -90,6 +91,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_cryptographyProvider = cryptographyProvider;
|
||||||
_logger = logManager.GetLogger("SecurityManager");
|
_logger = logManager.GetLogger("SecurityManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +193,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
var msg = "Result from appstore registration was null.";
|
var msg = "Result from appstore registration was null.";
|
||||||
_logger.Error(msg);
|
_logger.Error(msg);
|
||||||
throw new ApplicationException(msg);
|
throw new ArgumentException(msg);
|
||||||
}
|
}
|
||||||
if (!String.IsNullOrEmpty(reg.key))
|
if (!String.IsNullOrEmpty(reg.key))
|
||||||
{
|
{
|
||||||
|
@ -200,7 +202,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (ApplicationException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
SaveAppStoreInfo(parameters);
|
SaveAppStoreInfo(parameters);
|
||||||
throw;
|
throw;
|
||||||
|
@ -213,14 +215,14 @@ namespace MediaBrowser.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
throw new PaymentRequiredException();
|
throw new PaymentRequiredException();
|
||||||
}
|
}
|
||||||
throw new ApplicationException("Error registering store sale");
|
throw new Exception("Error registering store sale");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.ErrorException("Error registering appstore purchase {0}", e, parameters ?? "NO PARMS SENT");
|
_logger.ErrorException("Error registering appstore purchase {0}", e, parameters ?? "NO PARMS SENT");
|
||||||
SaveAppStoreInfo(parameters);
|
SaveAppStoreInfo(parameters);
|
||||||
//TODO - could create a re-try routine on start-up if this file is there. For now we can handle manually.
|
//TODO - could create a re-try routine on start-up if this file is there. For now we can handle manually.
|
||||||
throw new ApplicationException("Error registering store sale");
|
throw new Exception("Error registering store sale");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.Security
|
namespace Emby.Server.Implementations.Security
|
||||||
{
|
{
|
||||||
class RegRecord
|
class RegRecord
|
||||||
{
|
{
|
|
@ -276,6 +276,10 @@ namespace MediaBrowser.Model.IO
|
||||||
/// <returns>System.String.</returns>
|
/// <returns>System.String.</returns>
|
||||||
string ReadAllText(string path, Encoding encoding);
|
string ReadAllText(string path, Encoding encoding);
|
||||||
|
|
||||||
|
string[] ReadAllLines(string path);
|
||||||
|
|
||||||
|
void WriteAllLines(string path, IEnumerable<string> lines);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the directory paths.
|
/// Gets the directory paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -171,9 +171,6 @@
|
||||||
<Compile Include="Persistence\DataExtensions.cs" />
|
<Compile Include="Persistence\DataExtensions.cs" />
|
||||||
<Compile Include="Persistence\IDbConnector.cs" />
|
<Compile Include="Persistence\IDbConnector.cs" />
|
||||||
<Compile Include="Persistence\MediaStreamColumns.cs" />
|
<Compile Include="Persistence\MediaStreamColumns.cs" />
|
||||||
<Compile Include="Security\MBLicenseFile.cs" />
|
|
||||||
<Compile Include="Security\PluginSecurityManager.cs" />
|
|
||||||
<Compile Include="Security\RegRecord.cs" />
|
|
||||||
<Compile Include="Serialization\JsonSerializer.cs" />
|
<Compile Include="Serialization\JsonSerializer.cs" />
|
||||||
<Compile Include="Social\SharingManager.cs" />
|
<Compile Include="Social\SharingManager.cs" />
|
||||||
<Compile Include="Social\SharingRepository.cs" />
|
<Compile Include="Social\SharingRepository.cs" />
|
||||||
|
|
|
@ -112,6 +112,7 @@ using Emby.Server.Implementations.MediaEncoder;
|
||||||
using Emby.Server.Implementations.Notifications;
|
using Emby.Server.Implementations.Notifications;
|
||||||
using Emby.Server.Implementations.Persistence;
|
using Emby.Server.Implementations.Persistence;
|
||||||
using Emby.Server.Implementations.Playlists;
|
using Emby.Server.Implementations.Playlists;
|
||||||
|
using Emby.Server.Implementations.Security;
|
||||||
using Emby.Server.Implementations.ServerManager;
|
using Emby.Server.Implementations.ServerManager;
|
||||||
using Emby.Server.Implementations.Session;
|
using Emby.Server.Implementations.Session;
|
||||||
using Emby.Server.Implementations.Sync;
|
using Emby.Server.Implementations.Sync;
|
||||||
|
@ -532,7 +533,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
{
|
{
|
||||||
await base.RegisterResources(progress).ConfigureAwait(false);
|
await base.RegisterResources(progress).ConfigureAwait(false);
|
||||||
|
|
||||||
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager, FileSystemManager);
|
SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager, FileSystemManager, CryptographyProvider);
|
||||||
RegisterSingleInstance(SecurityManager);
|
RegisterSingleInstance(SecurityManager);
|
||||||
|
|
||||||
InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager, CryptographyProvider);
|
InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager, CryptographyProvider);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user