Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyRainchik committed Dec 4, 2019
1 parent a490426 commit b397ed3
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions src/main/java/burp/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> headers = requestInfo.getHeaders();
if (!token.isEmpty()) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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<hex.length()-1; i+=2 ){
String output = hex.substring(i, (i + 2));
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
temp.append(decimal);
}
return sb.toString();
}
Expand Down

0 comments on commit b397ed3

Please sign in to comment.