Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-auth
Submodule aws-c-auth updated 45 files
+67 −0 README.md
+12 −0 include/aws/auth/auth.h
+255 −0 include/aws/auth/aws_imds_client.h
+47 −66 include/aws/auth/credentials.h
+7 −2 include/aws/auth/private/aws_signing.h
+1 −1 include/aws/auth/private/credentials_utils.h
+23 −2 include/aws/auth/signable.h
+28 −4 include/aws/auth/signing.h
+153 −40 include/aws/auth/signing_config.h
+37 −0 source/auth.c
+1,612 −0 source/aws_imds_client.c
+3 −2 source/aws_profile.c
+326 −202 source/aws_signing.c
+134 −64 source/credentials.c
+41 −27 source/credentials_provider_cached.c
+16 −6 source/credentials_provider_chain.c
+24 −7 source/credentials_provider_ecs.c
+23 −26 source/credentials_provider_environment.c
+95 −851 source/credentials_provider_imds.c
+13 −2 source/credentials_provider_process.c
+10 −2 source/credentials_provider_profile.c
+4 −11 source/credentials_provider_static.c
+61 −40 source/credentials_provider_sts.c
+218 −163 source/credentials_provider_sts_web_identity.c
+26 −7 source/credentials_provider_x509.c
+43 −43 source/credentials_utils.c
+3 −5 source/signable.c
+95 −58 source/signing.c
+50 −10 source/signing_config.c
+125 −17 source/sigv4_http_request.c
+1 −1 source/xml_parser.c
+19 −2 tests/CMakeLists.txt
+1,391 −0 tests/aws_imds_client_test.c
+20 −38 tests/credentials_provider_ecs_tests.c
+57 −98 tests/credentials_provider_imds_tests.c
+23 −25 tests/credentials_provider_process_tests.c
+30 −31 tests/credentials_provider_sts_tests.c
+114 −161 tests/credentials_provider_sts_web_identity_tests.c
+9 −8 tests/credentials_provider_utils.c
+2 −1 tests/credentials_provider_utils.h
+19 −38 tests/credentials_provider_x509_tests.c
+65 −85 tests/credentials_tests.c
+42 −65 tests/sigv4_tests.c
+332 −0 tests/test_chunked_signing.c
+10 −14 tests/test_signable.c
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-cal
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-mqtt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Map;

import software.amazon.awssdk.crt.auth.credentials.Credentials;
import software.amazon.awssdk.crt.auth.credentials.CredentialsProvider;
import software.amazon.awssdk.crt.CrtResource;

