Commit 9f5870832b991cc1db0be6a62ad973a367628110

Authored by perry.werneck@gmail.com
1 parent 358c84c0

Melhorando tratamento de erros SSL

Showing 4 changed files with 120 additions and 91 deletions   Show diff stats
@@ -985,9 +985,17 @@ LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 * @@ -985,9 +985,17 @@ LIB3270_EXPORT int lib3270_call_thread(int(*callback)(H3270 *h, void *), H3270 *
985 985
986 lib3270_main_iterate(0); 986 lib3270_main_iterate(0);
987 if(callbacks->callthread) 987 if(callbacks->callthread)
  988 + {
  989 + h->bgthread = 1;
  990 + trace("%s: background thread for %p starts",__FUNCTION__,h);
988 rc = callbacks->callthread(callback,h,parm); 991 rc = callbacks->callthread(callback,h,parm);
  992 + trace("%s: background thread for %p ends",__FUNCTION__,h);
  993 + h->bgthread = 0;
  994 + }
989 else 995 else
  996 + {
990 rc = callback(h,parm); 997 rc = callback(h,parm);
  998 + }
991 lib3270_main_iterate(0); 999 lib3270_main_iterate(0);
992 1000
993 if(h->set_timer) 1001 if(h->set_timer)
@@ -111,6 +111,13 @@ static void set_cursor(H3270 *session, LIB3270_CURSOR id) @@ -111,6 +111,13 @@ static void set_cursor(H3270 *session, LIB3270_CURSOR id)
111 { 111 {
112 } 112 }
113 113
  114 +static void message(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *text)
  115 +{
  116 + lib3270_write_log(session,"%s",title);
  117 + lib3270_write_log(session,"%s",message);
  118 + lib3270_write_log(session,"%s",text);
  119 +}
  120 +
114 static void lib3270_session_init(H3270 *hSession, const char *model) 121 static void lib3270_session_init(H3270 *hSession, const char *model)
115 { 122 {
116 int ovc, ovr; 123 int ovc, ovr;
@@ -136,6 +143,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) @@ -136,6 +143,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model)
136 hSession->update_oia = update_oia; 143 hSession->update_oia = update_oia;
137 hSession->update_selection = update_selection; 144 hSession->update_selection = update_selection;
138 hSession->cursor = set_cursor; 145 hSession->cursor = set_cursor;
  146 + hSession->message = message;
139 147
140 hSession->sock = -1; 148 hSession->sock = -1;
141 hSession->model_num = -1; 149 hSession->model_num = -1;
@@ -596,6 +596,8 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit @@ -596,6 +596,8 @@ void show_3270_popup_dialog(H3270 *session, LIB3270_NOTIFY type, const char *tit
596 { 596 {
597 CHECK_SESSION_HANDLE(session); 597 CHECK_SESSION_HANDLE(session);
598 598
  599 + trace("%s: title=%s msg=%s",__FUNCTION__,title,msg);
  600 +
599 if(!fmt) 601 if(!fmt)
600 fmt = ""; 602 fmt = "";
601 603
@@ -618,6 +620,8 @@ void Error(H3270 *session, const char *fmt, ...) @@ -618,6 +620,8 @@ void Error(H3270 *session, const char *fmt, ...)
618 620
619 CHECK_SESSION_HANDLE(session); 621 CHECK_SESSION_HANDLE(session);
620 622
  623 + trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt);
  624 +
621 va_start(arg_ptr, fmt); 625 va_start(arg_ptr, fmt);
622 popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr); 626 popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR, _( "3270 Error" ),NULL,fmt,arg_ptr);
623 va_end(arg_ptr); 627 va_end(arg_ptr);
@@ -630,6 +634,8 @@ void Warning(H3270 *session, const char *fmt, ...) @@ -630,6 +634,8 @@ void Warning(H3270 *session, const char *fmt, ...)
630 634
631 CHECK_SESSION_HANDLE(session); 635 CHECK_SESSION_HANDLE(session);
632 636
  637 + trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Warning",fmt);
  638 +
633 va_start(arg_ptr, fmt); 639 va_start(arg_ptr, fmt);
634 popup_handler(session,session->widget,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr); 640 popup_handler(session,session->widget,LIB3270_NOTIFY_WARNING, _( "3270 Warning" ),NULL,fmt,arg_ptr);
635 va_end(arg_ptr); 641 va_end(arg_ptr);
@@ -643,6 +649,8 @@ extern void popup_an_error(H3270 *session, const char *fmt, ...) @@ -643,6 +649,8 @@ extern void popup_an_error(H3270 *session, const char *fmt, ...)
643 649
644 CHECK_SESSION_HANDLE(session); 650 CHECK_SESSION_HANDLE(session);
645 651
  652 + trace("%s: title=%s fmt=%s",__FUNCTION__,"3270 Error",fmt);
  653 +
646 va_start(args, fmt); 654 va_start(args, fmt);
647 popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args); 655 popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,_( "3270 Error" ),NULL,fmt,args);
648 va_end(args); 656 va_end(args);
@@ -655,6 +663,8 @@ void popup_system_error(H3270 *session, const char *title, const char *message, @@ -655,6 +663,8 @@ void popup_system_error(H3270 *session, const char *title, const char *message,
655 663
656 CHECK_SESSION_HANDLE(session); 664 CHECK_SESSION_HANDLE(session);
657 665
  666 + trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message);
  667 +
658 va_start(args, fmt); 668 va_start(args, fmt);
659 popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args); 669 popup_handler(session,session->widget,LIB3270_NOTIFY_ERROR,title ? title : _( "3270 Error" ), message,fmt,args);
660 va_end(args); 670 va_end(args);
@@ -764,6 +774,8 @@ LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , con @@ -764,6 +774,8 @@ LIB3270_EXPORT void lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , con
764 774
765 CHECK_SESSION_HANDLE(session); 775 CHECK_SESSION_HANDLE(session);
766 776
  777 + trace("%s: title=%s msg=%s",__FUNCTION__,"3270 Error",message);
  778 +
