Skip to content

Commit

Permalink
Swap HMAC Validation method parameters (#1185)
Browse files Browse the repository at this point in the history
* Swap HMAC Validation method parameters

* Update src/main/java/com/adyen/util/HMACValidator.java

Co-authored-by: Alessio Zampatti <alessio.zampatti@adyen.com>

* Update src/main/java/com/adyen/util/HMACValidator.java

Co-authored-by: Alessio Zampatti <alessio.zampatti@adyen.com>

* Fix the method

* Correct the parameters

* Flip the params again

* fix format

* revert changes

* typos in comment

* Revert test case

---------

Co-authored-by: Alessio Zampatti <alessio.zampatti@adyen.com>
Co-authored-by: jillingk <93914435+jillingk@users.noreply.github.com>
Co-authored-by: Wouter Boereboom <62436079+wboereboom@users.noreply.github.com>
  • Loading branch information
4 people committed Jan 31, 2024
1 parent c3063f3 commit c46cab5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/com/adyen/util/HMACValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ public String calculateHMAC(NotificationRequestItem notificationRequestItem, Str
return calculateHMAC(getDataToSign(notificationRequestItem), key);
}

// Calculate HMAC for BankingWebhooks and ManagementWebhooks (Generic webhooks)
public boolean validateHMAC(String hmacKey, String hmacSignature, String payload) throws SignatureException {
String calculatedSign = calculateHMAC(payload, hmacSignature);
final byte [] expectedSign = calculatedSign.getBytes(StandardCharsets.UTF_8);
final byte[] merchantSign = hmacKey.getBytes(StandardCharsets.UTF_8);
//Calculate HMAC for BankingWebhooks and ManagementWebhooks (Generic webhooks)
//First parameter is hmacSignature which is get from webhook and the second hmackey which is configured
public boolean validateHMAC(String hmacSignature, String hmacKey, String payload) throws SignatureException {
String calculatedSign = calculateHMAC(payload, hmacKey);
final byte[] expectedSign = calculatedSign.getBytes(StandardCharsets.UTF_8);
final byte[] merchantSign = hmacSignature.getBytes(StandardCharsets.UTF_8);
return MessageDigest.isEqual(expectedSign, merchantSign);
}

Expand Down

0 comments on commit c46cab5

Please sign in to comment.