-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add hmac hashing and request body hashing algorithm in header * remove AllowMD5AndSHA256RequestBodyHash, add unit tess for all combinations of HmacHashingMethod and RequestBodyHashingMethod * add unit tests for old headers without hashing methods
- Loading branch information
1 parent
3a5ffd7
commit f1436c9
Showing
12 changed files
with
312 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
softaware.Authentication.Hmac.AspNetCore.Test/RemoveHashingMethodDelegatingHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace softaware.Authentication.Hmac.AspNetCore.Test | ||
{ | ||
internal class RemoveHashingMethodDelegatingHandler : DelegatingHandler | ||
{ | ||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
var hmacAuthHeaderValue = request.Headers.Authorization?.Parameter; | ||
if (hmacAuthHeaderValue != null) | ||
{ | ||
var values = hmacAuthHeaderValue.Split(":").ToList(); | ||
|
||
if (values.Count == 6) // Hmac header has HmacHashingAlgorithm and RequestBodyHashingAlgorithm paramemters set | ||
{ | ||
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( | ||
request.Headers.Authorization.Scheme, | ||
string.Join(":", values.Skip(2))); // remove first two parameters (= HmacHashingAlgorithm and RequestBodyHashingAlgorithm) | ||
} | ||
} | ||
|
||
return base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.