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