LaDeak.HttpMessageSigner.AspNetCore
0.0.1
See the version list below for details.
dotnet add package LaDeak.HttpMessageSigner.AspNetCore --version 0.0.1
NuGet\Install-Package LaDeak.HttpMessageSigner.AspNetCore -Version 0.0.1
<PackageReference Include="LaDeak.HttpMessageSigner.AspNetCore" Version="0.0.1" />
<PackageVersion Include="LaDeak.HttpMessageSigner.AspNetCore" Version="0.0.1" />
<PackageReference Include="LaDeak.HttpMessageSigner.AspNetCore" />
paket add LaDeak.HttpMessageSigner.AspNetCore --version 0.0.1
#r "nuget: LaDeak.HttpMessageSigner.AspNetCore, 0.0.1"
#:package LaDeak.HttpMessageSigner.AspNetCore@0.0.1
#addin nuget:?package=LaDeak.HttpMessageSigner.AspNetCore&version=0.0.1
#tool nuget:?package=LaDeak.HttpMessageSigner.AspNetCore&version=0.0.1
HttpMessageSigner
ASP.NET Core middleware for signing HTTP responses with HTTP Message Signatures (RFC 9421). It can also calculate a response Content-Digest (RFC 9530) and include it in the signature.
This is useful in the following scenarios:
- A message is saved for temporal reference. The source and integrity of the message can be validated across databases reads and writes that are separate events in time. For example, signatures in a legal archive preserves the integrity of the message.
- Protection against intermediaries in transport security. It provides end-to-end integrity. For example, protection against early TLS termination or compromised intermediaries (API gateways).
- Signed business assertions.
- Response binding to a request.
Getting started
Install
Add the NuGet package to your ASP.NET Core project:
dotnet add package LaDeak.HttpMessageSigner.AspNetCore
The package targets .NET and uses the ASP.NET Core framework.
Configure ASP.NET Core
The middleware needs a signing certificate with a private key. Configure its path and password using your normal configuration provider (for example, environment variables Signing__CertificatePath and Signing__CertificatePassword). Keep production private keys and passwords in a secure store; do not commit them to source control.
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using HttpMessageSigner.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignatureGenerator(x =>
{
x.Algorithm = "ecdsa-p256-sha256";
x.Components.Add("@method");
x.Components.Add("@path");
x.Components.Add("@authority");
x.Components.Add("@scheme");
x.Components.Add("@status");
x.Components.Add("Content-Digest");
x.IncludeCreated = true;
x.ContentDigestHashAlgorithm = System.Security.Cryptography.HashAlgorithmName.SHA256;
x.KeyId = "ecdsa256";
x.SigningCertificate = X509CertificateLoader.LoadPkcs12FromFile("<path to certificate>", "<cert password>", X509KeyStorageFlags.EphemeralKeySet | X509KeyStorageFlags.Exportable);
});
var app = builder.Build();
app.UseHttpsRedirection();
app.UseSignature();
app.MapGet("/hello", () => new { Message = "Hello, signed world!" });
app.Run();
The middleware hashes the response body to produce Content-Digest and signs it together with the configured request and response components. Where the server supports response trailers, the digest and signature are written as trailers, allowing the response body to stream without buffering (for example, over HTTP/2). For HTTP/1.1 responses, the middleware buffers the response so it can calculate the digest and add the signature before sending the response.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.