Я добавил для этого настройки, тогда запрос клиента вообще не отображается в приложении. В журнале сервера нет запроса. Похоже, что вместо того, чтобы игнорировать отзыв, TLS или сервер отклоняет сертификат до того, как он поступает в приложение.
Дополнительная информация:
- Используется TLS.
- Веб-сервер — только Kestrel.
- API — на Windows Server 2022.
public void ConfigureKestrel()
{
builder.WebHost.ConfigureKestrel((context, kestrelOptions) =>
{
kestrelOptions.ConfigureHttpsDefaults(httpOptions =>
{
httpOptions.ServerCertificate = serverCert;
httpOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
httpOptions.OnAuthenticate = (subCtx, sslOptions) =>
{
sslOptions.ClientCertificateRequired = false;
sslOptions.ServerCertificate = serverCert;
sslOptions.CertificateRevocationCheckMode = X509RevocationMode.NoCheck;
};
});
kestrelOptions.ListenAnyIP(httpsPort, listenOptions =>
{
listenOptions.UseHttps(ServerOptionsSelectionCallback, state: listenOptions.Protocols);
ValueTask ServerOptionsSelectionCallback(SslStream stream, SslClientHelloInfo clientHelloInfo, object? state, CancellationToken cancellationToken)
{
var serverOptions = new SslServerAuthenticationOptions
{
EnabledSslProtocols = SslProtocols.Tls12,// | SslProtocols.Tls13,
CertificateRevocationCheckMode = X509RevocationMode.NoCheck,
ServerCertificateContext = SslStreamCertificateContext.Create(serverCert, null, offline: true),
ClientCertificateRequired = false,
};
//ConfigureAlpn / Enable Http2
if (state == null)
{
throw new ArgumentNullException("The parameter is null.", nameof(state));
}
var httpProtocols = (HttpProtocols)state;
ConfigureAlpn(serverOptions, httpProtocols);
return new ValueTask(serverOptions);
}
void ConfigureAlpn(SslServerAuthenticationOptions serverOptions, HttpProtocols httpProtocols)
{
// .....
}
});
});
}
И при аутентификации:
builder.Services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
.AddCertificate(certOptions =>
{
//because of the self signed certificate it is "All"
certOptions.AllowedCertificateTypes = CertificateTypes.All;
certOptions.RevocationMode = X509RevocationMode.NoCheck;
//logic to check thumbnail of cert
OnChallenge = async chllgCtx =>
{
var cert = await chllgCtx.HttpContext.Connection.GetClientCertificateAsync();
_ = chllgCtx;
return;
},
OnAuthenticationFailed = failedCtx =>
{
_ = failedCtx;
return Task.CompletedTask;
},
OnCertificateValidated = async ctx =>
{
bool isValid = ValidateCert(clientCertificate);
if(isValid)
{
return ctx.Success();
}
ctx.Fail("certificate is not valid. ");
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... entication
Мобильная версия