示例#1
0
            public AwsSigningConfigNative(AwsSigningConfig config)
            {
                Algorithm              = config.Algorithm;
                SignatureType          = config.SignatureType;
                Region                 = config.Region;
                Service                = config.Service;
                MillisecondsSinceEpoch = MillisecondsSinceEpoch = (long)(config.Timestamp.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

                Credentials creds = config.Credentials;

                if (creds != null)
                {
                    AccessKeyId = creds.AccessKeyId != null?System.Text.Encoding.UTF8.GetString(creds.AccessKeyId) : null;

                    SecretAccessKey = creds.SecretAccessKey != null?System.Text.Encoding.UTF8.GetString(creds.SecretAccessKey) : null;

                    SessionToken = creds.SessionToken != null?System.Text.Encoding.UTF8.GetString(creds.SessionToken) : null;
                }
                else
                {
                    AccessKeyId     = null;
                    SecretAccessKey = null;
                    SessionToken    = null;
                }

                ShouldSignHeader       = config.ShouldSignHeader;
                UseDoubleUriEncode     = config.UseDoubleUriEncode;
                ShouldNormalizeUriPath = config.ShouldNormalizeUriPath;
                OmitSessionToken       = config.OmitSessionToken;
                SignedBodyValue        = config.SignedBodyValue;
                SignedBodyHeader       = config.SignedBodyHeader;
                ExpirationInSeconds    = config.ExpirationInSeconds;
            }
示例#2
0
        public static CrtResult <HttpRequest> SignHttpRequest(HttpRequest request, AwsSigningConfig signingConfig)
        {
            if (request == null || signingConfig == null)
            {
                throw new CrtException("Null argument passed to SignRequest");
            }

            if (request.BodyStream != null)
            {
                if (!request.BodyStream.CanSeek)
                {
                    throw new CrtException("Http request payload stream must be seekable in order to be signed");
                }
            }

            var nativeConfig = new AwsSigningConfigNative(signingConfig);

            uint headerCount = 0;

            if (request.Headers != null)
            {
                headerCount = (uint)request.Headers.Length;
            }

            HttpRequestSigningCallback callback = new HttpRequestSigningCallback();

            callback.OriginalRequest  = request;                        /* needed to build final signed request */
            callback.ShouldSignHeader = signingConfig.ShouldSignHeader; /* prevent GC while signing */
            callback.BodyStream       = new CrtStreamWrapper(request.BodyStream);

            ulong id = PendingHttpRequestSignings.AcquireStrongReference(callback);

            API.SignRequestNative(request.Method, request.Uri, request.Headers, headerCount, callback.BodyStream.Delegates, nativeConfig, id, API.OnHttpRequestSigningComplete);

            return(callback.Result);
        }
示例#3
0
        public static CrtResult <String> SignCanonicalRequest(String canonicalRequest, AwsSigningConfig signingConfig)
        {
            if (canonicalRequest == null || signingConfig == null)
            {
                throw new CrtException("Null argument passed to SignRequest");
            }

            if (signingConfig.SignatureType != AwsSignatureType.CANONICAL_REQUEST_VIA_HEADERS &&
                signingConfig.SignatureType != AwsSignatureType.CANONICAL_REQUEST_VIA_QUERY_PARAMS)
            {
                throw new CrtException("Illegal signing type for canonical request signing");
            }

            var nativeConfig = new AwsSigningConfigNative(signingConfig);

            CanonicalRequestSigningCallback callback = new CanonicalRequestSigningCallback();

            callback.OriginalCanonicalRequest = canonicalRequest;

            ulong id = PendingCanonicalRequestSignings.AcquireStrongReference(callback);

            API.SignCanonicalRequestNative(canonicalRequest, nativeConfig, id, API.OnCanonicalRequestSigningComplete);

            return(callback.Result);
        }