Skip to content

Commit

Permalink
Fixed SHA256 Hashing result. Closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Aug 16, 2024
1 parent ba1b752 commit 3042b31
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AncillaryInfrastructure/Api/3rdParties/MailgunApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal static Result<Error> AuthenticateRequest(IRecorder recorder, ICallerCon
return Error.NotAuthenticated();
}

var signature = $"sha1={parameters.Signature}";
var signature = $"sha256={parameters.Signature}";
var text = $"{parameters.Timestamp}{parameters.Token}";

var signer = new HMACSigner(text, webhookSigningKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void WhenSetHmacAuthWithEmptyRequest_ThenSetsSignatureHeader()
message.SetHMACAuth(request, "asecret");

message.Headers.GetValues(HttpConstants.Headers.HMACSignature).Should().OnlyContain(hdr =>
hdr == "sha1=f8dbae1fc1114a368a46f762db4a5ad5417e0e1ea4bc34d7924d166621c45653");
hdr == "sha256=f8dbae1fc1114a368a46f762db4a5ad5417e0e1ea4bc34d7924d166621c45653");
}

[Fact]
Expand All @@ -113,7 +113,7 @@ public void WhenSetHmacAuthWithPopulatedRequest_ThenSetsSignatureHeader()
message.SetHMACAuth(request, "asecret");

message.Headers.GetValues(HttpConstants.Headers.HMACSignature).Should().OnlyContain(hdr =>
hdr == "sha1=efab63816eb3c3ab799dfd64e717865116f7aa1547177293ec6598fe3cc8e3de");
hdr == "sha256=efab63816eb3c3ab799dfd64e717865116f7aa1547177293ec6598fe3cc8e3de");
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure.Web.Api.Common.UnitTests/HMACSignerSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void WhenSignAndRequestIsHollow_ThenReturnsSignature()

var result = signer.Sign();

result.Should().Be("sha1=f8dbae1fc1114a368a46f762db4a5ad5417e0e1ea4bc34d7924d166621c45653");
result.Should().Be("sha256=f8dbae1fc1114a368a46f762db4a5ad5417e0e1ea4bc34d7924d166621c45653");
}

[Fact]
Expand All @@ -38,7 +38,7 @@ public void WhenSignAndRequestIsPopulated_ThenReturnsSignature()

var result = signer.Sign();

result.Should().Be("sha1=5ac3c7a7378d5f293359720f1bf64cfcbfbf672b61640121a11526638a57a2c5");
result.Should().Be("sha256=5ac3c7a7378d5f293359720f1bf64cfcbfbf672b61640121a11526638a57a2c5");
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure.Web.Api.Common/HMACSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Infrastructure.Web.Api.Common;
/// </summary>
public class HMACSigner
{
private const string SignatureFormat = @"sha1={0}";
private const string SignatureFormat = @"sha256={0}";
private static readonly Encoding SignatureEncoding = Encoding.UTF8;
private readonly byte[] _data;
private readonly string _secret;
Expand Down

0 comments on commit 3042b31

Please sign in to comment.