首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >根证书不是使用HTTP .NET 6与客户端证书一起发送的

根证书不是使用HTTP .NET 6与客户端证书一起发送的
EN

Stack Overflow用户
提问于 2022-06-09 11:05:36
回答 2查看 535关注 0票数 1

我有一个包含三个证书(和一个私钥)的p12文件。

  1. 客户证书
  2. 中间证书
  3. 根证书

使用openssl s_client连接是成功的,但是使用HTTP连接不是成功的。

检查Wireshark中的有效负载,我可以看到只发送了两个证书(1,2)和根(3)丢失。

我已经在我的和根证书中安装了当前用户和本地计算机中的证书,但是没有任何改变结果。证书应该安装在哪里?

有趣的是,使用var chain = new X509Chain(); chain.Build(certificate)正确地找到了所有中间证书。

更新:我尝试添加从链中解析的所有证书,但是结果是一样的。

代码

代码语言:javascript
运行
复制
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;

const string thumbprint = "";

using var store = new X509Store(StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false)[0];

var clientHandler = new HttpClientHandler
{
    ClientCertificateOptions = ClientCertificateOption.Manual,
    SslProtocols = SslProtocols.Tls12,
    ClientCertificates = { certificate }
};

var client = new HttpClient(clientHandler)
{
    BaseAddress = new Uri("url")
};

var response = await client.GetAsync(string.Empty);
// Exception:
//  The SSL connection could not be established, see inner exception.' -> 
//  AuthenticationException: Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure'.

我一直在跟踪的帖子,但对我来说不管用。

Update I从执行OpenSSL s_client时使用的crt文件中删除根证书,并更仔细地读取所有输出。似乎它从未起过作用..。

代码语言:javascript
运行
复制
139645152049040:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:s3_pkt.c:1493:SSL alert number 40
139645152049040:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:

我注意到输出的最后一部分

代码语言:javascript
运行
复制
SSL handshake has read 5917 bytes and written 2674 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID:
    Session-ID-ctx:
    Master-Key: 13838C2676F91215679A69B491D9117198CAD86B24CDBBFE6357A0D34B58317DD6F9C57FAFE99264CB73A94204280300
    Key-Arg   : None
    Krb5 Principal: None
    PSK identity: None
    PSK identity hint: None
    Start Time: 1654810361
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---

这给我的印象是一切都很好。我将回到证书和服务的提供者,因为我怀疑客户机证书CA不在服务器的允许列表中(在openssl输出中找不到),@Oliver在评论中指出了这一点。

很抱歉浪费了你的时间,谢谢你的感谢!

更新: @crypt32 32他们现在已经成功地在服务器上安装了必要的证书,并且它使用openssl

  1. 所有三份证书
  2. 中间和客户
  3. 只有客户端(在上面的所有文件中都包括私钥作为pem文件的一部分)

.NET (来自Windows)仍然不能工作。

更新:,它也是从.NET工作的!结案

EN

回答 2

Stack Overflow用户

发布于 2022-06-09 13:00:28

证书应该安装在哪里?

在连接到的服务器上。

背后的想法是,您将叶子和所有中间CA证书发送到服务器。服务器在收到证书时构建证书链。如果服务器无法找到根证书,则服务器不信任客户端证书,验证检查将失败。请求中存在根证书没有什么意义,因为服务器不会仅仅因为您发送了根证书就自动信任您的根。根证书必须显式安装在受信任根存储中的服务器上。

适用于服务器证书和客户端证书的RFC 5246§7.4.2摘录:

代码语言:javascript
运行
复制
certificate_list
      This is a sequence (chain) of certificates.  The sender's
      certificate MUST come first in the list.  Each following
      certificate MUST directly certify the one preceding it.  Because
      certificate validation requires that root keys be distributed
      independently, the self-signed certificate that specifies the root
      certificate authority MAY be omitted from the chain, under the
      assumption that the remote end must already possess it in order to
      validate it in any case.

换句话说,你没有什么可以做或不应该做的事。

票数 4
EN

Stack Overflow用户

发布于 2022-06-09 13:39:51

可以将此添加到客户端处理程序初始化中:

代码语言:javascript
运行
复制
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72559210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档