]> git.ozlabs.org Git - ppp.git/blob - pppd/eap-tls.c
pppd: Expose the MPPE keys generated through an API (#267)
[ppp.git] / pppd / eap-tls.c
1 /* * eap-tls.c - EAP-TLS implementation for PPP
2  *
3  * Copyright (c) Beniamino Galvani 2005 All rights reserved.
4  *               Jan Just Keijser  2006-2019 All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name(s) of the authors of this software must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission.
21  *
22  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
23  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
28  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29  *
30  */
31
32 #include <string.h>
33 #include <strings.h>
34 #include <unistd.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <fcntl.h>
38
39 #include <openssl/conf.h>
40 #include <openssl/engine.h>
41 #include <openssl/hmac.h>
42 #include <openssl/err.h>
43 #include <openssl/ui.h>
44 #include <openssl/x509v3.h>
45
46 #include "pppd.h"
47 #include "eap.h"
48 #include "eap-tls.h"
49 #include "fsm.h"
50 #include "lcp.h"
51 #include "chap_ms.h"
52 #include "mppe.h"
53 #include "pathnames.h"
54
55 typedef struct pw_cb_data
56 {
57     const void *password;
58     const char *prompt_info;
59 } PW_CB_DATA;
60
61 #ifndef OPENSSL_NO_ENGINE
62 /* The openssl configuration file and engines can be loaded only once */
63 static CONF   *ssl_config  = NULL;
64 static ENGINE *cert_engine = NULL;
65 static ENGINE *pkey_engine = NULL;
66 #endif
67
68 /* TLSv1.3 do we have a session ticket ? */
69 static int have_session_ticket = 0;
70
71 int ssl_verify_callback(int, X509_STORE_CTX *);
72 void ssl_msg_callback(int write_p, int version, int ct, const void *buf,
73               size_t len, SSL * ssl, void *arg);
74 int ssl_new_session_cb(SSL *s, SSL_SESSION *sess);
75
76 X509 *get_X509_from_file(char *filename);
77 int ssl_cmp_certs(char *filename, X509 * a); 
78
79 /*
80  *  OpenSSL 1.1+ introduced a generic TLS_method()
81  *  For older releases we substitute the appropriate method
82  */
83
84 #if OPENSSL_VERSION_NUMBER < 0x10100000L
85
86 #define TLS_method SSLv23_method
87
88 #define SSL3_RT_HEADER  0x100
89
90 #ifndef SSL_CTX_set_max_proto_version
91 /** Mimics SSL_CTX_set_max_proto_version for OpenSSL < 1.1 */
92 static inline int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max)
93 {
94     long sslopt = 0;
95
96     if (tls_ver_max < TLS1_VERSION)
97     {
98         sslopt |= SSL_OP_NO_TLSv1;
99     }
100 #ifdef SSL_OP_NO_TLSv1_1
101     if (tls_ver_max < TLS1_1_VERSION)
102     {
103         sslopt |= SSL_OP_NO_TLSv1_1;
104     }
105 #endif
106 #ifdef SSL_OP_NO_TLSv1_2
107     if (tls_ver_max < TLS1_2_VERSION)
108     {
109         sslopt |= SSL_OP_NO_TLSv1_2;
110     }
111 #endif
112     SSL_CTX_set_options(ctx, sslopt);
113
114     return 1;
115 }
116 #endif /* SSL_CTX_set_max_proto_version */
117
118 #endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */
119
120 #ifdef MPPE
121 #define EAPTLS_MPPE_KEY_LEN     32
122
123 /*
124  *  Generate keys according to RFC 2716 and add to reply
125  */
126 void eaptls_gen_mppe_keys(struct eaptls_session *ets, int client)
127 {
128     unsigned char  out[4*EAPTLS_MPPE_KEY_LEN];
129     const char    *prf_label;
130     size_t         prf_size;
131     unsigned char  eap_tls13_context[] = { EAPT_TLS };
132     unsigned char *context = NULL;
133     size_t         context_len = 0;
134     unsigned char *p;
135
136     dbglog("EAP-TLS generating MPPE keys");
137     if (ets->tls_v13)
138     {
139         prf_label = "EXPORTER_EAP_TLS_Key_Material";
140         context   = eap_tls13_context;
141         context_len = 1;
142     }
143     else
144     {
145         prf_label = "client EAP encryption";
146     }
147
148     dbglog("EAP-TLS PRF label = %s", prf_label);
149     prf_size = strlen(prf_label);
150     if (SSL_export_keying_material(ets->ssl, out, sizeof(out), prf_label, prf_size, 
151                                    context, context_len, 0) != 1)
152     {
153         warn( "EAP-TLS: Failed generating keying material" );
154         return;
155     }   
156
157     /* 
158      * We now have the master send and receive keys.
159      * From these, generate the session send and receive keys.
160      * (see RFC3079 / draft-ietf-pppext-mppe-keys-03.txt for details)
161      */
162     if (client)
163     {
164         mppe_set_keys(out, out + EAPTLS_MPPE_KEY_LEN, EAPTLS_MPPE_KEY_LEN);
165     }
166     else
167     {
168         mppe_set_keys(out + EAPTLS_MPPE_KEY_LEN, out, EAPTLS_MPPE_KEY_LEN);
169     }
170 }
171
172 #endif /* MPPE */
173
174
175 void log_ssl_errors( void )
176 {
177     unsigned long ssl_err = ERR_get_error();
178
179     if (ssl_err != 0)
180         dbglog("EAP-TLS SSL error stack:");
181     while (ssl_err != 0) {
182         dbglog( ERR_error_string( ssl_err, NULL ) );
183         ssl_err = ERR_get_error();
184     }
185 }
186
187
188 int password_callback (char *buf, int size, int rwflag, void *u)
189 {
190     if (buf)
191     {
192         strlcpy (buf, passwd, size);
193         return strlen (buf);
194     }
195     return 0;
196 }
197
198
199 CONF *eaptls_ssl_load_config( void )
200 {
201     CONF        *config;
202     int          ret_code;
203     long         error_line = 33;
204
205     config = NCONF_new( NULL );
206     dbglog( "Loading OpenSSL config file" );
207     ret_code = NCONF_load( config, _PATH_OPENSSLCONFFILE, &error_line );
208     if (ret_code == 0)
209     {
210         warn( "EAP-TLS: Error in OpenSSL config file %s at line %d", _PATH_OPENSSLCONFFILE, error_line );
211         NCONF_free( config );
212         config = NULL;
213         ERR_clear_error();
214     }
215
216     dbglog( "Loading OpenSSL built-ins" );
217 #ifndef OPENSSL_NO_ENGINE
218     ENGINE_load_builtin_engines();
219 #endif
220     OPENSSL_load_builtin_modules();
221    
222     dbglog( "Loading OpenSSL configured modules" );
223     if (CONF_modules_load( config, NULL, 0 ) <= 0 )
224     {
225         warn( "EAP-TLS: Error loading OpenSSL modules" );
226         log_ssl_errors();
227         config = NULL;
228     }
229
230     return config;
231 }
232
233 #ifndef OPENSSL_NO_ENGINE
234 ENGINE *eaptls_ssl_load_engine( char *engine_name )
235 {
236     ENGINE      *e = NULL;
237
238     dbglog( "Enabling OpenSSL auto engines" );
239     ENGINE_register_all_complete();
240
241     dbglog( "Loading OpenSSL '%s' engine support", engine_name );
242     e = ENGINE_by_id( engine_name );
243     if (!e) 
244     {
245         dbglog( "EAP-TLS: Cannot load '%s' engine support, trying 'dynamic'", engine_name );
246         e = ENGINE_by_id( "dynamic" );
247         if (e)
248         {
249             if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", engine_name, 0)
250              || !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
251             {
252                 warn( "EAP-TLS: Error loading dynamic engine '%s'", engine_name );
253                 log_ssl_errors();
254                 ENGINE_free(e);
255                 e = NULL;
256             }
257         }
258         else
259         {
260             warn( "EAP-TLS: Cannot load dynamic engine support" );
261         }
262     }
263
264     if (e)
265     {
266         dbglog( "Initialising engine" );
267         if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
268         {
269             warn( "EAP-TLS: Cannot use that engine" );
270             log_ssl_errors();
271             ENGINE_free(e);
272             e = NULL;
273         }
274     }
275
276     return e;
277 }
278 #endif
279
280
281 /*
282  * Initialize the SSL stacks and tests if certificates, key and crl
283  * for client or server use can be loaded.
284  */
285 SSL_CTX *eaptls_init_ssl(int init_server, char *cacertfile, char *capath,
286             char *certfile, char *peer_certfile, char *privkeyfile)
287 {
288 #ifndef OPENSSL_NO_ENGINE
289     char        *cert_engine_name = NULL;
290     char        *cert_identifier = NULL;
291     char        *pkey_engine_name = NULL;
292     char        *pkey_identifier = NULL;
293 #endif
294     SSL_CTX     *ctx;
295     SSL         *ssl;
296     X509_STORE  *certstore;
297     X509_LOOKUP *lookup;
298     X509        *tmp;
299     int          ret;
300 #if defined(TLS1_2_VERSION)
301     long         tls_version = TLS1_2_VERSION; 
302 #elif defined(TLS1_1_VERSION)
303     long         tls_version = TLS1_1_VERSION; 
304 #else
305     long         tls_version = TLS1_VERSION; 
306 #endif
307
308     /*
309      * Without these can't continue 
310      */
311     if (!(cacertfile[0] || capath[0]))
312     {
313         error("EAP-TLS: CA certificate file or path missing");
314         return NULL;
315     }
316
317     if (!certfile[0])
318     {
319         error("EAP-TLS: Certificate missing");
320         return NULL;
321     }
322
323     if (!privkeyfile[0])
324     {
325         error("EAP-TLS: Private key missing");
326         return NULL;
327     }
328
329     SSL_library_init();
330     SSL_load_error_strings();
331
332 #ifndef OPENSSL_NO_ENGINE
333     /* load the openssl config file only once and load it before triggering
334        the loading of a global openssl config file via SSL_CTX_new()
335      */
336     if (!ssl_config)
337         ssl_config = eaptls_ssl_load_config();
338 #endif
339
340     ctx = SSL_CTX_new(TLS_method());
341
342     if (!ctx) {
343         error("EAP-TLS: Cannot initialize SSL CTX context");
344         goto fail;
345     }
346
347 #ifndef OPENSSL_NO_ENGINE
348     /* if the certificate filename is of the form engine:id. e.g.
349         pkcs11:12345
350        then we try to load and use this engine.
351        If the certificate filename starts with a / or . then we
352        ALWAYS assume it is a file and not an engine/pkcs11 identifier
353      */
354     if ( index( certfile, '/' ) == NULL && index( certfile, '.') == NULL )
355     {
356         cert_identifier = index( certfile, ':' );
357
358         if (cert_identifier)
359         {
360             cert_engine_name = certfile;
361             *cert_identifier = '\0';
362             cert_identifier++;
363
364             dbglog( "Found certificate engine '%s'", cert_engine_name );
365             dbglog( "Found certificate identifier '%s'", cert_identifier );
366         }
367     }
368
369     /* if the privatekey filename is of the form engine:id. e.g.
370         pkcs11:12345
371        then we try to load and use this engine.
372        If the privatekey filename starts with a / or . then we
373        ALWAYS assume it is a file and not an engine/pkcs11 identifier
374      */
375     if ( index( privkeyfile, '/' ) == NULL && index( privkeyfile, '.') == NULL )
376     {
377         pkey_identifier = index( privkeyfile, ':' );
378
379         if (pkey_identifier)
380         {
381             pkey_engine_name = privkeyfile;
382             *pkey_identifier = '\0';
383             pkey_identifier++;
384
385             dbglog( "Found privatekey engine '%s'", pkey_engine_name );
386             dbglog( "Found privatekey identifier '%s'", pkey_identifier );
387         }
388     }
389
390     if (cert_identifier && pkey_identifier)
391     {
392         if (strlen( cert_identifier ) == 0)
393         {
394             if (strlen( pkey_identifier ) == 0)
395                 error( "EAP-TLS: both the certificate and privatekey identifiers are missing!" );
396             else
397             {
398                 dbglog( "Substituting privatekey identifier for certificate identifier" );
399                 cert_identifier = pkey_identifier;
400             }
401         }
402         else
403         {
404             if (strlen( pkey_identifier ) == 0)
405             {
406                 dbglog( "Substituting certificate identifier for privatekey identifier" );
407                 pkey_identifier = cert_identifier;
408             }
409         }
410     }
411
412     if (ssl_config && cert_engine_name)
413         cert_engine = eaptls_ssl_load_engine( cert_engine_name );
414
415     if (ssl_config && pkey_engine_name)
416     {
417         /* don't load the same engine twice */
418         if ( cert_engine && strcmp( cert_engine_name, pkey_engine_name) == 0 )
419             pkey_engine = cert_engine;
420         else
421             pkey_engine = eaptls_ssl_load_engine( pkey_engine_name );
422     }
423 #endif
424
425     SSL_CTX_set_default_passwd_cb (ctx, password_callback);
426
427     if (strlen(cacertfile) == 0) cacertfile = NULL;
428     if (strlen(capath) == 0)     capath = NULL;
429
430     if (!SSL_CTX_load_verify_locations(ctx, cacertfile, capath))
431     {
432         error("EAP-TLS: Cannot load verify locations");
433         if (cacertfile) dbglog("CA certificate file = [%s]", cacertfile);
434         if (capath) dbglog("CA certificate path = [%s]", capath);
435         goto fail;
436     }
437
438     if (init_server)
439         SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(cacertfile));
440
441 #ifndef OPENSSL_NO_ENGINE
442     if (cert_engine)
443     {
444         struct
445         {
446             const char *s_slot_cert_id;
447             X509 *cert;
448         } cert_info;
449
450         cert_info.s_slot_cert_id = cert_identifier;
451         cert_info.cert = NULL;
452         
453         if (!ENGINE_ctrl_cmd( cert_engine, "LOAD_CERT_CTRL", 0, &cert_info, NULL, 0 ) )
454         {
455             error( "EAP-TLS: Error loading certificate with id '%s' from engine", cert_identifier );
456             goto fail;
457         }
458
459         if (cert_info.cert)
460         {
461             dbglog( "Got the certificate, adding it to SSL context" );
462             dbglog( "subject = %s", X509_NAME_oneline( X509_get_subject_name( cert_info.cert ), NULL, 0 ) );
463             if (SSL_CTX_use_certificate(ctx, cert_info.cert) <= 0)
464             {
465                 error("EAP-TLS: Cannot use PKCS11 certificate %s", cert_identifier);
466                 goto fail;
467             }
468         }
469         else
470         {
471             warn("EAP-TLS: Cannot load PKCS11 key %s", cert_identifier);
472             log_ssl_errors();
473         }
474     }
475     else
476 #endif
477     {
478         if (!SSL_CTX_use_certificate_chain_file(ctx, certfile))
479         {
480             error( "EAP-TLS: Cannot use public certificate %s", certfile );
481             goto fail;
482         }
483     }
484
485
486     /*
487      *  Check the Before and After dates of the certificate
488      */
489     ssl = SSL_new(ctx);
490     tmp = SSL_get_certificate(ssl);
491
492     ret = X509_cmp_time(X509_get_notBefore(tmp), NULL);
493     if (ret == 0)
494     {    
495         warn( "EAP-TLS: Failed to read certificate notBefore field.");
496     }    
497     if (ret > 0) 
498     {    
499         warn( "EAP-TLS: Your certificate is not yet valid!");
500     }    
501
502     ret = X509_cmp_time(X509_get_notAfter(tmp), NULL);
503     if (ret == 0)
504     {    
505         warn( "EAP-TLS: Failed to read certificate notAfter field.");
506     }    
507     if (ret < 0)
508     {
509         warn( "EAP-TLS: Your certificate has expired!");
510     }
511     SSL_free(ssl);
512
513 #ifndef OPENSSL_NO_ENGINE
514     if (pkey_engine)
515     {
516         EVP_PKEY   *pkey = NULL;
517         PW_CB_DATA  cb_data;
518
519         cb_data.password = passwd;
520         cb_data.prompt_info = pkey_identifier;
521
522         if (passwd[0] != 0)
523         {
524             UI_METHOD* transfer_pin = UI_create_method("transfer_pin");
525
526             int writer (UI *ui, UI_STRING *uis)
527             {
528                 PW_CB_DATA* cb_data = (PW_CB_DATA*)UI_get0_user_data(ui);
529                 UI_set_result(ui, uis, cb_data->password);
530                 return 1;
531             };
532             int stub (UI* ui) {return 1;};
533             int stub_reader (UI *ui, UI_STRING *uis) {return 1;};
534
535             UI_method_set_writer(transfer_pin,  writer);
536             UI_method_set_opener(transfer_pin,  stub);
537             UI_method_set_closer(transfer_pin,  stub);
538             UI_method_set_flusher(transfer_pin, stub);
539             UI_method_set_reader(transfer_pin,  stub_reader);
540
541             dbglog( "Using our private key '%s' in engine", pkey_identifier );
542             pkey = ENGINE_load_private_key(pkey_engine, pkey_identifier, transfer_pin, &cb_data);
543
544             if (transfer_pin) UI_destroy_method(transfer_pin);
545         }
546         else {
547             dbglog( "Loading private key '%s' from engine", pkey_identifier );
548             pkey = ENGINE_load_private_key(pkey_engine, pkey_identifier, NULL, NULL);
549         }
550         if (pkey)
551         {
552             dbglog( "Got the private key, adding it to SSL context" );
553             if (SSL_CTX_use_PrivateKey(ctx, pkey) <= 0)
554             {
555                 error("EAP-TLS: Cannot use PKCS11 key %s", pkey_identifier);
556                 goto fail;
557             }
558         }
559         else
560         {
561             warn("EAP-TLS: Cannot load PKCS11 key %s", pkey_identifier);
562             log_ssl_errors();
563         }
564     }
565     else
566 #endif
567     {
568         if (!SSL_CTX_use_PrivateKey_file(ctx, privkeyfile, SSL_FILETYPE_PEM))
569         { 
570             error("EAP-TLS: Cannot use private key %s", privkeyfile);
571             goto fail;
572         }
573     }
574
575     if (SSL_CTX_check_private_key(ctx) != 1) {
576         error("EAP-TLS: Private key %s fails security check", privkeyfile);
577         goto fail;
578     }
579
580     /* Explicitly set the NO_TICKETS flag to support Win7/Win8 clients */
581     SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3
582 #ifdef SSL_OP_NO_TICKET
583     | SSL_OP_NO_TICKET
584 #endif
585     );
586
587     /* OpenSSL 1.1.1+ does not include RC4 ciphers by default.
588      * This causes totally obsolete WinXP clients to fail. If you really
589      * need ppp+EAP-TLS+openssl 1.1.1+WinXP then enable RC4 cipers and
590      * make sure that you use an OpenSSL that supports them
591
592     SSL_CTX_set_cipher_list(ctx, "RC4");
593      */
594
595
596     /* Set up a SSL Session cache with a callback. This is needed for TLSv1.3+.
597      * During the initial handshake the server signals to the client early on
598      * that the handshake is finished, even before the client has sent its
599      * credentials to the server. The actual connection (and moment that the
600      * client sends its credentials) only starts after the arrival of the first
601      * session ticket. The 'ssl_new_session_cb' catches this ticket.
602      */
603     SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL_STORE);
604     SSL_CTX_sess_set_new_cb(ctx, ssl_new_session_cb);
605
606     /* As EAP-TLS+TLSv1.3 is highly experimental we offer the user a chance to override */
607     if (max_tls_version)
608     {
609         if (strncmp(max_tls_version, "1.0", 3) == 0)
610             tls_version = TLS1_VERSION;
611         else if (strncmp(max_tls_version, "1.1", 3) == 0)
612             tls_version = TLS1_1_VERSION;
613         else if (strncmp(max_tls_version, "1.2", 3) == 0)
614 #ifdef TLS1_2_VERSION
615             tls_version = TLS1_2_VERSION;
616 #else
617         {
618             warn("TLSv1.2 not available. Defaulting to TLSv1.1");
619             tls_version = TLS_1_1_VERSION;
620         }
621 #endif
622         else if (strncmp(max_tls_version, "1.3", 3) == 0)
623 #ifdef TLS1_3_VERSION
624             tls_version = TLS1_3_VERSION;
625 #else
626             warn("TLSv1.3 not available.");
627 #endif
628     }
629
630     dbglog("EAP-TLS: Setting max protocol version to 0x%X", tls_version);
631     SSL_CTX_set_max_proto_version(ctx, tls_version);
632
633     SSL_CTX_set_verify_depth(ctx, 5);
634     SSL_CTX_set_verify(ctx,
635                SSL_VERIFY_PEER |
636                SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
637                &ssl_verify_callback);
638
639     if (crl_dir) {
640         if (!(certstore = SSL_CTX_get_cert_store(ctx))) {
641             error("EAP-TLS: Failed to get certificate store");
642             goto fail;
643         }
644
645         if (!(lookup =
646              X509_STORE_add_lookup(certstore, X509_LOOKUP_hash_dir()))) {
647             error("EAP-TLS: Store lookup for CRL failed");
648
649             goto fail;
650         }
651
652         X509_LOOKUP_add_dir(lookup, crl_dir, X509_FILETYPE_PEM);
653         X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK);
654     }
655
656     if (crl_file) {
657         FILE     *fp  = NULL;
658         X509_CRL *crl = NULL;
659
660         fp = fopen(crl_file, "r");
661         if (!fp) {
662             error("EAP-TLS: Cannot open CRL file '%s'", crl_file);
663             goto fail;
664         }
665
666         crl = PEM_read_X509_CRL(fp, NULL, NULL, NULL);
667         if (!crl) {
668             error("EAP-TLS: Cannot read CRL file '%s'", crl_file);
669             goto fail;
670         }
671
672         if (!(certstore = SSL_CTX_get_cert_store(ctx))) {
673             error("EAP-TLS: Failed to get certificate store");
674             goto fail;
675         }
676         if (!X509_STORE_add_crl(certstore, crl)) {
677             error("EAP-TLS: Cannot add CRL to certificate store");
678             goto fail;
679         }
680         X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK);
681
682     }
683
684     /*
685      * If a peer certificate file was specified, it must be valid, else fail 
686      */
687     if (peer_certfile[0]) {
688         if (!(tmp = get_X509_from_file(peer_certfile))) {
689             error("EAP-TLS: Error loading client certificate from file %s",
690                  peer_certfile);
691             goto fail;
692         }
693         X509_free(tmp);
694     }
695
696     return ctx;
697
698 fail:
699     log_ssl_errors();
700     SSL_CTX_free(ctx);
701     return NULL;
702 }
703
704 /*
705  * Determine the maximum packet size by looking at the LCP handshake
706  */
707
708 int eaptls_get_mtu(int unit)
709 {
710     int mtu, mru;
711
712     lcp_options *wo = &lcp_wantoptions[unit];
713     lcp_options *go = &lcp_gotoptions[unit];
714     lcp_options *ho = &lcp_hisoptions[unit];
715     lcp_options *ao = &lcp_allowoptions[unit];
716
717     mtu = ho->neg_mru? ho->mru: PPP_MRU;
718     mru = go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU;
719     mtu = MIN(MIN(mtu, mru), ao->mru)- PPP_HDRLEN - 10;
720
721     dbglog("MTU = %d", mtu);
722     return mtu;
723 }
724
725
726 /*
727  * Init the ssl handshake (server mode)
728  */
729 int eaptls_init_ssl_server(eap_state * esp)
730 {
731     struct eaptls_session *ets;
732     char servcertfile[MAXWORDLEN];
733     char clicertfile[MAXWORDLEN];
734     char cacertfile[MAXWORDLEN];
735     char capath[MAXWORDLEN];
736     char pkfile[MAXWORDLEN];
737     /*
738      * Allocate new eaptls session 
739      */
740     esp->es_server.ea_session = malloc(sizeof(struct eaptls_session));
741     if (!esp->es_server.ea_session)
742         fatal("Allocation error");
743     ets = esp->es_server.ea_session;
744     ets->client = 0;
745
746     if (!esp->es_server.ea_peer) {
747         error("EAP-TLS: Error: client name not set (BUG)");
748         return 0;
749     }
750
751     strlcpy(ets->peer, esp->es_server.ea_peer, MAXWORDLEN-1);
752
753     dbglog( "getting eaptls secret" );
754     if (!get_eaptls_secret(esp->es_unit, esp->es_server.ea_peer,
755                    esp->es_server.ea_name, clicertfile,
756                    servcertfile, cacertfile, capath, pkfile, 1)) {
757         error( "EAP-TLS: Cannot get secret/password for client \"%s\", server \"%s\"",
758                 esp->es_server.ea_peer, esp->es_server.ea_name );
759         return 0;
760     }
761
762     ets->mtu = eaptls_get_mtu(esp->es_unit);
763
764     ets->ctx = eaptls_init_ssl(1, cacertfile, capath, servcertfile, clicertfile, pkfile);
765     if (!ets->ctx)
766         goto fail;
767
768     if (!(ets->ssl = SSL_new(ets->ctx)))
769         goto fail;
770
771     /*
772      * Set auto-retry to avoid timeouts on BIO_read
773      */
774     SSL_set_mode(ets->ssl, SSL_MODE_AUTO_RETRY);
775
776     /*
777      * Initialize the BIOs we use to read/write to ssl engine 
778      */
779     ets->into_ssl = BIO_new(BIO_s_mem());
780     ets->from_ssl = BIO_new(BIO_s_mem());
781     SSL_set_bio(ets->ssl, ets->into_ssl, ets->from_ssl);
782
783     SSL_set_msg_callback(ets->ssl, ssl_msg_callback);
784     SSL_set_msg_callback_arg(ets->ssl, ets);
785
786     /*
787      * Attach the session struct to the connection, so we can later
788      * retrieve it when doing certificate verification
789      */
790     SSL_set_ex_data(ets->ssl, 0, ets);
791
792     SSL_set_accept_state(ets->ssl);
793
794     ets->tls_v13 = 0;
795
796     ets->data = NULL;
797     ets->datalen = 0;
798     ets->alert_sent = 0;
799     ets->alert_recv = 0;
800
801     /*
802      * If we specified the client certificate file, store it in ets->peercertfile,
803      * so we can check it later in ssl_verify_callback()
804      */
805     if (clicertfile[0])
806         strlcpy(&ets->peercertfile[0], clicertfile, MAXWORDLEN);
807     else
808         ets->peercertfile[0] = 0;
809
810     return 1;
811
812 fail:
813     SSL_CTX_free(ets->ctx);
814     return 0;
815 }
816
817 /*
818  * Init the ssl handshake (client mode)
819  */
820 int eaptls_init_ssl_client(eap_state * esp)
821 {
822     struct eaptls_session *ets;
823     char servcertfile[MAXWORDLEN];
824     char clicertfile[MAXWORDLEN];
825     char cacertfile[MAXWORDLEN];
826     char capath[MAXWORDLEN];
827     char pkfile[MAXWORDLEN];
828
829     /*
830      * Allocate new eaptls session 
831      */
832     esp->es_client.ea_session = malloc(sizeof(struct eaptls_session));
833     if (!esp->es_client.ea_session)
834         fatal("Allocation error");
835     ets = esp->es_client.ea_session;
836     ets->client = 1;
837
838     /*
839      * If available, copy server name in ets; it will be used in cert
840      * verify 
841      */
842     if (esp->es_client.ea_peer)
843         strlcpy(ets->peer, esp->es_client.ea_peer, MAXWORDLEN-1);
844     else
845         ets->peer[0] = 0;
846     
847     ets->mtu = eaptls_get_mtu(esp->es_unit);
848
849     dbglog( "calling get_eaptls_secret" );
850     if (!get_eaptls_secret(esp->es_unit, esp->es_client.ea_name,
851                    ets->peer, clicertfile,
852                    servcertfile, cacertfile, capath, pkfile, 0)) {
853         error( "EAP-TLS: Cannot get secret/password for client \"%s\", server \"%s\"",
854                 esp->es_client.ea_name, ets->peer );
855         return 0;
856     }
857
858     dbglog( "calling eaptls_init_ssl" );
859     ets->ctx = eaptls_init_ssl(0, cacertfile, capath, clicertfile, servcertfile, pkfile);
860     if (!ets->ctx)
861         goto fail;
862
863     ets->ssl = SSL_new(ets->ctx);
864
865     if (!ets->ssl)
866         goto fail;
867
868     /*
869      * Initialize the BIOs we use to read/write to ssl engine 
870      */
871     dbglog( "Initializing SSL BIOs" );
872     ets->into_ssl = BIO_new(BIO_s_mem());
873     ets->from_ssl = BIO_new(BIO_s_mem());
874     SSL_set_bio(ets->ssl, ets->into_ssl, ets->from_ssl);
875
876     SSL_set_msg_callback(ets->ssl, ssl_msg_callback);
877     SSL_set_msg_callback_arg(ets->ssl, ets);
878
879     /*
880      * Attach the session struct to the connection, so we can later
881      * retrieve it when doing certificate verification
882      */
883     SSL_set_ex_data(ets->ssl, 0, ets);
884
885     SSL_set_connect_state(ets->ssl);
886
887     ets->tls_v13 = 0;
888
889     ets->data = NULL;
890     ets->datalen = 0;
891     ets->alert_sent = 0;
892     ets->alert_recv = 0;
893
894     /*
895      * If we specified the server certificate file, store it in
896      * ets->peercertfile, so we can check it later in
897      * ssl_verify_callback() 
898      */
899     if (servcertfile[0])
900         strlcpy(ets->peercertfile, servcertfile, MAXWORDLEN);
901     else
902         ets->peercertfile[0] = 0;
903
904     return 1;
905
906 fail:
907     dbglog( "eaptls_init_ssl_client: fail" );
908     SSL_CTX_free(ets->ctx);
909     return 0;
910
911 }
912
913 void eaptls_free_session(struct eaptls_session *ets)
914 {
915     if (ets->ssl)
916         SSL_free(ets->ssl);
917
918     if (ets->ctx)
919         SSL_CTX_free(ets->ctx);
920
921     free(ets);
922 }
923
924
925 int eaptls_is_init_finished(struct eaptls_session *ets)
926 {
927     if (ets->ssl && SSL_is_init_finished(ets->ssl))
928     {
929         if (ets->tls_v13) 
930             return have_session_ticket;
931         else
932             return 1;
933     }
934
935     return 0;
936 }
937
938 /*
939  * Handle a received packet, reassembling fragmented messages and
940  * passing them to the ssl engine
941  */
942 int eaptls_receive(struct eaptls_session *ets, u_char * inp, int len)
943 {
944     u_char flags;
945     u_int tlslen = 0;
946     u_char dummy[65536];
947
948     if (len < 1) {
949         warn("EAP-TLS: received no or invalid data");
950         return 1;
951     }
952         
953     GETCHAR(flags, inp);
954     len--;
955
956     if (flags & EAP_TLS_FLAGS_LI && len > 4) {
957         /*
958          * LenghtIncluded flag set -> this is the first packet of a message
959         */
960
961         /*
962          * the first 4 octets are the length of the EAP-TLS message
963          */
964         GETLONG(tlslen, inp);
965         len -= 4;
966
967         if (!ets->data) {
968
969             if (tlslen > EAP_TLS_MAX_LEN) {
970                 error("EAP-TLS: TLS message length > %d, truncated", EAP_TLS_MAX_LEN);
971                 tlslen = EAP_TLS_MAX_LEN;
972             }
973
974             /*
975              * Allocate memory for the whole message
976             */
977             ets->data = malloc(tlslen);
978             if (!ets->data)
979                 fatal("EAP-TLS: allocation error\n");
980
981             ets->datalen = 0;
982             ets->tlslen = tlslen;
983         }
984         else
985             warn("EAP-TLS: non-first LI packet? that's odd...");
986     }
987     else if (!ets->data) {
988         /*
989          * A non fragmented message without LI flag
990         */
991  
992         ets->data = malloc(len);
993         if (!ets->data)
994             fatal("EAP-TLS: memory allocation error in eaptls_receive\n");
995  
996         ets->datalen = 0;
997         ets->tlslen = len;
998     }
999
1000     if (flags & EAP_TLS_FLAGS_MF)
1001         ets->frag = 1;
1002     else
1003         ets->frag = 0;
1004
1005     if (len < 0) {
1006         warn("EAP-TLS: received malformed data");
1007         return 1;
1008     }
1009
1010     if (len + ets->datalen > ets->tlslen) {
1011         warn("EAP-TLS: received data > TLS message length");
1012         return 1;
1013     }
1014
1015     BCOPY(inp, ets->data + ets->datalen, len);
1016     ets->datalen += len;
1017
1018     if (!ets->frag) {
1019
1020         /*
1021          * If we have the whole message, pass it to ssl 
1022          */
1023
1024         if (ets->datalen != ets->tlslen) {
1025             warn("EAP-TLS: received data != TLS message length");
1026             return 1;
1027         }
1028
1029         if (BIO_write(ets->into_ssl, ets->data, ets->datalen) == -1)
1030             log_ssl_errors();
1031
1032         SSL_read(ets->ssl, dummy, 65536);
1033
1034         free(ets->data);
1035         ets->data = NULL;
1036         ets->datalen = 0;
1037     }
1038
1039     return 0;
1040 }
1041
1042 /*
1043  * Return an eap-tls packet in outp.
1044  * A TLS message read from the ssl engine is buffered in ets->data.
1045  * At each call we control if there is buffered data and send a 
1046  * packet of mtu bytes.
1047  */
1048 int eaptls_send(struct eaptls_session *ets, u_char ** outp)
1049 {
1050     bool first = 0;
1051     int size;
1052     u_char fromtls[65536];
1053     int res;
1054     u_char *start;
1055
1056     start = *outp;
1057
1058     if (!ets->data)
1059     {
1060         if(!ets->alert_sent)
1061         {
1062             res = SSL_read(ets->ssl, fromtls, 65536);
1063         }
1064
1065         /*
1066          * Read from ssl 
1067          */
1068         if ((res = BIO_read(ets->from_ssl, fromtls, 65536)) == -1)
1069         {
1070             warn("EAP-TLS send: No data from BIO_read");
1071             return 1;
1072         }
1073
1074         ets->datalen = res;
1075
1076         ets->data = malloc(ets->datalen);
1077         if (!ets->data)
1078             fatal("EAP-TLS: memory allocation error in eaptls_send\n");
1079
1080         BCOPY(fromtls, ets->data, ets->datalen);
1081
1082         ets->offset = 0;
1083         first = 1;
1084     }
1085
1086     size = ets->datalen - ets->offset;
1087     
1088     if (size > ets->mtu) {
1089         size = ets->mtu;
1090         ets->frag = 1;
1091     } else
1092         ets->frag = 0;
1093
1094     PUTCHAR(EAPT_TLS, *outp);
1095
1096     /*
1097      * Set right flags and length if necessary 
1098      */
1099     if (ets->frag && first) {
1100         PUTCHAR(EAP_TLS_FLAGS_LI | EAP_TLS_FLAGS_MF, *outp);
1101         PUTLONG(ets->datalen, *outp);
1102     } else if (ets->frag) {
1103         PUTCHAR(EAP_TLS_FLAGS_MF, *outp);
1104     } else
1105         PUTCHAR(0, *outp);
1106
1107     /*
1108      * Copy the data in outp 
1109      */
1110     BCOPY(ets->data + ets->offset, *outp, size);
1111     INCPTR(size, *outp);
1112
1113     /*
1114      * Copy the packet in retransmission buffer 
1115      */
1116     BCOPY(start, &ets->rtx[0], *outp - start);
1117     ets->rtx_len = *outp - start;
1118
1119     ets->offset += size;
1120
1121     if (ets->offset >= ets->datalen) {
1122
1123         /*
1124          * The whole message has been sent 
1125          */
1126
1127         free(ets->data);
1128         ets->data = NULL;
1129         ets->datalen = 0;
1130         ets->offset = 0;
1131     }
1132
1133     return 0;
1134 }
1135
1136 /*
1137  * Get the sent packet from the retransmission buffer
1138  */
1139 void eaptls_retransmit(struct eaptls_session *ets, u_char ** outp)
1140 {
1141     BCOPY(ets->rtx, *outp, ets->rtx_len);
1142     INCPTR(ets->rtx_len, *outp);
1143 }
1144
1145 /*
1146  * Verify a certificate.
1147  * Most of the work (signatures and issuer attributes checking)
1148  * is done by ssl; we check the CN in the peer certificate 
1149  * against the peer name.
1150  */
1151 int ssl_verify_callback(int ok, X509_STORE_CTX * ctx)
1152 {
1153     char subject[256];
1154     char cn_str[256];
1155     X509 *peer_cert;
1156     int err, depth;
1157     SSL *ssl;
1158     struct eaptls_session *ets;
1159     char *ptr1 = NULL, *ptr2 = NULL;
1160
1161     peer_cert = X509_STORE_CTX_get_current_cert(ctx);
1162     err = X509_STORE_CTX_get_error(ctx);
1163     depth = X509_STORE_CTX_get_error_depth(ctx);
1164
1165     dbglog("certificate verify depth: %d", depth);
1166
1167     if (auth_required && !ok) {
1168         X509_NAME_oneline(X509_get_subject_name(peer_cert),
1169                   subject, 256);
1170
1171         X509_NAME_get_text_by_NID(X509_get_subject_name(peer_cert),
1172                       NID_commonName, cn_str, 256);
1173
1174         dbglog("Certificate verification error:\n depth: %d CN: %s"
1175                "\n err: %d (%s)\n", depth, cn_str, err,
1176                X509_verify_cert_error_string(err));
1177
1178         return 0;
1179     }
1180
1181     ssl = X509_STORE_CTX_get_ex_data(ctx,
1182                        SSL_get_ex_data_X509_STORE_CTX_idx());
1183
1184     ets = (struct eaptls_session *)SSL_get_ex_data(ssl, 0);
1185
1186     if (ets == NULL) {
1187         error("Error: SSL_get_ex_data returned NULL");
1188         return 0;
1189     }
1190
1191     log_ssl_errors();
1192
1193     if (!depth) 
1194     {
1195         /* Verify certificate based on certificate type and extended key usage */
1196         if (tls_verify_key_usage) {
1197             int purpose = ets->client ? X509_PURPOSE_SSL_SERVER : X509_PURPOSE_SSL_CLIENT ;
1198             if (X509_check_purpose(peer_cert, purpose, 0) == 0) {
1199                 error("Certificate verification error: nsCertType mismatch");
1200                 return 0;
1201             }
1202
1203 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
1204             int flags = ets->client ? XKU_SSL_SERVER : XKU_SSL_CLIENT;
1205             if (!(X509_get_extended_key_usage(peer_cert) & flags)) {
1206                 error("Certificate verification error: invalid extended key usage");
1207                 return 0;
1208             }
1209 #endif
1210             info("Certificate key usage: OK");
1211         }
1212
1213         /*
1214          * If acting as client and the name of the server wasn't specified
1215          * explicitely, we can't verify the server authenticity 
1216          */
1217         if (!tls_verify_method)
1218             tls_verify_method = TLS_VERIFY_NONE;
1219
1220         if (!ets->peer[0] || !strcmp(TLS_VERIFY_NONE, tls_verify_method)) {
1221             warn("Certificate verication disabled or no peer name was specified");
1222             return ok;
1223         }
1224
1225         /* This is the peer certificate */
1226         X509_NAME_oneline(X509_get_subject_name(peer_cert),
1227                   subject, 256);
1228
1229         X509_NAME_get_text_by_NID(X509_get_subject_name(peer_cert),
1230                       NID_commonName, cn_str, 256);
1231
1232         /* Verify based on subject name */
1233         ptr1 = ets->peer;
1234         if (!strcmp(TLS_VERIFY_SUBJECT, tls_verify_method)) {
1235             ptr2 = subject;
1236         }
1237
1238         /* Verify based on common name (default) */
1239         if (strlen(tls_verify_method) == 0 ||
1240             !strcmp(TLS_VERIFY_NAME, tls_verify_method)) {
1241             ptr2 = cn_str;
1242         }
1243
1244         /* Match the suffix of common name */
1245         if (!strcmp(TLS_VERIFY_SUFFIX, tls_verify_method)) {
1246             int len = strlen(ptr1);
1247             int off = strlen(cn_str) - len;
1248             ptr2 = cn_str;
1249             if (off > 0) {
1250                 ptr2 = cn_str + off;
1251             }
1252         }
1253
1254         if (strcmp(ptr1, ptr2)) {
1255             error("Certificate verification error: CN (%s) != %s", ptr1, ptr2);
1256             return 0;
1257         }
1258
1259         info("Certificate CN: %s, peer name %s", cn_str, ets->peer);
1260
1261         /*
1262          * If a peer certificate file was specified, here we check it 
1263          */
1264         if (ets->peercertfile[0]) {
1265             if (ssl_cmp_certs(&ets->peercertfile[0], peer_cert)
1266                 != 0) {
1267                 error
1268                     ("Peer certificate doesn't match stored certificate");
1269                 return 0;
1270             }
1271         }
1272     }
1273
1274     return ok;
1275 }
1276
1277 /*
1278  * Compare a certificate with the one stored in a file
1279  */
1280 int ssl_cmp_certs(char *filename, X509 * a)
1281 {
1282     X509 *b;
1283     int ret;
1284
1285     if (!(b = get_X509_from_file(filename)))
1286         return 1;
1287
1288     ret = X509_cmp(a, b);
1289     X509_free(b);
1290
1291     return ret;
1292
1293 }
1294
1295 X509 *get_X509_from_file(char *filename)
1296 {
1297     FILE *fp;
1298     X509 *ret;
1299
1300     if (!(fp = fopen(filename, "r")))
1301         return NULL;
1302
1303     ret = PEM_read_X509(fp, NULL, NULL, NULL);
1304
1305     fclose(fp);
1306
1307     return ret;
1308 }
1309
1310 /*
1311  * Every sent & received message this callback function is invoked,
1312  * so we know when alert messages have arrived or are sent and
1313  * we can print debug information about TLS handshake.
1314  */
1315 void
1316 ssl_msg_callback(int write_p, int version, int content_type,
1317          const void *buf, size_t len, SSL * ssl, void *arg)
1318 {
1319     char string[256];
1320     struct eaptls_session *ets = (struct eaptls_session *)arg;
1321     unsigned char code;
1322     const unsigned char*msg = buf;
1323     int hvers = msg[1] << 8 | msg[2];
1324
1325     if(write_p)
1326         strcpy(string, " -> ");
1327     else
1328         strcpy(string, " <- ");
1329
1330     switch(content_type) {
1331
1332     case SSL3_RT_HEADER:
1333         strcat(string, "SSL/TLS Header: ");
1334         switch(hvers) {
1335         case SSL3_VERSION:
1336                 strcat(string, "SSL 3.0");
1337                 break;
1338         case TLS1_VERSION:
1339                 strcat(string, "TLS 1.0");
1340                 break;
1341         case TLS1_1_VERSION:
1342                 strcat(string, "TLS 1.1");
1343                 break;
1344         case TLS1_2_VERSION:
1345                 strcat(string, "TLS 1.2");
1346                 break;
1347         default:
1348             sprintf(string, "SSL/TLS Header: Unknown version (%d)", hvers);
1349         }
1350         break;
1351
1352     case SSL3_RT_ALERT:
1353         strcat(string, "Alert: ");
1354         code = msg[1];
1355
1356         if (write_p) {
1357             ets->alert_sent = 1;
1358             ets->alert_sent_desc = code;
1359         } else {
1360             ets->alert_recv = 1;
1361             ets->alert_recv_desc = code;
1362         }
1363
1364         strcat(string, SSL_alert_desc_string_long(code));
1365         break;
1366
1367     case SSL3_RT_CHANGE_CIPHER_SPEC:
1368         strcat(string, "ChangeCipherSpec");
1369         break;
1370
1371 #ifdef SSL3_RT_INNER_CONTENT_TYPE
1372     case SSL3_RT_INNER_CONTENT_TYPE:
1373         strcat(string, "InnerContentType (TLS1.3)");
1374         break;
1375 #endif
1376
1377     case SSL3_RT_HANDSHAKE:
1378
1379         strcat(string, "Handshake: ");
1380         code = msg[0];
1381
1382         switch(code) {
1383             case SSL3_MT_HELLO_REQUEST:
1384                 strcat(string,"Hello Request");
1385                 break;
1386             case SSL3_MT_CLIENT_HELLO:
1387                 strcat(string,"Client Hello");
1388                 break;
1389             case SSL3_MT_SERVER_HELLO:
1390                 strcat(string,"Server Hello");
1391                 break;
1392 #ifdef SSL3_MT_NEWSESSION_TICKET
1393             case SSL3_MT_NEWSESSION_TICKET:
1394                 strcat(string,"New Session Ticket");
1395                 break;
1396 #endif
1397 #ifdef SSL3_MT_END_OF_EARLY_DATA
1398             case SSL3_MT_END_OF_EARLY_DATA:
1399                 strcat(string,"End of Early Data");
1400                 break;
1401 #endif
1402 #ifdef SSL3_MT_ENCRYPTED_EXTENSIONS
1403             case SSL3_MT_ENCRYPTED_EXTENSIONS:
1404                 strcat(string,"Encryped Extensions");
1405                 break;
1406 #endif
1407             case SSL3_MT_CERTIFICATE:
1408                 strcat(string,"Certificate");
1409                 break;
1410             case SSL3_MT_SERVER_KEY_EXCHANGE:
1411                 strcat(string,"Server Key Exchange");
1412                 break;
1413             case SSL3_MT_CERTIFICATE_REQUEST:
1414                 strcat(string,"Certificate Request");
1415                 break;
1416             case SSL3_MT_SERVER_DONE:
1417                 strcat(string,"Server Hello Done");
1418                 break;
1419             case SSL3_MT_CERTIFICATE_VERIFY:
1420                 strcat(string,"Certificate Verify");
1421                 break;
1422             case SSL3_MT_CLIENT_KEY_EXCHANGE:
1423                 strcat(string,"Client Key Exchange");
1424                 break;
1425             case SSL3_MT_FINISHED:
1426                 strcat(string,"Finished: ");
1427                 hvers = SSL_version(ssl);
1428                 switch(hvers){
1429                     case SSL3_VERSION:
1430                         strcat(string, "SSL 3.0");
1431                         break;
1432                     case TLS1_VERSION:
1433                         strcat(string, "TLS 1.0");
1434                         break;
1435                     case TLS1_1_VERSION:
1436                         strcat(string, "TLS 1.1");
1437                         break;
1438                     case TLS1_2_VERSION:
1439                         strcat(string, "TLS 1.2");
1440                         break;
1441 #ifdef TLS1_3_VERSION
1442                     case TLS1_3_VERSION:
1443                         strcat(string, "TLS 1.3 (experimental)");
1444                         ets->tls_v13 = 1;
1445                         break;
1446 #endif
1447                     default:
1448                         strcat(string, "Unknown version");
1449                 }
1450                 break;
1451             default:
1452                 sprintf( string, "Handshake: Unknown SSL3 code received: %d", code );
1453         }
1454         break;
1455
1456     default:
1457         sprintf( string, "SSL message contains unknown content type: %d", content_type );
1458     }
1459
1460     /* Alert messages must always be displayed */
1461     if(content_type == SSL3_RT_ALERT)
1462         error("%s", string);
1463     else
1464         dbglog("%s", string);
1465 }
1466
1467 int 
1468 ssl_new_session_cb(SSL *s, SSL_SESSION *sess)
1469 {
1470     dbglog("EAP-TLS: Post-Handshake New Session Ticket arrived:");
1471     have_session_ticket = 1;
1472
1473     /* always return success */
1474     return 1;
1475 }
1476