diff --git a/Iceshrimp.Backend/Core/Configuration/Config.cs b/Iceshrimp.Backend/Core/Configuration/Config.cs index b206cebc..4a67fd95 100644 --- a/Iceshrimp.Backend/Core/Configuration/Config.cs +++ b/Iceshrimp.Backend/Core/Configuration/Config.cs @@ -49,6 +49,8 @@ public sealed class Config public sealed class SecuritySection { public bool AuthorizedFetch { get; init; } = true; + public bool AttachLdSignatures { get; init; } = false; + public bool AcceptLdSignatures { get; init; } = false; public ExceptionVerbosity ExceptionVerbosity { get; init; } = ExceptionVerbosity.Basic; public Enums.Registrations Registrations { get; init; } = Enums.Registrations.Closed; public Enums.FederationMode FederationMode { get; init; } = Enums.FederationMode.BlockList; diff --git a/Iceshrimp.Backend/Core/Federation/ActivityStreams/LDHelpers.cs b/Iceshrimp.Backend/Core/Federation/ActivityStreams/LDHelpers.cs index c0fd56ab..5e06c7fa 100644 --- a/Iceshrimp.Backend/Core/Federation/ActivityStreams/LDHelpers.cs +++ b/Iceshrimp.Backend/Core/Federation/ActivityStreams/LDHelpers.cs @@ -103,6 +103,14 @@ public static class LdHelpers return payload; } + + public static async Task CompactAsync(this ASActivity activity) + { + var compacted = Compact(activity) ?? throw new Exception("Failed to compact signed activity"); + var payload = JsonConvert.SerializeObject(compacted, JsonSerializerSettings); + + return payload; + } public static JObject? Compact(object obj) { diff --git a/Iceshrimp.Backend/Core/Middleware/AuthorizedFetchMiddleware.cs b/Iceshrimp.Backend/Core/Middleware/AuthorizedFetchMiddleware.cs index e027921f..aba27046 100644 --- a/Iceshrimp.Backend/Core/Middleware/AuthorizedFetchMiddleware.cs +++ b/Iceshrimp.Backend/Core/Middleware/AuthorizedFetchMiddleware.cs @@ -116,7 +116,9 @@ public class AuthorizedFetchMiddleware( logger.LogDebug("Error validating HTTP signature: {error}", e.Message); } - if (!verified && request is { ContentType: not null, ContentLength: > 0 }) + if (!verified && + request is { ContentType: not null, ContentLength: > 0 } && + config.Value.AcceptLdSignatures) { logger.LogDebug("Trying LD signature next..."); try diff --git a/Iceshrimp.Backend/Core/Queues/PreDeliverQueue.cs b/Iceshrimp.Backend/Core/Queues/PreDeliverQueue.cs index 12967b39..d736c073 100644 --- a/Iceshrimp.Backend/Core/Queues/PreDeliverQueue.cs +++ b/Iceshrimp.Backend/Core/Queues/PreDeliverQueue.cs @@ -1,9 +1,11 @@ using System.Diagnostics.CodeAnalysis; +using Iceshrimp.Backend.Core.Configuration; using Iceshrimp.Backend.Core.Database; using Iceshrimp.Backend.Core.Federation.ActivityStreams; using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types; using Iceshrimp.Backend.Core.Services; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using Newtonsoft.Json.Linq; using ProtoBuf; using StackExchange.Redis; @@ -24,6 +26,7 @@ public class PreDeliverQueue var logger = scope.GetRequiredService>(); var db = scope.GetRequiredService(); var queueSvc = scope.GetRequiredService(); + var config = scope.GetRequiredService>(); var parsed = JToken.Parse(job.SerializedActivity); var expanded = LdHelpers.Expand(parsed) ?? throw new Exception("Failed to expand activity"); @@ -64,8 +67,16 @@ public class PreDeliverQueue if (inboxQueryResults.Count == 0) return; - var keypair = await db.UserKeypairs.FirstAsync(p => p.UserId == job.ActorId, token); - var payload = await activity.SignAndCompactAsync(keypair); + string payload; + if (config.Value.AttachLdSignatures) + { + var keypair = await db.UserKeypairs.FirstAsync(p => p.UserId == job.ActorId, token); + payload = await activity.SignAndCompactAsync(keypair); + } + else + { + payload = await activity.CompactAsync(); + } foreach (var inboxQueryResult in inboxQueryResults) await queueSvc.DeliverQueue.EnqueueAsync(new DeliverJob diff --git a/Iceshrimp.Backend/configuration.ini b/Iceshrimp.Backend/configuration.ini index 71b8177d..ff0e01d3 100644 --- a/Iceshrimp.Backend/configuration.ini +++ b/Iceshrimp.Backend/configuration.ini @@ -18,6 +18,12 @@ CharacterLimit = 8192 ;; It is highly recommend you keep this enabled if you intend to use block- or allowlist federation AuthorizedFetch = true +;; Whether to attach LD signatures to outgoing activities +AttachLdSignatures = false + +;; Whether to accept activities signed using LD signatures +AcceptLdSignatures = false + ;; The level of detail in API error responses ;; Options: [None, Basic, Full] ExceptionVerbosity = Basic