767 va_start(args, fmt); 779 va_start(args, fmt);
768 popup_handler(session,session->widget,id,title ? title : _( "3270 Error" ), message,fmt,args); 780 popup_handler(session,session->widget,id,title ? title : _( "3270 Error" ), message,fmt,args);
769 va_end(args); 781 va_end(args);
@@ -61,10 +61,6 @@ @@ -61,10 +61,6 @@
61 #endif /*]*/ 61 #endif /*]*/
62 #include <stdarg.h> 62 #include <stdarg.h>
63 63
64 -#if defined(HAVE_LIBSSL) /*[*/  
65 - #include <openssl/ssl.h>  
66 - #include <openssl/err.h>  
67 -#endif /*]*/  
68 #include "tn3270e.h" 64 #include "tn3270e.h"
69 #include "3270ds.h" 65 #include "3270ds.h"
70 66
@@ -196,7 +192,7 @@ static void net_rawout(unsigned const char *buf, int len); @@ -196,7 +192,7 @@ static void net_rawout(unsigned const char *buf, int len);
196 static void check_in3270(void); 192 static void check_in3270(void);
197 static void store3270in(unsigned char c); 193 static void store3270in(unsigned char c);
198 static void check_linemode(Boolean init); 194 static void check_linemode(Boolean init);
199 -// static int non_blocking(Boolean on); 195 +static int non_blocking(Boolean on);
200 static void net_connected(H3270 *session); 196 static void net_connected(H3270 *session);
201 #if defined(X3270_TN3270E) /*[*/ 197 #if defined(X3270_TN3270E) /*[*/
202 static int tn3270e_negotiate(void); 198 static int tn3270e_negotiate(void);
@@ -308,11 +304,13 @@ static const char *trsp_flag[2] = { &quot;POSITIVE-RESPONSE&quot;, &quot;NEGATIVE-RESPONSE&quot; }; @@ -308,11 +304,13 @@ static const char *trsp_flag[2] = { &quot;POSITIVE-RESPONSE&quot;, &quot;NEGATIVE-RESPONSE&quot; };
308 #define XMIT_COLS h3270.maxCOLS 304 #define XMIT_COLS h3270.maxCOLS
309 // #endif /*]*/ 305 // #endif /*]*/
310 306
  307 +// #if defined(HAVE_LIBSSL)
  308 +// static SSL *ssl_con;
  309 +// #endif
  310 +
