1

我有一个面向外部的 Web 服务,但是我需要生成一个验证系统以确保请求来自有效的客户端。

假设原始 Web 服务定义如下:

[OperationContract]
public void Service.RequestMethod (string clientId, int reqNumber,
    string reqText)
{
    // do stuff with the parameters
}

我想确保请求实际上来自clientId参数指定的客户端。

我目前的计划是在方法签名中添加另一个参数,给出各种校验和。

[OperationContract]
public void Service.RequestMethod (string clientId, int reqNumber,
    string reqText, string reqChecksum)
{
    // verify reqChecksum, then
    // do stuff with the parameters
}

我需要一个函数来验证校验和是否由批准​​的客户端计算。它应该根据reqNumberreqText参数以及客户端和服务器都知道的特定于客户端的“密码”来计算。

实际上,它应该是:

private bool VerifyChecksum(int reqNumber, string reqText,
    string clientPassword, string reqChecksum)
{
    // hash reqNumber, reqTxt, and clientPassword
    // ensure it matches reqChecksum
}

有人对这个散列函数或整个模型有什么建议吗?

它需要特定于消息、特定于客户端且难以猜测(高熵)。

4

2 回答 2

1

您可能正在寻找某种MAC。像 MD5 这样的哈希值。MD5 的整个想法是将其应用于“一些”数据并获得一个值。只要“一些数据”部分不为所有人所知,那么价值的再现几乎是不可能的。

于 2009-04-07T05:44:01.120 回答
1

为什么不使用标准 Web 服务身份验证方法之一?您可以选择知名且广泛实施的解决方案,并且不会因为尝试同时传递参数和身份验证信息而弄乱您的界面。

You might still have an authorization problem if an authenticated client can pass more than one 'clientId', but again there are plenty of known solutions to this and it's entirely on your side. E.g., you could go as far as an ACL implementation that lists all acceptable (userId, clientId, methodname) combinations and forbids everything else.

于 2009-04-14T14:27:11.153 回答