Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

c# - .Net Core - Redirect Client certificate from Request

I have a Razor Pages app with the certificate authorization and an API service for it with the same authorization. These applications running under Nginx reverse proxy. Nginx also has certificate verification.

I need to redirect Client Certificate from application to an API through HttpClient. Can I redirect that way?

Here's the code I tried

private async Task<HttpClient> GetClient()
{
    var handler = new HttpClientHandler();
    var cert = await GetCertificate();
    handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
    handler.ClientCertificateOptions = ClientCertificateOption.Manual;
    handler.CheckCertificateRevocationList = false;
    handler.ServerCertificateCustomValidationCallback = delegate { return true; };
    handler.ClientCertificates.Add(cert);
    var client = new HttpClient(handler);
    return client;
}

private async Task<X509Certificate2> GetCertificate()
{
    return await _httpContext.HttpContext.Connection.GetClientCertificateAsync();
}

But the nginx response that certificate's not provided

<head><title>400 No required SSL certificate was sent</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<center>No required SSL certificate was sent</center>
<hr><center>nginx</center>
</body>

I've also tried without proxy but then API doesn't see certificate. If I add cert to the header manually it works, with forwarding service.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...