Skip to content

Commit

Permalink
Merge pull request #50 from QuantozTechnology/nagarwal4-patch-3
Browse files Browse the repository at this point in the history
Update SignatureVerificationMiddleware.cs
  • Loading branch information
PJvGrol authored Dec 22, 2023
2 parents 843365f + 4446293 commit 646c851
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Quantoz Technology B.V. and contributors. Licensed
// Copyright 2023 Quantoz Technology B.V. and contributors. Licensed
// under the Apache License, Version 2.0. See the NOTICE file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

Expand Down Expand Up @@ -69,21 +69,6 @@ public async Task Invoke(HttpContext context)
byte[] publicKeyBytes = Convert.FromBase64String(publicKeyHeader);
var publicKey = Encoding.UTF8.GetString(publicKeyBytes);

if (method == "POST" || method == "PUT")
{
// Check if the "PostPayload" property is present
if (payloadJson.TryGetValue(SignaturePayload.PostPayload, out var post))
{
}
else
{
_logger.LogError("Missing postPayload header");
var customErrors = new CustomErrors(new CustomError("Forbidden", "Missing Header", "postPayload"));
await WriteCustomErrors(context.Response, customErrors, (int)HttpStatusCode.Forbidden);
return;
}
}

// Get the current Unix UTC timestamp (rounded to 30 seconds)
long currentTimestamp = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
currentTimestamp = (currentTimestamp / 30) * 30; // Round to the nearest 30 seconds
Expand Down Expand Up @@ -132,6 +117,11 @@ public async Task Invoke(HttpContext context)
await WriteCustomErrors(context.Response, customErrors, (int)HttpStatusCode.Forbidden);
}
}
catch (CustomErrorsException ex)
{
_logger.LogError("Unknown exception thrown: {message}", ex.Message);
throw;
}
catch (Exception ex)
{
_logger.LogError("Unknown exception thrown: {message}", ex.Message);
Expand Down

0 comments on commit 646c851

Please sign in to comment.