【问题标题】:winldap can't connect to openldap with sslwinldap 无法使用 ssl 连接到 openldap
【发布时间】:2014-04-29 07:57:44
【问题描述】:

我可以通过这个命令查询服务器的数据

ldapsearch -H ldaps://CS-GAMEBOY-PC -x -b dc=micmiu,dc=com -D cn=Manager,dc=micmiu,dc=com -w secret

但是我无法通过winldap的示例代码查询数据(我删除了大部分错误句柄和资源清理以简化代码)

#include <iostream>

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

int main()
{                                
    char *LdapServer = "CS-GAMEBOY-PC";
    LDAP *ldap = ldap_sslinitA(LdapServer, LDAP_SSL_PORT, 1);    

    unsigned long version = LDAP_VERSION3;
    ldap_set_option(ldap,
                    LDAP_OPT_PROTOCOL_VERSION,
                    (void*)&version);              

    //  If SSL is not enabled, enable it.
    ldap_set_option(ldap, LDAP_OPT_SSL, LDAP_OPT_ON);        

    // Connect to the server.
    unsigned long connectSuccess = ldap_connect(ldap, NULL);
    if(connectSuccess == LDAP_SUCCESS){
        std::cout<<"ldap_connect succeeded \n";
    }else{
        std::cout<<"ldap_connect failed with "<<ldap_err2string(connectSuccess)<<std::endl;
        std::cout<<"error codes = 0x"<<std::hex<<connectSuccess<<std::endl;
        return -1;
    }            
}

ldap_connect 失败并给我错误代码“0X51”

服务器站点给我的错误为

....... tls_read: 想要=5 错误=未知错误 TLS 跟踪:SSL_accept:SSLv3 读取客户端证书 A 中的错误 TLS 跟踪:SSL_accept:SSLv3 读取客户端证书 A 中的错误 ........... tls_read: 想要=5 错误=未知错误 TLS 跟踪:SSL_accept:SSLv3 读取客户端证书 A 中的错误 TLS:无法接受:(未知)。

我应该如何解决这个问题?

【问题讨论】:

    标签: c++ windows ssl openssl ldap


    【解决方案1】:
     //
        static bool VerifyCert(void/*LDAP* ld, PCCERT_CONTEXT pServerCert*/)
        {
           return true;
        }
     //
    
    ..
    //  Set the version to 3.0 (default is 2.0). and than ->
    
        ldap_set_option(pLdapConnection, LDAP_OPT_SERVER_CERTIFICATE, &VerifyCert);
    
    // Now you can Bind.
    ..
    

    【讨论】:

      猜你喜欢
      • 2021-04-01
      • 2017-07-31
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 2015-09-29
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多