在 WCF 中验证调用者/服务器
我的场景:
- 许多位于我控制
- 范围之外的环境中的 WCF 客户端服务器要么是我的,要么位于我控制范围之外的环境中
,所以最坏的情况是客户端和服务器超出了我的控制范围。更具体地说,我可能假设托管此代码的人可能会尝试恶意冒充服务器或客户端(服务器更有可能)。但是,客户端需要验证服务器是我的代码,服务器需要验证客户端是我的代码。我已经看过所有使用证书的建议;但是,考虑到我的情况,这是一个选择吗?
我考虑过的一种方法是编写 IClientMessageInspector 和 IDispatchMessageInspector 来设置和验证双方的自定义 SOAP 标头。我将根据源代码中包含的密钥创建 HMAC 签名(假设我有办法隐藏它),然后根据消息正文验证摘要。
我觉得这会起作用;然而,我觉得这里可能缺少一些更开箱即用的东西。我是否已经接近、偏离轨道了?感谢您的指导!
My scenario:
- Many WCF clients which are in environments outside of my control
- Server will either be mine OR in an environment outside of my control
So worst case the client and the server is outside of my control. More specifically, I might assume that someone hosting this code could try to maliciously impersonate either the server or the client (the server being more likely). However, the client needs to verify that the server is my code and the server needs to verify that the client is my code. I've seen all the recommendations to use certificates; however, is that an option given my scenario?
One approach I've considered is to write an IClientMessageInspector and an IDispatchMessageInspector to set and verify a custom SOAP header on both sides. I would create an HMAC signature based on a secret key contained within the source code (assume I have a way to keep this hidden) and then verify the digest based on the message body.
I feel like this would work; however, I feel like there might be something more out-of-the-box that I'm missing here. Am I close, way off track? Thanks for any guidance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
证书绝对适合您的情况。
您的服务器将很容易被客户端验证,因为它将提供每个客户端都知道的证书,SSL 是一个不错的选择。
服务器还可以通过请求每个客户端提供证书来对客户端进行身份验证(服务器可以检查证书的特定颁发者 - 在这种情况下是您自己的颁发者)。
现在您只需要正确管理/保护您的证书服务器以确保它不会受到损害。
Certificates are definitely the way to go in your situation.
Your server will easily be authenticated by clients because it will provide a certificate known to each client, SSL is a good option here.
The server will also be able to authenticate clients by requesting that every client should provide a certificate (server can check for a specific issuer of the certificate - your own issuer in that case).
Now you just need to correctly manage/secure your certificate server to make sure that it won't be compromised.
我认为没有任何开箱即用的方法可以做到这一点,只是因为服务器验证调用服务的客户端上的代码是否是授权代码是一个不寻常的要求。
一般来说,按如下方式建立信任就足够了:
您试图采取额外的步骤来验证不仅验证了用户/机器,而且验证了正在运行的代码 - 这简直是矫枉过正。如果正在运行的代码未经过验证,则可能是:
I don't think there is anything out of the box to do this, simply because it is an unusual requirement for the server to verify that the code on the client calling the service is authorized code.
Generally, it is sufficient to establish trust as follows:
You are attempting to go the extra step to verify that not only are the users/machines verified, but also that the code running is verified - this is simply overkill. If the code running is not verified, either: