示例#1
0
        public void SignCanonicalRequestByHeaders()
        {
            var config = BuildBaseSigningConfig();

            config.SignedBodyHeader = AwsSignedBodyHeaderType.X_AMZ_CONTENT_SHA256;
            config.SignatureType    = AwsSignatureType.CANONICAL_REQUEST_VIA_HEADERS;


            var canonicalRequest = String.Join("\n",
                                               "POST",
                                               "/",
                                               "",
                                               "content-length:13",
                                               "content-type:application/x-www-form-urlencoded",
                                               "host:example.amazonaws.com",
                                               "x-amz-content-sha256:9095672bbd1f56dfc5b65f3e153adc8731a4a654192329106275f4c7b24d0b6e",
                                               "x-amz-date:20150830T123600Z",
                                               "",
                                               "content-length;content-type;host;x-amz-content-sha256;x-amz-date",
                                               "9095672bbd1f56dfc5b65f3e153adc8731a4a654192329106275f4c7b24d0b6e");

            CrtResult <String> result         = AwsSigner.SignCanonicalRequest(canonicalRequest, config);
            String             signatureValue = result.Get();

            Assert.Equal("d3875051da38690788ef43de4db0d8f280229d82040bfac253562e56c3f20e0b", signatureValue);
        }
示例#2
0
        public void SignRequestFailureIllegalHeader()
        {
            var config = BuildBaseSigningConfig();

            var request = BuildRequestWithIllegalHeader();

            CrtResult <HttpRequest> result = AwsSigner.SignHttpRequest(request, config);

            Assert.Throws <CrtException>(() => result.Get());

            int crtErrorCode = 0;

            try {
                HttpRequest req = result.Get();
            } catch (CrtException e) {
                crtErrorCode = e.ErrorCode;
            }

            /* AWS_AUTH_SIGNING_ILLEGAL_REQUEST_HEADER */
            Assert.Equal(1024 * 6 + 6, crtErrorCode);
        }
示例#3
0
        public void SignRequestFailureNoCredentials()
        {
            var config = BuildBaseSigningConfig();

            config.Credentials = null;

            var request = BuildTestSuiteRequestWithoutBody();

            CrtResult <HttpRequest> result = AwsSigner.SignHttpRequest(request, config);

            Assert.Throws <CrtException>(() => result.Get());

            int crtErrorCode = 0;

            try {
                HttpRequest req = result.Get();
            } catch (CrtException e) {
                crtErrorCode = e.ErrorCode;
            }

            /* AWS_AUTH_SIGNING_INVALID_CONFIGURATION */
            Assert.Equal(1024 * 6 + 7, crtErrorCode);
        }
示例#4
0
        public void SignBodylessRequestByHeaders()
        {
            var config  = BuildBaseSigningConfig();
            var request = BuildTestSuiteRequestWithoutBody();

            CrtResult <HttpRequest> result        = AwsSigner.SignHttpRequest(request, config);
            HttpRequest             signedRequest = result.Get();

            Assert.Equal("GET", signedRequest.Method);
            Assert.Equal("/?Param-3=Value3&Param=Value2&%E1%88%B4=Value1", signedRequest.Uri);
            Assert.Equal(3, signedRequest.Headers.Length);
            Assert.True(HasHeader(signedRequest, "Host", "example.amazonaws.com"));
            Assert.True(HasHeader(signedRequest, "X-Amz-Date", "20150830T123600Z"));
            Assert.True(HasHeader(signedRequest, "Authorization", "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=371d3713e185cc334048618a97f809c9ffe339c62934c032af5a0e595648fcac"));
        }
示例#5
0
        public void SignBodylessRequestByQuery()
        {
            var config = BuildBaseSigningConfig();

            config.SignatureType       = AwsSignatureType.HTTP_REQUEST_VIA_QUERY_PARAMS;
            config.ExpirationInSeconds = 3600;

            var request = BuildTestSuiteRequestWithoutBody();

            CrtResult <HttpRequest> result        = AwsSigner.SignHttpRequest(request, config);
            HttpRequest             signedRequest = result.Get();

            Assert.Equal("GET", signedRequest.Method);
            Assert.Equal("/?Param-3=Value3&Param=Value2&%E1%88%B4=Value1&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIDEXAMPLE%2F20150830%2Fus-east-1%2Fservice%2Faws4_request&X-Amz-Date=20150830T123600Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=c5f1848ceec943ac2ca68ee720460c23aaae30a2300586597ada94c4a65e4787", signedRequest.Uri);
            Assert.Equal(1, signedRequest.Headers.Length);
            Assert.True(HasHeader(signedRequest, "Host", "example.amazonaws.com"));
        }
示例#6
0
        public void SignBodyRequestByHeaders()
        {
            var config = BuildBaseSigningConfig();

            config.SignedBodyHeader = AwsSignedBodyHeaderType.X_AMZ_CONTENT_SHA256;

            var request = BuildTestSuiteRequestWithBody();

            CrtResult <HttpRequest> result        = AwsSigner.SignHttpRequest(request, config);
            HttpRequest             signedRequest = result.Get();

            Assert.Equal("POST", signedRequest.Method);
            Assert.Equal("/", signedRequest.Uri);
            Assert.Equal(6, signedRequest.Headers.Length);
            Assert.True(HasHeader(signedRequest, "Host", "example.amazonaws.com"));
            Assert.True(HasHeader(signedRequest, "X-Amz-Date", "20150830T123600Z"));
            Assert.True(HasHeader(signedRequest, "Authorization", "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date, Signature=d3875051da38690788ef43de4db0d8f280229d82040bfac253562e56c3f20e0b"));
            Assert.True(HasHeader(signedRequest, "Content-Type", "application/x-www-form-urlencoded"));
            Assert.True(HasHeader(signedRequest, "x-amz-content-sha256", "9095672bbd1f56dfc5b65f3e153adc8731a4a654192329106275f4c7b24d0b6e"));
            Assert.True(HasHeader(signedRequest, "Content-Length", "13"));
        }
示例#7
0
        public void SignRequestByHeadersWithHeaderSkip()
        {
            var config = BuildBaseSigningConfig();

            config.ShouldSignHeader = ShouldSignHeader;

            var request = BuildRequestWithSkippedHeader();

            CrtResult <HttpRequest> result        = AwsSigner.SignHttpRequest(request, config);
            HttpRequest             signedRequest = result.Get();

            Assert.Equal("GET", signedRequest.Method);
            Assert.Equal("/", signedRequest.Uri);
            Assert.Equal(4, signedRequest.Headers.Length);
            Assert.True(HasHeader(signedRequest, "Host", "example.amazonaws.com"));
            Assert.True(HasHeader(signedRequest, "X-Amz-Date", "20150830T123600Z"));
            Assert.True(HasHeader(signedRequest, "Skip", "me"));

            /* Verify Skip is not in the signed headers component of the Authorization header */
            String authValue = GetHeaderValue(signedRequest, "Authorization");

            Assert.Equal(false, authValue.Contains("Skip"));
        }