Skip to content
Docs Try Aspire

CertificateTrustConfigurationCallbackAnnotationContext Methods

Class Methods 1 member
Context provided to a CertificateTrustConfigurationCallbackAnnotation callback.
CreateCustomBundle(Func<X509Certificate2Collection, CancellationToken, Task<byte[]>>) Section titled CreateCustomBundle(Func<X509Certificate2Collection, CancellationToken, Task<byte[]>>) ReferenceExpression
Adds a custom certificate bundle to the callback context. The provided generator will be invoked during trust configuration and should return the bundle contents as a byte array.
public sealed class CertificateTrustConfigurationCallbackAnnotationContext
{
public ReferenceExpression CreateCustomBundle(
Func<X509Certificate2Collection, CancellationToken, Task<byte[]>> bundleGenerator)
{
// ...
}
}
bundleGenerator Func<X509Certificate2Collection, CancellationToken, Task<byte[]>> A function that generates the custom certificate bundle and returns the bundle contents as a byte array.
ReferenceExpression A ReferenceExpression that can be used to reference the custom bundle.
builder.AddContainer("my-java-app", "my-image:latest")
.WithCertificateTrustConfiguration(ctx =>
{
ctx
.EnvironmentVariables["JAVAX_NET_SSL_TRUSTSTORE"] = ctx
.CreateCustomBundle(
(certs, ct) =>
{
var pkcs12Builder = new Pkcs12Builder();
var safeContents = new Pkcs12SafeContents();
foreach (var cert in certs)
{
safeContents.AddCertificate(cert);
}
pkcs12Builder.AddSafeContentsUnencrypted(safeContents);
pkcs12Builder.SealWithMac(
string.Empty,
HashAlgorithmName.SHA256,
2048);
return Task.FromResult(pkcs12Builder.Encode());
});
return Task.CompletedTask;
});