我想问您一个有关使用SSPI和LDAP API与Kerberos实施相互认证的问题。

我正在使用: LDAP_SASL_BIND_S(GSSAPI) - 凭证结构应提供的内容.

这是我正在使用的算法:


//--------------------------------------------------------------------------------------------
// 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),并且它应包含服务器凭据,我必须传递给下一个初始化ecitizeSecurityContext Call。如果我使用该数据为以下呼叫构建secbufferdesc结构,则它将返回sec_e_invalid_token。

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

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

感谢您抽出宝贵的时间回答!胡安

有帮助吗?

解决方案

我发现了这个问题。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top