Implementare l'autenticazione reciproca con API LDAP e SSPI
-
24-10-2019 - |
Domanda
Vorrei porle una domanda circa l'attuazione di autenticazione reciproca con Kerberos, utilizzando SSPI e API LDAP.
Sto usando le linee guida descritte in: ldap_sasl_bind_s (GSSAPI) - Quale dovrebbe essere fornita nel credenziali Berval struttura
.Questa è l'algoritmo che sto usando:
//--------------------------------------------------------------------------------------------
// 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
E qui è il problema: entrambi i codici di errore LDAP sono ok, ma pServerCreds punta a una struttura vuota Berval (non NULL, ma uguali bv_len a 0), e dovrebbe contenere il server credenziale devo passare a quello successivo InitializeSecurityContext chiamata. Se io uso che i dati per costruire la struttura SecBufferDesc per il seguente invito, restituisce SEC_E_INVALID_TOKEN.
È ldap_sasl_bind_s dovrebbe restituire un Berval vuoto o sto facendo qualcosa di sbagliato?
Ho testato l'autenticazione utilizzando le chiamate piene SSPI (AcceptSecurityContext per il server) e funziona come previsto. Il problema è che ho bisogno del server di essere cross-platform, quindi non posso usare SSPI.
Grazie per il tempo dedicato alla risposta! Juan
Soluzione
Ho trovato il problema.
questa discussione c'è un bug con ldap_sasl_bind_s
ritorno credenziali del server vuoti in Windows XP. Ho testato la mia applicazione in Windows 2008 Server e le credenziali sono correttamente restituito.