From b397ed365fb9f75d44617f899b9d26c758a25658 Mon Sep 17 00:00:00 2001 From: Andrey Rainchik Date: Wed, 4 Dec 2019 15:39:35 -0600 Subject: [PATCH] Clean up --- src/main/java/burp/Utility.java | 42 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/main/java/burp/Utility.java b/src/main/java/burp/Utility.java index cdb41fb..c206bba 100644 --- a/src/main/java/burp/Utility.java +++ b/src/main/java/burp/Utility.java @@ -15,16 +15,16 @@ import java.util.*; import java.util.regex.Matcher; -public class Utility { - - public static byte[] signRequest(IHttpRequestResponse messageInfo, - IExtensionHelpers helpers, - String service, - String region, - String accessKey, - String secretKey, - String token, - PrintWriter pw) throws Exception { +class Utility { + + static byte[] signRequest(IHttpRequestResponse messageInfo, + IExtensionHelpers helpers, + String service, + String region, + String accessKey, + String secretKey, + String token, + PrintWriter pw) throws Exception { IRequestInfo requestInfo = helpers.analyzeRequest(messageInfo); List headers = requestInfo.getHeaders(); if (!token.isEmpty()) { @@ -109,8 +109,8 @@ public static byte[] signRequest(IHttpRequestResponse messageInfo, if(!body.matches(notUnicode)) { char[] chars = body.toCharArray(); String sanitize = ""; - for (int i = 0; i < chars.length; ++i) { - String test = Character.toString(chars[i]); + for (char aChar : chars) { + String test = Character.toString(aChar); if (Pattern.matches(notUnicode, test)) { sanitize = sanitize.concat(URLEncoder.encode(test, StandardCharsets.UTF_8.toString())); } else { @@ -129,8 +129,8 @@ public static byte[] signRequest(IHttpRequestResponse messageInfo, if(!canonicalUri.matches(notUnicode)) { char[] chars = canonicalUri.toCharArray(); String sanitize = ""; - for (int i = 0; i < chars.length; ++i) { - String test = Character.toString(chars[i]); + for (char aChar : chars) { + String test = Character.toString(aChar); if (Pattern.matches(notUnicode, test)) { sanitize = sanitize.concat(URLEncoder.encode(test, StandardCharsets.UTF_8.toString())); } else { @@ -169,8 +169,8 @@ public static byte[] signRequest(IHttpRequestResponse messageInfo, if(!canonicalQueryString.matches(notUnicode)) { char[] chars = canonicalQueryString.toCharArray(); String sanitize = ""; - for (int i = 0; i < chars.length; ++i) { - String test = Character.toString(chars[i]); + for (char aChar : chars) { + String test = Character.toString(aChar); if (Pattern.matches(notUnicode, test)) { sanitize = sanitize.concat(URLEncoder.encode(test, StandardCharsets.UTF_8.toString())); } else { @@ -233,8 +233,8 @@ public static byte[] signRequest(IHttpRequestResponse messageInfo, if(!newHeaders.get(0).matches(notUnicode)) { char[] chars = newHeaders.get(0).toCharArray(); String sanitize = ""; - for (int i = 0; i < chars.length; ++i) { - String test = Character.toString(chars[i]); + for (char aChar : chars) { + String test = Character.toString(aChar); if (Pattern.matches(notUnicode, test)) { sanitize = sanitize.concat(URLEncoder.encode(test, StandardCharsets.UTF_8.toString())); } else { @@ -251,11 +251,11 @@ private static byte[] HmacSHA256(String data, byte[] key) throws Exception { String algorithm="HmacSHA256"; Mac mac = Mac.getInstance(algorithm); mac.init(new SecretKeySpec(key, algorithm)); - return mac.doFinal(data.getBytes("UTF8")); + return mac.doFinal(data.getBytes(StandardCharsets.UTF_8)); } private static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName) throws Exception { - byte[] kSecret = ("AWS4" + key).getBytes("UTF8"); + byte[] kSecret = ("AWS4" + key).getBytes(StandardCharsets.UTF_8); byte[] kDate = HmacSHA256(dateStamp, kSecret); byte[] kRegion = HmacSHA256(regionName, kDate); byte[] kService = HmacSHA256(serviceName, kRegion); @@ -288,12 +288,10 @@ private static String bytesToHex(byte[] bytes) { } private static String hexToString(String hex){ StringBuilder sb = new StringBuilder(); - StringBuilder temp = new StringBuilder(); for( int i=0; i