Merge pull request #915 from cvium/remove_encryptionmanager
Remove IEncryptionManager
This commit is contained in:
commit
2242c8d793
|
@ -744,10 +744,8 @@ namespace Emby.Server.Implementations
|
||||||
TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager, ServerConfigurationManager);
|
TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager, ServerConfigurationManager);
|
||||||
serviceCollection.AddSingleton(TVSeriesManager);
|
serviceCollection.AddSingleton(TVSeriesManager);
|
||||||
|
|
||||||
var encryptionManager = new EncryptionManager();
|
|
||||||
serviceCollection.AddSingleton<IEncryptionManager>(encryptionManager);
|
|
||||||
|
|
||||||
DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager);
|
DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager);
|
||||||
|
|
||||||
serviceCollection.AddSingleton(DeviceManager);
|
serviceCollection.AddSingleton(DeviceManager);
|
||||||
|
|
||||||
MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder);
|
MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder);
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using MediaBrowser.Controller.Security;
|
|
||||||
|
|
||||||
namespace Emby.Server.Implementations.Security
|
|
||||||
{
|
|
||||||
public class EncryptionManager : IEncryptionManager
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Encrypts the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
|
||||||
/// <exception cref="ArgumentNullException">value</exception>
|
|
||||||
public string EncryptString(string value)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
return EncryptStringUniversal(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Decrypts the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
|
||||||
/// <exception cref="ArgumentNullException">value</exception>
|
|
||||||
public string DecryptString(string value)
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
return DecryptStringUniversal(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string EncryptStringUniversal(string value)
|
|
||||||
{
|
|
||||||
// Yes, this isn't good, but ProtectedData in mono is throwing exceptions, so use this for now
|
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(value);
|
|
||||||
return Convert.ToBase64String(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string DecryptStringUniversal(string value)
|
|
||||||
{
|
|
||||||
// Yes, this isn't good, but ProtectedData in mono is throwing exceptions, so use this for now
|
|
||||||
|
|
||||||
var bytes = Convert.FromBase64String(value);
|
|
||||||
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
namespace MediaBrowser.Controller.Security
|
|
||||||
{
|
|
||||||
public interface IEncryptionManager
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Encrypts the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
|
||||||
string EncryptString(string value);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Decrypts the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
/// <returns>System.String.</returns>
|
|
||||||
string DecryptString(string value);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
|
@ -29,17 +30,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||||
|
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly IEncryptionManager _encryption;
|
|
||||||
|
|
||||||
private readonly IJsonSerializer _json;
|
private readonly IJsonSerializer _json;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
|
||||||
public OpenSubtitleDownloader(ILoggerFactory loggerFactory, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json, IFileSystem fileSystem)
|
public OpenSubtitleDownloader(ILoggerFactory loggerFactory, IHttpClient httpClient, IServerConfigurationManager config, IJsonSerializer json, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger(GetType().Name);
|
_logger = loggerFactory.CreateLogger(GetType().Name);
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
_config = config;
|
_config = config;
|
||||||
_encryption = encryption;
|
|
||||||
_json = json;
|
_json = json;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
|
||||||
|
@ -63,16 +62,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
!string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash) &&
|
!string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash) &&
|
||||||
!options.OpenSubtitlesPasswordHash.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
|
!options.OpenSubtitlesPasswordHash.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
options.OpenSubtitlesPasswordHash = EncryptPassword(options.OpenSubtitlesPasswordHash);
|
options.OpenSubtitlesPasswordHash = EncodePassword(options.OpenSubtitlesPasswordHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string EncryptPassword(string password)
|
private static string EncodePassword(string password)
|
||||||
{
|
{
|
||||||
return PasswordHashPrefix + _encryption.EncryptString(password);
|
var bytes = Encoding.UTF8.GetBytes(password);
|
||||||
|
return PasswordHashPrefix + Convert.ToBase64String(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DecryptPassword(string password)
|
private static string DecodePassword(string password)
|
||||||
{
|
{
|
||||||
if (password == null ||
|
if (password == null ||
|
||||||
!password.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
|
!password.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
|
||||||
|
@ -80,7 +80,8 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _encryption.DecryptString(password.Substring(2));
|
var bytes = Convert.FromBase64String(password.Substring(2));
|
||||||
|
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => "Open Subtitles";
|
public string Name => "Open Subtitles";
|
||||||
|
@ -186,7 +187,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
var options = GetOptions();
|
var options = GetOptions();
|
||||||
|
|
||||||
var user = options.OpenSubtitlesUsername ?? string.Empty;
|
var user = options.OpenSubtitlesUsername ?? string.Empty;
|
||||||
var password = DecryptPassword(options.OpenSubtitlesPasswordHash);
|
var password = DecodePassword(options.OpenSubtitlesPasswordHash);
|
||||||
|
|
||||||
var loginResponse = await OpenSubtitles.LogInAsync(user, password, "en", cancellationToken).ConfigureAwait(false);
|
var loginResponse = await OpenSubtitles.LogInAsync(user, password, "en", cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user