Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for Unsigned-Payload type of SigV4 signatures. Also a small bug fix. #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.stream.Collectors;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner;
import software.amazon.awssdk.auth.signer.AwsS3V4Signer;
import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute;
import software.amazon.awssdk.auth.signer.S3SignerExecutionAttribute;
Expand Down Expand Up @@ -95,13 +96,21 @@ public byte[] sign(IHttpRequestResponse messageInfo, IRequestInfo request, Parse
}).map(header -> {
//Only keep the header's value.
//We know from the filter that there is a colon character, so this is safe.
return header.split(":", 2)[1];
return header.split(":", 2)[1].trim();
}).collect(Collectors.toList());
LogWriter.logDebug("For header \"" + signedHeader + "\" found the following values: " + headerValues);
signedHeaderMap.put(signedHeader, headerValues);
}
LogWriter.logDebug("signedHeaderMap: " + signedHeaderMap);

//Check header for UNSIGNED-PAYLOAD, indicating auth type v4-unsigned-body is used. There may be other possible indicators.
boolean unsignedBodyType = false;
for(List<String> value: signedHeaderMap.values()){
if (value.contains("UNSIGNED-PAYLOAD")){
unsignedBodyType = true;
}
}

//Build request object for signing
URI uri;
try {
Expand Down Expand Up @@ -185,7 +194,7 @@ public byte[] sign(IHttpRequestResponse messageInfo, IRequestInfo request, Parse
.map(header -> {
//Only keep the header's value.
//We know from the filter that there is a colon character, so this is safe.
return header.split(":", 2)[1];
return header.split(":", 2)[1].trim();
}).findFirst();

//We want to find the right region for our request
Expand Down Expand Up @@ -228,6 +237,9 @@ public byte[] sign(IHttpRequestResponse messageInfo, IRequestInfo request, Parse
if (authHeader.getAlgorithm() == SigningAlgorithm.SIGV4A) {
LogWriter.logDebug("Handling non-S3 SigV4a signature.");
signer = AwsCrtV4aSigner.create();
} else if (unsignedBodyType) {
LogWriter.logDebug("Handling unsigned payload SigV4 signature.");
signer = Aws4UnsignedPayloadSigner.create();
} else {
LogWriter.logDebug("Handling non-S3 SigV4 signature.");
signer = Aws4Signer.create();
Expand Down