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}"); } }
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); }
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(); } }
private void AddCoordinates(PipelineMethod pipelineMethod, double x, double y, double? z, double? m) { CheckAlwaysThrow(); LogMethodCall(pipelineMethod, new double?[] { x, y, z, m }); }
private void BeginShape(PipelineMethod pipelineMethod, SpatialType type) { CheckAlwaysThrow(); LogMethodCall(pipelineMethod, type); }
private void LogMethodCall(PipelineMethod pipelineMethod, object methodArgs) { methodCalls.Add(new KeyValuePair <PipelineMethod, object>(pipelineMethod, methodArgs)); }
private void Reset(PipelineMethod pipelineMethod) { CheckAlwaysThrow(); LogMethodCall(pipelineMethod, null); }
protected virtual object GetPipelineMethodProcessor(PipelineMethod method) { return(typeof(PipelineMethod).GetField("_object", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(method)); }
protected override object GetPipelineMethodProcessor(PipelineMethod method) { return(typeof(PipelineMethod).GetField("target", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(method)); }
public override void SetRequestLine(PipelineMethod method, Uri uri) { _requestMessage.Method = ToHttpClientMethod(method); _requestMessage.RequestUri = uri; }
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); }
private void EndShape(PipelineMethod pipelineMethod) { CheckAlwaysThrow(); LogMethodCall(pipelineMethod, null); }
private void AddCoordinates(PipelineMethod pipelineMethod, double x, double y, double?z, double?m) { CheckAlwaysThrow(); LogMethodCall(pipelineMethod, new double?[] { x, y, z, m }); }
private void SetCoordinateSystem(PipelineMethod pipelineMethod, CoordinateSystem coordinateSystem) { CheckAlwaysThrow(); LogMethodCall(pipelineMethod, coordinateSystem); }
private void LogMethodCall(PipelineMethod pipelineMethod, object methodArgs) { methodCalls.Add(new KeyValuePair<PipelineMethod, object>(pipelineMethod, methodArgs)); }
public override void SetRequestLine(PipelineMethod method, Uri uri) { _uri = uri.ToString(); _method = method; }
// TODO (pri 1): what happens if this is called after AddHeader? Especially for SocketTransport public abstract void SetRequestLine(PipelineMethod method, Uri uri);