【问题标题】:How to determine if binding of certificate to port has been done?如何确定证书与端口的绑定是否已完成?
【发布时间】:2015-12-15 22:30:22
【问题描述】:

我在一台机器上设置了一个 OWIN selfhost,我使用以下命令为特定端口注册了证书:

netsh http add sslcert ipport=0.0.0.0:8082 certhash=<cert_thumbprint_here> appid={00000000-0000-0000-0000-AABBCCDDEEFF}

我的 OWIN 主机已针对此 URL 启动:

using (WebApp.Start<OwinStartup>(url: https://my-pc:8082))
{
    // do stuff
}

我想知道的是是否可以使用 C# 确定证书是否绑定到此端口。基本上,我想检查我的应用程序是否已在用户的服务器上执行了 netsh 命令,因为 OWIN 在 https 上运行得很好,但没有人能够连接。

【问题讨论】:

  • 可以执行netsh http show sslcert ipport=0.0.0.0:8082并解析结果。可能还有一种使用 PowerShell 的方法,它可以让您免于解析结果。
  • 您可以PInvoke相关的HTTP API。明年我将开源 Jexus Manager,然后我可以向您展示一些示例代码。但是没有人可以连接到您的网站可能是由其他因素造成的,因此您应该深入研究。

标签: c# ssl ssl-certificate owin netsh


【解决方案1】:

要查找绑定是否已完成,您需要检查该特定端口发生的情况。
为此,您需要在 CMD 中执行如下命令:

netstat -o -n -a | find /c "0.0.0.0:8082"

此命令将在特定 IP (0.0.0.0) 和端口 (8082) 上为您提供没有活动的套接字

这是您可以使用 C# 执行的 CMD,如下所示:

            try
            {
                var configProc = new ProcessStartInfo();
                string cmdConfig = @"netstat -o -n -a | find /c "0.0.0.0:8082";
                configProc.UseShellExecute = true;

                configProc.WorkingDirectory = @"C:\Windows\System32";
                configProc.FileName = @"C:\Windows\System32\cmd.exe";
                configProc.Verb = "runas";
                configProc.Arguments = "/c " + cmdConfig;
                configProc.WindowStyle = ProcessWindowStyle.Hidden;
                Process.Start(configProc);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 2019-11-28
    • 2017-02-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多