2017-12-21 3 views
0

나는 LDAP 설정을 사용하여 응용 프로그램에 로그인 할 수있는 응용 프로그램을 작성 중입니다. 시작 TLS/LDAPS를 지원하지 않는 샘플 프로그램 :LDAP에 StartTLS 및 LDAPS 옵션을 추가하는 동안 클라이언트 인증서 확인

#include <windows.h> 
#include <winldap.h> 

int main(){ 
    LDAP *ldap =NULL; 
    int returnCode = -1; 
    int version = LDAP_VERSION3; 

    ldap = ldap_init(hostName, PORT); 
    if (ldap == NULL) { 
     printf("Failed to init LDAP connection"); 
     return FALSE; 
    } 

    returnCode = ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, (void*)&version); 
    if (returnCode != LDAP_SUCCESS) { 
     cout<<"LDAP: Could not set options. Error: "<< returnCode <<" "<< ldap_err2string(returnCode); 
     ldap_unbind(ldap); 
     return FALSE; 
    } 

    returnCode = ldap_connect(ldap, NULL); 
    if (returnCode != LDAP_SUCCESS) { 
     printf("LDAP: Could not establish connection. Error: %d %s", returnCode, ldap_err2string(returnCode)); 
     ldap_unbind(ldap); 
     return FALSE; 
    } 

    returnCode = ldap_bind_s(ldap, binddn, bindpwd, LDAP_AUTH_SIMPLE); 
    if (returnCode != LDAP_SUCCESS) { 
     printf("LDAP: Could not establish connection. Error: %d %s", returnCode, ldap_err2string(returnCode)); 
     ldap_unbind(ldap); 
     return FALSE; 
    } 
} 

StartTLS를가 ldap_start_tls_s 기능을 사용하여 구현 될 수있다. 하지만 연결을 허용하기 전에 인증서를 확인하고 싶습니다. 어떤 제안?

답변

1

StarTLS는 확장 LDAP 작업이므로 연결을 설정 한 후에 보내야합니다. 그러나 서버 및/또는 클라이언트 인증서 확인은 TLS 프로토콜의 일부입니다. 따라서 ldap_start_tls_s 기능을 사용하면 자동으로 수행됩니다.

연결시 서버 인증서를 확인하려면 SSL을 통한 LDAP를 사용해야하며 LDAPS 포트에 연결해야합니다. 이를 위해 ldap_sslinit() 메소드를 사용할 수 있습니다.