chat: add database types and auth middleware
This commit is contained in:
parent
656eec81d8
commit
6f6e19bbb5
24 changed files with 1165 additions and 15 deletions
|
@ -31,23 +31,22 @@ public partial class RequestSigningService(ILogger logger, IClock clock, IDataba
|
|||
}
|
||||
|
||||
public bool VerifySignature(
|
||||
string publicKey, string encodedSignature, string dateHeader, string host, string requestPath, int? contentLength, string? userId)
|
||||
string publicKey, string encodedSignature, SignatureData data)
|
||||
{
|
||||
var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(publicKey);
|
||||
|
||||
var now = _clock.GetCurrentInstant();
|
||||
var time = ParseTime(dateHeader);
|
||||
if ((now + Duration.FromMinutes(1)) < time)
|
||||
if ((now + Duration.FromMinutes(1)) < data.Time)
|
||||
{
|
||||
throw new ApiError.IncomingFederationError("Request was made in the future");
|
||||
}
|
||||
else if ((now - Duration.FromMinutes(1)) > time)
|
||||
else if ((now - Duration.FromMinutes(1)) > data.Time)
|
||||
{
|
||||
throw new ApiError.IncomingFederationError("Request was made too long ago");
|
||||
}
|
||||
|
||||
var plaintext = GeneratePlaintext(new SignatureData(time, host, requestPath, contentLength, userId));
|
||||
var plaintext = GeneratePlaintext(data);
|
||||
var plaintextBytes = Encoding.UTF8.GetBytes(plaintext);
|
||||
var hash = SHA256.HashData(plaintextBytes);
|
||||
|
||||
|
@ -73,5 +72,5 @@ public partial class RequestSigningService(ILogger logger, IClock clock, IDataba
|
|||
|
||||
private static readonly InstantPattern _pattern = InstantPattern.Create("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.GetCultureInfo("en-US"));
|
||||
private static string FormatTime(Instant time) => _pattern.Format(time);
|
||||
private static Instant ParseTime(string header) => _pattern.Parse(header).GetValueOrThrow();
|
||||
public static Instant ParseTime(string header) => _pattern.Parse(header).GetValueOrThrow();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue