diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-10-15 20:23:00 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-10-15 20:23:00 -0500 |
| commit | d03d436c618114f89c39a756596a23fd56b2e979 (patch) | |
| tree | 78e77bc20708e990e4ca8a10780efd15c20b4078 /src | |
| parent | 71dcc7a60650b5a61d1d2a35609b65f3467d1396 (diff) | |
| download | slskd-d03d436c618114f89c39a756596a23fd56b2e979.tar.gz | |
suppress data protection keys
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Core/Security/DataProtectionKeyRepository.cs | 63 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 13 |
2 files changed, 73 insertions, 3 deletions
diff --git a/src/slskd/Core/Security/DataProtectionKeyRepository.cs b/src/slskd/Core/Security/DataProtectionKeyRepository.cs new file mode 100644 index 00000000..4d962190 --- /dev/null +++ b/src/slskd/Core/Security/DataProtectionKeyRepository.cs @@ -0,0 +1,63 @@ +// <copyright file="DataProtectionKeyRepository.cs" company="JP Dillingham"> +// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ +// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █ +// █__ --█ █__ --█ ◄█ - █ +// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█ +// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉ +// │ Copyright (c) JP Dillingham. +// │ +// │ This program is free software: you can redistribute it and/or modify +// │ it under the terms of the GNU Affero General Public License as published +// │ by the Free Software Foundation, version 3. +// │ +// │ This program is distributed in the hope that it will be useful, +// │ but WITHOUT ANY WARRANTY; without even the implied warranty of +// │ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// │ GNU Affero General Public License for more details. +// │ +// │ You should have received a copy of the GNU Affero General Public License +// │ along with this program. If not, see https://www.gnu.org/licenses/. +// │ +// │ This program is distributed with Additional Terms pursuant to Section 7 +// │ of the AGPLv3. See the LICENSE file in the root directory of this +// │ project for the complete terms and conditions. +// │ +// │ https://slskd.org +// │ +// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌ +// │ SPDX-FileCopyrightText: JP Dillingham +// │ SPDX-License-Identifier: AGPL-3.0-only +// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈ +// </copyright> + +namespace slskd +{ + using System.Collections.Generic; + using System.Xml.Linq; + using Microsoft.AspNetCore.DataProtection.Repositories; + + /// <summary> + /// An <see cref="IXmlRepository"/> that keeps data protection keys in memory, so that they are never written to disk. + /// </summary> + public class DataProtectionKeyRepository : IXmlRepository + { + private List<XElement> Elements { get; } = new(); + private object SyncRoot { get; } = new(); + + public IReadOnlyCollection<XElement> GetAllElements() + { + lock (SyncRoot) + { + return Elements.ConvertAll(element => new XElement(element)); + } + } + + public void StoreElement(XElement element, string friendlyName) + { + lock (SyncRoot) + { + Elements.Add(new XElement(element)); + } + } + } +} diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index cfe8bcba..5e349dba 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -52,7 +52,7 @@ namespace slskd using Asp.Versioning.ApiExplorer; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; - using Microsoft.AspNetCore.DataProtection; + using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; @@ -835,8 +835,15 @@ namespace slskd services.ConfigureTelemetry(); - services.AddDataProtection() - .PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(DataDirectory, "misc", ".DataProtection-Keys"))); + /* + by default, adding authentication of any kind adds data protection, and the default configuration for + data protection drops .DataProtection-Keys on the filesystem. we're not using data protection, but this + can't be suppressed. + + instead, we must fake the key manager into using a dummy repository to stop it from using the filesystem + */ + services.AddDataProtection(); + services.Configure<KeyManagementOptions>(options => options.XmlRepository = new DataProtectionKeyRepository()); var jwtSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(OptionsAtStartup.Web.Authentication.Jwt.Key)); |
