【问题标题】:GRPC 20908 ssl_transport_security.cc:1575] No match found for server name: 0.0.0.0GRPC 20908 ssl_transport_security.cc:1575] 找不到服务器名称的匹配项:0.0.0.0
【发布时间】:2020-05-18 13:46:13
【问题描述】:

我的服务器和客户端在同一台机器上。我的服务器在 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。

同样的错误!

【问题讨论】:

    标签: php node.js ssl grpc


    【解决方案1】:

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

    【讨论】:

    • "将 ip 的名称更改为 localhost 示例对我有用。"您的意思是为服务器更改它?
    • 生成证书,正如我在 powershell 中向您展示的那样,为我在 .net 核心中的 gRPC 服务工作。
    猜你喜欢
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 2016-12-09
    相关资源
    最近更新 更多