コード例 #1
0
        internal static void AddAuthenticationHeaders(HttpMessage message, Uri uri, PipelineMethod method, ReadOnlyMemory <byte> content, byte[] secret, string credential)
        {
            string contentHash = null;

            using (var alg = SHA256.Create())
            {
                // TODO (pri 3): ToArray should nopt be called here. Instead, TryGetArray, or PipelineContent should do hashing on the fly
                contentHash = Convert.ToBase64String(alg.ComputeHash(content.ToArray()));
            }

            using (var hmac = new HMACSHA256(secret))
            {
                var host         = uri.Host;
                var pathAndQuery = uri.PathAndQuery;

                string         verb          = method.ToString().ToUpper();
                DateTimeOffset utcNow        = DateTimeOffset.UtcNow;
                var            utcNowString  = utcNow.ToString("r");
                var            stringToSign  = $"{verb}\n{pathAndQuery}\n{utcNowString};{host};{contentHash}";
                var            signature     = Convert.ToBase64String(hmac.ComputeHash(Encoding.ASCII.GetBytes(stringToSign))); // Calculate the signature
                string         signedHeaders = "date;host;x-ms-content-sha256";                                                 // Semicolon separated header names

                // TODO (pri 3): should date header writing be moved out from here?
                message.AddHeader("Date", utcNowString);
                message.AddHeader("x-ms-content-sha256", contentHash);
                message.AddHeader("Authorization", $"HMAC-SHA256 Credential={credential}, SignedHeaders={signedHeaders}, Signature={signature}");
            }
        }
コード例 #2
0
            public override void SetRequestLine(PipelineMethod method, Uri uri)
            {
                _method = method;
                _host   = uri.Host;
                var path = uri.PathAndQuery;

                Http.WriteRequestLine(ref _requestBuffer, "https", method, Encoding.ASCII.GetBytes(path));
                AddHeader("Host", _host);
            }
コード例 #3
0
            public static HttpMethod ToHttpClientMethod(PipelineMethod method)
            {
                switch (method)
                {
                case PipelineMethod.Get: return(HttpMethod.Get);

                case PipelineMethod.Post: return(HttpMethod.Post);

                case PipelineMethod.Put: return(HttpMethod.Put);

                case PipelineMethod.Delete: return(HttpMethod.Delete);

                default: throw new NotImplementedException();
                }
            }
コード例 #4
0
 private void AddCoordinates(PipelineMethod pipelineMethod, double x, double y, double? z, double? m)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, new double?[] { x, y, z, m });
 }
コード例 #5
0
 private void BeginShape(PipelineMethod pipelineMethod, SpatialType type)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, type);
 }
コード例 #6
0
ファイル: LoggingPipelines.cs プロジェクト: zhonli/odata.net
 private void LogMethodCall(PipelineMethod pipelineMethod, object methodArgs)
 {
     methodCalls.Add(new KeyValuePair <PipelineMethod, object>(pipelineMethod, methodArgs));
 }
コード例 #7
0
ファイル: LoggingPipelines.cs プロジェクト: zhonli/odata.net
 private void Reset(PipelineMethod pipelineMethod)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, null);
 }
コード例 #8
0
 protected virtual object GetPipelineMethodProcessor(PipelineMethod method)
 {
     return(typeof(PipelineMethod).GetField("_object", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(method));
 }
コード例 #9
0
 private void Reset(PipelineMethod pipelineMethod)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, null);
 }
コード例 #10
0
ファイル: LoggingPipelines.cs プロジェクト: zhonli/odata.net
 private void BeginShape(PipelineMethod pipelineMethod, SpatialType type)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, type);
 }
コード例 #11
0
 protected override object GetPipelineMethodProcessor(PipelineMethod method)
 {
     return(typeof(PipelineMethod).GetField("target", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(method));
 }
コード例 #12
0
 public override void SetRequestLine(PipelineMethod method, Uri uri)
 {
     _requestMessage.Method     = ToHttpClientMethod(method);
     _requestMessage.RequestUri = uri;
 }
コード例 #13
0
        internal static void WriteRequestLine(ref Sequence <byte> buffer, string protocol, PipelineMethod method, ReadOnlySpan <byte> path)
        {
            if (protocol != "https")
            {
                throw new NotImplementedException();
            }

            var segment = buffer.GetMemory().Span;
            int written = 0;

            if (method == PipelineMethod.Get)
            {
                s_get.CopyTo(segment);
                written = s_get.Length;
            }
            else if (method == PipelineMethod.Post)
            {
                s_post.CopyTo(segment);
                written = s_post.Length;
            }

            path.CopyTo(segment.Slice(written));
            written += path.Length;

            s_http11CrLf.CopyTo(segment.Slice(written));
            written += s_http11CrLf.Length;

            buffer.Advance(written);
        }
コード例 #14
0
 private void EndShape(PipelineMethod pipelineMethod)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, null);
 }
コード例 #15
0
ファイル: LoggingPipelines.cs プロジェクト: zhonli/odata.net
 private void AddCoordinates(PipelineMethod pipelineMethod, double x, double y, double?z, double?m)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, new double?[] { x, y, z, m });
 }
コード例 #16
0
 private void SetCoordinateSystem(PipelineMethod pipelineMethod, CoordinateSystem coordinateSystem)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, coordinateSystem);
 }
コード例 #17
0
ファイル: LoggingPipelines.cs プロジェクト: zhonli/odata.net
 private void EndShape(PipelineMethod pipelineMethod)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, null);
 }
コード例 #18
0
 private void LogMethodCall(PipelineMethod pipelineMethod, object methodArgs)
 {
     methodCalls.Add(new KeyValuePair<PipelineMethod, object>(pipelineMethod, methodArgs));
 }
コード例 #19
0
ファイル: LoggingPipelines.cs プロジェクト: zhonli/odata.net
 private void SetCoordinateSystem(PipelineMethod pipelineMethod, CoordinateSystem coordinateSystem)
 {
     CheckAlwaysThrow();
     LogMethodCall(pipelineMethod, coordinateSystem);
 }
コード例 #20
0
 public override void SetRequestLine(PipelineMethod method, Uri uri)
 {
     _uri    = uri.ToString();
     _method = method;
 }
コード例 #21
0
 // TODO (pri 1): what happens if this is called after AddHeader? Especially for SocketTransport
 public abstract void SetRequestLine(PipelineMethod method, Uri uri);