Back to index

openldap  2.4.31
tls_o.c
Go to the documentation of this file.
00001 /* tls_o.c - Handle tls/ssl using OpenSSL */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2008-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS: Rewritten by Howard Chu
00017  */
00018 
00019 #include "portable.h"
00020 
00021 #ifdef HAVE_OPENSSL
00022 
00023 #include "ldap_config.h"
00024 
00025 #include <stdio.h>
00026 
00027 #include <ac/stdlib.h>
00028 #include <ac/errno.h>
00029 #include <ac/socket.h>
00030 #include <ac/string.h>
00031 #include <ac/ctype.h>
00032 #include <ac/time.h>
00033 #include <ac/unistd.h>
00034 #include <ac/param.h>
00035 #include <ac/dirent.h>
00036 
00037 #include "ldap-int.h"
00038 #include "ldap-tls.h"
00039 
00040 #ifdef HAVE_OPENSSL_SSL_H
00041 #include <openssl/ssl.h>
00042 #include <openssl/x509v3.h>
00043 #include <openssl/err.h>
00044 #include <openssl/rand.h>
00045 #include <openssl/safestack.h>
00046 #elif defined( HAVE_SSL_H )
00047 #include <ssl.h>
00048 #endif
00049 
00050 typedef SSL_CTX tlso_ctx;
00051 typedef SSL tlso_session;
00052 
00053 static int  tlso_opt_trace = 1;
00054 
00055 static void tlso_report_error( void );
00056 
00057 static void tlso_info_cb( const SSL *ssl, int where, int ret );
00058 static int tlso_verify_cb( int ok, X509_STORE_CTX *ctx );
00059 static int tlso_verify_ok( int ok, X509_STORE_CTX *ctx );
00060 static RSA * tlso_tmp_rsa_cb( SSL *ssl, int is_export, int key_length );
00061 
00062 static DH * tlso_tmp_dh_cb( SSL *ssl, int is_export, int key_length );
00063 
00064 typedef struct dhplist {
00065        struct dhplist *next;
00066        int keylength;
00067        DH *param;
00068 } dhplist;
00069 
00070 static dhplist *tlso_dhparams;
00071 
00072 static int tlso_seed_PRNG( const char *randfile );
00073 
00074 #ifdef LDAP_R_COMPILE
00075 /*
00076  * provide mutexes for the OpenSSL library.
00077  */
00078 static ldap_pvt_thread_mutex_t     tlso_mutexes[CRYPTO_NUM_LOCKS];
00079 static ldap_pvt_thread_mutex_t     tlso_dh_mutex;
00080 
00081 static void tlso_locking_cb( int mode, int type, const char *file, int line )
00082 {
00083        if ( mode & CRYPTO_LOCK ) {
00084               ldap_pvt_thread_mutex_lock( &tlso_mutexes[type] );
00085        } else {
00086               ldap_pvt_thread_mutex_unlock( &tlso_mutexes[type] );
00087        }
00088 }
00089 
00090 static unsigned long tlso_thread_self( void )
00091 {
00092        /* FIXME: CRYPTO_set_id_callback only works when ldap_pvt_thread_t
00093         * is an integral type that fits in an unsigned long
00094         */
00095 
00096        /* force an error if the ldap_pvt_thread_t type is too large */
00097        enum { ok = sizeof( ldap_pvt_thread_t ) <= sizeof( unsigned long ) };
00098        typedef struct { int dummy: ok ? 1 : -1; } Check[ok ? 1 : -1];
00099 
00100        return (unsigned long) ldap_pvt_thread_self();
00101 }
00102 
00103 static void tlso_thr_init( void )
00104 {
00105        int i;
00106 
00107        for( i=0; i< CRYPTO_NUM_LOCKS ; i++ ) {
00108               ldap_pvt_thread_mutex_init( &tlso_mutexes[i] );
00109        }
00110        ldap_pvt_thread_mutex_init( &tlso_dh_mutex );
00111        CRYPTO_set_locking_callback( tlso_locking_cb );
00112        CRYPTO_set_id_callback( tlso_thread_self );
00113 }
00114 #endif /* LDAP_R_COMPILE */
00115 
00116 static STACK_OF(X509_NAME) *
00117 tlso_ca_list( char * bundle, char * dir )
00118 {
00119        STACK_OF(X509_NAME) *ca_list = NULL;
00120 
00121        if ( bundle ) {
00122               ca_list = SSL_load_client_CA_file( bundle );
00123        }
00124 #if defined(HAVE_DIRENT_H) || defined(dirent)
00125        if ( dir ) {
00126               int freeit = 0;
00127 
00128               if ( !ca_list ) {
00129                      ca_list = sk_X509_NAME_new_null();
00130                      freeit = 1;
00131               }
00132               if ( !SSL_add_dir_cert_subjects_to_stack( ca_list, dir ) &&
00133                      freeit ) {
00134                      sk_X509_NAME_free( ca_list );
00135                      ca_list = NULL;
00136               }
00137        }
00138 #endif
00139        return ca_list;
00140 }
00141 
00142 /*
00143  * Initialize TLS subsystem. Should be called only once.
00144  */
00145 static int
00146 tlso_init( void )
00147 {
00148        struct ldapoptions *lo = LDAP_INT_GLOBAL_OPT();   
00149 #ifdef HAVE_EBCDIC
00150        {
00151               char *file = LDAP_STRDUP( lo->ldo_tls_randfile );
00152               if ( file ) __atoe( file );
00153               (void) tlso_seed_PRNG( file );
00154               LDAP_FREE( file );
00155        }
00156 #else
00157        (void) tlso_seed_PRNG( lo->ldo_tls_randfile );
00158 #endif
00159 
00160        SSL_load_error_strings();
00161        SSL_library_init();
00162        OpenSSL_add_all_digests();
00163 
00164        /* FIXME: mod_ssl does this */
00165        X509V3_add_standard_extensions();
00166 
00167        return 0;
00168 }
00169 
00170 /*
00171  * Tear down the TLS subsystem. Should only be called once.
00172  */
00173 static void
00174 tlso_destroy( void )
00175 {
00176        struct ldapoptions *lo = LDAP_INT_GLOBAL_OPT();   
00177 
00178        EVP_cleanup();
00179        ERR_remove_state(0);
00180        ERR_free_strings();
00181 
00182        if ( lo->ldo_tls_randfile ) {
00183               LDAP_FREE( lo->ldo_tls_randfile );
00184               lo->ldo_tls_randfile = NULL;
00185        }
00186 }
00187 
00188 static tls_ctx *
00189 tlso_ctx_new( struct ldapoptions *lo )
00190 {
00191        return (tls_ctx *) SSL_CTX_new( SSLv23_method() );
00192 }
00193 
00194 static void
00195 tlso_ctx_ref( tls_ctx *ctx )
00196 {
00197        tlso_ctx *c = (tlso_ctx *)ctx;
00198        CRYPTO_add( &c->references, 1, CRYPTO_LOCK_SSL_CTX );
00199 }
00200 
00201 static void
00202 tlso_ctx_free ( tls_ctx *ctx )
00203 {
00204        tlso_ctx *c = (tlso_ctx *)ctx;
00205        SSL_CTX_free( c );
00206 }
00207 
00208 /*
00209  * initialize a new TLS context
00210  */
00211 static int
00212 tlso_ctx_init( struct ldapoptions *lo, struct ldaptls *lt, int is_server )
00213 {
00214        tlso_ctx *ctx = (tlso_ctx *)lo->ldo_tls_ctx;
00215        int i;
00216 
00217        if ( is_server ) {
00218               SSL_CTX_set_session_id_context( ctx,
00219                      (const unsigned char *) "OpenLDAP", sizeof("OpenLDAP")-1 );
00220        }
00221 
00222        if ( lo->ldo_tls_protocol_min > LDAP_OPT_X_TLS_PROTOCOL_SSL3 )
00223               SSL_CTX_set_options( ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 );
00224        else if ( lo->ldo_tls_protocol_min > LDAP_OPT_X_TLS_PROTOCOL_SSL2 )
00225               SSL_CTX_set_options( ctx, SSL_OP_NO_SSLv2 );
00226 
00227        if ( lo->ldo_tls_ciphersuite &&
00228               !SSL_CTX_set_cipher_list( ctx, lt->lt_ciphersuite ) )
00229        {
00230               Debug( LDAP_DEBUG_ANY,
00231                         "TLS: could not set cipher list %s.\n",
00232                         lo->ldo_tls_ciphersuite, 0, 0 );
00233               tlso_report_error();
00234               return -1;
00235        }
00236 
00237        if (lo->ldo_tls_cacertfile != NULL || lo->ldo_tls_cacertdir != NULL) {
00238               if ( !SSL_CTX_load_verify_locations( ctx,
00239                             lt->lt_cacertfile, lt->lt_cacertdir ) ||
00240                      !SSL_CTX_set_default_verify_paths( ctx ) )
00241               {
00242                      Debug( LDAP_DEBUG_ANY, "TLS: "
00243                             "could not load verify locations (file:`%s',dir:`%s').\n",
00244                             lo->ldo_tls_cacertfile ? lo->ldo_tls_cacertfile : "",
00245                             lo->ldo_tls_cacertdir ? lo->ldo_tls_cacertdir : "",
00246                             0 );
00247                      tlso_report_error();
00248                      return -1;
00249               }
00250 
00251               if ( is_server ) {
00252                      STACK_OF(X509_NAME) *calist;
00253                      /* List of CA names to send to a client */
00254                      calist = tlso_ca_list( lt->lt_cacertfile, lt->lt_cacertdir );
00255                      if ( !calist ) {
00256                             Debug( LDAP_DEBUG_ANY, "TLS: "
00257                                    "could not load client CA list (file:`%s',dir:`%s').\n",
00258                                    lo->ldo_tls_cacertfile ? lo->ldo_tls_cacertfile : "",
00259                                    lo->ldo_tls_cacertdir ? lo->ldo_tls_cacertdir : "",
00260                                    0 );
00261                             tlso_report_error();
00262                             return -1;
00263                      }
00264 
00265                      SSL_CTX_set_client_CA_list( ctx, calist );
00266               }
00267        }
00268 
00269        if ( lo->ldo_tls_certfile &&
00270               !SSL_CTX_use_certificate_file( ctx,
00271                      lt->lt_certfile, SSL_FILETYPE_PEM ) )
00272        {
00273               Debug( LDAP_DEBUG_ANY,
00274                      "TLS: could not use certificate `%s'.\n",
00275                      lo->ldo_tls_certfile,0,0);
00276               tlso_report_error();
00277               return -1;
00278        }
00279 
00280        /* Key validity is checked automatically if cert has already been set */
00281        if ( lo->ldo_tls_keyfile &&
00282               !SSL_CTX_use_PrivateKey_file( ctx,
00283                      lt->lt_keyfile, SSL_FILETYPE_PEM ) )
00284        {
00285               Debug( LDAP_DEBUG_ANY,
00286                      "TLS: could not use key file `%s'.\n",
00287                      lo->ldo_tls_keyfile,0,0);
00288               tlso_report_error();
00289               return -1;
00290        }
00291 
00292        if ( lo->ldo_tls_dhfile ) {
00293               DH *dh = NULL;
00294               BIO *bio;
00295               dhplist *p;
00296 
00297               if (( bio=BIO_new_file( lt->lt_dhfile,"r" )) == NULL ) {
00298                      Debug( LDAP_DEBUG_ANY,
00299                             "TLS: could not use DH parameters file `%s'.\n",
00300                             lo->ldo_tls_dhfile,0,0);
00301                      tlso_report_error();
00302                      return -1;
00303               }
00304               while (( dh=PEM_read_bio_DHparams( bio, NULL, NULL, NULL ))) {
00305                      p = LDAP_MALLOC( sizeof(dhplist) );
00306                      if ( p != NULL ) {
00307                             p->keylength = DH_size( dh ) * 8;
00308                             p->param = dh;
00309                             p->next = tlso_dhparams;
00310                             tlso_dhparams = p;
00311                      }
00312               }
00313               BIO_free( bio );
00314        }
00315 
00316        if ( tlso_opt_trace ) {
00317               SSL_CTX_set_info_callback( ctx, tlso_info_cb );
00318        }
00319 
00320        i = SSL_VERIFY_NONE;
00321        if ( lo->ldo_tls_require_cert ) {
00322               i = SSL_VERIFY_PEER;
00323               if ( lo->ldo_tls_require_cert == LDAP_OPT_X_TLS_DEMAND ||
00324                       lo->ldo_tls_require_cert == LDAP_OPT_X_TLS_HARD ) {
00325                      i |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
00326               }
00327        }
00328 
00329        SSL_CTX_set_verify( ctx, i,
00330               lo->ldo_tls_require_cert == LDAP_OPT_X_TLS_ALLOW ?
00331               tlso_verify_ok : tlso_verify_cb );
00332        SSL_CTX_set_tmp_rsa_callback( ctx, tlso_tmp_rsa_cb );
00333        if ( lo->ldo_tls_dhfile ) {
00334               SSL_CTX_set_tmp_dh_callback( ctx, tlso_tmp_dh_cb );
00335        }
00336 #ifdef HAVE_OPENSSL_CRL
00337        if ( lo->ldo_tls_crlcheck ) {
00338               X509_STORE *x509_s = SSL_CTX_get_cert_store( ctx );
00339               if ( lo->ldo_tls_crlcheck == LDAP_OPT_X_TLS_CRL_PEER ) {
00340                      X509_STORE_set_flags( x509_s, X509_V_FLAG_CRL_CHECK );
00341               } else if ( lo->ldo_tls_crlcheck == LDAP_OPT_X_TLS_CRL_ALL ) {
00342                      X509_STORE_set_flags( x509_s, 
00343                                    X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL  );
00344               }
00345        }
00346 #endif
00347        return 0;
00348 }
00349 
00350 static tls_session *
00351 tlso_session_new( tls_ctx *ctx, int is_server )
00352 {
00353        tlso_ctx *c = (tlso_ctx *)ctx;
00354        return (tls_session *)SSL_new( c );
00355 }
00356 
00357 static int
00358 tlso_session_connect( LDAP *ld, tls_session *sess )
00359 {
00360        tlso_session *s = (tlso_session *)sess;
00361 
00362        /* Caller expects 0 = success, OpenSSL returns 1 = success */
00363        return SSL_connect( s ) - 1;
00364 }
00365 
00366 static int
00367 tlso_session_accept( tls_session *sess )
00368 {
00369        tlso_session *s = (tlso_session *)sess;
00370 
00371        /* Caller expects 0 = success, OpenSSL returns 1 = success */
00372        return SSL_accept( s ) - 1;
00373 }
00374 
00375 static int
00376 tlso_session_upflags( Sockbuf *sb, tls_session *sess, int rc )
00377 {
00378        tlso_session *s = (tlso_session *)sess;
00379 
00380        /* 1 was subtracted above, offset it back now */
00381        rc = SSL_get_error(s, rc+1);
00382        if (rc == SSL_ERROR_WANT_READ) {
00383               sb->sb_trans_needs_read  = 1;
00384               return 1;
00385 
00386        } else if (rc == SSL_ERROR_WANT_WRITE) {
00387               sb->sb_trans_needs_write = 1;
00388               return 1;
00389 
00390        } else if (rc == SSL_ERROR_WANT_CONNECT) {
00391               return 1;
00392        }
00393        return 0;
00394 }
00395 
00396 static char *
00397 tlso_session_errmsg( tls_session *sess, int rc, char *buf, size_t len )
00398 {
00399        char err[256] = "";
00400        const char *certerr=NULL;
00401        tlso_session *s = (tlso_session *)sess;
00402 
00403        rc = ERR_peek_error();
00404        if ( rc ) {
00405               ERR_error_string_n( rc, err, sizeof(err) );
00406               if ( ( ERR_GET_LIB(rc) == ERR_LIB_SSL ) && 
00407                             ( ERR_GET_REASON(rc) == SSL_R_CERTIFICATE_VERIFY_FAILED ) ) {
00408                      int certrc = SSL_get_verify_result(s);
00409                      certerr = (char *)X509_verify_cert_error_string(certrc);
00410               }
00411               snprintf(buf, len, "%s%s%s%s", err, certerr ? " (" :"", 
00412                             certerr ? certerr : "", certerr ?  ")" : "" );
00413               return buf;
00414        }
00415        return NULL;
00416 }
00417 
00418 static int
00419 tlso_session_my_dn( tls_session *sess, struct berval *der_dn )
00420 {
00421        tlso_session *s = (tlso_session *)sess;
00422        X509 *x;
00423        X509_NAME *xn;
00424 
00425        x = SSL_get_certificate( s );
00426 
00427        if (!x) return LDAP_INVALID_CREDENTIALS;
00428        
00429        xn = X509_get_subject_name(x);
00430        der_dn->bv_len = i2d_X509_NAME( xn, NULL );
00431        der_dn->bv_val = xn->bytes->data;
00432        /* Don't X509_free, the session is still using it */
00433        return 0;
00434 }
00435 
00436 static X509 *
00437 tlso_get_cert( SSL *s )
00438 {
00439        /* If peer cert was bad, treat as if no cert was given */
00440        if (SSL_get_verify_result(s)) {
00441               return NULL;
00442        }
00443        return SSL_get_peer_certificate(s);
00444 }
00445 
00446 static int
00447 tlso_session_peer_dn( tls_session *sess, struct berval *der_dn )
00448 {
00449        tlso_session *s = (tlso_session *)sess;
00450        X509 *x = tlso_get_cert( s );
00451        X509_NAME *xn;
00452 
00453        if ( !x )
00454               return LDAP_INVALID_CREDENTIALS;
00455 
00456        xn = X509_get_subject_name(x);
00457        der_dn->bv_len = i2d_X509_NAME( xn, NULL );
00458        der_dn->bv_val = xn->bytes->data;
00459        X509_free(x);
00460        return 0;
00461 }
00462 
00463 /* what kind of hostname were we given? */
00464 #define       IS_DNS 0
00465 #define       IS_IP4 1
00466 #define       IS_IP6 2
00467 
00468 static int
00469 tlso_session_chkhost( LDAP *ld, tls_session *sess, const char *name_in )
00470 {
00471        tlso_session *s = (tlso_session *)sess;
00472        int i, ret = LDAP_LOCAL_ERROR;
00473        X509 *x;
00474        const char *name;
00475        char *ptr;
00476        int ntype = IS_DNS, nlen;
00477 #ifdef LDAP_PF_INET6
00478        struct in6_addr addr;
00479 #else
00480        struct in_addr addr;
00481 #endif
00482 
00483        if( ldap_int_hostname &&
00484               ( !name_in || !strcasecmp( name_in, "localhost" ) ) )
00485        {
00486               name = ldap_int_hostname;
00487        } else {
00488               name = name_in;
00489        }
00490        nlen = strlen(name);
00491 
00492        x = tlso_get_cert(s);
00493        if (!x) {
00494               Debug( LDAP_DEBUG_ANY,
00495                      "TLS: unable to get peer certificate.\n",
00496                      0, 0, 0 );
00497               /* If this was a fatal condition, things would have
00498                * aborted long before now.
00499                */
00500               return LDAP_SUCCESS;
00501        }
00502 
00503 #ifdef LDAP_PF_INET6
00504        if (inet_pton(AF_INET6, name, &addr)) {
00505               ntype = IS_IP6;
00506        } else 
00507 #endif
00508        if ((ptr = strrchr(name, '.')) && isdigit((unsigned char)ptr[1])) {
00509               if (inet_aton(name, (struct in_addr *)&addr)) ntype = IS_IP4;
00510        }
00511        
00512        i = X509_get_ext_by_NID(x, NID_subject_alt_name, -1);
00513        if (i >= 0) {
00514               X509_EXTENSION *ex;
00515               STACK_OF(GENERAL_NAME) *alt;
00516 
00517               ex = X509_get_ext(x, i);
00518               alt = X509V3_EXT_d2i(ex);
00519               if (alt) {
00520                      int n, len2 = 0;
00521                      char *domain = NULL;
00522                      GENERAL_NAME *gn;
00523 
00524                      if (ntype == IS_DNS) {
00525                             domain = strchr(name, '.');
00526                             if (domain) {
00527                                    len2 = nlen - (domain-name);
00528                             }
00529                      }
00530                      n = sk_GENERAL_NAME_num(alt);
00531                      for (i=0; i<n; i++) {
00532                             char *sn;
00533                             int sl;
00534                             gn = sk_GENERAL_NAME_value(alt, i);
00535                             if (gn->type == GEN_DNS) {
00536                                    if (ntype != IS_DNS) continue;
00537 
00538                                    sn = (char *) ASN1_STRING_data(gn->d.ia5);
00539                                    sl = ASN1_STRING_length(gn->d.ia5);
00540 
00541                                    /* ignore empty */
00542                                    if (sl == 0) continue;
00543 
00544                                    /* Is this an exact match? */
00545                                    if ((nlen == sl) && !strncasecmp(name, sn, nlen)) {
00546                                           break;
00547                                    }
00548 
00549                                    /* Is this a wildcard match? */
00550                                    if (domain && (sn[0] == '*') && (sn[1] == '.') &&
00551                                           (len2 == sl-1) && !strncasecmp(domain, &sn[1], len2))
00552                                    {
00553                                           break;
00554                                    }
00555 
00556                             } else if (gn->type == GEN_IPADD) {
00557                                    if (ntype == IS_DNS) continue;
00558 
00559                                    sn = (char *) ASN1_STRING_data(gn->d.ia5);
00560                                    sl = ASN1_STRING_length(gn->d.ia5);
00561 
00562 #ifdef LDAP_PF_INET6
00563                                    if (ntype == IS_IP6 && sl != sizeof(struct in6_addr)) {
00564                                           continue;
00565                                    } else
00566 #endif
00567                                    if (ntype == IS_IP4 && sl != sizeof(struct in_addr)) {
00568                                           continue;
00569                                    }
00570                                    if (!memcmp(sn, &addr, sl)) {
00571                                           break;
00572                                    }
00573                             }
00574                      }
00575 
00576                      GENERAL_NAMES_free(alt);
00577                      if (i < n) {  /* Found a match */
00578                             ret = LDAP_SUCCESS;
00579                      }
00580               }
00581        }
00582 
00583        if (ret != LDAP_SUCCESS) {
00584               X509_NAME *xn;
00585               X509_NAME_ENTRY *ne;
00586               ASN1_OBJECT *obj;
00587               ASN1_STRING *cn = NULL;
00588               int navas;
00589 
00590               /* find the last CN */
00591               obj = OBJ_nid2obj( NID_commonName );
00592               if ( !obj ) goto no_cn;     /* should never happen */
00593 
00594               xn = X509_get_subject_name(x);
00595               navas = X509_NAME_entry_count( xn );
00596               for ( i=navas-1; i>=0; i-- ) {
00597                      ne = X509_NAME_get_entry( xn, i );
00598                      if ( !OBJ_cmp( ne->object, obj )) {
00599                             cn = X509_NAME_ENTRY_get_data( ne );
00600                             break;
00601                      }
00602               }
00603 
00604               if( !cn )
00605               {
00606 no_cn:
00607                      Debug( LDAP_DEBUG_ANY,
00608                             "TLS: unable to get common name from peer certificate.\n",
00609                             0, 0, 0 );
00610                      ret = LDAP_CONNECT_ERROR;
00611                      if ( ld->ld_error ) {
00612                             LDAP_FREE( ld->ld_error );
00613                      }
00614                      ld->ld_error = LDAP_STRDUP(
00615                             _("TLS: unable to get CN from peer certificate"));
00616 
00617               } else if ( cn->length == nlen &&
00618                      strncasecmp( name, (char *) cn->data, nlen ) == 0 ) {
00619                      ret = LDAP_SUCCESS;
00620 
00621               } else if (( cn->data[0] == '*' ) && ( cn->data[1] == '.' )) {
00622                      char *domain = strchr(name, '.');
00623                      if( domain ) {
00624                             int dlen;
00625 
00626                             dlen = nlen - (domain-name);
00627 
00628                             /* Is this a wildcard match? */
00629                             if ((dlen == cn->length-1) &&
00630                                    !strncasecmp(domain, (char *) &cn->data[1], dlen)) {
00631                                    ret = LDAP_SUCCESS;
00632                             }
00633                      }
00634               }
00635 
00636               if( ret == LDAP_LOCAL_ERROR ) {
00637                      Debug( LDAP_DEBUG_ANY, "TLS: hostname (%s) does not match "
00638                             "common name in certificate (%.*s).\n", 
00639                             name, cn->length, cn->data );
00640                      ret = LDAP_CONNECT_ERROR;
00641                      if ( ld->ld_error ) {
00642                             LDAP_FREE( ld->ld_error );
00643                      }
00644                      ld->ld_error = LDAP_STRDUP(
00645                             _("TLS: hostname does not match CN in peer certificate"));
00646               }
00647        }
00648        X509_free(x);
00649        return ret;
00650 }
00651 
00652 static int
00653 tlso_session_strength( tls_session *sess )
00654 {
00655        tlso_session *s = (tlso_session *)sess;
00656 
00657        return SSL_CIPHER_get_bits(SSL_get_current_cipher(s), NULL);
00658 }
00659 
00660 /*
00661  * TLS support for LBER Sockbufs
00662  */
00663 
00664 struct tls_data {
00665        tlso_session         *session;
00666        Sockbuf_IO_Desc             *sbiod;
00667 };
00668 
00669 static int
00670 tlso_bio_create( BIO *b ) {
00671        b->init = 1;
00672        b->num = 0;
00673        b->ptr = NULL;
00674        b->flags = 0;
00675        return 1;
00676 }
00677 
00678 static int
00679 tlso_bio_destroy( BIO *b )
00680 {
00681        if ( b == NULL ) return 0;
00682 
00683        b->ptr = NULL;              /* sb_tls_remove() will free it */
00684        b->init = 0;
00685        b->flags = 0;
00686        return 1;
00687 }
00688 
00689 static int
00690 tlso_bio_read( BIO *b, char *buf, int len )
00691 {
00692        struct tls_data             *p;
00693        int                  ret;
00694               
00695        if ( buf == NULL || len <= 0 ) return 0;
00696 
00697        p = (struct tls_data *)b->ptr;
00698 
00699        if ( p == NULL || p->sbiod == NULL ) {
00700               return 0;
00701        }
00702 
00703        ret = LBER_SBIOD_READ_NEXT( p->sbiod, buf, len );
00704 
00705        BIO_clear_retry_flags( b );
00706        if ( ret < 0 ) {
00707               int err = sock_errno();
00708               if ( err == EAGAIN || err == EWOULDBLOCK ) {
00709                      BIO_set_retry_read( b );
00710               }
00711        }
00712 
00713        return ret;
00714 }
00715 
00716 static int
00717 tlso_bio_write( BIO *b, const char *buf, int len )
00718 {
00719        struct tls_data             *p;
00720        int                  ret;
00721        
00722        if ( buf == NULL || len <= 0 ) return 0;
00723        
00724        p = (struct tls_data *)b->ptr;
00725 
00726        if ( p == NULL || p->sbiod == NULL ) {
00727               return 0;
00728        }
00729 
00730        ret = LBER_SBIOD_WRITE_NEXT( p->sbiod, (char *)buf, len );
00731 
00732        BIO_clear_retry_flags( b );
00733        if ( ret < 0 ) {
00734               int err = sock_errno();
00735               if ( err == EAGAIN || err == EWOULDBLOCK ) {
00736                      BIO_set_retry_write( b );
00737               }
00738        }
00739 
00740        return ret;
00741 }
00742 
00743 static long
00744 tlso_bio_ctrl( BIO *b, int cmd, long num, void *ptr )
00745 {
00746        if ( cmd == BIO_CTRL_FLUSH ) {
00747               /* The OpenSSL library needs this */
00748               return 1;
00749        }
00750        return 0;
00751 }
00752 
00753 static int
00754 tlso_bio_gets( BIO *b, char *buf, int len )
00755 {
00756        return -1;
00757 }
00758 
00759 static int
00760 tlso_bio_puts( BIO *b, const char *str )
00761 {
00762        return tlso_bio_write( b, str, strlen( str ) );
00763 }
00764        
00765 static BIO_METHOD tlso_bio_method =
00766 {
00767        ( 100 | 0x400 ),            /* it's a source/sink BIO */
00768        "sockbuf glue",
00769        tlso_bio_write,
00770        tlso_bio_read,
00771        tlso_bio_puts,
00772        tlso_bio_gets,
00773        tlso_bio_ctrl,
00774        tlso_bio_create,
00775        tlso_bio_destroy
00776 };
00777 
00778 static int
00779 tlso_sb_setup( Sockbuf_IO_Desc *sbiod, void *arg )
00780 {
00781        struct tls_data             *p;
00782        BIO                  *bio;
00783 
00784        assert( sbiod != NULL );
00785 
00786        p = LBER_MALLOC( sizeof( *p ) );
00787        if ( p == NULL ) {
00788               return -1;
00789        }
00790        
00791        p->session = arg;
00792        p->sbiod = sbiod;
00793        bio = BIO_new( &tlso_bio_method );
00794        bio->ptr = (void *)p;
00795        SSL_set_bio( p->session, bio, bio );
00796        sbiod->sbiod_pvt = p;
00797        return 0;
00798 }
00799 
00800 static int
00801 tlso_sb_remove( Sockbuf_IO_Desc *sbiod )
00802 {
00803        struct tls_data             *p;
00804        
00805        assert( sbiod != NULL );
00806        assert( sbiod->sbiod_pvt != NULL );
00807 
00808        p = (struct tls_data *)sbiod->sbiod_pvt;
00809        SSL_free( p->session );
00810        LBER_FREE( sbiod->sbiod_pvt );
00811        sbiod->sbiod_pvt = NULL;
00812        return 0;
00813 }
00814 
00815 static int
00816 tlso_sb_close( Sockbuf_IO_Desc *sbiod )
00817 {
00818        struct tls_data             *p;
00819        
00820        assert( sbiod != NULL );
00821        assert( sbiod->sbiod_pvt != NULL );
00822 
00823        p = (struct tls_data *)sbiod->sbiod_pvt;
00824        SSL_shutdown( p->session );
00825        return 0;
00826 }
00827 
00828 static int
00829 tlso_sb_ctrl( Sockbuf_IO_Desc *sbiod, int opt, void *arg )
00830 {
00831        struct tls_data             *p;
00832        
00833        assert( sbiod != NULL );
00834        assert( sbiod->sbiod_pvt != NULL );
00835 
00836        p = (struct tls_data *)sbiod->sbiod_pvt;
00837        
00838        if ( opt == LBER_SB_OPT_GET_SSL ) {
00839               *((tlso_session **)arg) = p->session;
00840               return 1;
00841 
00842        } else if ( opt == LBER_SB_OPT_DATA_READY ) {
00843               if( SSL_pending( p->session ) > 0 ) {
00844                      return 1;
00845               }
00846        }
00847        
00848        return LBER_SBIOD_CTRL_NEXT( sbiod, opt, arg );
00849 }
00850 
00851 static ber_slen_t
00852 tlso_sb_read( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
00853 {
00854        struct tls_data             *p;
00855        ber_slen_t           ret;
00856        int                  err;
00857 
00858        assert( sbiod != NULL );
00859        assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
00860 
00861        p = (struct tls_data *)sbiod->sbiod_pvt;
00862 
00863        ret = SSL_read( p->session, (char *)buf, len );
00864 #ifdef HAVE_WINSOCK
00865        errno = WSAGetLastError();
00866 #endif
00867        err = SSL_get_error( p->session, ret );
00868        if (err == SSL_ERROR_WANT_READ ) {
00869               sbiod->sbiod_sb->sb_trans_needs_read = 1;
00870               sock_errset(EWOULDBLOCK);
00871        }
00872        else
00873               sbiod->sbiod_sb->sb_trans_needs_read = 0;
00874        return ret;
00875 }
00876 
00877 static ber_slen_t
00878 tlso_sb_write( Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
00879 {
00880        struct tls_data             *p;
00881        ber_slen_t           ret;
00882        int                  err;
00883 
00884        assert( sbiod != NULL );
00885        assert( SOCKBUF_VALID( sbiod->sbiod_sb ) );
00886 
00887        p = (struct tls_data *)sbiod->sbiod_pvt;
00888 
00889        ret = SSL_write( p->session, (char *)buf, len );
00890 #ifdef HAVE_WINSOCK
00891        errno = WSAGetLastError();
00892 #endif
00893        err = SSL_get_error( p->session, ret );
00894        if (err == SSL_ERROR_WANT_WRITE ) {
00895               sbiod->sbiod_sb->sb_trans_needs_write = 1;
00896               sock_errset(EWOULDBLOCK);
00897 
00898        } else {
00899               sbiod->sbiod_sb->sb_trans_needs_write = 0;
00900        }
00901        return ret;
00902 }
00903 
00904 static Sockbuf_IO tlso_sbio =
00905 {
00906        tlso_sb_setup,              /* sbi_setup */
00907        tlso_sb_remove,             /* sbi_remove */
00908        tlso_sb_ctrl,        /* sbi_ctrl */
00909        tlso_sb_read,        /* sbi_read */
00910        tlso_sb_write,              /* sbi_write */
00911        tlso_sb_close        /* sbi_close */
00912 };
00913 
00914 /* Derived from openssl/apps/s_cb.c */
00915 static void
00916 tlso_info_cb( const SSL *ssl, int where, int ret )
00917 {
00918        int w;
00919        char *op;
00920        char *state = (char *) SSL_state_string_long( (SSL *)ssl );
00921 
00922        w = where & ~SSL_ST_MASK;
00923        if ( w & SSL_ST_CONNECT ) {
00924               op = "SSL_connect";
00925        } else if ( w & SSL_ST_ACCEPT ) {
00926               op = "SSL_accept";
00927        } else {
00928               op = "undefined";
00929        }
00930 
00931 #ifdef HAVE_EBCDIC
00932        if ( state ) {
00933               state = LDAP_STRDUP( state );
00934               __etoa( state );
00935        }
00936 #endif
00937        if ( where & SSL_CB_LOOP ) {
00938               Debug( LDAP_DEBUG_TRACE,
00939                         "TLS trace: %s:%s\n",
00940                         op, state, 0 );
00941 
00942        } else if ( where & SSL_CB_ALERT ) {
00943               char *atype = (char *) SSL_alert_type_string_long( ret );
00944               char *adesc = (char *) SSL_alert_desc_string_long( ret );
00945               op = ( where & SSL_CB_READ ) ? "read" : "write";
00946 #ifdef HAVE_EBCDIC
00947               if ( atype ) {
00948                      atype = LDAP_STRDUP( atype );
00949                      __etoa( atype );
00950               }
00951               if ( adesc ) {
00952                      adesc = LDAP_STRDUP( adesc );
00953                      __etoa( adesc );
00954               }
00955 #endif
00956               Debug( LDAP_DEBUG_TRACE,
00957                         "TLS trace: SSL3 alert %s:%s:%s\n",
00958                         op, atype, adesc );
00959 #ifdef HAVE_EBCDIC
00960               if ( atype ) LDAP_FREE( atype );
00961               if ( adesc ) LDAP_FREE( adesc );
00962 #endif
00963        } else if ( where & SSL_CB_EXIT ) {
00964               if ( ret == 0 ) {
00965                      Debug( LDAP_DEBUG_TRACE,
00966                                "TLS trace: %s:failed in %s\n",
00967                                op, state, 0 );
00968               } else if ( ret < 0 ) {
00969                      Debug( LDAP_DEBUG_TRACE,
00970                                "TLS trace: %s:error in %s\n",
00971                                op, state, 0 );
00972               }
00973        }
00974 #ifdef HAVE_EBCDIC
00975        if ( state ) LDAP_FREE( state );
00976 #endif
00977 }
00978 
00979 static int
00980 tlso_verify_cb( int ok, X509_STORE_CTX *ctx )
00981 {
00982        X509 *cert;
00983        int errnum;
00984        int errdepth;
00985        X509_NAME *subject;
00986        X509_NAME *issuer;
00987        char *sname;
00988        char *iname;
00989        char *certerr = NULL;
00990 
00991        cert = X509_STORE_CTX_get_current_cert( ctx );
00992        errnum = X509_STORE_CTX_get_error( ctx );
00993        errdepth = X509_STORE_CTX_get_error_depth( ctx );
00994 
00995        /*
00996         * X509_get_*_name return pointers to the internal copies of
00997         * those things requested.  So do not free them.
00998         */
00999        subject = X509_get_subject_name( cert );
01000        issuer = X509_get_issuer_name( cert );
01001        /* X509_NAME_oneline, if passed a NULL buf, allocate memomry */
01002        sname = X509_NAME_oneline( subject, NULL, 0 );
01003        iname = X509_NAME_oneline( issuer, NULL, 0 );
01004        if ( !ok ) certerr = (char *)X509_verify_cert_error_string( errnum );
01005 #ifdef HAVE_EBCDIC
01006        if ( sname ) __etoa( sname );
01007        if ( iname ) __etoa( iname );
01008        if ( certerr ) {
01009               certerr = LDAP_STRDUP( certerr );
01010               __etoa( certerr );
01011        }
01012 #endif
01013        Debug( LDAP_DEBUG_TRACE,
01014                  "TLS certificate verification: depth: %d, err: %d, subject: %s,",
01015                  errdepth, errnum,
01016                  sname ? sname : "-unknown-" );
01017        Debug( LDAP_DEBUG_TRACE, " issuer: %s\n", iname ? iname : "-unknown-", 0, 0 );
01018        if ( !ok ) {
01019               Debug( LDAP_DEBUG_ANY,
01020                      "TLS certificate verification: Error, %s\n",
01021                      certerr, 0, 0 );
01022        }
01023        if ( sname )
01024               CRYPTO_free ( sname );
01025        if ( iname )
01026               CRYPTO_free ( iname );
01027 #ifdef HAVE_EBCDIC
01028        if ( certerr ) LDAP_FREE( certerr );
01029 #endif
01030        return ok;
01031 }
01032 
01033 static int
01034 tlso_verify_ok( int ok, X509_STORE_CTX *ctx )
01035 {
01036        (void) tlso_verify_cb( ok, ctx );
01037        return 1;
01038 }
01039 
01040 /* Inspired by ERR_print_errors in OpenSSL */
01041 static void
01042 tlso_report_error( void )
01043 {
01044        unsigned long l;
01045        char buf[200];
01046        const char *file;
01047        int line;
01048 
01049        while ( ( l = ERR_get_error_line( &file, &line ) ) != 0 ) {
01050               ERR_error_string_n( l, buf, sizeof( buf ) );
01051 #ifdef HAVE_EBCDIC
01052               if ( file ) {
01053                      file = LDAP_STRDUP( file );
01054                      __etoa( (char *)file );
01055               }
01056               __etoa( buf );
01057 #endif
01058               Debug( LDAP_DEBUG_ANY, "TLS: %s %s:%d\n",
01059                      buf, file, line );
01060 #ifdef HAVE_EBCDIC
01061               if ( file ) LDAP_FREE( (void *)file );
01062 #endif
01063        }
01064 }
01065 
01066 static RSA *
01067 tlso_tmp_rsa_cb( SSL *ssl, int is_export, int key_length )
01068 {
01069        RSA *tmp_rsa;
01070        /* FIXME:  Pregenerate the key on startup */
01071        /* FIXME:  Who frees the key? */
01072 #if OPENSSL_VERSION_NUMBER >= 0x00908000
01073        BIGNUM *bn = BN_new();
01074        tmp_rsa = NULL;
01075        if ( bn ) {
01076               if ( BN_set_word( bn, RSA_F4 )) {
01077                      tmp_rsa = RSA_new();
01078                      if ( tmp_rsa && !RSA_generate_key_ex( tmp_rsa, key_length, bn, NULL )) {
01079                             RSA_free( tmp_rsa );
01080                             tmp_rsa = NULL;
01081                      }
01082               }
01083               BN_free( bn );
01084        }
01085 #else
01086        tmp_rsa = RSA_generate_key( key_length, RSA_F4, NULL, NULL );
01087 #endif
01088 
01089        if ( !tmp_rsa ) {
01090               Debug( LDAP_DEBUG_ANY,
01091                      "TLS: Failed to generate temporary %d-bit %s RSA key\n",
01092                      key_length, is_export ? "export" : "domestic", 0 );
01093        }
01094        return tmp_rsa;
01095 }
01096 
01097 static int
01098 tlso_seed_PRNG( const char *randfile )
01099 {
01100 #ifndef URANDOM_DEVICE
01101        /* no /dev/urandom (or equiv) */
01102        long total=0;
01103        char buffer[MAXPATHLEN];
01104 
01105        if (randfile == NULL) {
01106               /* The seed file is $RANDFILE if defined, otherwise $HOME/.rnd.
01107                * If $HOME is not set or buffer too small to hold the pathname,
01108                * an error occurs.  - From RAND_file_name() man page.
01109                * The fact is that when $HOME is NULL, .rnd is used.
01110                */
01111               randfile = RAND_file_name( buffer, sizeof( buffer ) );
01112 
01113        } else if (RAND_egd(randfile) > 0) {
01114               /* EGD socket */
01115               return 0;
01116        }
01117 
01118        if (randfile == NULL) {
01119               Debug( LDAP_DEBUG_ANY,
01120                      "TLS: Use configuration file or $RANDFILE to define seed PRNG\n",
01121                      0, 0, 0);
01122               return -1;
01123        }
01124 
01125        total = RAND_load_file(randfile, -1);
01126 
01127        if (RAND_status() == 0) {
01128               Debug( LDAP_DEBUG_ANY,
01129                      "TLS: PRNG not been seeded with enough data\n",
01130                      0, 0, 0);
01131               return -1;
01132        }
01133 
01134        /* assume if there was enough bits to seed that it's okay
01135         * to write derived bits to the file
01136         */
01137        RAND_write_file(randfile);
01138 
01139 #endif
01140 
01141        return 0;
01142 }
01143 
01144 struct dhinfo {
01145        int keylength;
01146        const char *pem;
01147        size_t size;
01148 };
01149 
01150 
01151 /* From the OpenSSL 0.9.7 distro */
01152 static const char tlso_dhpem512[] =
01153 "-----BEGIN DH PARAMETERS-----\n\
01154 MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn\n\
01155 a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC\n\
01156 -----END DH PARAMETERS-----\n";
01157 
01158 static const char tlso_dhpem1024[] =
01159 "-----BEGIN DH PARAMETERS-----\n\
01160 MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/K3g6TG1Z1fkq\n\
01161 /Gz/PWk/eLI9TzFgqVAuPvr3q14a1aZeVUMTgo2oO5/y2UHe6VaJ+trqCTat3xlx\n\
01162 /mNbIK9HA2RgPC3gWfVLZQrY+gz3ASHHR5nXWHEyvpuZm7m3h+irAgEC\n\
01163 -----END DH PARAMETERS-----\n";
01164 
01165 static const char tlso_dhpem2048[] =
01166 "-----BEGIN DH PARAMETERS-----\n\
01167 MIIBCAKCAQEA7ZKJNYJFVcs7+6J2WmkEYb8h86tT0s0h2v94GRFS8Q7B4lW9aG9o\n\
01168 AFO5Imov5Jo0H2XMWTKKvbHbSe3fpxJmw/0hBHAY8H/W91hRGXKCeyKpNBgdL8sh\n\
01169 z22SrkO2qCnHJ6PLAMXy5fsKpFmFor2tRfCzrfnggTXu2YOzzK7q62bmqVdmufEo\n\
01170 pT8igNcLpvZxk5uBDvhakObMym9mX3rAEBoe8PwttggMYiiw7NuJKO4MqD1llGkW\n\
01171 aVM8U2ATsCun1IKHrRxynkE1/MJ86VHeYYX8GZt2YA8z+GuzylIOKcMH6JAWzMwA\n\
01172 Gbatw6QwizOhr9iMjZ0B26TE3X8LvW84wwIBAg==\n\
01173 -----END DH PARAMETERS-----\n";
01174 
01175 static const char tlso_dhpem4096[] =
01176 "-----BEGIN DH PARAMETERS-----\n\
01177 MIICCAKCAgEA/urRnb6vkPYc/KEGXWnbCIOaKitq7ySIq9dTH7s+Ri59zs77zty7\n\
01178 vfVlSe6VFTBWgYjD2XKUFmtqq6CqXMhVX5ElUDoYDpAyTH85xqNFLzFC7nKrff/H\n\
01179 TFKNttp22cZE9V0IPpzedPfnQkE7aUdmF9JnDyv21Z/818O93u1B4r0szdnmEvEF\n\
01180 bKuIxEHX+bp0ZR7RqE1AeifXGJX3d6tsd2PMAObxwwsv55RGkn50vHO4QxtTARr1\n\
01181 rRUV5j3B3oPMgC7Offxx+98Xn45B1/G0Prp11anDsR1PGwtaCYipqsvMwQUSJtyE\n\
01182 EOQWk+yFkeMe4vWv367eEi0Sd/wnC+TSXBE3pYvpYerJ8n1MceI5GQTdarJ77OW9\n\
01183 bGTHmxRsLSCM1jpLdPja5jjb4siAa6EHc4qN9c/iFKS3PQPJEnX7pXKBRs5f7AF3\n\
01184 W3RIGt+G9IVNZfXaS7Z/iCpgzgvKCs0VeqN38QsJGtC1aIkwOeyjPNy2G6jJ4yqH\n\
01185 ovXYt/0mc00vCWeSNS1wren0pR2EiLxX0ypjjgsU1mk/Z3b/+zVf7fZSIB+nDLjb\n\
01186 NPtUlJCVGnAeBK1J1nG3TQicqowOXoM6ISkdaXj5GPJdXHab2+S7cqhKGv5qC7rR\n\
01187 jT6sx7RUr0CNTxzLI7muV2/a4tGmj0PSdXQdsZ7tw7gbXlaWT1+MM2MCAQI=\n\
01188 -----END DH PARAMETERS-----\n";
01189 
01190 static const struct dhinfo tlso_dhpem[] = {
01191        { 512, tlso_dhpem512, sizeof(tlso_dhpem512) },
01192        { 1024, tlso_dhpem1024, sizeof(tlso_dhpem1024) },
01193        { 2048, tlso_dhpem2048, sizeof(tlso_dhpem2048) },
01194        { 4096, tlso_dhpem4096, sizeof(tlso_dhpem4096) },
01195        { 0, NULL, 0 }
01196 };
01197 
01198 static DH *
01199 tlso_tmp_dh_cb( SSL *ssl, int is_export, int key_length )
01200 {
01201        struct dhplist *p = NULL;
01202        BIO *b = NULL;
01203        DH *dh = NULL;
01204        int i;
01205 
01206        /* Do we have params of this length already? */
01207        LDAP_MUTEX_LOCK( &tlso_dh_mutex );
01208        for ( p = tlso_dhparams; p; p=p->next ) {
01209               if ( p->keylength == key_length ) {
01210                      LDAP_MUTEX_UNLOCK( &tlso_dh_mutex );
01211                      return p->param;
01212               }
01213        }
01214 
01215        /* No - check for hardcoded params */
01216 
01217        for (i=0; tlso_dhpem[i].keylength; i++) {
01218               if ( tlso_dhpem[i].keylength == key_length ) {
01219                      b = BIO_new_mem_buf( (char *)tlso_dhpem[i].pem, tlso_dhpem[i].size );
01220                      break;
01221               }
01222        }
01223 
01224        if ( b ) {
01225               dh = PEM_read_bio_DHparams( b, NULL, NULL, NULL );
01226               BIO_free( b );
01227        }
01228 
01229        /* Generating on the fly is expensive/slow... */
01230        if ( !dh ) {
01231               dh = DH_generate_parameters( key_length, DH_GENERATOR_2, NULL, NULL );
01232        }
01233        if ( dh ) {
01234               p = LDAP_MALLOC( sizeof(struct dhplist) );
01235               if ( p != NULL ) {
01236                      p->keylength = key_length;
01237                      p->param = dh;
01238                      p->next = tlso_dhparams;
01239                      tlso_dhparams = p;
01240               }
01241        }
01242 
01243        LDAP_MUTEX_UNLOCK( &tlso_dh_mutex );
01244        return dh;
01245 }
01246 
01247 tls_impl ldap_int_tls_impl = {
01248        "OpenSSL",
01249 
01250        tlso_init,
01251        tlso_destroy,
01252 
01253        tlso_ctx_new,
01254        tlso_ctx_ref,
01255        tlso_ctx_free,
01256        tlso_ctx_init,
01257 
01258        tlso_session_new,
01259        tlso_session_connect,
01260        tlso_session_accept,
01261        tlso_session_upflags,
01262        tlso_session_errmsg,
01263        tlso_session_my_dn,
01264        tlso_session_peer_dn,
01265        tlso_session_chkhost,
01266        tlso_session_strength,
01267 
01268        &tlso_sbio,
01269 
01270 #ifdef LDAP_R_COMPILE
01271        tlso_thr_init,
01272 #else
01273        NULL,
01274 #endif
01275 
01276        0
01277 };
01278 
01279 #endif /* HAVE_OPENSSL */