2

我正在处理的应用程序与在远程机器上运行的现有应用程序接口。与远程应用程序的通信是通过其公共 Web 服务进行的。我被要求构建一个增强功能,这将涉及客户端使用 Web 服务来处理需要安全传输的敏感数据。

谁能给我一些关于如何最好地进行的指示?

4

2 回答 2

4

首先,您应该使用 SSL 并拒绝任何未使用它的请求。这将加密通过 Internet 传输的数据。

如果您使用的是 SOAP,您可以在您的服务中定义一个自定义标头,该标头采用用户名/密码。然后,对于每个公共方法的第一行,针对数据库验证用户名和密码。如果成功,请适当设置 HttpContext.Current.User,您的服务将与内置的 Asp.NET 基础结构很好地结合。

添加:下面是一个示例 SoapHeader,其中包含用于身份验证的用户名/密码。

// define the header
public class AuthenticationHeader : SoapHeader
{
    public String UserName { get; set; }
    public String Password { get; set; }
}

// your service
public class PublicWebService : WebService
{
    // defines an instance of the header as part of the service
    public AuthenticationHeader Authentication;

    private void Authenticate()
    {
        // validate the username / password against a database
        // set the HttpContext.Current.User if successful.
        // Maybe throw a SoapException() if authentication fails
    }

    // Notice the SoapHeader("Authentication") attribute...
    // This tells ASP.Net to look for the incoming header for this method...
    [WebMethod]
    [SoapHeader("Authentication")]
    public void PublicMethod1()
    {
        Authenticate();

        // your code goes here
    }

    // Expose another method with the same authentication mechanism
    [WebMethod]
    [SoapHeader("Authentication")]
    public void PublicMethod2()
    {
        Authenticate();

        // your code goes here
    }
}

现在,如果您运行 wsdl 工具,生成的代理类将包含定义的身份验证标头:

PublicWebService s = new PublicWebService();
s.Authentication = new AuthenticationHeader();
s.Authentication.UserName = "xxxxxxxx";
s.Authentication.Password = "yyyyyyyy";
s.PublicMethod1();
s.PublicMethod2();
于 2010-11-18T13:45:24.850 回答
-1

DIY路线:

  1. 阅读安全性(从“秘密与谎言”和其他类似的一般书籍开始,然后再进入技术细节)

  2. 执行风险分析和线程评估。了解您要保护的内容、保护的内容以及威胁的来源。您不太可能需要“高安全性” 1

  3. 使用 TLS(又名 SSL)。

  4. 在客户端中,验证服务器的证书是否正确。

更好的途径:聘请一位享有盛誉的专家来帮助您。


1除非您真的在建造核武器工厂或类似设施。

于 2010-11-18T10:28:59.907 回答