[backend/federation] Fix HttpSignature validation on systems using CRLF line endings
This commit is contained in:
parent
88bef87ef5
commit
0f97845b88
2 changed files with 17 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
using EntityFrameworkCore.Projectables;
|
using EntityFrameworkCore.Projectables;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Extensions;
|
namespace Iceshrimp.Backend.Core.Extensions;
|
||||||
|
@ -50,3 +51,17 @@ public static class ProjectableStringExtensions
|
||||||
[Projectable]
|
[Projectable]
|
||||||
public static bool IsGreaterOrEqualTo(this string a, string b) => a.CompareTo(b) >= 0;
|
public static bool IsGreaterOrEqualTo(this string a, string b) => a.CompareTo(b) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class StringBuilderExtensions
|
||||||
|
{
|
||||||
|
private const char NewLineLf = '\n';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Equivalent to .AppendLine, but always uses \n instead of Environment.NewLine
|
||||||
|
/// </summary>
|
||||||
|
public static StringBuilder AppendLineLf(this StringBuilder sb, string? value)
|
||||||
|
{
|
||||||
|
sb.Append(value);
|
||||||
|
return sb.Append(NewLineLf);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ using System.Net;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
|
@ -108,7 +109,6 @@ public static class HttpSignature
|
||||||
keyId="{keyId}",headers="{string.Join(' ', requiredHeadersEnum)}",algorithm="hs2019",signature="{signatureBase64}"
|
keyId="{keyId}",headers="{string.Join(' ', requiredHeadersEnum)}",algorithm="hs2019",signature="{signatureBase64}"
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
|
||||||
request.Headers.Add("Signature", signatureHeader);
|
request.Headers.Add("Signature", signatureHeader);
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ public static class HttpSignature
|
||||||
foreach (var header in headers)
|
foreach (var header in headers)
|
||||||
{
|
{
|
||||||
sb.Append($"{header}: ");
|
sb.Append($"{header}: ");
|
||||||
sb.AppendLine(header switch
|
sb.AppendLineLf(header switch
|
||||||
{
|
{
|
||||||
"(request-target)" => $"{requestMethod.ToLowerInvariant()} {requestPath}",
|
"(request-target)" => $"{requestMethod.ToLowerInvariant()} {requestPath}",
|
||||||
"(created)" => signature?.Created ?? throw new Exception("Signature is missing created param"),
|
"(created)" => signature?.Created ?? throw new Exception("Signature is missing created param"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue