Commit 68cd0fe9a1ab0f2276767cd6995dd0dfa79c921e

Authored by perry.werneck@gmail.com
1 parent 8beca250

Resolvendo "Hang" quando tenta conectar a um host seguro sem que a opção corresp…

…ondente esteja setada
Showing 2 changed files with 66 additions and 49 deletions   Show diff stats
@@ -317,13 +317,17 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); @@ -317,13 +317,17 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
317 317
318 /* Build the ind$file command */ 318 /* Build the ind$file command */
319 snprintf(op,4095,"%s%s%s", 319 snprintf(op,4095,"%s%s%s",
320 - (ft->flags & LIB3270_FT_OPTION_ASCII) ? " ASCII" : "",  
321 - (ft->flags & LIB3270_FT_OPTION_CRLF) ? " CRLF" : "",  
322 - (ft->flags & LIB3270_FT_OPTION_APPEND) ? " APPEND" : "" 320 + (ft->flags & LIB3270_FT_OPTION_ASCII) ? " ascii" : "",
  321 + (ft->flags & LIB3270_FT_OPTION_CRLF) ? " crlf" : "",
  322 + (ft->flags & LIB3270_FT_OPTION_APPEND) ? " append" : ""
323 ); 323 );
324 324
325 if(!(ft->flags & LIB3270_FT_OPTION_RECEIVE)) 325 if(!(ft->flags & LIB3270_FT_OPTION_RECEIVE))
326 { 326 {
  327 + // Sending file
  328 +
  329 + trace("tso=%d",ft->flags & LIB3270_FT_OPTION_TSO);
  330 +
327 if(ft->flags & LIB3270_FT_OPTION_TSO) 331 if(ft->flags & LIB3270_FT_OPTION_TSO)
328 { 332 {
329 // TSO Host 333 // TSO Host
@@ -365,16 +369,16 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); @@ -365,16 +369,16 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
365 } 369 }
366 } 370 }
367 371
368 - snprintf(buffer,4095,"%s %s %s", "IND$FILE",  
369 - (ft->flags & LIB3270_FT_OPTION_RECEIVE) ? "GET" : "PUT", 372 + snprintf(buffer,4095,"%s %s %s", "ind$file",
  373 + (ft->flags & LIB3270_FT_OPTION_RECEIVE) ? "get" : "put",
370 ft->remote ); 374 ft->remote );
371 375
372 if(*op) 376 if(*op)
373 { 377 {
374 if(ft->flags & LIB3270_FT_OPTION_TSO) 378 if(ft->flags & LIB3270_FT_OPTION_TSO)
375 - snconcat(buffer,4095," (%s)",op+1);  
376 - else  
377 snconcat(buffer,4095," %s",op+1); 379 snconcat(buffer,4095," %s",op+1);
  380 + else
  381 + snconcat(buffer,4095," (%s",op+1);
378 } 382 }
379 383
380 snconcat(buffer,4095,"%s","\n"); 384 snconcat(buffer,4095,"%s","\n");
@@ -801,6 +801,56 @@ static void setup_lus(H3270 *hSession) @@ -801,6 +801,56 @@ static void setup_lus(H3270 *hSession)
801 hSession->try_lu = *hSession->curr_lu; 801 hSession->try_lu = *hSession->curr_lu;
802 } 802 }
803 803
  804 +#if defined(HAVE_LIBSSL)
  805 +static void ssl_negotiate(H3270 *hSession)
  806 +{
  807 + int rv;
  808 +
  809 + set_ssl_state(hSession,LIB3270_SSL_NEGOTIATING);
  810 + non_blocking(hSession,False);
  811 +
  812 + /* Initialize the SSL library. */
  813 + ssl_init(hSession);
  814 + if(hSession->ssl_con == NULL)
  815 + {
  816 + /* Failed. */
  817 + popup_an_error(hSession,_( "SSL init failed!"));
  818 + net_disconnect(hSession);
  819 + return;
  820 + }
  821 +
  822 + /* Set up the TLS/SSL connection. */
  823 + if(SSL_set_fd(hSession->ssl_con, hSession->sock) != 1)
  824 + {
  825 + trace_dsn(hSession,"SSL_set_fd failed!\n");
  826 + popup_an_error(hSession,_( "SSL_set_fd failed!"));
  827 + net_disconnect(hSession);
  828 + return;
  829 + }
  830 +
  831 + trace("%s: Running SSL_connect",__FUNCTION__);
  832 + rv = SSL_connect(hSession->ssl_con);
  833 + trace("%s: SSL_connect exits with rc=%d",__FUNCTION__,rv);
  834 +
  835 + if (rv != 1)
  836 + {
  837 + trace_dsn(hSession,"continue_tls: SSL_connect failed\n");
  838 + popup_an_error(hSession,_( "SSL connect failed!"));
  839 + net_disconnect(hSession);
  840 + return;
  841 + }
  842 +
  843 +// hSession->secure_connection = True;
  844 + non_blocking(hSession,True);
  845 +
  846 + /* Success. */
  847 + trace_dsn(hSession,"TLS/SSL negotiated connection complete. Connection is now secure.\n");
  848 +
  849 + /* Tell the world that we are (still) connected, now in secure mode. */
  850 + lib3270_set_connected(hSession);
  851 +}
  852 +#endif // HAVE_LIBSSL
  853 +
