]> git.sur5r.net Git - openldap/blob - libraries/libldap/tls.c
bad5312c5caa6f74010aba24c5edd18f66215b35
[openldap] / libraries / libldap / tls.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  *
6  * tls.c - Handle tls/ssl using SSLeay or OpenSSL.
7  */
8
9 #include "portable.h"
10
11 #ifdef HAVE_TLS
12
13 #include <stdio.h>
14
15 #include <ac/stdlib.h>
16 #include <ac/errno.h>
17 #include <ac/socket.h>
18 #include <ac/string.h>
19 #include <ac/time.h>
20 #include <ac/unistd.h>
21
22 #include "ldap-int.h"
23
24 #ifdef LDAP_R_COMPILE
25 #include <ldap_pvt_thread.h>
26 #endif
27
28 #ifdef HAVE_OPENSSL_SSL_H
29 #include <openssl/ssl.h>
30 #elif defined( HAVE_SSL_H )
31 #include <ssl.h>
32 #endif
33
34 static int  tls_opt_trace = 1;
35 static char *tls_opt_certfile = NULL;
36 static char *tls_opt_keyfile = NULL;
37 static char *tls_opt_cacertfile = NULL;
38 static char *tls_opt_cacertdir = NULL;
39 static int  tls_opt_require_cert = 0;
40 static char *tls_opt_ciphersuite = NULL;
41
42 #define HAS_TLS( sb ) ((sb)->sb_io==&tls_io)
43
44 static int tls_setup( Sockbuf *sb, void *arg );
45 static int tls_remove( Sockbuf *sb );
46 static ber_slen_t tls_read( Sockbuf *sb, void *buf, ber_len_t len );
47 static ber_slen_t tls_write( Sockbuf *sb, void *buf, ber_len_t len );
48 static int tls_close( Sockbuf *sb );
49 static int tls_report_error( void );
50
51 static Sockbuf_IO tls_io=
52 {
53    tls_setup,
54    tls_remove,
55    tls_read,
56    tls_write,
57    tls_close
58 };
59
60 static void tls_info_cb( SSL *ssl, int where, int ret );
61 static int tls_verify_cb( int ok, X509_STORE_CTX *ctx );
62 static RSA * tls_tmp_rsa_cb( SSL *ssl, int is_export, int key_length );
63 static DH * tls_tmp_dh_cb( SSL *ssl, int is_export, int key_length );
64 static STACK_OF(X509_NAME) * get_ca_list( char * bundle, char * dir );
65
66 static SSL_CTX *tls_def_ctx = NULL;
67
68 #ifdef LDAP_R_COMPILE
69 /*
70  * provide mutexes for the SSLeay library.
71  */
72 static ldap_pvt_thread_mutex_t  tls_mutexes[CRYPTO_NUM_LOCKS];
73
74 static void tls_locking_cb( int mode, int type, const char *file, int line )
75 {
76         if ( mode & CRYPTO_LOCK ) {
77                 ldap_pvt_thread_mutex_lock( tls_mutexes+type );
78         } else {
79                 ldap_pvt_thread_mutex_unlock( tls_mutexes+type );
80         }
81 }
82
83 /*
84  * an extra mutex for the default ctx.
85  */
86
87 static ldap_pvt_thread_mutex_t tls_def_ctx_mutex;
88
89 static void tls_init_threads( void )
90 {
91         int i;
92
93         for( i=0; i< CRYPTO_NUM_LOCKS ; i++ ) {
94                 ldap_pvt_thread_mutex_init( tls_mutexes+i );
95         }
96         CRYPTO_set_locking_callback( tls_locking_cb );
97         /* FIXME: the thread id should be added somehow... */
98
99         ldap_pvt_thread_mutex_init( &tls_def_ctx_mutex );
100 }
101 #endif /* LDAP_R_COMPILE */
102
103 /*
104  * Initialize tls system. Should be called only once.
105  */
106 int
107 ldap_pvt_tls_init( void )
108 {
109         static int tls_initialized = 0;
110
111         if ( tls_initialized )
112                 return -1;
113 #ifdef LDAP_R_COMPILE
114         tls_init_threads();
115 #endif
116         SSL_load_error_strings();
117         SSLeay_add_ssl_algorithms();
118         /* FIXME: mod_ssl does this */
119         X509V3_add_standard_extensions();
120         return 0;
121 }
122
123 /*
124  * initialize the default context
125  */
126 int
127 ldap_pvt_tls_init_def_ctx( void )
128 {
129         STACK_OF(X509_NAME) *calist;
130
131 #ifdef LDAP_R_COMPILE
132         ldap_pvt_thread_mutex_lock( &tls_def_ctx_mutex );
133 #endif
134         if ( tls_def_ctx == NULL ) {
135                 tls_def_ctx = SSL_CTX_new( SSLv23_method() );
136                 if ( tls_def_ctx == NULL ) {
137                         Debug( LDAP_DEBUG_ANY,
138                                "TLS: could not allocate default ctx.\n",0,0,0);
139                         goto error_exit;
140                 }
141                 if ( tls_opt_ciphersuite &&
142                      !SSL_CTX_set_cipher_list( tls_def_ctx,
143                         tls_opt_ciphersuite ) ) {
144                         Debug( LDAP_DEBUG_ANY,
145                                "TLS: could not set cipher list %s.\n",
146                                tls_opt_ciphersuite, 0, 0 );
147                         tls_report_error();
148                         goto error_exit;
149                 }
150                 if (tls_opt_cacertfile != NULL || tls_opt_cacertdir != NULL) {
151                         if ( !SSL_CTX_load_verify_locations( tls_def_ctx,
152                                                              tls_opt_cacertfile,
153                                                              tls_opt_cacertdir )
154                              || !SSL_CTX_set_default_verify_paths( tls_def_ctx ) )
155                         {
156                                 Debug( LDAP_DEBUG_ANY,
157                         "TLS: could not load verify locations (file:`%s',dir:`%s').\n",
158                                        tls_opt_cacertfile,tls_opt_cacertdir,0);
159                                 tls_report_error();
160                                 goto error_exit;
161                         }
162                         calist = get_ca_list( tls_opt_cacertfile, tls_opt_cacertdir );
163                         if ( !calist ) {
164                                 Debug( LDAP_DEBUG_ANY,
165                         "TLS: could not load client CA list (file:`%s',dir:`%s').\n",
166                                        tls_opt_cacertfile,tls_opt_cacertdir,0);
167                                 tls_report_error();
168                                 goto error_exit;
169                         }
170                         SSL_CTX_set_client_CA_list( tls_def_ctx, calist );
171                 }
172                 if ( tls_opt_keyfile &&
173                      !SSL_CTX_use_PrivateKey_file( tls_def_ctx,
174                                                    tls_opt_keyfile,
175                                                    SSL_FILETYPE_PEM ) ) {
176                         Debug( LDAP_DEBUG_ANY,
177                                "TLS: could not use key file `%s'.\n",
178                                tls_opt_keyfile,0,0);
179                         tls_report_error();
180                         goto error_exit;
181                 }
182                 if ( tls_opt_certfile &&
183                      !SSL_CTX_use_certificate_file( tls_def_ctx,
184                                                     tls_opt_certfile,
185                                                     SSL_FILETYPE_PEM ) ) {
186                         Debug( LDAP_DEBUG_ANY,
187                                "TLS: could not use certificate `%s'.\n",
188                                tls_opt_certfile,0,0);
189                         tls_report_error();
190                         goto error_exit;
191                 }
192                 if ( ( tls_opt_certfile || tls_opt_keyfile ) &&
193                      !SSL_CTX_check_private_key( tls_def_ctx ) ) {
194                         Debug( LDAP_DEBUG_ANY,
195                                "TLS: private key mismatch.\n",
196                                0,0,0);
197                         tls_report_error();
198                         goto error_exit;
199                 }
200                 if ( tls_opt_trace ) {
201                         SSL_CTX_set_info_callback( tls_def_ctx, tls_info_cb );
202                 }
203                 SSL_CTX_set_verify( tls_def_ctx, (tls_opt_require_cert) ?
204                         (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT) :
205                         SSL_VERIFY_PEER, tls_verify_cb );
206                 SSL_CTX_set_tmp_rsa_callback( tls_def_ctx, tls_tmp_rsa_cb );
207                 /* SSL_CTX_set_tmp_dh_callback( tls_def_ctx, tls_tmp_dh_cb ); */
208         }
209 #ifdef LDAP_R_COMPILE
210         ldap_pvt_thread_mutex_unlock( &tls_def_ctx_mutex );
211 #endif
212         return 0;
213 error_exit:
214 #ifdef LDAP_R_COMPILE
215         ldap_pvt_thread_mutex_unlock( &tls_def_ctx_mutex );
216 #endif
217         return -1;
218 }
219
220 static STACK_OF(X509_NAME) *
221 get_ca_list( char * bundle, char * dir )
222 {
223         STACK_OF(X509_NAME) *ca_list = NULL;
224
225         if ( bundle ) {
226                 ca_list = SSL_load_client_CA_file( bundle );
227         }
228         /*
229          * FIXME: We have now to go over all files in dir, load them
230          * and add every certificate there to ca_list.
231          */
232         return ca_list;
233 }
234
235 static SSL *
236 alloc_handle( Sockbuf *sb, void *ctx_arg )
237 {
238         int     err;
239         SSL_CTX *ctx;
240         SSL     *ssl;
241
242         if ( ctx_arg ) {
243                 ctx = (SSL_CTX *) ctx_arg;
244         } else {
245                 if ( ldap_pvt_tls_init_def_ctx() < 0 )
246                         return NULL;
247                 ctx = tls_def_ctx;
248         }
249
250         ssl = SSL_new( ctx );
251         if ( ssl == NULL ) {
252                 Debug( LDAP_DEBUG_ANY,"TLS: can't create ssl handle.\n",0,0,0);
253                 return NULL;
254         }
255
256         if ( tls_opt_trace ) {
257                 SSL_set_info_callback( ssl, tls_info_cb );
258         }
259         sb->sb_iodata = ssl;
260         SSL_set_fd( ssl, ber_pvt_sb_get_desc( sb ) );
261         return ssl;
262 }
263
264 static void
265 update_flags( Sockbuf *sb, SSL * ssl )
266 {
267         sb->sb_trans_needs_read  = (SSL_want_read(ssl) ? 1 : 0);
268         sb->sb_trans_needs_write = (SSL_want_write(ssl) ? 1 : 0);
269 }
270
271 /*
272  * Call this to do a TLS connect on a sockbuf. ctx_arg can be
273  * a SSL_CTX * or NULL, in which case the default ctx is used.
274  *
275  * Return value:
276  *
277  *  0 - Success. Connection is ready for communication.
278  * <0 - Error. Can't create a TLS stream.
279  * >0 - Partial success.
280  *        Do a select (using information from lber_pvt_sb_needs_{read,write}
281  *              and call again.
282  */
283
284 int
285 ldap_pvt_tls_connect( Sockbuf *sb, void *ctx_arg )
286 {
287         int     err;
288         SSL     *ssl;
289
290         if ( HAS_TLS( sb ) ) {
291                 ssl = (SSL *) sb->sb_iodata;
292         } else {
293                 ssl = alloc_handle( sb, ctx_arg );
294                 if ( ssl == NULL )
295                         return -1;
296                 ber_pvt_sb_clear_io( sb );
297                 ber_pvt_sb_set_io( sb, &tls_io, (void *)ssl );
298         }
299
300         err = SSL_connect( ssl );
301
302         if ( err <= 0 ) {
303                 if (
304 #ifdef EWOULDBLOCK
305                     (errno==EWOULDBLOCK) ||
306 #endif
307 #ifdef EAGAIN
308                     (errno==EAGAIN) ||
309 #endif
310                     (0)) {
311                         update_flags( sb, ssl );
312                         return 1;
313                 }
314                 Debug( LDAP_DEBUG_ANY,"TLS: can't connect.\n",0,0,0);
315                 ber_pvt_sb_clear_io( sb );
316                 ber_pvt_sb_set_io( sb, &ber_pvt_sb_io_tcp, NULL );
317                 return -1;
318         }
319         return 0;
320 }
321
322 /*
323  * Call this to do a TLS accept on a sockbuf.
324  * Everything else is the same as with tls_connect.
325  */
326 int
327 ldap_pvt_tls_accept( Sockbuf *sb, void *ctx_arg )
328 {
329         int     err;
330         SSL     *ssl;
331
332         if ( HAS_TLS( sb ) ) {
333                 ssl = (SSL *) sb->sb_iodata;
334         } else {
335                 ssl = alloc_handle( sb, ctx_arg );
336                 if ( ssl == NULL )
337                         return -1;
338                 ber_pvt_sb_clear_io( sb );
339                 ber_pvt_sb_set_io( sb, &tls_io, (void *)ssl );
340         }
341
342         err = SSL_accept( ssl );
343
344         if ( err <= 0 ) {
345                 if ( !SSL_want_nothing( ssl ) ) {
346                         update_flags( sb, ssl );
347                         return 1;
348                 }
349                 Debug( LDAP_DEBUG_ANY,"TLS: can't accept.\n",0,0,0 );
350                 tls_report_error();
351                 ber_pvt_sb_clear_io( sb );
352                 ber_pvt_sb_set_io( sb, &ber_pvt_sb_io_tcp, NULL );
353                 return -1;
354         }
355         return 0;
356 }
357
358 int
359 ldap_pvt_tls_inplace ( Sockbuf *sb )
360 {
361         if ( HAS_TLS( sb ) )
362                 return(1);
363         return(0);
364 }
365
366 const char *
367 ldap_pvt_tls_get_peer( LDAP *ld )
368 {
369 }
370
371 const char *
372 ldap_pvt_tls_get_peer_issuer( LDAP *ld )
373 {
374 }
375
376 int
377 ldap_pvt_tls_config( struct ldapoptions *lo, int option, const char *arg )
378 {
379         int i;
380
381         switch( option ) {
382         case LDAP_OPT_X_TLS_CACERTFILE:
383         case LDAP_OPT_X_TLS_CACERTDIR:
384         case LDAP_OPT_X_TLS_CERTFILE:
385         case LDAP_OPT_X_TLS_KEYFILE:
386                 return ldap_pvt_tls_set_option( NULL, option, (void *) arg );
387         case LDAP_OPT_X_TLS_REQUIRE_CERT:
388                 i = ( ( strcasecmp( arg, "on" ) == 0 ) ||
389                       ( strcasecmp( arg, "yes" ) == 0) ||
390                       ( strcasecmp( arg, "true" ) == 0 ) );
391                 return ldap_pvt_tls_set_option( NULL, option, (void *) &i );
392         case LDAP_OPT_X_TLS:
393                 i = -1;
394                 if ( strcasecmp( arg, "never" ) == 0 )
395                         i = LDAP_OPT_X_TLS_NEVER ;
396                 if ( strcasecmp( arg, "demand" ) == 0 )
397                         i = LDAP_OPT_X_TLS_DEMAND ;
398                 if ( strcasecmp( arg, "allow" ) == 0 )
399                         i = LDAP_OPT_X_TLS_ALLOW ;
400                 if ( strcasecmp( arg, "try" ) == 0 )
401                         i = LDAP_OPT_X_TLS_TRY ;
402                 if ( strcasecmp( arg, "hard" ) == 0 )
403                         i = LDAP_OPT_X_TLS_HARD ;
404                 if (i >= 0)
405                         return ldap_pvt_tls_set_option( lo, option, &i );
406                 return -1;
407         default:
408                 return -1;
409         }
410 }
411
412 int
413 ldap_pvt_tls_get_option( struct ldapoptions *lo, int option, void *arg )
414 {
415         switch( option ) {
416         case LDAP_OPT_X_TLS:
417                 *(int *)arg = lo->ldo_tls_mode;
418                 break;
419         case LDAP_OPT_X_TLS_CERT:
420                 if ( lo == NULL )
421                         arg = (void *) tls_def_ctx;
422                 else
423                         arg = lo->ldo_tls_ctx;
424                 break;
425         case LDAP_OPT_X_TLS_CACERTFILE:
426                 *(char **)arg = tls_opt_cacertfile ?
427                         LDAP_STRDUP( tls_opt_cacertfile ) : NULL;
428                 break;
429         case LDAP_OPT_X_TLS_CACERTDIR:
430                 *(char **)arg = tls_opt_cacertdir ?
431                         LDAP_STRDUP( tls_opt_cacertdir ) : NULL;
432                 break;
433         case LDAP_OPT_X_TLS_CERTFILE:
434                 *(char **)arg = tls_opt_certfile ?
435                         LDAP_STRDUP( tls_opt_certfile ) : NULL;
436                 break;
437         case LDAP_OPT_X_TLS_KEYFILE:
438                 *(char **)arg = tls_opt_keyfile ?
439                         LDAP_STRDUP( tls_opt_keyfile ) : NULL;
440                 break;
441         case LDAP_OPT_X_TLS_REQUIRE_CERT:
442                 *(int *)arg = tls_opt_require_cert;
443                 break;
444         default:
445                 return -1;
446         }
447         return 0;
448 }
449
450 int
451 ldap_pvt_tls_set_option( struct ldapoptions *lo, int option, void *arg )
452 {
453         switch( option ) {
454         case LDAP_OPT_X_TLS:
455                 switch( *(int *) arg ) {
456                 case LDAP_OPT_X_TLS_NEVER:
457                 case LDAP_OPT_X_TLS_DEMAND:
458                 case LDAP_OPT_X_TLS_ALLOW:
459                 case LDAP_OPT_X_TLS_TRY:
460                 case LDAP_OPT_X_TLS_HARD:
461                         if (lo != NULL)
462                                 lo->ldo_tls_mode = *(int *)arg;
463                         return 0;
464                 default:
465                         return -1;
466                 }
467                 break;
468         case LDAP_OPT_X_TLS_CERT:
469                 if ( lo == NULL )
470                         tls_def_ctx = (SSL_CTX *) arg;
471                 else
472                         lo->ldo_tls_ctx = arg;
473                 break;
474         }
475         if ( lo != NULL )
476                 return -1;
477         switch( option ) {
478         case LDAP_OPT_X_TLS_CACERTFILE:
479                 if ( tls_opt_cacertfile ) free( tls_opt_cacertfile );
480                 tls_opt_cacertfile = arg ? LDAP_STRDUP( (char *) arg ) : NULL;
481                 break;
482         case LDAP_OPT_X_TLS_CACERTDIR:
483                 if ( tls_opt_cacertdir ) free( tls_opt_cacertdir );
484                 tls_opt_cacertdir = arg ? LDAP_STRDUP( (char *) arg ) : NULL;
485                 break;
486         case LDAP_OPT_X_TLS_CERTFILE:
487                 if ( tls_opt_certfile ) free( tls_opt_certfile );
488                 tls_opt_certfile = arg ? LDAP_STRDUP( (char *) arg ) : NULL;
489                 break;
490         case LDAP_OPT_X_TLS_KEYFILE:
491                 if ( tls_opt_keyfile ) free( tls_opt_keyfile );
492                 tls_opt_keyfile = arg ? LDAP_STRDUP( (char *) arg ) : NULL;
493                 break;
494         case LDAP_OPT_X_TLS_REQUIRE_CERT:
495                 tls_opt_require_cert = * (int *) arg;
496                 break;
497         case LDAP_OPT_X_TLS_CIPHER_SUITE:
498                 if ( tls_opt_ciphersuite ) free( tls_opt_ciphersuite );
499                 tls_opt_ciphersuite = arg ? LDAP_STRDUP( (char *) arg ) : NULL;
500                 break;
501         default:
502                 return -1;
503         }
504         return 0;
505 }
506
507 int
508 ldap_pvt_tls_start ( Sockbuf *sb, void *ctx_arg )
509 {
510         /*
511          * Fortunately, the lib uses blocking io...
512          */
513         if ( ldap_pvt_tls_connect( sb, ctx_arg ) < 0 ) {
514                 return LDAP_CONNECT_ERROR;
515         }
516
517         /* FIXME: hostname of server must be compared with name in
518          * certificate....
519          */
520
521         return LDAP_SUCCESS;
522 }
523
524
525 static int
526 tls_setup( Sockbuf *sb, void *arg )
527 {
528         sb->sb_iodata = arg;
529         return 0;
530 }
531
532 static int
533 tls_remove( Sockbuf *sb )
534 {
535         SSL_free( (SSL *) sb->sb_iodata );
536         return 0;
537 }
538
539 static ber_slen_t
540 tls_write( Sockbuf *sb, void *buf, ber_len_t sz )
541 {
542         int ret = SSL_write( (SSL *)sb->sb_iodata, buf, sz );
543
544         update_flags(sb, (SSL *)sb->sb_iodata );
545 #ifdef WIN32
546         if (sb->sb_trans_needs_write)
547                 errno = EWOULDBLOCK;
548 #endif
549         return ret;
550 }
551
552 static ber_slen_t
553 tls_read( Sockbuf *sb, void *buf, ber_len_t sz )
554 {
555         int ret = SSL_read( (SSL *)sb->sb_iodata, buf, sz );
556
557         update_flags(sb, (SSL *)sb->sb_iodata );
558 #ifdef WIN32
559         if (sb->sb_trans_needs_read)
560                 errno = EWOULDBLOCK;
561 #endif
562         return ret;
563 }
564
565 static int
566 tls_close( Sockbuf *sb )
567 {
568         tcp_close( ber_pvt_sb_get_desc( sb ) );
569         return 0;
570 }
571
572 /* Derived from openssl/apps/s_cb.c */
573 static void
574 tls_info_cb( SSL *ssl, int where, int ret )
575 {
576         int w;
577         char *op;
578
579         w = where & ~SSL_ST_MASK;
580         if ( w & SSL_ST_CONNECT ) {
581                 op = "SSL_connect";
582         } else if ( w & SSL_ST_ACCEPT ) {
583                 op = "SSL_accept";
584         } else {
585                 op = "undefined";
586         }
587
588         if ( where & SSL_CB_LOOP ) {
589                 Debug( LDAP_DEBUG_TRACE,
590                        "TLS trace: %s:%s\n",
591                        op, SSL_state_string_long( ssl ), 0 );
592         } else if ( where & SSL_CB_ALERT ) {
593                 op = ( where & SSL_CB_READ ) ? "read" : "write";
594                 Debug( LDAP_DEBUG_TRACE,
595                        "TLS trace: SSL3 alert %s:%s:%s\n",
596                        op,
597                        SSL_alert_type_string_long( ret ),
598                        SSL_alert_desc_string_long( ret) );
599         } else if ( where & SSL_CB_EXIT ) {
600                 if ( ret == 0 ) {
601                         Debug( LDAP_DEBUG_TRACE,
602                                "TLS trace: %s:failed in %s\n",
603                                op, SSL_state_string_long( ssl ), 0 );
604                 } else if ( ret < 0 ) {
605                         Debug( LDAP_DEBUG_TRACE,
606                                "TLS trace: %s:error in %s\n",
607                                op, SSL_state_string_long( ssl ), 0 );
608                 }
609         }
610 }
611
612 static int
613 tls_verify_cb( int ok, X509_STORE_CTX *ctx )
614 {
615         X509 *cert;
616         int errnum;
617         int errdepth;
618         X509_NAME *subject;
619         X509_NAME *issuer;
620         char *sname;
621         char *iname;
622
623         cert = X509_STORE_CTX_get_current_cert( ctx );
624         errnum = X509_STORE_CTX_get_error( ctx );
625         errdepth = X509_STORE_CTX_get_error_depth( ctx );
626
627         /*
628          * X509_get_*_name return pointers to the internal copies of
629          * those things requested.  So do not free them.
630          */
631         subject = X509_get_subject_name( cert );
632         issuer = X509_get_issuer_name( cert );
633         /* X509_NAME_oneline, if passed a NULL buf, allocate memomry */
634         sname = X509_NAME_oneline( subject, NULL, 0 );
635         iname = X509_NAME_oneline( issuer, NULL, 0 );
636         Debug( LDAP_DEBUG_TRACE,
637                "TLS certificate verification: depth: %d, subject: %s, issuer: %s\n",
638                errdepth,
639                sname ? sname : "-unknown-",
640                iname ? iname : "-unknown-" );
641         if ( sname )
642                 free ( sname );
643         if ( iname )
644                 free ( iname );
645
646         return 1;
647 }
648
649 /* Inspired by ERR_print_errors in OpenSSL */
650 static int
651 tls_report_error( void )
652 {
653         unsigned long l;
654         char buf[200];
655         const char *file;
656         int line;
657
658         while ( ( l = ERR_get_error_line( &file, &line ) ) != 0 ) {
659                         Debug( LDAP_DEBUG_ANY, "TLS: %s %s:%d\n",
660                                ERR_error_string( l, buf ), file, line );
661         }
662 }
663
664 static RSA *
665 tls_tmp_rsa_cb( SSL *ssl, int is_export, int key_length )
666 {
667         RSA *tmp_rsa;
668
669         /* FIXME:  Pregenerate the key on startup */
670         /* FIXME:  Who frees the key? */
671         tmp_rsa = RSA_generate_key( key_length, RSA_F4, NULL, NULL );
672
673         if ( !tmp_rsa ) {
674                 Debug( LDAP_DEBUG_ANY, "TLS: Failed to generate temporary %d-bit %s RSA key\n",
675                        key_length, is_export ? "export" : "domestic", 0 );
676                 return NULL;
677         }
678         return tmp_rsa;
679 }
680
681 static DH *
682 tls_tmp_dh_cb( SSL *ssl, int is_export, int key_length )
683 {
684         return NULL;
685 }
686
687 #else
688 static int dummy;
689 #endif