1

我想问你一个关于使用 SSPI 和 LDAP API 使用 Kerberos 实现相互身份验证的问题。

我正在使用以下指南:ldap_sasl_bind_s(GSSAPI) - What should be provided in the credentials BERVAL structure

这是我正在使用的算法:


//--------------------------------------------------------------------------------------------
// client side

AcquireCredentialsHandle(NULL, "Kerberos", SECPKG_CRED_BOTH, NULL, &secIdent, NULL, NULL, &kClientCredential, &kClientTimeOut); 
// AcquireCredentialsHandle returns SEC_E_OK

// begin validation

unsigned long ulClientFlags = ISC_REQ_CONNECTION | ISC_REQ_MUTUAL_AUTH | ISC_REQ_DELEGATE;

int iCliStatus = InitializeSecurityContext(&kClientCredential, isContextNull(kClientContext) ? NULL : &kClientContext, 
                             pacTargetName, ulClientFlags, 0, SECURITY_NATIVE_DREP, pkServerToken, 
                             0, &kClientContext, &kClientToken, &ulContextAttr, NULL);

// InitializeSecurityContext returns SEC_I_CONTINUE_NEEDED

//--------------------------------------------------------------------------------------------
// server side

// ldap_init returns ok

ldap_set_option(ld, LDAP_OPT_SIGN, LDAP_OPT_OFF);
ldap_set_option(ld, LDAP_OPT_ENCRYPT, LDAP_OPT_OFF);

unsigned long ulVersion = LDAP_VERSION3;
ldap_set_option(ld, LDAP_OPT_VERSION, &ulVersion);

// ldap_connect returns LDAP_SUCCESS

// build the credentials based on what InitializeSecurityContext returned
BERVAL creds;
creds.bv_len = kClientToken.pBuffers[0].cbBuffer;
creds.bv_val = reinterpret_cast(kClientToken.pBuffers[0].pvBuffer);

BERVAL* pServerCreds = NULL;
int iError = ldap_sasl_bind_s(ld, "", "GSSAPI", &creds, NULL, NULL, &pServerCreds);

// ldap_sasl_bind_s returns LDAP_SUCCESS

unsigned long ulError = 0;
ldap_get_option(ld, LDAP_OPT_ERROR_NUMBER, &ulError);

// ulError is equal to LDAP_SASL_BIND_IN_PROGRESS

这就是问题所在:两个 LDAP 错误代码都可以,但 pServerCreds 指向一个空的 BERVAL 结构(不是 NULL,但 bv_len 等于 0),它应该包含我必须传递给下一个 InitializeSecurityContext 调用的服务器凭据。如果我使用该数据为以下调用构建 SecBufferDesc 结构,它将返回 SEC_E_INVALID_TOKEN。

ldap_sasl_bind_s 应该返回一个空的 BERVAL 还是我做错了什么?

我已经使用完整的 SSPI 调用(服务器的 AcceptSecurityContext)测试了身份验证,它按预期工作。问题是我需要服务器是跨平台的,所以我不能使用 SSPI。

感谢您花时间回答!胡安

4

1 回答 1

0

我发现了问题。

根据此线程ldap_sasl_bind_s,在 Windows XP 中返回空服务器凭据存在错误。我已经在 Windows 2008 Server 下测试了我的应用程序,并且正确返回了凭据。

于 2011-01-31T13:30:05.020 回答