804 static void net_connected(H3270 *hSession) 854 static void net_connected(H3270 *hSession)
805 { 855 {
806 if(hSession->proxy_type > 0) 856 if(hSession->proxy_type > 0)
@@ -821,6 +871,8 @@ static void net_connected(H3270 *hSession) @@ -821,6 +871,8 @@ static void net_connected(H3270 *hSession)
821 /* Set up SSL. */ 871 /* Set up SSL. */
822 if(hSession->ssl_con && hSession->secure == LIB3270_SSL_UNDEFINED) 872 if(hSession->ssl_con && hSession->secure == LIB3270_SSL_UNDEFINED)
823 { 873 {
  874 + ssl_negotiate(hSession);
  875 +/*
824 int rc; 876 int rc;
825 877
826 set_ssl_state(hSession,LIB3270_SSL_NEGOTIATING); 878 set_ssl_state(hSession,LIB3270_SSL_NEGOTIATING);
@@ -857,8 +909,9 @@ static void net_connected(H3270 *hSession) @@ -857,8 +909,9 @@ static void net_connected(H3270 *hSession)
857 // hSession->secure_connection = True; 909 // hSession->secure_connection = True;
858 trace_dsn(hSession,"TLS/SSL tunneled connection complete. Connection is now secure.\n"); 910 trace_dsn(hSession,"TLS/SSL tunneled connection complete. Connection is now secure.\n");
859 911
860 - /* Tell everyone else again. */ 912 + // Tell everyone else again.
861 lib3270_set_connected(hSession); 913 lib3270_set_connected(hSession);
  914 +*/
862 } 915 }
863 #endif /*]*/ 916 #endif /*]*/
864 917
@@ -3220,8 +3273,6 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret) @@ -3220,8 +3273,6 @@ static void ssl_info_callback(INFO_CONST SSL *s, int where, int ret)
3220 */ 3273 */
3221 static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len) 3274 static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len)
3222 { 3275 {
3223 - int rv;  
3224 -  
3225 /* Whatever happens, we're not expecting another SB STARTTLS. */ 3276 /* Whatever happens, we're not expecting another SB STARTTLS. */
3226 hSession->need_tls_follows = 0; 3277 hSession->need_tls_follows = 0;
3227 3278
@@ -3237,45 +3288,7 @@ static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len) @@ -3237,45 +3288,7 @@ static void continue_tls(H3270 *hSession, unsigned char *sbbuf, int len)
3237 3288
3238 /* Trace what we got. */ 3289 /* Trace what we got. */
3239 trace_dsn(hSession,"%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE)); 3290 trace_dsn(hSession,"%s FOLLOWS %s\n", opt(TELOPT_STARTTLS), cmd(SE));
3240 -  
3241 - /* Initialize the SSL library. */  
3242 - ssl_init(hSession);  
3243 - if(hSession->ssl_con == NULL)  
3244 - {  
3245 - /* Failed. */  
3246 - popup_an_error(hSession,_( "SSL init failed!"));  
3247 - net_disconnect(hSession);  
3248 - return;  
3249 - }  
3250 -  
3251 - /* Set up the TLS/SSL connection. */  
3252 - if(SSL_set_fd(hSession->ssl_con, hSession->sock) != 1)  
3253 - {  
3254 - trace_dsn(hSession,"SSL_set_fd failed!\n");  
3255 - popup_an_error(hSession,_( "SSL_set_fd failed!"));  
3256 - net_disconnect(hSession);  
3257 - return;  
3258 - }  
3259 -  
3260 - trace("%s: Running SSL_connect",__FUNCTION__);  
3261 - rv = SSL_connect(hSession->ssl_con);  
3262 - trace("%s: SSL_connect exits with rc=%d",__FUNCTION__,rv);  
3263 -  
3264 - if (rv != 1)  
3265 - {  
3266 - trace_dsn(hSession,"continue_tls: SSL_connect failed\n");  
3267 - popup_an_error(hSession,_( "SSL connect failed!"));  
3268 - net_disconnect(hSession);  
3269 - return;  
3270 - }  
3271 -  
3272 -// hSession->secure_connection = True;  
3273 -  
3274 - /* Success. */  
3275 - trace_dsn(hSession,"TLS/SSL negotiated connection complete. Connection is now secure.\n");  
3276 -  
3277 - /* Tell the world that we are (still) connected, now in secure mode. */  
3278 - lib3270_set_connected(hSession); 3291 + ssl_negotiate(hSession);
3279 } 3292 }
3280 3293
3281 #endif /*]*/ 3294 #endif /*]*/