gpt4 book ai didi

c# - 什么是 NTLM/Authenticate/Negotiate Web 身份验证

转载 作者:行者123 更新时间:2023-12-02 20:03:15 29 4
gpt4 key购买 nike

我了解基本身份验证和摘要身份验证。但我已经搜索了很多,而且我正在为 NTLM、身份验证和协商而苦苦挣扎。

我认为,如果我错了,请纠正我,NTLM 和 Authenticate 是同一协议(protocol)的两个术语。

协商首先尝试 NTLM,然后回退到消化,然后回退到基本连接。

这样对吗?如果是的话,哪里有一个很好的例子说明如何在 C# 中连接仅用于 NTLM 和协商。

我有两个用例。首先是我需要下载一个文件。所以发出一个请求,得到一个 XML 文件作为响应,读下来,完成。

第二个是查询 OData,因此有成百上千个 Web 请求,每个请求都将提供 JSON(或 XML)作为响应。

最佳答案

Microsoft Negotiate is a security support provider (SSP) that acts as an application layer between Security Support Provider Interface (SSPI) and the other SSPs. When an application calls into SSPI to log on to a network, it can specify an SSP to process the request. If the application specifies Negotiate, Negotiate analyzes the request and picks the best SSP to handle the request based on customer-configured security policy.

https://learn.microsoft.com/en-us/windows/desktop/secauthn/microsoft-negotiate

正如文章 Negotiate does not fall back to digest 中给出的那样。在某种程度上,协商类似于 Kerberos,但具有 NTLM 的默认备份

Currently, the Negotiate security package selects between Kerberos and NTLM. Negotiate selects Kerberos unless it cannot be used by one of the systems involved in the authentication or the calling application did not provide sufficient information to use Kerberos.

Windows Challenge/Response (NTLM) is the authentication protocol used on networks that include systems running the Windows operating system and on stand-alone systems.

Authenticate 只是一种内部方法,不确定您为什么会对它和协议(protocol)感到困惑,在这里仔细看看内部结构:https://blogs.msdn.microsoft.com/dsnotes/2015/12/30/negotiate-vs-ntlm/

看待这个问题的方式是:

  1. Microsoft 最初提出了一种在 Windows 服务器/机器上进行身份验证的方法,他们称之为 NTLM ,这使用了请求/响应(有时称为挑战)方法。
  2. 随后他们提出了一个名为 Kerberos 的新协议(protocol),该协议(protocol)被采用。
  3. 为确保现有应用程序在旧版/新版中都能正常运行,我们有一种名为“协商”的新身份验证方法,它尝试了 Kerberos,如果无法使用,则使用 NTLM。

编辑 1:RFC 4559 中正式将这些身份验证机制应用于 Web .

编辑 2: NTLM 验证一个连接,而不是一个请求,而其他验证机制通常验证一个请求。在第一个用例中,这不应该有太大变化,但对于第二个用例,在保持单个连接的同时尝试 NTLM 是有意义的(通过使用 HTTP Keep-Alive,并在第一个请求中仅发送一次凭据)。可能存在性能差异。让我们了解您的最新结果。

取自 Microsoft docs 的示例 WebRequest 代码,您可以将 Webrequest 替换为 HttpWebRequest。

            // Create a request for the URL.   
WebRequest request = WebRequest.Create(
"http://www.contoso.com/default.html");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine(responseFromServer);
// Clean up the streams and the response.
reader.Close();
response.Close();

关于c# - 什么是 NTLM/Authenticate/Negotiate Web 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55348267/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com