如何安全地传送数据,从一个公共网服务
-
26-09-2019 - |
题
一个应用程序,我工作上的接口,与现有应用程序上运行的远程框。交流系统的远程是通过其公共网服务。我已经要求建立一个增强其将涉及一个客户使用的网络服务,处理敏感数据,这将需要传输的安全。
任何人都可以给我一些指针,关于如何最好地继续吗?
解决方案
要开始,你应该使用SSL,并拒绝在不使用任何请求。因为它是被通过互联网传输这将加密的数据。
如果您正在使用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();
其他提示
DIY路线:
阅读了安全(开始"秘密谎言"和其他这类一般书籍之前要的技术细节)
执行风险分析和线评估。明白什么你保护和从什么,并威胁将来自何方。你是不太可能需要的"高保安"1.
使用TLS(又名SSL)。
在客户,验证服务器的证明是正确的。
更好的途径: 采用专家,他已经建立的名声以帮助你。
1 除非你真的是建设核武器工厂或类似。
不隶属于 StackOverflow