- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
Windows SSPI API是 Windows 安全服务的一个接口(interface),允许您相互验证客户端和服务器。 API 的主要用途之一是提供 Windows 集成身份验证,也称为单点登录 - 应用程序能够通过使用用户登录时的凭据自动向服务器验证用户身份。
这个过程的正常流程:
AcquireCredentialsHandle()
获取用户登录时创建的现有凭据的句柄。AcquireCredentialsHandle()
返回的句柄参与服务器的 SSPI 身份验证周期,使用 InitializeSecurityContext()
API。InitializeSecurityContext()
(客户端)和 AcceptSecurityContext()
交换不透明的字节数组(“ token ”) (服务器端)用于验证彼此 token 并继续身份验证周期的 API。当使用 API 作为单点登录的一部分时,这是此过程的正常流程。
AcquireCredentialsHandle()
的签名是:
SECURITY_STATUS SEC_Entry AcquireCredentialsHandle(
_In_ SEC_CHAR *pszPrincipal,
_In_ SEC_CHAR *pszPackage,
_In_ ULONG fCredentialUse,
_In_ PLUID pvLogonID,
_In_ PVOID pAuthData,
_In_ SEC_GET_KEY_FN pGetKeyFn,
_In_ PVOID pvGetKeyArgument,
_Out_ PCredHandle phCredential,
_Out_ PTimeStamp ptsExpiry
);
在上述典型的 Windows 集成身份验证案例中使用时,通常不提供 pAuthData
参数 - 而是提供空引用。
我希望能够以直接向其提供用户名和密码的方式使用 AcquireCredentialsHandle()
。它似乎可以处理这个问题,因为 pAuthData
参数(上面为 null)可以是对 SEC_WINNT_AUTH_IDENTITY
的引用结构,允许您直接指定用户名和密码。
我尝试以这种方式调用 AcquireCredentialsHandle()
,为其提供一个包含我的用户名和密码的完整 SEC_WINNT_AUTH_IDENTITY
结构。但是,每次我调用它时,我都会返回成功,即使我使用虚构的用户名或密码也是如此。作为健全性检查,我尝试使用相同的凭据调用 LogonUser()
,结果如预期的那样成功或失败,具体取决于我是否为其提供了有效的用户名/密码组合。
我做错了什么? 为什么即使凭据完全不正确,AcquireCredentialsHandle()
也总是返回成功?
下面显示了我用来调用 AcquireCredentialsHandle()
的代码的基础知识:
public class SuppliedCredential : Credential
{
public SuppliedCredential( string securityPackage, CredentialUse use, string username, string domain, string password ) :
base( securityPackage )
{
Init( use, username, domain, password );
}
private void Init( CredentialUse use, string username, string domain, string password )
{
// Copy off for the call, since this.SecurityPackage is a property.
string packageName = this.SecurityPackage;
TimeStamp rawExpiry = new TimeStamp();
SecurityStatus status = SecurityStatus.InternalError;
AuthIdentity auth = new AuthIdentity();
auth.User = username;
auth.UserLength = username.Length;
auth.Domain = domain;
auth.DomainLength = domain.Length;
auth.Password = password;
auth.PasswordLength = password.Length;
auth.Flags = 0x2; // unicode
this.Handle = new SafeCredentialHandle();
RuntimeHelpers.PrepareConstrainedRegions();
try { }
finally
{
status = CredentialNativeMethods.AcquireCredentialsHandle_2(
"",
packageName,
use,
IntPtr.Zero,
ref auth,
IntPtr.Zero,
IntPtr.Zero,
ref this.Handle.rawHandle,
ref rawExpiry
);
}
if( status != SecurityStatus.OK )
{
throw new SSPIException( "Failed to call AcquireCredentialHandle", status );
}
this.Expiry = rawExpiry.ToDateTime();
}
}
...
[StructLayout( LayoutKind.Sequential )]
public struct AuthIdentity
{
[MarshalAs(UnmanagedType.LPWStr)]
public string User;
public int UserLength;
[MarshalAs(UnmanagedType.LPWStr)]
public string Domain;
public int DomainLength;
[MarshalAs(UnmanagedType.LPWStr)]
public string Password;
public int PasswordLength;
public int Flags;
};
...
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )]
[DllImport( "Secur32.dll", EntryPoint = "AcquireCredentialsHandle", CharSet = CharSet.Unicode )]
internal static extern SecurityStatus AcquireCredentialsHandle_2(
string principleName,
string packageName,
CredentialUse credentialUse,
IntPtr loginId,
ref AuthIdentity packageData,
IntPtr getKeyFunc,
IntPtr getKeyData,
ref RawSspiHandle credentialHandle,
ref TimeStamp expiry
);
最佳答案
AcquireCredentialsHandle()
即使凭据是伪造的,也会返回 true;只有当客户端尝试调用 InitializeSecurityContext()
时,API 才会验证用户名和密码。 AcquireCredentialsHandle()
仅执行参数验证(指针值有效、结构填写正确、参数彼此有意义等)。由于我正确地提供了不正确的参数,AcquireCredentialsHandle()
没有在意。
...
总而言之,客户端应用程序参与 SSPI 身份验证的正常周期如下:
AcquireCredentialsHandle()
。InitializeSecurityContext()
,它返回一些 token 以发送到服务器。AcceptSecurityContext()
,返回一些 token 以发送回客户端。InitializeSecurityContext()
。在上述情况下,使用提供的 SEC_WINNT_AUTH_IDENTITY
结构调用 AcquireCredentialsHandle()
获得的凭据(依次填写有效的用户名、域和密码)是在客户端第一次调用 InitializeSecurityContext()
之前,在客户端将其第一个 token 发送到服务器之前进行验证。
在回答类似问题时,Dave Christiansen(微软员工?)posted the following在 2003 年 9 月 19 日的新闻组“microsoft.public.platformsdk.security”中:
How are you determining that the credentials are those of the localuser? SSPI is sometimes tricky this way. What package are you using(Sounds like NTLM, Kerberos, or Negotiate if you're usingSEC_WINNT_AUTH_IDENTITY)?
Note that AcquireCredentialsHandle will succeed even if thecredentials given are incorrect (e.g. wrong password), because itdoesn't actually use them until you call InitializeSecurityContext.
关于c# - 如何使用提供的凭据调用 SSPI 的 'AcquireCredentialsHandle'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45290882/
我正在开发一个 .NET 应用程序,我试图在其中构建数据库脚本。在构建项目时,我收到错误“无法创建 SSPI 上下文。”。此错误显示在输出窗口(VS2008 屏幕内)中,并且构建过程失败。请帮忙解决这
我使用的是 Windows XP Pro SP3。我想在我的代码中使用 SSPI 函数。我编译了我的代码,没有错误。 我将安全包设置为用于协商,这是推荐的。 当我启动我的程序时,Negotiate 无
我正在尝试创建一个 SEC_WINNT_AUTH_IDENTITY 以用于调用 AcquireCredentialsHandle 以获得此身份的凭据。但是我很难创建身份验证日期。 这是用于创建结构的代
当我在本地机器上运行 WCF 服务时,它工作正常。当我将相同的文件部署到我们的测试服务器时,当我的测试客户端尝试连接到 WCF 服务时出现此错误: Security Support Provider
我正在尝试调用托管在 IIS 上并应用了 Windows 身份验证安全性的 Web 服务。 我正在将 Delphi XE 与 INDY 10 和 TIdHttp 组件结合使用。 如果我传入有效的用户名
我在工作中遇到了一个问题,即我们使用 WCF 进行 SSO 的应用程序在与其他域通信时对域信任使用选择性身份验证失败。这是在服务器 2k8R2 机器上,它们的两个域都处于完整的 2k8R2 功能级别(
我的应用程序在两天前运行良好。我能够在实时应用程序上完全正常地发送推送通知,但突然我开始收到此错误 {System.Security.Authentication.AuthenticationExce
我有以下代码: public GetUserDataResponse GetUserDataFromService(X509Certificate2 certificate) { Channe
我想在Windows域环境(使用Kerberos)中使用Microsoft的安全支持提供程序接口(SSPI)在两个实体之间(在C ++中)发送加密和签名的消息。 根据MSDN中的文档,有两个函数Mak
try { _apnsStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", certificates, System.Se
我的项目出现了一些 fatal error ,错误来自 sspi.h,我必须定义一些东西,但我不知道是什么以及为什么,请有人解释。 sspi.h(60): fatal error C1189: #er
背景 Windows SSPI API是 Windows 安全服务的一个接口(interface),允许您相互验证客户端和服务器。 API 的主要用途之一是提供 Windows 集成身份验证,也称为单
我正在开发一个客户端-服务器应用程序,我希望客户端使用用户的登录凭据向服务器进行身份验证,但我不希望用户必须输入他们的用户名和密码。我当然不想负责安全处理密码。我只需要用户向我证明他们就是他们所说的那
我正在尝试访问 wcf 客户端。我知道人们现在正在从中获取信息,所以我知道它有效。我的问题是我似乎无法克服它。该服务是相互认证的服务。我在本地计算机上的个人商店中有适当的证书。即使这样,我也会遇到以下
在我们的 Windows C++ 应用程序中,我使用 InitializeSecurityContext() 客户端打开与运行 stunnel SSL 代理的服务器的 schannel 连接。我的代码
注:我设法取得了一些进展,请参阅我当前问题的编辑,谢谢。 我想在 Windows 上使用 libcurl 通过 Kerberos/GSSAPI 身份验证访问网站。我首先尝试使用 MIT Kerbero
我正在努力获取从计算机 A 到运行 SQL Server 的计算机 B 的 SQL Server 连接。 我在谷歌上进行了广泛的搜索,但我发现的所有东西都不起作用。他们也不会引导您一步步解决这个问题。
我有一个奇怪的问题:我在基于 .net2 的 c# 中编写了一个服务器和客户端,它们正在通过 .net 2 SslStream 聊天。 Cl和S之间有1个发送命令的连接,cl和s之间有1个发送文件的连
我有一个 Linux 服务器应用程序,它使用 Kerberos 进行客户端身份验证和需要在 Windows 上运行的客户端。 Kerberos 票证由 Windows Active Directory
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我是一名优秀的程序员,十分优秀!