move classes
This commit is contained in:
parent
6d250c4050
commit
67ffbed93e
|
@ -641,6 +641,16 @@ namespace Emby.Common.Implementations.IO
|
|||
}).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)
|
||||
{
|
||||
return File.OpenRead(path);
|
||||
|
|
|
@ -159,6 +159,9 @@
|
|||
<Compile Include="ScheduledTasks\RefreshIntrosTask.cs" />
|
||||
<Compile Include="ScheduledTasks\RefreshMediaLibraryTask.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\WebSocketConnection.cs" />
|
||||
<Compile Include="Session\HttpSessionController.cs" />
|
||||
|
|
|
@ -4,15 +4,18 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
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
|
||||
{
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ICryptographyProvider _cryptographyProvider;
|
||||
|
||||
public string RegKey
|
||||
{
|
||||
|
@ -40,9 +43,11 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
private readonly object _fileLock = new object();
|
||||
private string _regKey;
|
||||
|
||||
public MBLicenseFile(IApplicationPaths appPaths)
|
||||
public MBLicenseFile(IApplicationPaths appPaths, IFileSystem fileSystem, ICryptographyProvider cryptographyProvider)
|
||||
{
|
||||
_appPaths = appPaths;
|
||||
_fileSystem = fileSystem;
|
||||
_cryptographyProvider = cryptographyProvider;
|
||||
|
||||
Load();
|
||||
}
|
||||
|
@ -54,22 +59,16 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
|
||||
public void AddRegCheck(string featureId)
|
||||
{
|
||||
using (var provider = new MD5CryptoServiceProvider())
|
||||
{
|
||||
var key = new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId)));
|
||||
var key = new Guid(_cryptographyProvider.GetMD5Bytes(Encoding.Unicode.GetBytes(featureId)));
|
||||
var value = DateTime.UtcNow;
|
||||
|
||||
SetUpdateRecord(key, value);
|
||||
Save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void RemoveRegCheck(string featureId)
|
||||
{
|
||||
using (var provider = new MD5CryptoServiceProvider())
|
||||
{
|
||||
var key = new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId)));
|
||||
var key = new Guid(_cryptographyProvider.GetMD5Bytes(Encoding.Unicode.GetBytes(featureId)));
|
||||
DateTime val;
|
||||
|
||||
_updateRecords.TryRemove(key, out val);
|
||||
|
@ -77,19 +76,14 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
Save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DateTime LastChecked(string featureId)
|
||||
{
|
||||
using (var provider = new MD5CryptoServiceProvider())
|
||||
{
|
||||
DateTime last;
|
||||
_updateRecords.TryGetValue(new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId))), out last);
|
||||
_updateRecords.TryGetValue(new Guid(_cryptographyProvider.GetMD5Bytes(Encoding.Unicode.GetBytes(featureId))), out last);
|
||||
|
||||
// guard agains people just putting a large number in the file
|
||||
return last < DateTime.UtcNow ? last : DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
private void Load()
|
||||
{
|
||||
|
@ -99,15 +93,21 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
{
|
||||
try
|
||||
{
|
||||
contents = File.ReadAllLines(licenseFile);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
File.Create(licenseFile).Close();
|
||||
contents = _fileSystem.ReadAllLines(licenseFile);
|
||||
}
|
||||
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)
|
||||
|
@ -150,8 +150,11 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
}
|
||||
|
||||
var licenseFile = Filename;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
||||
lock (_fileLock) File.WriteAllLines(licenseFile, lines);
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
||||
lock (_fileLock)
|
||||
{
|
||||
_fileSystem.WriteAllLines(licenseFile, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,18 +5,18 @@ using System.Linq;
|
|||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Security;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Model.Cryptography;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Net;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Security
|
||||
namespace Emby.Server.Implementations.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// Class PluginSecurityManager
|
||||
|
@ -55,7 +55,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
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;
|
||||
|
@ -64,6 +64,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
private readonly ILogger _logger;
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ICryptographyProvider _cryptographyProvider;
|
||||
|
||||
private 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.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
|
@ -90,6 +91,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
_jsonSerializer = jsonSerializer;
|
||||
_appPaths = appPaths;
|
||||
_fileSystem = fileSystem;
|
||||
_cryptographyProvider = cryptographyProvider;
|
||||
_logger = logManager.GetLogger("SecurityManager");
|
||||
}
|
||||
|
||||
|
@ -191,7 +193,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
{
|
||||
var msg = "Result from appstore registration was null.";
|
||||
_logger.Error(msg);
|
||||
throw new ApplicationException(msg);
|
||||
throw new ArgumentException(msg);
|
||||
}
|
||||
if (!String.IsNullOrEmpty(reg.key))
|
||||
{
|
||||
|
@ -200,7 +202,7 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
}
|
||||
|
||||
}
|
||||
catch (ApplicationException)
|
||||
catch (ArgumentException)
|
||||
{
|
||||
SaveAppStoreInfo(parameters);
|
||||
throw;
|
||||
|
@ -213,14 +215,14 @@ namespace MediaBrowser.Server.Implementations.Security
|
|||
{
|
||||
throw new PaymentRequiredException();
|
||||
}
|
||||
throw new ApplicationException("Error registering store sale");
|
||||
throw new Exception("Error registering store sale");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Error registering appstore purchase {0}", e, parameters ?? "NO PARMS SENT");
|
||||
SaveAppStoreInfo(parameters);
|
||||
//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;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Security
|
||||
namespace Emby.Server.Implementations.Security
|
||||
{
|
||||
class RegRecord
|
||||
{
|
|
@ -276,6 +276,10 @@ namespace MediaBrowser.Model.IO
|
|||
/// <returns>System.String.</returns>
|
||||
string ReadAllText(string path, Encoding encoding);
|
||||
|
||||
string[] ReadAllLines(string path);
|
||||
|
||||
void WriteAllLines(string path, IEnumerable<string> lines);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the directory paths.
|
||||
/// </summary>
|
||||
|
|
|
@ -171,9 +171,6 @@
|
|||
<Compile Include="Persistence\DataExtensions.cs" />
|
||||
<Compile Include="Persistence\IDbConnector.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="Social\SharingManager.cs" />
|
||||
<Compile Include="Social\SharingRepository.cs" />
|
||||
|
|
|
@ -112,6 +112,7 @@ using Emby.Server.Implementations.MediaEncoder;
|
|||
using Emby.Server.Implementations.Notifications;
|
||||
using Emby.Server.Implementations.Persistence;
|
||||
using Emby.Server.Implementations.Playlists;
|
||||
using Emby.Server.Implementations.Security;
|
||||
using Emby.Server.Implementations.ServerManager;
|
||||
using Emby.Server.Implementations.Session;
|
||||
using Emby.Server.Implementations.Sync;
|
||||
|
@ -532,7 +533,7 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
{
|
||||
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);
|
||||
|
||||
InstallationManager = new InstallationManager(LogManager.GetLogger("InstallationManager"), this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager, CryptographyProvider);
|
||||
|
|
Loading…
Reference in New Issue
Block a user