Hello. We are trying to implement a generateSignature method for our Feign interceptor to WC1 Screening Requests.
The problem is, that the signature that I am receiving seems not to be correct, nor even its length seems to be the same as in Postman, though the "dataToSign" looks correct in the logs and debugger.
This is a code example:
private String generateSignature(String gmtDate, String method, String endpoint, TreeMap<String, String> additionalHeaders) {
try {
StringBuilder sbDataToSign = new StringBuilder("(request-target): " + method.toLowerCase() + " " + gatewayUrl + endpoint + "\n"
+ "host: " + gatewayHost + "\n"
+ "date: " + gmtDate + "\n");
if(additionalHeaders != null) {
for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) {
sbDataToSign.append(entry.getKey()).append(": ").append(entry.getValue());
if(entry != additionalHeaders.lastEntry())
sbDataToSign.append("\n");
}
}
log.trace(sbDataToSign.toString());
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(apiSecret.getBytes("UTF-8"), "HmacSHA256");
sha256_HMAC.init(secret_key);
String result = Base64.getEncoder().encodeToString(
Hex.encodeHexString(sha256_HMAC.doFinal(sbDataToSign.toString().getBytes("UTF-8"))).getBytes());
log.debug("generateSignature: OK.");
return result;
} catch(Exception ex) {
log.error(ex.getMessage());
log.debug(ex.getStackTrace().toString());
throw new RuntimeException(ex);
}
}
dataToSign is as follows:
(request-target): post /v2/cases/screeningRequest
host: rms-world-check-one-api-pilot.thomsonreuters.com
date: Thu, 03 Dec 2020 02:09:42 GMT
content-type: application/json
content-length: 315
{"groupId": "XXXXXXXXXXXX", "clientCaseId": "8ebd0f0c-27c4-4f17-8294-aa59408b962e", "entityType": "INDIVIDUAL", "providerTypes": ["WATCHLIST"], "name": "XXXXX XX XX", "nameTransposition": true, "secondaryFields": [{ "typeId": "SFCT_1", "value": "MALE" }], "customFields": []}
The request runs successfully via the Postman collection that is provided in devs portal.
I assume that either the content length is not correct when calculating it with Java in the feign interceptor, or the signature is incorrect. e.g.: Signature in postman is of size 44. Signature length in Java is +80 chars.
Any thoughts on this would be appreciated.
Thanks!!!