php - GRPC 20908 ssl_transport_security.cc:1575] 找不到服务器名称的匹配项:0.0.0.0
问题描述
我的服务器和客户端在同一台机器上。我的服务器在 Node.js 中,我的客户端在 PHP 中。我的服务器在 0.0.0.0:50053 上运行,我的客户端是 127.0.0.1:80。因此,我的客户端向服务器发送请求,如果我使用不安全的连接,一切正常,但如果我添加 SSL(我使用双向 TLS),我的服务器会告诉我:
E0518 16:20:47.295923933 20908 ssl_transport_security.cc:1575] 找不到服务器名称的匹配项:0.0.0.0。
- 我用 CN(通用名称)制作了根证书:localhost(我的 CA 是我,同一台机器)-rootCA.crt。
- 我制作了服务器证书并使用 rootCA.crt CN(通用名称)签名:0.0.0.0 - server.crt。
- 我制作了客户端证书并使用 rootCA.crt CN(通用名称)签名:localhost - client.crt。
因此,看起来当我运行我的服务器时,它会检查证书,并且 CN (Common Name): 0.0.0.0 不是一个好名字。
因此,我将服务器的 IP 更改为 127.0.0.2,并为具有 CN(通用名称)的服务器创建了一个新证书:127.0.0.2。当我发送请求时,我得到:
21897 ssl_transport_security.cc:1575] 找不到服务器名称的匹配项:127.0.0.2。
同样的错误!
解决方案
将 ip 的名称更改为 localhost 示例对我有用。
$certificate = New-SelfSignedCertificate `
-Subject localhost `
-DnsName localhost `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-NotBefore (Get-Date) `
-NotAfter (Get-Date).AddYears(2) `
-CertStoreLocation "cert:CurrentUser\My" `
-FriendlyName "Localhost Certificate for .NET Core" `
-HashAlgorithm SHA256 `
-KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
$certificatePath = 'Cert:\CurrentUser\My\' + ($certificate.ThumbPrint)
创建临时证书路径
$tmpPath = "C:\tmp"
If(!(test-path $tmpPath))
{
New-Item -ItemType Directory -Force -Path $tmpPath
}
在此处设置证书密码
$pfxPassword = ConvertTo-SecureString -String "123abc456def" -Force -AsPlainText
$pfxFilePath = "c:\tmp\localhost.pfx"
$cerFilePath = "c:\tmp\localhost.cer"
创建 pfx 证书
Export-PfxCertificate -Cert $certificatePath -FilePath $pfxFilePath -Password $pfxPassword
Export-Certificate -Cert $certificatePath -FilePath $cerFilePath
导入 pfx 证书
Import-PfxCertificate -FilePath $pfxFilePath Cert:\LocalMachine\My -Password $pfxPassword -Exportable
通过将 pfx 证书导入受信任的根目录来信任证书
Import-Certificate -FilePath $cerFilePath -CertStoreLocation Cert:\CurrentUser\Root
这是一个powershell脚本
推荐阅读
- c - 如何用循环缓冲区解决这个问题?
- python-3.x - Mac 无法安装“dlib”
- matplotlib - matplotlib png 和 pdf 输出不同,线条坐标错误
- javascript - 连接 MongoDB 时出错:`openUri()` 的 `uri` 参数必须是字符串
- microsoft-graph-api - 无论日历组如何,是否可以从所有日历中获取所有事件
- graph - 如何在 Neo4J 中的箭头本身上显示关系船属性?
- scala - 如何重用数据框并使用 iloc 的替代方法在 Azure databricks 中运行迭代插补
- r - R:将以“阶段”开头的列中的所有值除以称为时间的列中的值:逐行
- python - 如果只执行 get 请求(并且忽略 cookie),Python 的 Requests 库线程是否安全?
- arrays - 我无法在 Angular [object Object] 错误中显示数据