chat: add initial GuildsController
This commit is contained in:
parent
7b4cbd4fb7
commit
727f2f6ba2
23 changed files with 248 additions and 38 deletions
|
@ -33,18 +33,17 @@ public partial class RequestSigningService(ILogger logger, IClock clock, IDataba
|
|||
public bool VerifySignature(
|
||||
string publicKey, string encodedSignature, SignatureData data)
|
||||
{
|
||||
var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(publicKey);
|
||||
if (data.Host != _config.Domain)
|
||||
throw new ApiError.IncomingFederationError("Request is not for this instance");
|
||||
|
||||
var now = _clock.GetCurrentInstant();
|
||||
if ((now + Duration.FromMinutes(1)) < data.Time)
|
||||
{
|
||||
if (now + Duration.FromMinutes(1) < data.Time)
|
||||
throw new ApiError.IncomingFederationError("Request was made in the future");
|
||||
}
|
||||
else if ((now - Duration.FromMinutes(1)) > data.Time)
|
||||
{
|
||||
if (now - Duration.FromMinutes(1) > data.Time)
|
||||
throw new ApiError.IncomingFederationError("Request was made too long ago");
|
||||
}
|
||||
|
||||
var rsa = RSA.Create();
|
||||
rsa.ImportFromPem(publicKey);
|
||||
|
||||
var plaintext = GeneratePlaintext(data);
|
||||
var plaintextBytes = Encoding.UTF8.GetBytes(plaintext);
|
||||
|
@ -70,7 +69,9 @@ public partial class RequestSigningService(ILogger logger, IClock clock, IDataba
|
|||
return $"{time}:{data.Host}:{data.RequestPath}:{contentLength}:{userId}";
|
||||
}
|
||||
|
||||
private static readonly InstantPattern _pattern = InstantPattern.Create("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.GetCultureInfo("en-US"));
|
||||
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);
|
||||
public static Instant ParseTime(string header) => _pattern.Parse(header).GetValueOrThrow();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue