diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index 17b82d4f9..31ec962b7 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -287,6 +287,11 @@ namespace NzbDrone.Common.Extensions return appFolderInfo.AppDataFolder; } + public static string GetDataProtectionPath(this IAppFolderInfo appFolderInfo) + { + return Path.Combine(GetAppDataPath(appFolderInfo), "asp"); + } + public static string GetLogFolder(this IAppFolderInfo appFolderInfo) { return Path.Combine(GetAppDataPath(appFolderInfo), "logs"); diff --git a/src/NzbDrone.Host/Bootstrap.cs b/src/NzbDrone.Host/Bootstrap.cs index f272de799..c6a8d71dd 100644 --- a/src/NzbDrone.Host/Bootstrap.cs +++ b/src/NzbDrone.Host/Bootstrap.cs @@ -8,8 +8,10 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using DryIoc; using DryIoc.Microsoft.DependencyInjection; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting.WindowsServices; using NLog; @@ -131,6 +133,7 @@ namespace Radarr.Host }) .ConfigureWebHost(builder => { + builder.UseConfiguration(config); builder.UseUrls(urls.ToArray()); builder.UseKestrel(options => { @@ -186,6 +189,7 @@ namespace Radarr.Host var appFolder = new AppFolderInfo(context); return new ConfigurationBuilder() .AddXmlFile(appFolder.GetConfigPath(), optional: true, reloadOnChange: false) + .AddInMemoryCollection(new List> { new ("dataProtectionFolder", appFolder.GetDataProtectionPath()) }) .Build(); } diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index e938ae4cd..7c7436608 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; @@ -46,6 +48,7 @@ namespace NzbDrone.Host b.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); b.AddFilter("Microsoft.AspNetCore", Microsoft.Extensions.Logging.LogLevel.Warning); b.AddFilter("Radarr.Http.Authentication", LogLevel.Information); + b.AddFilter("Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", LogLevel.Error); b.AddNLog(); }); @@ -95,6 +98,9 @@ namespace NzbDrone.Host options.PayloadSerializerOptions = STJson.GetSerializerSettings(); }); + services.AddDataProtection() + .PersistKeysToFileSystem(new DirectoryInfo(Configuration["dataProtectionFolder"])); + services.AddSingleton(); services.AddAuthorization(options => {