【问题标题】:Https Listener Certificate errorHTTPS 侦听器证书错误
【发布时间】:2018-07-13 14:12:08
【问题描述】:

我做了以下事情: httplistener-with-https-support 我通过所有步骤都没有出错,但现在如果我想连接到监听器,我会收到以下错误:

  1. 从 Chrome 我得到:“NET::ERR_CERT_COMMON_NAME_INVALID”
  2. 从 Edge 我得到:“DLG_FLAGS_SEC_CERT_CN_INVALID”
  3. 从 Firefox 我得到:“SEC_ERROR_UNKNOWN_ISSUER”

这是我的代码:

static void Main(string[] args)
    {
        var prefixes = "https://*:8080/";
        var listener = new HttpListener();
            listener.Prefixes.Add(prefixes);
        listener.Start();
        Console.WriteLine("Listening...");

        HttpListenerContext context = listener.GetContext();
        HttpListenerRequest request = context.Request;
        // Obtain a response object.
        HttpListenerResponse response = context.Response;
        // Construct a response.
        string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
        // Get a response stream and write the response to it.
        response.ContentLength64 = buffer.Length;
        System.IO.Stream output = response.OutputStream;
        output.Write(buffer, 0, buffer.Length);
        // You must close the output stream.
        Console.ReadKey();
        output.Close();
        listener.Stop();

这是我的认证:HERE

我做错了什么?

【问题讨论】:

  • 证书是谁颁发的?您在浏览器中使用的主机名是什么?证书适用于哪些域?
  • 我在浏览器中使用了 localhost,但我不知道证书中有哪些域。我只是做了这些步骤,我猜没有特定的域
  • 我最近使用 HTTPListener 实现了 HTTPS,并通过添加防火墙规则允许通过 LAN 进行通信。不需要任何输入,一切都由 C# 代码处理。我在这里分享了解决方案的完整代码:stackoverflow.com/a/58149405/983548

标签: .net x509certificate httplistener


【解决方案1】:

Edge 和 Chrome 都信任该证书,因为您将它放在 Windows 证书信任库中。他们都不喜欢它向“localhost”提供请求,因为您的证书似乎具有主题 CN 值 vMargeBySignedCA 并且没有主题备用名称扩展名。

Firefox 不使用 Windows 信任库,因此它不信任 CA(您需要将其添加到 Firefox 的信任库中)。在报告该名称在上下文中没有意义之前,它会报告未知的颁发者/不受信任的证书。

【讨论】:

  • 我仍然没有得到我需要做的事情。我将 ssl 证书的 CN 更改为我的主机名,但仍然出现相同的错误:/
  • 经过长时间的搜索,这对我在 power Shell 中有效New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\LocalMachine\My"
猜你喜欢
  • 2020-08-29
  • 2015-12-02
  • 2021-05-02
  • 2020-10-02
  • 2011-06-03
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
  • 2017-06-12
相关资源
最近更新 更多