【发布时间】:2018-07-30 02:50:28
【问题描述】:
我已经使用
创建了一个自签名证书openssl req -x509 -newkey rsa:2048 -keyout https-key.pem -out https.pem -days 365
然后我使用(我已将 CN 设置为服务器的 ip 地址)创建了 pkcs12:
openssl pkcs12 -export -out https.pfx -inkey https-key.pem -in https.pem -password pass:123456
在我的服务器中使用生成的 https.pfx 文件用于 https。
在我的客户端中,我将生成的证书导入 Windows 的 Trusted Root Certification Authorities(当前用户和本地系统)。
当我从客户端向服务器发送 HTTP 请求时,我得到了
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: A security error occurred
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task).
在 chrome 中它说:
Attackers might be trying to steal your information from *** (for example, passwords, messages, or credit cards). NET::ERR_CERT_AUTHORITY_INVALID
.NET Core 2.0 的 HttpClient 是否使用 Windows 证书存储?什么可能导致问题。
【问题讨论】:
-
我认为您遇到了 Windows 凭据问题。要让两台 PC 在 Windows 中进行通信,它们必须在同一个组中。如果您在公司网络中,则适用组策略,您需要带您的 MIS 人员将两台 PC 放在同一组中。网站通常具有访客凭据,因此不需要组。受信任的 Root 意味着两台 PC 在同一个组中,然后不需要密码,因为正在使用 Windows 凭据。使用 Windows 凭据时,用户必须在本地和远程 PC 上都有一个帐户。
-
@jdweng 我在同一台电脑上同时拥有客户端和服务器。
-
为什么你认为这是一个证书例外?通常,我看到的错误与您看到的认证错误不同。我会首先使用像wireshark或fiddler这样的嗅探器来获取更多关于错误的信息。还要确定您失败的代码中的确切指令。
-
您创建的证书是正确的 SSL 证书吗?此外,Chrome(至少)要求在接受证书之前在证书中设置 SAN。你设置正确吗?另外,您是否仅在受信任的根存储中或其他地方拥有证书?此外,在尝试您的 HTTP 客户端之前,请先检查其他客户端(其他浏览器等)以确认一切正常。
标签: c# ssl https asp.net-core .net-core