首页 > 解决方案 > 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 (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。

同样的错误!

标签: phpnode.jssslgrpc

解决方案


将 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脚本


推荐阅读