在 ASP.Net 中编写自定义 NTLM 质询/响应
我知道您可以使用以下方法在 ASP.Net 应用程序中启用 NTLM 身份验证:
<authentication mode="Windows" />
但是 - 我需要在同一应用程序中处理表单、HTTP 和其他自定义身份验证,因此 ASP.Net 的内置支持有限是没有用的。
NTLM 握手应该相当简单:
Request - [unauthenticated - no user info passed]
Response - 401 Unauthorized
WWW-Authenticate: NTLM
Request - Authorization: NTLM <base64-encoded type-1-message>
Response - 401 Unauthorized
WWW-Authenticate: NTLM <base64-encoded type-2-message>
Request - Authorization: NTLM <base64-encoded type-3-message>
Server can now check username/password against LDAP from type-3 message
Response - 200 Ok [now authenticated & authorised]
因此,要推出自己的握手,我需要解析 type-1 和 type-3 消息并生成 type-2 em> 消息。
这些消息的结构是记录良好但相当复杂 - 看起来非常混乱编写我自己的消息生成器和解析器。我认为读写这些消息的方法应该已经在.Net中了,但我一直没能找到它们。
如何使用 .Net 构建和解析这些 NTLM 消息?
I know that you can enable NTLM authentication in an ASP.Net app using:
<authentication mode="Windows" />
However - I need to handle Forms, HTTP and other custom authentications in the same app, so ASP.Net's limited built-in support is no use.
The NTLM handshake should be fairly simple:
Request - [unauthenticated - no user info passed]
Response - 401 Unauthorized
WWW-Authenticate: NTLM
Request - Authorization: NTLM <base64-encoded type-1-message>
Response - 401 Unauthorized
WWW-Authenticate: NTLM <base64-encoded type-2-message>
Request - Authorization: NTLM <base64-encoded type-3-message>
Server can now check username/password against LDAP from type-3 message
Response - 200 Ok [now authenticated & authorised]
So to roll my own I need to parse type-1 and type-3 messages and generate a type-2 message.
The structure for those messages is well documented but fairly complex - it seems very messy to write my own message generators and parsers. I think the methods to read and write these messages should already be in .Net, but I haven't been able to find them.
How can I build and parse these NTLM messages using .Net?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cassini 支持 NTLM 身份验证,因此您可以使用源代码更轻松地创建解析 NTLM 授权消息的类。
http://cassinidev.codeplex.com/
Cassini supports NTLM authentication, so you could use the source to more easily create a class which parses the NTLM authorization messages.
http://cassinidev.codeplex.com/