-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/DEV-23903 Changes getHeadersV2 parameter to path instead of u…
…rl (#155) * DEV-23903 Transition from header V1 to header V2 * DEV-23903 remove unused import * DEV-23903 Changes getHeadersV2 parameter to path instead of uri * DEV-23903 Changes parameter name uri to path * DEV-23903 Adds response checksum signature * DEV-23903 Changes response field checksum to signature --------- Co-authored-by: Abdurrahman Basgoynuk <[email protected]>
- Loading branch information
1 parent
a47ebd2
commit 60a73df
Showing
84 changed files
with
624 additions
and
204 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.iyzipay; | ||
|
||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class HashValidator { | ||
private HashValidator() { | ||
} | ||
|
||
public static boolean hashValid(String calculatedHash, String hash) { | ||
return StringUtils.equals(calculatedHash, hash); | ||
} | ||
} |
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
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,50 @@ | ||
package com.iyzipay; | ||
|
||
import com.iyzipay.exception.HttpClientException; | ||
|
||
import javax.crypto.Mac; | ||
import javax.crypto.spec.SecretKeySpec; | ||
import javax.xml.bind.DatatypeConverter; | ||
import java.math.BigDecimal; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public interface ResponseSignatureGenerator { | ||
String SEPARATOR = ":"; | ||
String HMAC_SHA_256 = "HmacSHA256"; | ||
String EMPTY_PARAM = ""; | ||
|
||
default String generateSignature(String secretKey, List<Object> params) { | ||
try { | ||
String dataToSign = appendSignatureParams(params); | ||
Mac mac = Mac.getInstance(HMAC_SHA_256); | ||
mac.init(new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), HMAC_SHA_256)); | ||
return DatatypeConverter.printHexBinary(mac.doFinal(dataToSign.getBytes(StandardCharsets.UTF_8))).toLowerCase(Locale.ENGLISH); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new HttpClientException("HMAC couldn't be generated", e); | ||
} catch (InvalidKeyException e) { | ||
throw new HttpClientException("Authentication content couldn't be generated", e); | ||
} | ||
} | ||
|
||
default String appendSignatureParams(List<Object> signatureParameters) { | ||
return signatureParameters.stream() | ||
.map(this::convertParamToString) | ||
.collect(Collectors.joining(SEPARATOR)); | ||
} | ||
|
||
default String convertParamToString(Object parameter) { | ||
if (Objects.isNull(parameter)) { | ||
return EMPTY_PARAM; | ||
} else if (parameter instanceof BigDecimal) { | ||
return ((BigDecimal) parameter).stripTrailingZeros().toPlainString(); | ||
} else { | ||
return parameter.toString(); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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.