Expand All @@ -27,8 +28,7 @@
public class AwsSigningConfig extends CrtResource {

public enum AwsSigningAlgorithm {
SIGV4_HEADER(0),
SIGV4_QUERY_PARAM(1);
SIGV4(0);

AwsSigningAlgorithm(int nativeValue) {
this.nativeValue = nativeValue;
Expand All @@ -47,8 +47,7 @@ public static AwsSigningAlgorithm getEnumValueFromInteger(int value) {

private static Map<Integer, AwsSigningAlgorithm> buildEnumMapping() {
Map<Integer, AwsSigningAlgorithm> enumMapping = new HashMap<Integer, AwsSigningAlgorithm>();
enumMapping.put(SIGV4_HEADER.getNativeValue(), SIGV4_HEADER);
enumMapping.put(SIGV4_QUERY_PARAM.getNativeValue(), SIGV4_QUERY_PARAM);
enumMapping.put(SIGV4.getNativeValue(), SIGV4);

return enumMapping;
}
Expand All @@ -58,64 +57,146 @@ private static Map<Integer, AwsSigningAlgorithm> buildEnumMapping() {
private static Map<Integer, AwsSigningAlgorithm> enumMapping = buildEnumMapping();
}

public enum AwsBodySigningConfigType {
AWS_BODY_SIGNING_OFF(0),
AWS_BODY_SIGNING_ON(1),
AWS_BODY_SIGNING_UNSIGNED_PAYLOAD(2);
public enum AwsSignatureType {
HTTP_REQUEST_VIA_HEADERS(0),
HTTP_REQUEST_VIA_QUERY_PARAMS(1),
HTTP_REQUEST_CHUNK(2),
HTTP_REQUEST_EVENT(3);

AwsBodySigningConfigType(int nativeValue) {
AwsSignatureType(int nativeValue) {
this.nativeValue = nativeValue;
}

public int getNativeValue() { return nativeValue; }

public static AwsBodySigningConfigType getEnumValueFromInteger(int value) {
AwsBodySigningConfigType enumValue = enumMapping.get(value);
public static AwsSignatureType getEnumValueFromInteger(int value) {
AwsSignatureType enumValue = enumMapping.get(value);
if (enumValue != null) {
return enumValue;
}

throw new RuntimeException("Illegal body signing config type value in signing configuration");
throw new RuntimeException("Illegal signature type value in signing configuration");
}

private static Map<Integer, AwsBodySigningConfigType> buildEnumMapping() {
Map<Integer, AwsBodySigningConfigType> enumMapping = new HashMap<Integer, AwsBodySigningConfigType>();
enumMapping.put(AWS_BODY_SIGNING_OFF.getNativeValue(), AWS_BODY_SIGNING_OFF);
enumMapping.put(AWS_BODY_SIGNING_ON.getNativeValue(), AWS_BODY_SIGNING_ON);
enumMapping.put(AWS_BODY_SIGNING_UNSIGNED_PAYLOAD.getNativeValue(), AWS_BODY_SIGNING_UNSIGNED_PAYLOAD);
private static Map<Integer, AwsSignatureType> buildEnumMapping() {
Map<Integer, AwsSignatureType> enumMapping = new HashMap<Integer, AwsSignatureType>();
enumMapping.put(HTTP_REQUEST_VIA_HEADERS.getNativeValue(), HTTP_REQUEST_VIA_HEADERS);
enumMapping.put(HTTP_REQUEST_VIA_QUERY_PARAMS.getNativeValue(), HTTP_REQUEST_VIA_QUERY_PARAMS);
enumMapping.put(HTTP_REQUEST_CHUNK.getNativeValue(), HTTP_REQUEST_CHUNK);
enumMapping.put(HTTP_REQUEST_EVENT.getNativeValue(), HTTP_REQUEST_EVENT);

return enumMapping;
}

private int nativeValue;

private static Map<Integer, AwsBodySigningConfigType> enumMapping = buildEnumMapping();
private static Map<Integer, AwsSignatureType> enumMapping = buildEnumMapping();
}

private int signingAlgorithm = AwsSigningAlgorithm.SIGV4_HEADER.getNativeValue();
public enum AwsSignedBodyValueType {
EMPTY(0),
PAYLOAD(1),
UNSIGNED_PAYLOAD(2),
STREAMING_AWS4_HMAC_SHA256_PAYLOAD(3),
STREAMING_AWS4_HMAC_SHA256_EVENTS(4);

AwsSignedBodyValueType(int nativeValue) {
this.nativeValue = nativeValue;
}

public int getNativeValue() { return nativeValue; }

public static AwsSignedBodyValueType getEnumValueFromInteger(int value) {
AwsSignedBodyValueType enumValue = enumMapping.get(value);
if (enumValue != null) {
return enumValue;
}

throw new RuntimeException("Illegal signed body value type value in signing configuration");
}

private static Map<Integer, AwsSignedBodyValueType> buildEnumMapping() {
Map<Integer, AwsSignedBodyValueType> enumMapping = new HashMap<Integer, AwsSignedBodyValueType>();
enumMapping.put(EMPTY.getNativeValue(), EMPTY);
enumMapping.put(PAYLOAD.getNativeValue(), PAYLOAD);
enumMapping.put(UNSIGNED_PAYLOAD.getNativeValue(), UNSIGNED_PAYLOAD);
enumMapping.put(STREAMING_AWS4_HMAC_SHA256_PAYLOAD.getNativeValue(), STREAMING_AWS4_HMAC_SHA256_PAYLOAD);
enumMapping.put(STREAMING_AWS4_HMAC_SHA256_EVENTS.getNativeValue(), STREAMING_AWS4_HMAC_SHA256_EVENTS);

return enumMapping;
}

private int nativeValue;

private static Map<Integer, AwsSignedBodyValueType> enumMapping = buildEnumMapping();
}

public enum AwsSignedBodyHeaderType {
NONE(0),
X_AMZ_CONTENT_SHA256(1);

AwsSignedBodyHeaderType(int nativeValue) {
this.nativeValue = nativeValue;
}

public int getNativeValue() { return nativeValue; }

public static AwsSignedBodyHeaderType getEnumValueFromInteger(int value) {
AwsSignedBodyHeaderType enumValue = enumMapping.get(value);
if (enumValue != null) {
return enumValue;
}

throw new RuntimeException("Illegal signed body header value in signing configuration");
}

private static Map<Integer, AwsSignedBodyHeaderType> buildEnumMapping() {
Map<Integer, AwsSignedBodyHeaderType> enumMapping = new HashMap<Integer, AwsSignedBodyHeaderType>();
enumMapping.put(NONE.getNativeValue(), NONE);
enumMapping.put(X_AMZ_CONTENT_SHA256.getNativeValue(), X_AMZ_CONTENT_SHA256);

return enumMapping;
}

private int nativeValue;

private static Map<Integer, AwsSignedBodyHeaderType> enumMapping = buildEnumMapping();
}

private int algorithm = AwsSigningAlgorithm.SIGV4.getNativeValue();
private int signatureType = AwsSignatureType.HTTP_REQUEST_VIA_HEADERS.getNativeValue();
private String region;
private String service;
private long time = System.currentTimeMillis();
private CredentialsProvider credentialsProvider;
private Predicate<String> shouldSignParameter;
private Credentials credentials;
private Predicate<String> shouldSignHeader;
private boolean useDoubleUriEncode = true;
private boolean shouldNormalizeUriPath = true;
private int signBody = AwsBodySigningConfigType.AWS_BODY_SIGNING_OFF.getNativeValue();
private boolean omitSessionToken = false;
private int signedBodyValue = AwsSignedBodyValueType.PAYLOAD.getNativeValue();
private int signedBodyHeader = AwsSignedBodyHeaderType.NONE.getNativeValue();
private long expirationInSeconds = 0;

public AwsSigningConfig() {}

public AwsSigningConfig clone() {
try (AwsSigningConfig clone = new AwsSigningConfig()) {

clone.setSigningAlgorithm(getSigningAlgorithm());
clone.setAlgorithm(getAlgorithm());
clone.setSignatureType(getSignatureType());
clone.setRegion(getRegion());
clone.setService(getService());
clone.setTime(getTime());
clone.setCredentialsProvider(getCredentialsProvider());
clone.setShouldSignParameter(getShouldSignParameter());
clone.setCredentials(getCredentials());
clone.setShouldSignHeader(getShouldSignHeader());
clone.setUseDoubleUriEncode(getUseDoubleUriEncode());
clone.setShouldNormalizeUriPath(getShouldNormalizeUriPath());
clone.setSignBody(getSignBody());
clone.setOmitSessionToken(getOmitSessionToken());
clone.setSignedBodyValue(getSignedBodyValue());
clone.setSignedBodyHeader(getSignedBodyHeader());
clone.setExpirationInSeconds(getExpirationInSeconds());

// success, bump up the ref count so we can escape the try-with-resources block
clone.addRef();
Expand All @@ -137,9 +218,14 @@ protected void releaseNativeHandle() {}
@Override
protected boolean canReleaseReferencesImmediately() { return true; }

public void setSigningAlgorithm(AwsSigningAlgorithm algorithm) { this.signingAlgorithm = algorithm.getNativeValue(); }
public AwsSigningAlgorithm getSigningAlgorithm() {
return AwsSigningAlgorithm.getEnumValueFromInteger(signingAlgorithm);
public void setAlgorithm(AwsSigningAlgorithm algorithm) { this.algorithm = algorithm.getNativeValue(); }
public AwsSigningAlgorithm getAlgorithm() {
return AwsSigningAlgorithm.getEnumValueFromInteger(algorithm);
}

public void setSignatureType(AwsSignatureType signatureType) { this.signatureType = signatureType.getNativeValue(); }
public AwsSignatureType getSignatureType() {
return AwsSignatureType.getEnumValueFromInteger(signatureType);
}

public void setRegion(String region) { this.region = region; }
Expand All @@ -158,17 +244,29 @@ public void setCredentialsProvider(CredentialsProvider credentialsProvider) {

public CredentialsProvider getCredentialsProvider() { return credentialsProvider; }

public void setShouldSignParameter(Predicate<String> shouldSignParameter) { this.shouldSignParameter = shouldSignParameter; }
public Predicate<String> getShouldSignParameter() { return shouldSignParameter; }
public void setCredentials(Credentials credentials) { this.credentials = credentials; }
public Credentials getCredentials() { return credentials; }

public void setShouldSignHeader(Predicate<String> shouldSignHeader) { this.shouldSignHeader = shouldSignHeader; }
public Predicate<String> getShouldSignHeader() { return shouldSignHeader; }

public void setUseDoubleUriEncode(boolean useDoubleUriEncode) { this.useDoubleUriEncode = useDoubleUriEncode; }
public boolean getUseDoubleUriEncode() { return useDoubleUriEncode; }

public void setShouldNormalizeUriPath(boolean shouldNormalizeUriPath) { this.shouldNormalizeUriPath = shouldNormalizeUriPath; }
public boolean getShouldNormalizeUriPath() { return shouldNormalizeUriPath; }

public void setSignBody(AwsBodySigningConfigType signBody) { this.signBody = signBody.getNativeValue(); }
public AwsBodySigningConfigType getSignBody() { return AwsBodySigningConfigType.getEnumValueFromInteger(signBody); }
public void setOmitSessionToken(boolean omitSessionToken) { this.omitSessionToken = omitSessionToken; }
public boolean getOmitSessionToken() { return omitSessionToken; }

public void setSignedBodyValue(AwsSignedBodyValueType signedBodyValue) { this.signedBodyValue = signedBodyValue.getNativeValue(); }
public AwsSignedBodyValueType getSignedBodyValue() { return AwsSignedBodyValueType.getEnumValueFromInteger(signedBodyValue); }

public void setSignedBodyHeader(AwsSignedBodyHeaderType signedBodyHeader) { this.signedBodyHeader = signedBodyHeader.getNativeValue(); }
public AwsSignedBodyHeaderType getSignedBodyHeader() { return AwsSignedBodyHeaderType.getEnumValueFromInteger(signedBodyHeader); }

public void setExpirationInSeconds(long expirationInSeconds) { this.expirationInSeconds = expirationInSeconds; }
public long getExpirationInSeconds() { return expirationInSeconds; }
}


Expand Down
Loading