2

我必须在本地网络上做一个对等应用程序,基本上是一个发布文件的服务,而本地网络上的另一个应用程序使用它。

我的想法是在服务中使用 WebAPI 并希望使用 SSL。用户将在本地安装这两个应用程序。这是一个可行的解决方案吗?如果是这样,我找到了这篇文章,但不知道如何获得证书。

4

2 回答 2

1

Yes - it's a feasible solution.

Here's a quick overview of what's going on behind the scenes when you've got SSL (or TLS) in the mix: http://www.moserware.com/2009/06/first-few-milliseconds-of-https.html

Specifically, you'll get two benefits from using HTTPS: - Encryption - Trust (as in, IF you've got certificates that identify each end-point, then you'll be able to be 'sure' that your client apps are connecting to each other and not, presumably, some 'sneak' on a laptop in the lobby/etc.)

The problem, then, is just finding some decent docs on how to get this all set up (and determining WHERE you're going to get your certs from (if they're self-signed (i.e., without your own/corporate signing authority or without a trusted 3rd party authority), then you can LOSE the trust benefit listed above).

In terms of docs, the following resource seem to be quite decent (though I've only GLANCED at it):

And, it appears that Matias has even created a Nuget package that should make this all tons easier to set up: http://nuget.org/packages/Auth10.AspNet.WebApi.ClientCert/

(I need to check that out myself - as I've only glanced at it.)

于 2013-06-07T05:39:52.567 回答
0

我把这个放在这里供参考;您的 certhash 问题的具体答案如下:

(这篇)文章比较详细地描述了如何在客户端/自托管 .net 应用程序上设置 HTTPS。

我可以使用我正在处理的在 Windows 服务下运行的自托管项目的变体跳过第 1 步,但如果您使用在用户下运行的控制台或其他应用程序,则绝对需要这样做。

如果您在 VB.NET 中工作,您的 MyHttpsSelfHostConfiguration 类将如下所示:

Imports System.ServiceModel.Channels
Imports System.Web.Http.SelfHost
Imports System.Web.Http.SelfHost.Channels

Public Class MyHttpsSelfHostConfiguration
    Inherits HttpSelfHostConfiguration
    Public Sub New(baseAddress As String)
        MyBase.New(baseAddress)
    End Sub
    Public Sub New(baseAddress As Uri)
        MyBase.New(baseAddress)
    End Sub
    Protected Overrides Function OnConfigureBinding(httpBinding As HttpBinding) As BindingParameterCollection
        httpBinding.Security.Mode = HttpBindingSecurityMode.Transport
        Return MyBase.OnConfigureBinding(httpBinding)
    End Function

End Class

此外,如果您选择在 Windows 服务而不是标准应用程序下运行它(此处供参考),您需要将'server As New HttpSelfHostServer(config)' 调暗,而不是使用 Using 子句,Windows 服务会立即处理 Using (或者我在别处读过)。

如果您选择的 REST 客户端(用于测试)未连接,请尝试在浏览器中指向您的服务方法(如果可能),因为浏览器会在尝试通过 https 通信时告诉您安装的证书是否存在问题。

我也很难获得证书。

您可以通过以下步骤执行此操作:

  1. 打开“MMC”
  2. 文件 > 添加管理单元 > 证书(计算机帐户/本地计算机)> 确定
  3. 打开证书管理单元 > 个人 > 证书,并找到具有服务器身份验证的预期目的的证书(在预期目的列中)
  4. 双击此证书。
  5. 转到详细信息选项卡,然后找到指纹键
  6. 复制此键的值。将其粘贴到记事本++中。
  7. 转到编码菜单,然后选择转换为 ANSI。这将显示一个隐藏字符“?” 在开始时,您必须删除。清除此数字中的空格,然后您可以将其用于您的证书哈希。

如果您在上述证书列表中没有证书,您可以通过以下步骤轻松创建一个(自签名):

  1. 打开 IIS 管理器
  2. 在 IIS 管理器中打开您的服务器
  3. 打开“服务器证书”页面
  4. 在右侧的“操作”下,选择“创建自签名证书”
于 2016-09-28T00:47:34.857 回答