311 #if defined(HAVE_LIBSSL) /*[*/ 311 #if defined(HAVE_LIBSSL) /*[*/
312 -static SSL_CTX *ssl_ctx;  
313 -static SSL *ssl_con;  
314 static Boolean need_tls_follows = False; 312 static Boolean need_tls_follows = False;
315 -static void ssl_init(void); 313 +static void ssl_init(H3270 *session);
316 #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/ 314 #if OPENSSL_VERSION_NUMBER >= 0x00907000L /*[*/
317 #define INFO_CONST const 315 #define INFO_CONST const
318 #else /*][*/ 316 #else /*][*/
@@ -600,14 +598,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -600,14 +598,8 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
600 #endif 598 #endif
601 599
602 /* set the socket to be non-delaying */ 600 /* set the socket to be non-delaying */
603 -/*  
604 -#if defined(_WIN32)  
605 - if (non_blocking(False) < 0)  
606 -#else  
607 if (non_blocking(True) < 0) 601 if (non_blocking(True) < 0)
608 -#endif  
609 close_fail; 602 close_fail;
610 -*/  
611 603
612 #if !defined(_WIN32) 604 #if !defined(_WIN32)
613 /* don't share the socket with our children */ 605 /* don't share the socket with our children */
@@ -616,26 +608,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -616,26 +608,14 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
616 608
617 /* init ssl */ 609 /* init ssl */
618 #if defined(HAVE_LIBSSL) 610 #if defined(HAVE_LIBSSL)
619 - session->last_ssl_error = 0; 611 + session->last_ssl_error = !0;
620 if (session->ssl_host) 612 if (session->ssl_host)
621 - ssl_init(); 613 + ssl_init(session);
622 #endif 614 #endif
623 615
624 /* connect */ 616 /* connect */
625 status_connecting(session,1); 617 status_connecting(session,1);
626 618
627 - if(connect_sock(session, session->sock, &haddr.sa,ha_len) == 0)  
628 - {  
629 - trace_dsn("Connected.\n");  
630 - net_connected(session);  
631 - }  
632 - else  
633 - {  
634 - popup_a_sockerr(session, N_( "Can't connect to %s:%d" ),session->hostname, session->current_port);  
635 - close_fail;  
636 - }  
637 -  
638 -/*  
639 switch(connect_sock(session, session->sock, &haddr.sa,ha_len)) 619 switch(connect_sock(session, session->sock, &haddr.sa,ha_len))
640 { 620 {
641 case 0: // Connected 621 case 0: // Connected
@@ -650,9 +630,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -650,9 +630,9 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
650 case SE_EINPROGRESS: 630 case SE_EINPROGRESS:
651 *pending = True; 631 *pending = True;
652 trace_dsn("Connection pending.\n"); 632 trace_dsn("Connection pending.\n");
653 -#if !defined(_WIN32) 633 +// #if !defined(_WIN32)
654 output_id = AddOutput(session->sock, session, output_possible); 634 output_id = AddOutput(session->sock, session, output_possible);
655 -#endif 635 +// #endif
656 break; 636 break;
657 637
658 default: 638 default:
@@ -660,7 +640,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo @@ -660,7 +640,6 @@ int net_connect(H3270 *session, const char *host, char *portname, Boolean ls, Bo
660 close_fail; 640 close_fail;
661 641
662 } 642 }
663 -*/  
664 643
665 /* set up temporary termtype */ 644 /* set up temporary termtype */
666 if (appres.termname == CN && session->std_ds_host) 645 if (appres.termname == CN && session->std_ds_host)
@@ -784,25 +763,40 @@ static void net_connected(H3270 *session) @@ -784,25 +763,40 @@ static void net_connected(H3270 *session)
784 /* Set up SSL. */ 763 /* Set up SSL. */
785 if(session->ssl_host && !session->secure_connection) 764 if(session->ssl_host && !session->secure_connection)
786 { 765 {
787 - if (SSL_set_fd(ssl_con, session->sock) != 1) 766 + int rc;
  767 +
  768 + if (SSL_set_fd(session->ssl_con, session->sock) != 1)
788 { 769 {
789 trace_dsn("Can't set fd!\n"); 770 trace_dsn("Can't set fd!\n");
  771 + popup_system_error(&h3270,_( "Connection failed error" ), _( "Can't set SSL socket file descriptor" ), "%s", SSL_state_string_long(session->ssl_con));
790 } 772 }
791 773
792 - if (SSL_connect(ssl_con) != 1) 774 + non_blocking(False);
  775 + rc = SSL_connect(session->ssl_con);
  776 +
  777 + if(rc != 1)
793 { 778 {
794 - unsigned long e = ERR_get_error(); 779 + unsigned long e = ERR_get_error();
  780 + const char * state = SSL_state_string_long(session->ssl_con);
  781 +
  782 + trace_dsn("TLS/SSL tunneled connection failed with error %ld, rc=%d and state=%s",e,rc,state);
  783 +
  784 + host_disconnect(session,True);
  785 +
795 if(e != session->last_ssl_error) 786 if(e != session->last_ssl_error)
796 { 787 {
797 - popup_system_error(&h3270,_( "Connection failed error" ), _( "SSL negotiation failed" ), "%s", SSL_state_string_long(ssl_con)); 788 + session->message( &h3270,
  789 + LIB3270_NOTIFY_ERROR,
  790 + _( "Connection failed" ),
  791 + _( "SSL negotiation failed" ),
  792 + state);
798 session->last_ssl_error = e; 793 session->last_ssl_error = e;
799 } 794 }
800 -  
801 - trace_dsn("TLS/SSL tunneled connection failed with error %ld.",e);  
802 - trace("%s: SSL_connect failed with error %ld",__FUNCTION__,e);  
803 - host_disconnect(session,True);  
804 return; 795 return;
  796 +
805 } 797 }
  798 + non_blocking(True);
  799 +
806 session->secure_connection = True; 800 session->secure_connection = True;
807 trace_dsn("TLS/SSL tunneled connection complete. Connection is now secure.\n"); 801 trace_dsn("TLS/SSL tunneled connection complete. Connection is now secure.\n");
808 802
@@ -864,15 +858,11 @@ static void net_connected(H3270 *session) @@ -864,15 +858,11 @@ static void net_connected(H3270 *session)
864 */ 858 */
865 static void connection_complete(void) 859 static void connection_complete(void)
866 { 860 {
867 -/*  
868 -#if !defined(_WIN32)  
869 if (non_blocking(False) < 0) 861 if (non_blocking(False) < 0)
870 { 862 {
871 host_disconnect(&h3270,True); 863 host_disconnect(&h3270,True);
872 return; 864 return;
873 } 865 }
874 -#endif  
875 -*/  
876 host_connected(&h3270); 866 host_connected(&h3270);
877 net_connected(&h3270); 867 net_connected(&h3270);
878 } 868 }
@@ -903,14 +893,14 @@ static void output_possible(H3270 *session) @@ -903,14 +893,14 @@ static void output_possible(H3270 *session)
903 * net_disconnect 893 * net_disconnect
904 * Shut down the socket. 894 * Shut down the socket.
905 */ 895 */
906 -void  
907 -net_disconnect(void) 896 +void net_disconnect(void)
908 { 897 {
909 #if defined(HAVE_LIBSSL) /*[*/ 898 #if defined(HAVE_LIBSSL) /*[*/
910 - if (ssl_con != NULL) {  
911 - SSL_shutdown(ssl_con);  
912 - SSL_free(ssl_con);  
913 - ssl_con = NULL; 899 + if (h3270.ssl_con != NULL)
  900 + {
  901 + SSL_shutdown(h3270.ssl_con);
  902 + SSL_free(h3270.ssl_con);
  903 + h3270.ssl_con = NULL;
914 } 904 }
915 h3270.secure_connection = False; 905 h3270.secure_connection = False;
916 #endif /*]*/ 906 #endif /*]*/
@@ -991,13 +981,13 @@ void net_input(H3270 *session) @@ -991,13 +981,13 @@ void net_input(H3270 *session)
991 ansi_data = 0; 981 ansi_data = 0;
992 #endif /*]*/ 982 #endif /*]*/
993 983
994 -#if defined(_WIN32) /*[*/  
995 - (void) ResetEvent(session->sock_handle);  
996 -#endif /*]*/ 984 +// #if defined(_WIN32)
  985 +// (void) ResetEvent(session->sock_handle);
  986 +//#endif /*]*/
997 987
998 #if defined(HAVE_LIBSSL) 988 #if defined(HAVE_LIBSSL)
999 - if (ssl_con != NULL)  
1000 - nr = SSL_read(ssl_con, (char *) netrbuf, BUFSZ); 989 + if (session->ssl_con != NULL)
  990 + nr = SSL_read(session->ssl_con, (char *) netrbuf, BUFSZ);
1001 else 991 else
1002 #endif // HAVE_LIBSSL 992 #endif // HAVE_LIBSSL
1003 /* 993 /*
@@ -1013,7 +1003,7 @@ void net_input(H3270 *session) @@ -1013,7 +1003,7 @@ void net_input(H3270 *session)
1013 return; 1003 return;
1014 } 1004 }
1015 #if defined(HAVE_LIBSSL) /*[*/ 1005 #if defined(HAVE_LIBSSL) /*[*/
1016 - if (ssl_con != NULL) 1006 + if(session->ssl_con != NULL)
1017 { 1007 {
1018 unsigned long e; 1008 unsigned long e;
1019 char err_buf[120]; 1009 char err_buf[120];
@@ -1026,11 +1016,11 @@ void net_input(H3270 *session) @@ -1026,11 +1016,11 @@ void net_input(H3270 *session)
1026 1016
1027 trace_dsn("RCVD SSL_read error %ld (%s)\n", e,err_buf); 1017 trace_dsn("RCVD SSL_read error %ld (%s)\n", e,err_buf);
1028 1018
1029 - lib3270_popup_dialog( session,  
1030 - LIB3270_NOTIFY_CRITICAL,  
1031 - N_( "SSL Error" ),  
1032 - N_( "SSL Read error" ),  
1033 - "%s", err_buf); 1019 + h3270.message( &h3270,
  1020 + LIB3270_NOTIFY_ERROR,
  1021 + _( "SSL Error" ),
  1022 + _( "SSL Read error" ),
  1023 + err_buf );
1034 1024
1035 host_disconnect(session,True); 1025 host_disconnect(session,True);
1036 return; 1026 return;
@@ -1074,13 +1064,11 @@ void net_input(H3270 *session) @@ -1074,13 +1064,11 @@ void net_input(H3270 *session)
1074 1064
1075 if (HALF_CONNECTED) 1065 if (HALF_CONNECTED)
1076 { 1066 {
1077 -/*  
1078 if (non_blocking(False) < 0) 1067 if (non_blocking(False) < 0)
1079 { 1068 {
1080 host_disconnect(session,True); 1069 host_disconnect(session,True);
1081 return; 1070 return;
1082 } 1071 }
1083 -*/  
1084 host_connected(session); 1072 host_connected(session);
1085 net_connected(session); 1073 net_connected(session);
1086 } 1074 }
@@ -2022,8 +2010,8 @@ net_rawout(unsigned const char *buf, int len) @@ -2022,8 +2010,8 @@ net_rawout(unsigned const char *buf, int len)
2022 # define n2w len 2010 # define n2w len
2023 #endif 2011 #endif
2024 #if defined(HAVE_LIBSSL) /*[*/ 2012 #if defined(HAVE_LIBSSL) /*[*/
2025 - if (ssl_con != NULL)  
2026 - nw = SSL_write(ssl_con, (const char *) buf, n2w); 2013 + if(h3270.ssl_con != NULL)
  2014 + nw = SSL_write(h3270.ssl_con, (const char *) buf, n2w);
2027 else 2015 else
2028 #endif /*]*/ 2016 #endif /*]*/
2029 2017
@@ -2037,7 +2025,8 @@ net_rawout(unsigned const char *buf, int len) @@ -2037,7 +2025,8 @@ net_rawout(unsigned const char *buf, int len)
2037 nw = send(h3270.sock, (const char *) buf, n2w, 0); 2025 nw = send(h3270.sock, (const char *) buf, n2w, 0);
2038 if (nw < 0) { 2026 if (nw < 0) {
2039 #if defined(HAVE_LIBSSL) /*[*/ 2027 #if defined(HAVE_LIBSSL) /*[*/
2040 - if (ssl_con != NULL) { 2028 + if (h3270.ssl_con != NULL)
  2029 + {
2041 unsigned long e; 2030 unsigned long e;
2042 char err_buf[120]; 2031 char err_buf[120];
2043 2032
@@ -3196,11 +3185,11 @@ net_snap_options(void) @@ -3196,11 +3185,11 @@ net_snap_options(void)
3196 /* 3185 /*
3197 * Set blocking/non-blocking mode on the socket. On error, pops up an error 3186 * Set blocking/non-blocking mode on the socket. On error, pops up an error
3198 * message, but does not close the socket. 3187 * message, but does not close the socket.
3199 - */ /*  
3200 -static int  
3201 -non_blocking(Boolean on) 3188 + */
  3189 +static int non_blocking(Boolean on)
3202 { 3190 {
3203 #if !defined(BLOCKING_CONNECT_ONLY) 3191 #if !defined(BLOCKING_CONNECT_ONLY)
  3192 +
3204 # if defined(FIONBIO) 3193 # if defined(FIONBIO)
3205 int i = on ? 1 : 0; 3194 int i = on ? 1 : 0;
3206 3195
@@ -3209,7 +3198,9 @@ non_blocking(Boolean on) @@ -3209,7 +3198,9 @@ non_blocking(Boolean on)
3209 popup_a_sockerr(NULL, N_( "ioctl(%s)" ), "FIONBIO"); 3198 popup_a_sockerr(NULL, N_( "ioctl(%s)" ), "FIONBIO");
3210 return -1; 3199 return -1;
3211 } 3200 }
  3201 +
3212 # else 3202 # else
  3203 +
3213 int f; 3204 int f;
3214 3205
3215 if ((f = fcntl(sock, F_GETFL, 0)) == -1) 3206 if ((f = fcntl(sock, F_GETFL, 0)) == -1)
@@ -3226,42 +3217,52 @@ non_blocking(Boolean on) @@ -3226,42 +3217,52 @@ non_blocking(Boolean on)
3226 popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL"); 3217 popup_an_errno(NULL,errno, N_( "fcntl(%s)" ), "F_GETFL");
3227 return -1; 3218 return -1;
3228 } 3219 }
3229 -# endif  
3230 -#endif 3220 +#endif // FIONBIO
  3221 +
  3222 +#endif // !BLOCKING_CONNECT_ONLY
  3223 +
3231 return 0; 3224 return 0;
3232 } 3225 }
3233 -*/  
3234 3226
3235 #if defined(HAVE_LIBSSL) /*[*/ 3227 #if defined(HAVE_LIBSSL) /*[*/
3236 3228
3237 /* Initialize the OpenSSL library. */ 3229 /* Initialize the OpenSSL library. */
3238 -static void ssl_init(void) 3230 +static void ssl_init(H3270 *session)
3239 { 3231 {
3240 - static Boolean ssl_initted = False; 3232 + static SSL_CTX *ssl_ctx = NULL;
3241 3233
3242 - if (!ssl_initted) { 3234 + if(ssl_ctx == NULL)
  3235 + {
  3236 + lib3270_write_log(session,"%s","Initializing SSL context");
3243 SSL_load_error_strings(); 3237 SSL_load_error_strings();
3244 SSL_library_init(); 3238 SSL_library_init();
3245 - ssl_initted = True;  
3246 ssl_ctx = SSL_CTX_new(SSLv23_method()); 3239 ssl_ctx = SSL_CTX_new(SSLv23_method());
3247 - if (ssl_ctx == NULL) { 3240 + if(ssl_ctx == NULL)
  3241 + {
3248 popup_an_error(NULL,"SSL_CTX_new failed"); 3242 popup_an_error(NULL,"SSL_CTX_new failed");
3249 - h3270.ssl_host = False; 3243 + session->ssl_host = False;
3250 return; 3244 return;
3251 } 3245 }
3252 SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); 3246 SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);
  3247 + SSL_CTX_set_info_callback(ssl_ctx, client_info_callback);
  3248 + SSL_CTX_set_default_verify_paths(ssl_ctx);
3253 } 3249 }
3254 3250
3255 - ssl_con = SSL_new(ssl_ctx);  
3256 - if (ssl_con == NULL) {  
3257 - popup_an_error(NULL,"SSL_new failed");  
3258 - h3270.ssl_host = False; 3251 + if(session->ssl_con)
  3252 + SSL_free(session->ssl_con);
  3253 +
  3254 + session->ssl_con = SSL_new(ssl_ctx);
  3255 + if(session->ssl_con == NULL)
  3256 + {
  3257 + popup_an_error(session,"SSL_new failed");
  3258 + session->ssl_host = False;
  3259 + return;
3259 } 3260 }
3260 - SSL_set_verify(ssl_con, 0/*xxx*/, NULL);  
3261 3261
3262 - SSL_CTX_set_info_callback(ssl_ctx, client_info_callback); 3262 + SSL_set_verify(session->ssl_con, 0/*xxx*/, NULL);
3263 3263
3264 /* XXX: May need to get key file and password. */ 3264 /* XXX: May need to get key file and password. */
  3265 + /*
3265 if (appres.cert_file) 3266 if (appres.cert_file)
3266 { 3267 {
3267 if (!(SSL_CTX_use_certificate_chain_file(ssl_ctx, 3268 if (!(SSL_CTX_use_certificate_chain_file(ssl_ctx,
@@ -3277,8 +3278,7 @@ static void ssl_init(void) @@ -3277,8 +3278,7 @@ static void ssl_init(void)
3277 appres.cert_file, err_buf); 3278 appres.cert_file, err_buf);
3278 } 3279 }
3279 } 3280 }
3280 -  
3281 - SSL_CTX_set_default_verify_paths(ssl_ctx); 3281 + */
3282 } 3282 }
3283 3283
3284 /* Callback for tracing protocol negotiation. */ 3284 /* Callback for tracing protocol negotiation. */
@@ -3343,8 +3343,7 @@ static void client_info_callback(INFO_CONST SSL *s, int where, int ret) @@ -3343,8 +3343,7 @@ static void client_info_callback(INFO_CONST SSL *s, int where, int ret)
3343 } 3343 }
3344 3344
3345 /* Process a STARTTLS subnegotiation. */ 3345 /* Process a STARTTLS subnegotiation. */
3346 -static void  
3347 -continue_tls(unsigned char *sbbuf, int len) 3346 +static void continue_tls(unsigned char *sbbuf, int len)
3348 { 3347 {
3349 int rv; 3348 int rv;
3350 3349
@@ -3364,15 +3363,17 @@ continue_tls(unsigned char *sbbuf, int len) @@ -3364,15 +3363,17 @@ continue_tls(unsigned char *sbbuf, int len)
3364 trace_dsn("%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); 3363 trace_dsn("%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE));
3365 3364
3366 /* Initialize the SSL library. */ 3365 /* Initialize the SSL library. */
3367 - ssl_init();  
3368 - if (ssl_con == NULL) { 3366 + ssl_init(&h3270);
  3367 + if(h3270.ssl_con == NULL)
  3368 + {
3369 /* Failed. */ 3369 /* Failed. */
3370 net_disconnect(); 3370 net_disconnect();
3371 return; 3371 return;
3372 } 3372 }
3373 3373
3374 /* Set up the TLS/SSL connection. */ 3374 /* Set up the TLS/SSL connection. */
3375 - if (SSL_set_fd(ssl_con, h3270.sock) != 1) { 3375 + if(SSL_set_fd(h3270.ssl_con, h3270.sock) != 1)
  3376 + {
3376 trace_dsn("Can't set fd!\n"); 3377 trace_dsn("Can't set fd!\n");
3377 } 3378 }
3378 3379
@@ -3382,7 +3383,7 @@ continue_tls(unsigned char *sbbuf, int len) @@ -3382,7 +3383,7 @@ continue_tls(unsigned char *sbbuf, int len)
3382 // (void) non_blocking(False); 3383 // (void) non_blocking(False);
3383 //#endif 3384 //#endif
3384 3385
3385 - rv = SSL_connect(ssl_con); 3386 + rv = SSL_connect(h3270.ssl_con);
3386 3387
3387 //#if defined(_WIN32) 3388 //#if defined(_WIN32)
3388 // // Make the socket non-blocking again for event processing 3389 // // Make the socket non-blocking again for event processing