Actually use authorized fetch middleware
This commit is contained in:
parent
7524c5acc7
commit
28066784f2
3 changed files with 8 additions and 18 deletions
|
@ -1,10 +1,7 @@
|
|||
using System.Data;
|
||||
using System.Net.Mime;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Federation.Cryptography;
|
||||
using Iceshrimp.Backend.Controllers.Attributes;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers;
|
||||
|
@ -14,21 +11,13 @@ namespace Iceshrimp.Backend.Controllers;
|
|||
[Route("/users/{id}/inbox")]
|
||||
[AuthorizedFetch(true)]
|
||||
[Produces("application/json")]
|
||||
[UseNewtonsoftJson]
|
||||
[EnableRequestBuffering(1024 * 1024)]
|
||||
public class InboxController(ILogger<InboxController> logger, DatabaseContext db) : Controller {
|
||||
public class InboxController(ILogger<InboxController> logger) : Controller {
|
||||
[HttpPost]
|
||||
[Consumes(MediaTypeNames.Application.Json)]
|
||||
public async Task<IActionResult> Inbox([FromBody] JToken content) {
|
||||
if (!Request.Headers.TryGetValue("signature", out var sigHeader))
|
||||
throw new ConstraintException("Request is missing the signature header");
|
||||
|
||||
var sig = HttpSignature.Parse(sigHeader.ToString());
|
||||
var key = await db.UserPublickeys.SingleOrDefaultAsync(p => p.KeyId == sig.KeyId);
|
||||
var verified = key != null &&
|
||||
await HttpSignature.Verify(Request, sig, ["(request-target)", "digest", "host", "date"],
|
||||
key.KeyPem);
|
||||
|
||||
logger.LogDebug("HttpSignature.Verify returned {result} for key {keyId}", verified, sig.KeyId);
|
||||
return verified ? Ok() : StatusCode(StatusCodes.Status403Forbidden);
|
||||
public IActionResult Inbox([FromBody] JToken content) {
|
||||
logger.LogDebug("{count}", content.Count());
|
||||
return Ok();
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ public sealed class Config {
|
|||
}
|
||||
|
||||
public sealed class SecuritySection {
|
||||
public required bool AuthorizedFetch { get; set; }
|
||||
public required bool AuthorizedFetch { get; init; }
|
||||
}
|
||||
|
||||
public sealed class DatabaseSection {
|
||||
|
|
|
@ -29,6 +29,7 @@ public static class ServiceExtensions {
|
|||
//TODO: fail if config doesn't parse correctly / required things are missing
|
||||
services.Configure<Config>(configuration);
|
||||
services.Configure<Config.InstanceSection>(configuration.GetSection("Instance"));
|
||||
services.Configure<Config.SecuritySection>(configuration.GetSection("Security"));
|
||||
services.Configure<Config.DatabaseSection>(configuration.GetSection("Database"));
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue