@Override public String digestParams(RestInvocation restInvocation) { String nonce = restInvocation.getParamValue(HeaderParam.class, "api-expires").toString(); String path = restInvocation.getInvocationUrl().split(restInvocation.getBaseUrl())[1]; String payload = restInvocation.getHttpMethod() + "/" + path + nonce + restInvocation.getRequestBody(); return digestString(payload); }
@Override public String digestParams(RestInvocation restInvocation) { String method = restInvocation.getHttpMethod(); String uri = restInvocation.getInvocationUrl(); Map<Class<? extends Annotation>, Params> params = restInvocation.getParamsMap(); if (params.containsKey(QueryParam.class)) { uri = params.get(QueryParam.class).applyToPath(uri); String bodyStr = restInvocation.getRequestBody(); ObjectMapper mapper = new ObjectMapper(); StringBuilder bodyQuery = new StringBuilder(); restInvocation.getParamValue(HeaderParam.class, "FC-ACCESS-TIMESTAMP").toString(); String payload = method + uri + timestamp + bodyQuery; return Base64.getEncoder()
@Override public String digestParams(RestInvocation restInvocation) { String timestamp = restInvocation.getHttpHeadersFromParams().get("AC-ACCESS-TIMESTAMP"); String method = restInvocation.getHttpMethod(); String path = restInvocation.getPath(); String queryParameters = restInvocation.getQueryString(); if (!queryParameters.isEmpty()) { queryParameters = '?' + queryParameters; } String body = restInvocation.getRequestBody(); body = body == null ? "" : body; String queryArgs = timestamp + method + path + (queryParameters + body); Mac shaMac = getMac(); final byte[] macData = shaMac.doFinal(queryArgs.getBytes()); return Base64.getEncoder().encodeToString(macData); } }
@Override public String digestParams(RestInvocation restInvocation) { return digest( restInvocation.getHttpMethod(), restInvocation.getInvocationUrl(), restInvocation.getReqContentType(), restInvocation.getParamValue(HeaderParam.class, "API_REQUEST_DATE").toString()); }
@Override public String digestParams(RestInvocation inv) { final String nonce = inv.getParamValue(HeaderParam.class, "timestamp").toString(); return digest(inv.getMethodPath(), nonce, inv.getRequestBody()); }
@Override public String digestParams(RestInvocation restInvocation) { // Step 1: concatenate URL with query string String completeURL = restInvocation.getInvocationUrl(); // Step 2: create md5-Hash of the POST-Parameters for the HMAC-data String httpMethod = restInvocation.getHttpMethod(); String requestBody = restInvocation.getRequestBody(); String md5; if ("POST".equals(httpMethod)) { md5 = getMD5(requestBody); } else { md5 = "d41d8cd98f00b204e9800998ecf8427e"; // no post params for GET methods } // Step 3: concat HMAC-input // http_method+'#'+uri+'#'+api_key+'#'+nonce+'#'+post_parameter_md5_hashed_url_encoded_query_string String nonce = restInvocation.getHttpHeadersFromParams().get("X-API-NONCE"); String hmac_data = String.format("%s#%s#%s#%s#%s", httpMethod, completeURL, apiKey, nonce, md5); // Step 3: Create actual sha256-HMAC Mac mac256 = getMac(); mac256.update(hmac_data.getBytes()); return String.format("%064x", new BigInteger(1, mac256.doFinal())); }
@Override public synchronized String digestParams(RestInvocation restInvocation) { String postBody = restInvocation.getRequestBody(); return Base64.getEncoder().encodeToString(postBody.getBytes()); } }
@Override public String digestParams(RestInvocation restInvocation) { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "Illegal algorithm for post body digest. Check the implementation."); } sha256.update(restInvocation.getParamValue(FormParam.class, "nonce").toString().getBytes()); sha256.update(restInvocation.getRequestBody().getBytes()); Mac mac512 = getMac(); mac512.update(("/" + restInvocation.getPath()).getBytes()); mac512.update(sha256.digest()); return Base64.getEncoder().encodeToString(mac512.doFinal()).trim(); } }
final String input; if (restInvocation.getPath().startsWith("wapi/")) { switch (restInvocation.getHttpMethod()) { case "GET": case "DELETE": break; case "POST": input = restInvocation.getRequestBody(); break; default: throw new RuntimeException( "Not support http method: " + restInvocation.getHttpMethod()); String invocationUrl = restInvocation.getInvocationUrl();
@Override public String digestParams(RestInvocation restInvocation) { final String message = restInvocation.getParamValue(HeaderParam.class, "ACCESS_NONCE").toString() + restInvocation.getInvocationUrl() + restInvocation.getRequestBody(); Mac mac256 = getMac(); mac256.update(message.getBytes()); return String.format("%064x", new BigInteger(1, mac256.doFinal())); } }
@Override public String digestParams(RestInvocation restInvocation) { String postBody = restInvocation.getRequestBody(); if (postBody == null) { postBody = ""; } String uri = restInvocation.getPath() + "?" + restInvocation.getQueryString(); String message = uri + postBody; mac.update(message.getBytes()); return DigestUtils.bytesToHex(mac.doFinal()).toLowerCase(); } }
@Override public String digestParams(RestInvocation restInvocation) { final String nonce = restInvocation .getParamValue(HeaderParam.class, TheRockAuthenticated.X_TRT_NONCE) .toString(); mac.update(nonce.getBytes()); mac.update(restInvocation.getInvocationUrl().getBytes()); return String.format("%0128x", new BigInteger(1, mac.doFinal())); } }
@Override public String digestParams(RestInvocation restInvocation) { String message = restInvocation.getParamValue(HeaderParam.class, "CB-ACCESS-TIMESTAMP").toString() + restInvocation.getHttpMethod() + "/" + restInvocation.getMethodPath() + (restInvocation.getRequestBody() != null ? restInvocation.getRequestBody() : ""); Mac mac256 = getMac(); try { mac256.update(message.getBytes("UTF-8")); } catch (Exception e) { throw new ExchangeException("Digest encoding exception", e); } return Base64.encodeBytes(mac256.doFinal()); } }
@Override public String digestParams(RestInvocation restInvocation) { final String path = restInvocation.getPath(); final Map<String, String> httpHeadersFromParams = restInvocation.getHttpHeadersFromParams(); final String requestBody = restInvocation.getRequestBody(); final String input = String.join(";", path, requestBody, httpHeadersFromParams.get("Api-Nonce")); final Mac mac = getMac(); try { mac.update(input.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } final String printBase64Binary = bytesToHex(mac.doFinal()); return Base64.getEncoder().encodeToString(printBase64Binary.getBytes()); } }
@Override public String digestParams(RestInvocation restInvocation) { String timestamp = restInvocation.getParamValue(HeaderParam.class, CB_ACCESS_TIMESTAMP).toString(); String methodPath = "/v2" + restInvocation.getPath(); // todo - move the /v2 bit of the path to the interface String message = timestamp + restInvocation.getHttpMethod() + methodPath; String body = null; // todo - deal with POST requests String sign = DigestUtils.bytesToHex(getMac().doFinal(message.getBytes())); // String apiKey = restInvocation.getParamValue(HeaderParam.class, // CB_ACCESS_KEY).toString(); // showCurl(restInvocation.getHttpMethod(), apiKey, timestamp, sign, methodPath, body); return sign; }
@Override public String digestParams(RestInvocation restInvocation) { try { String urlMethod = restInvocation.getInvocationUrl(); String nonce = String.valueOf(nonceFactory.createValue()); String body = restInvocation.getRequestBody(); String md5 = Base64.getEncoder() .encodeToString(MessageDigest.getInstance("MD5").digest(body.getBytes("UTF-8"))); String reqSignature = apiKey + "POST" + URLEncoder.encode(urlMethod, StandardCharsets.UTF_8.toString()).toLowerCase() + nonce + md5; return "amx " + apiKey + ":" + Base64.getEncoder().encodeToString(getMac().doFinal(reqSignature.getBytes("UTF-8"))) + ":" + nonce; } catch (Exception e) { throw new IllegalStateException("Faile to sign request", e); } } }
@Override public String digestParams(RestInvocation restInvocation) { Mac mac256 = getMac(); mac256.update(restInvocation.getParamValue(FormParam.class, "nonce").toString().getBytes()); mac256.update(clientId.getBytes()); mac256.update(apiKey.getBytes()); return String.format("%064x", new BigInteger(1, mac256.doFinal())).toUpperCase(); } }
@Override public String digestParams(RestInvocation restInvocation) { String path = restInvocation.getMethodPath().replaceFirst("/", ""); String requestBody = restInvocation.getRequestBody(); String stringToSign = (path + "\0" + requestBody); Mac mac = getMac(); mac.update(stringToSign.getBytes()); byte[] rawSignature = mac.doFinal(); byte[] base64encoded = encoder.encode(rawSignature); return new String(base64encoded); } }
@Override public String digestParams(RestInvocation restInvocation) { String queryString = ""; if (restInvocation.getParamsMap().get(QueryParam.class) != null && !restInvocation.getParamsMap().get(QueryParam.class).isEmpty()) { queryString = String.valueOf(restInvocation.getParamsMap().get(QueryParam.class)); } else if (restInvocation.getRequestBody() != null && !restInvocation.getRequestBody().isEmpty()) { try { ObjectMapper mapper = new ObjectMapper(); Map<String, String> map = mapper.readValue(restInvocation.getRequestBody(), Map.class); Iterator it = map.keySet().iterator(); while (it.hasNext()) {
private void replaceInvocationUrl(RestInvocation restInvocation, String signature) { String invocationUrl = restInvocation.getInvocationUrl(); String newInvocationUrl = invocationUrl.replace(PLACEHOLDER, signature); try { invocationUrlField.set(restInvocation, newInvocationUrl); } catch (IllegalArgumentException | IllegalAccessException e) { throw new IllegalStateException("rescu library has been updated"); } }