![]() |
VOOZH | about |
dotnet add package Indice.Cryptography.AspNetCore --version 8.4.0
NuGet\Install-Package Indice.Cryptography.AspNetCore -Version 8.4.0
<PackageReference Include="Indice.Cryptography.AspNetCore" Version="8.4.0" />
<PackageVersion Include="Indice.Cryptography.AspNetCore" Version="8.4.0" />Directory.Packages.props
<PackageReference Include="Indice.Cryptography.AspNetCore" />Project file
paket add Indice.Cryptography.AspNetCore --version 8.4.0
#r "nuget: Indice.Cryptography.AspNetCore, 8.4.0"
#:package Indice.Cryptography.AspNetCore@8.4.0
#addin nuget:?package=Indice.Cryptography.AspNetCore&version=8.4.0Install as a Cake Addin
#tool nuget:?package=Indice.Cryptography.AspNetCore&version=8.4.0Install as a Cake Tool
ASP.NET Core extensions for the Indice.Cryptography library, providing certificate server capabilities and HTTP message signing middleware for web applications.
Install the package via NuGet Package Manager:
Install-Package Indice.Cryptography.AspNetCore
Or via .NET CLI:
dotnet add package Indice.Cryptography.AspNetCore
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Add certificate server
builder.Services.AddCertificateServer(builder.Environment, options => {
options.IssuerDomain = "ca.example.com";
options.PfxPassphrase = "your-secure-password";
});
// Add HTTP signatures
builder.Services.AddHttpSignatures(options => {
options.MapPath("/api/payments", "x-request-id", "(created)", "digest");
})
.AddSigningCredential(certificate);
var app = builder.Build();
// Configure middleware
app.UseHttpSignatures();
// Map certificate endpoints
app.MapCertificateStore();
app.Run();
builder.Services.AddCertificateServer(environment, options => {
options.IssuerDomain = "ca.example.com";
options.PfxPassphrase = "secure-ca-password";
options.Path = "/custom/cert/storage/path"; // Optional
// Add Entity Framework storage
options.AddEntityFrameworkStore(storeOptions => {
storeOptions.DefaultSchema = "certificates";
storeOptions.ConfigureDbContext = dbBuilder => {
dbBuilder.UseSqlServer(connectionString);
};
});
});
The certificate server automatically exposes the following REST endpoints:
| Method | Endpoint | Description |
|---|---|---|
GET |
/.certificates/ca.cer |
Download CA certificate |
POST |
/.certificates |
Create new certificate |
GET |
/.certificates/{keyId}.{format} |
Export certificate |
PUT |
/.certificates/{keyId}/revoke |
Revoke certificate |
GET |
/.certificates |
List certificates |
GET |
/.certificates/revoked.crl |
Certificate revocation list |
// POST /.certificates
var request = new Psd2CertificateRequest
{
City = "Athens",
State = "Attiki",
CountryCode = "GR",
Organization = "Example Bank",
OrganizationUnit = "IT",
CommonName = "api.example-bank.com",
AuthorityId = "BOG",
AuthorityName = "Bank of Greece",
AuthorizationNumber = "123456789",
ValidityInDays = 365,
Roles = new Psd2CertificateRequest.Psd2RoleFlags
{
Aisp = true,
Pisp = true,
Aspsp = false,
Piisp = false
},
QcType = QcTypeIdentifiers.Web
};
// The API will return a CertificateDetails object with metadata
// Export as different formats
GET /.certificates/{keyId}.cer // X.509 certificate (DER)
GET /.certificates/{keyId}.pem // PEM format
GET /.certificates/{keyId}.pfx // PKCS#12 with private key (requires password)
builder.Services.AddHttpSignatures(options => {
// Configure paths and headers to include in signatures
options.MapPath("/api/payments",
HeaderFieldNames.RequestTarget,
HeaderFieldNames.Created,
HttpDigest.HTTPHeaderName,
"x-request-id");
options.MapPath("/api/accounts/*",
HeaderFieldNames.RequestTarget,
HeaderFieldNames.Created);
// Global settings
options.RequestCreatedHeaderName = "x-created";
options.ForwardedPathHeaderName = "x-forwarded-path";
options.ResponseSigning = true; // Sign responses
})
.AddSigningCredential(certificate);
// Apply middleware (must be early in pipeline)
app.UseHttpSignatures();
The middleware supports various HTTP signature headers:
// Special header field names
HeaderFieldNames.RequestTarget // "(request-target)"
HeaderFieldNames.Created // "(created)"
HeaderFieldNames.Expires // "(expires)"
// Standard headers
HttpDigest.HTTPHeaderName // "digest"
"authorization"
"content-type"
"x-request-id"
// ... any custom headers
// The middleware automatically validates incoming signatures
// You can also manually validate:
var signature = HttpSignature.Parse(signatureHeader);
var isValid = signature.Validate(publicKey, httpRequest);
The library provides Entity Framework integration for persistent storage:
options.AddEntityFrameworkStore(storeOptions => {
storeOptions.DefaultSchema = "cert";
storeOptions.ConfigureDbContext = builder => {
builder.UseSqlServer(connectionString);
// Or any other EF Core provider
};
});
The database stores:
# Add migration for certificate schema
dotnet ef migrations add CertificateSchema
dotnet ef database update
The library includes a background service that automatically:
// Automatically registered when certificate store is configured
services.AddHostedService<CertificatesBackgroundService>();
// Implement custom storage
public class CustomCertificateStore : ICertificatesStore
{
public async Task<CertificateDetails> Add(X509Certificate2 certificate, Psd2CertificateRequest request)
{
// Custom storage logic
}
// ... implement other methods
}
// Register custom store
services.AddTransient<ICertificatesStore, CustomCertificateStore>();
// Custom validation key store
public class CustomValidationKeysStore : IHttpValidationKeysStore
{
public Task<SecurityKey[]> GetValidationKeysAsync()
{
// Return public keys for signature validation
}
}
services.AddSingleton<IHttpValidationKeysStore, CustomValidationKeysStore>();
// Custom signing credential store
public class CustomSigningCredentialsStore : IHttpSigningCredentialsStore
{
public Task<SigningCredentials> GetSigningCredentialsAsync()
{
// Return signing credentials
}
}
services.AddSingleton<IHttpSigningCredentialsStore, CustomSigningCredentialsStore>();
The certificate endpoints are automatically documented:
builder.Services.AddSwaggerGen(options => {
options.SwaggerDoc("cert", new OpenApiInfo
{
Title = "Certificate API",
Version = "v1"
});
// Include XML comments for better documentation
var xmlPath = Path.Combine(AppContext.BaseDirectory, "YourApp.xml");
options.IncludeXmlComments(xmlPath);
});
app.UseSwaggerUI(options => {
options.SwaggerEndpoint("/swagger/cert/swagger.json", "Certificate API");
});
// Production configuration
if (app.Environment.IsProduction())
{
// Use production certificate storage
options.Path = "/secure/certificate/storage";
// Enable HTTPS only
app.UseHttpsRedirection();
// Add security headers
app.UseHsts();
}
The library integrates with ASP.NET Core logging:
// Configure logging
builder.Logging.AddConsole();
builder.Logging.SetMinimumLevel(LogLevel.Information);
// The library will log:
// - Certificate creation and revocation
// - HTTP signature validation results
// - CA operations
// - Background service activities
// In test projects
var services = new ServiceCollection();
services.AddCertificateServer(environment, options => {
options.IssuerDomain = "test-ca.local";
options.Path = Path.GetTempPath();
});
services.AddHttpSignatures()
.AddSigningCredential(testCertificate);
var serviceProvider = services.BuildServiceProvider();
var factory = new WebApplicationFactory<Program>();
var client = factory.CreateClient();
// Test certificate creation
var response = await client.PostAsJsonAsync("/.certificates", request);
response.Should().BeSuccessful();
// Test signature validation
var signedRequest = new HttpRequestMessage(HttpMethod.Post, "/api/payments");
// Add signature headers...
var result = await client.SendAsync(signedRequest);
Contributions are welcome! Please:
This project is licensed under the MIT License.
For questions and support:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on Indice.Cryptography.AspNetCore:
| Package | Downloads |
|---|---|
|
Indice.Scalefin.Psd2Module
Package Description |
This package is not used by any popular GitHub repositories.
Expose header name.