Commit ca2f1d62c20b7ed86755d945d57522a8d97b1547

Authored by Perry Werneck
1 parent 36a2078d

Refactoring popup engine.

src/core/connect.c
... ... @@ -126,7 +126,7 @@
126 126 set_ssl_state(hSession,LIB3270_SSL_NEGOTIATING);
127 127 int rc = lib3270_run_task(hSession, background_ssl_init, &ssl_error);
128 128  
129   - if(rc && notify_ssl_error(hSession, rc, &ssl_error))
  129 + if(rc && popup_ssl_error(hSession, rc, &ssl_error))
130 130 return errno = rc;
131 131  
132 132 set_ssl_state(hSession,LIB3270_SSL_UNDEFINED);
... ...
src/include/internals.h
... ... @@ -780,25 +780,25 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
780 780  
781 781 #if defined(HAVE_LIBSSL)
782 782  
  783 + typedef struct ssl_status_msg
  784 + {
  785 + LIB3270_POPUP_HEAD
  786 +
  787 + long id;
  788 + const char * iconName; ///< @brief Icon name from https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
  789 + } SSL_STATUS_MSG;
  790 +
783 791 typedef struct _ssl_error_message
784 792 {
785   - int error;
786   - const char * id; ///< @brief Message identifier.
787   - const char * title; ///< @brief Title for popup window.
788   - const char * text; ///< @brief Message text.
789   - const char * description; ///< @brief Message description.
  793 + int code;
790 794 #ifdef _WIN32
791   - DWORD lasterror;
  795 + DWORD lasterror;
792 796 #endif // _WIN32
793   - } SSL_ERROR_MESSAGE;
794 797  
795   - struct ssl_status_msg
796   - {
797   - LIB3270_POPUP_HEAD
  798 + const LIB3270_POPUP_DESCRIPTOR *popup; /// @brief Pointer to popup message.
  799 +
  800 + } SSL_ERROR_MESSAGE;
798 801  
799   - long id;
800   - const char * iconName; ///< @brief Icon name from https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
801   - };
802 802  
803 803 LIB3270_INTERNAL int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE *message);
804 804 LIB3270_INTERNAL int ssl_init(H3270 *session);
... ... @@ -831,13 +831,15 @@ LIB3270_INTERNAL int non_blocking(H3270 *session, Boolean on);
831 831 * @brief Emit popup on ssl error.
832 832 *
833 833 */
834   - LIB3270_INTERNAL int popup_ssl_error(H3270 *session, int rc, const char *title, const char *summary, const char *body);
  834 + LIB3270_INTERNAL int popup_ssl_error(H3270 *session, int rc, const SSL_ERROR_MESSAGE *message);
835 835  
836 836 /**
837   - * @brief Emite popup on SSL error.
  837 + * @brief Emits SSL popup.
  838 + *
838 839 *
839 840 */
840   - LIB3270_INTERNAL int notify_ssl_error(H3270 *hSession, int rc, const SSL_ERROR_MESSAGE *message);
  841 + LIB3270_INTERNAL void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg);
  842 +
841 843  
842 844 #endif
843 845  
... ...
src/include/lib3270/popup.h
... ... @@ -88,6 +88,20 @@
88 88 LIB3270_EXPORT LIB3270_NOTIFY lib3270_get_ssl_state_icon(const H3270 *hSession);
89 89 LIB3270_EXPORT const char * lib3270_get_ssl_state_icon_name(const H3270 *hSession);
90 90  
  91 + /**
  92 + * @brief Emit popup message.
  93 + *
  94 + * @param hSession TN3270 Session handle.
  95 + * @param popup Popup descriptor.
  96 + * @param wait If non zero waits for user response.
  97 + *
  98 + * @return User action.
  99 + *
  100 + * @retval 0 User has confirmed, continue action.
  101 + * @retval ECANCELED Operation was cancelled.
  102 + */
  103 + LIB3270_EXPORT int lib3270_emit_popup(H3270 *hSession, const LIB3270_POPUP_DESCRIPTOR *popup, unsigned char wait);
  104 +
91 105 #ifdef __cplusplus
92 106 }
93 107 #endif
... ...
src/ssl/crl.c
... ... @@ -161,10 +161,14 @@ int lib3270_crl_new_from_x509(H3270 *hSession, void *ssl_error, X509 *cert)
161 161  
162 162 if(!dist_points)
163 163 {
164   - ((SSL_ERROR_MESSAGE *) ssl_error)->id = "NODISTPOINTS";
165   - ((SSL_ERROR_MESSAGE *) ssl_error)->title = _( "Security error" );
166   - ((SSL_ERROR_MESSAGE *) ssl_error)->text = _( "Can't verify." );
167   - ((SSL_ERROR_MESSAGE *) ssl_error)->description = _( "The host certificate doesn't have CRL distribution points" );
  164 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  165 + .name = "SSL-NoDistPoints",
  166 + .type = LIB3270_NOTIFY_SECURE,
  167 + .summary = N_("Can't verify"),
  168 + .body = N_( "The host certificate doesn't have CRL distribution points" )
  169 + };
  170 +
  171 + ((SSL_ERROR_MESSAGE *) ssl_error)->popup = &popup;
168 172 return EACCES;
169 173 }
170 174  
... ...
src/ssl/linux/getcrl.c
... ... @@ -51,11 +51,15 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
51 51  
52 52 if(!(consturl && *consturl))
53 53 {
54   - message->error = hSession->ssl.error = 0;
55   - message->id = "CRLINVURL";
56   - message->title = _( "Security error" );
57   - message->text = _( "Can't open CRL File" );
58   - message->description = _("The URL for the CRL is undefined or empty");
  54 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  55 + .type = LIB3270_NOTIFY_SECURE,
  56 + .name = "SSL-INVCRLURL",
  57 + .summary = N_( "Can't open CRL File" ),
  58 + .body = N_("The URL for the CRL is undefined or empty")
  59 + };
  60 +
  61 + message->code = hSession->ssl.error = 0;
  62 + message->popup = &popup;
59 63 errno = ENOENT;
60 64 return NULL;
61 65 }
... ... @@ -69,12 +73,17 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
69 73 // Can't open CRL File.
70 74 int err = errno;
71 75  
72   - message->error = hSession->ssl.error = 0;
73   - message->id = "CRLOPEN";
74   - message->title = _( "Security error" );
75   - message->text = _( "Can't open CRL File" );
76   - message->description = strerror(err);
77   - trace_ssl(hSession,"Can't open %s: %s\n",consturl,message->description);
  76 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  77 + .type = LIB3270_NOTIFY_SECURE,
  78 + .name = "SSL-CRLOPEN",
  79 + .summary = N_( "Can't open CRL File" )
  80 + };
  81 +
  82 + message->code = hSession->ssl.error = 0;
  83 + message->popup = &popup;
  84 +
  85 + trace_ssl(hSession,"Can't open %s: %s\n",consturl,strerror(err));
  86 +
78 87 return NULL;
79 88  
80 89 }
... ... @@ -82,16 +91,17 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co
82 91 trace_ssl(hSession,"Loading CRL from %s\n",consturl+7);
83 92 if(d2i_X509_CRL_fp(hCRL, &x509_crl))
84 93 {
85   - message->id = "CRLDECODE";
86   - message->error = hSession->ssl.error = ERR_get_error();
87   - message->title = _( "Security error" );
88   - message->text = _( "Can't decode CRL" );
89   - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text);
  94 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  95 + .type = LIB3270_NOTIFY_SECURE,
  96 + .name = "SSL-CRLDECODE",
  97 + .summary = N_( "Can't decode CRL" )
  98 + };
  99 + message->code = hSession->ssl.error = ERR_get_error();
  100 + message->popup = &popup;
  101 + lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary);
90 102 return NULL;
91 103 }
92 104  
93   -
94   -
95 105 }
96 106 #ifdef HAVE_LDAP
97 107 else if(strncasecmp(consturl,"ldap://",7) == 0 && strlen(consturl) > 8)
... ...
src/ssl/linux/init.c
... ... @@ -85,10 +85,14 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message)
85 85 ssl_ctx = SSL_CTX_new(SSLv23_method());
86 86 if(ssl_ctx == NULL)
87 87 {
88   - message->error = hSession->ssl.error = ERR_get_error();
89   - message->id = "SSLCTXERR";
90   - message->title = _( "Security error" );
91   - message->text = _( "Cant initialize the SSL context." );
  88 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  89 + .name = "SSL-CTXERROR",
  90 + .type = LIB3270_NOTIFY_SECURE,
  91 + .summary = N_( "Cant initialize the SSL context." )
  92 + };
  93 +
  94 + message->code = hSession->ssl.error = ERR_get_error();
  95 + message->popup = &popup;
92 96 return -1;
93 97 }
94 98  
... ...
src/ssl/linux/url.c
... ... @@ -58,12 +58,18 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
58 58 X509_CRL * x509_crl = NULL;
59 59  
60 60 size_t szText = 0;
61   - lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szText, &message->description);
  61 + const char * error_message = NULL;
  62 + lib3270_autoptr(char) httpText = lib3270_get_from_url(hSession, consturl, &szText, &error_message);
62 63  
63 64 if(!httpText)
64 65 {
65   - message->title = _( "Security error" );
66   - message->text = _( "Error getting certificate revocation list" );
  66 + LIB3270_POPUP_DESCRIPTOR popup = {
  67 + .type = LIB3270_NOTIFY_SECURE,
  68 + .name = "SSL-CantGetCRL",
  69 + .summary = N_( "Error getting certificate revocation list" ),
  70 + .body = error_message
  71 + };
  72 + message->popup = &popup;
67 73 return NULL;
68 74 }
69 75  
... ... @@ -76,9 +82,13 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
76 82 char * data = strstr((char *) httpText,":: ");
77 83 if(!data)
78 84 {
79   - message->error = hSession->ssl.error = ERR_get_error();
80   - message->title = _( "Security error" );
81   - message->text = _( "Got a bad formatted certificate revocation list from LDAP server" );
  85 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  86 + .type = LIB3270_NOTIFY_SECURE,
  87 + .summary = N_( "Got a bad formatted certificate revocation list from LDAP server" )
  88 + };
  89 +
  90 + message->code = hSession->ssl.error = ERR_get_error();
  91 + message->popup = &popup;
82 92 lib3270_write_log(hSession,"ssl","%s: invalid format:\n%s\n", consturl, httpText);
83 93 errno = EINVAL;
84 94 return NULL;
... ... @@ -94,10 +104,15 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
94 104  
95 105 if(!d2i_X509_CRL_bio(bio, &x509_crl))
96 106 {
97   - message->error = hSession->ssl.error = ERR_get_error();
98   - message->title = _( "Security error" );
99   - message->text = _( "Can't decode certificate revocation list got from LDAP server" );
100   - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text);
  107 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  108 + .type = LIB3270_NOTIFY_SECURE,
  109 + .summary = N_( "Can't decode certificate revocation list got from LDAP server" )
  110 + };
  111 +
  112 + message->code = hSession->ssl.error = ERR_get_error();
  113 + message->popup = &popup;
  114 +
  115 + lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary);
101 116 errno = EINVAL;
102 117 return NULL;
103 118 }
... ... @@ -111,10 +126,14 @@ LIB3270_INTERNAL X509_CRL * get_crl_using_url(H3270 *hSession, SSL_ERROR_MESSAGE
111 126  
112 127 if(!d2i_X509_CRL(&x509_crl, &crl_data, szText))
113 128 {
114   - message->error = hSession->ssl.error = ERR_get_error();
115   - message->title = _( "Security error" );
116   - message->text = _( "Can't decode certificate revocation list" );
117   - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text);
  129 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  130 + .type = LIB3270_NOTIFY_SECURE,
  131 + .summary = N_( "Can't decode certificate revocation list" )
  132 + };
  133 +
  134 + message->code = hSession->ssl.error = ERR_get_error();
  135 + message->popup = &popup;
  136 + lib3270_write_log(hSession,"ssl","%s: %s",consturl, popup.summary);
118 137 return NULL;
119 138 }
120 139  
... ...
src/ssl/negotiate.c
... ... @@ -103,9 +103,13 @@ static int background_ssl_init(H3270 *hSession, void *message)
103 103 hSession->ssl.con = SSL_new(ssl_ctx);
104 104 if(hSession->ssl.con == NULL)
105 105 {
106   - ((SSL_ERROR_MESSAGE *) message)->error = hSession->ssl.error = ERR_get_error();
107   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security error" );
108   - ((SSL_ERROR_MESSAGE *) message)->text = _( "Cant create a new SSL structure for current connection." );
  106 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  107 + .type = LIB3270_NOTIFY_SECURE,
  108 + .summary = N_( "Cant create a new SSL structure for current connection." )
  109 + };
  110 +
  111 + ((SSL_ERROR_MESSAGE *) message)->code = hSession->ssl.error = ERR_get_error();
  112 + ((SSL_ERROR_MESSAGE *) message)->popup = &popup;
109 113 return -1;
110 114 }
111 115  
... ... @@ -238,9 +242,12 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
238 242 {
239 243 trace_ssl(hSession,"%s","SSL_set_fd failed!\n");
240 244  
241   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security error" );
242   - ((SSL_ERROR_MESSAGE *) message)->text = _( "SSL negotiation failed" );
243   - ((SSL_ERROR_MESSAGE *) message)->description = _( "Cant set the file descriptor for the input/output facility for the TLS/SSL (encrypted) side of ssl." );
  245 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  246 + .summary = N_( "SSL negotiation failed" ),
  247 + .body = N_( "Cant set the file descriptor for the input/output facility for the TLS/SSL (encrypted) side of ssl." )
  248 + };
  249 +
  250 + ((SSL_ERROR_MESSAGE *) message)->popup = &popup;
244 251  
245 252 return -1;
246 253 }
... ... @@ -262,18 +269,20 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
262 269  
263 270 if (rv != 1)
264 271 {
265   - const char * msg = "";
  272 + ((SSL_ERROR_MESSAGE *) message)->code = SSL_get_error(hSession->ssl.con,rv);
  273 + if(((SSL_ERROR_MESSAGE *) message)->code == SSL_ERROR_SYSCALL && hSession->ssl.error)
  274 + ((SSL_ERROR_MESSAGE *) message)->code = hSession->ssl.error;
266 275  
267   - ((SSL_ERROR_MESSAGE *) message)->error = SSL_get_error(hSession->ssl.con,rv);
268   - if(((SSL_ERROR_MESSAGE *) message)->error == SSL_ERROR_SYSCALL && hSession->ssl.error)
269   - ((SSL_ERROR_MESSAGE *) message)->error = hSession->ssl.error;
270   -
271   - msg = ERR_lib_error_string(((SSL_ERROR_MESSAGE *) message)->error);
  276 + const char * msg = ERR_lib_error_string(((SSL_ERROR_MESSAGE *) message)->code);
272 277  
273 278 trace_ssl(hSession,"SSL_connect failed: %s %s\n",msg,ERR_reason_error_string(hSession->ssl.error));
274 279  
275   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security error" );
276   - ((SSL_ERROR_MESSAGE *) message)->text = _( "SSL Connect failed" );
  280 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  281 + .type = LIB3270_NOTIFY_ERROR,
  282 + .summary = N_( "SSL Connect failed" ),
  283 + };
  284 +
  285 + ((SSL_ERROR_MESSAGE *) message)->popup = &popup;
277 286  
278 287 return -1;
279 288  
... ... @@ -366,9 +375,12 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
366 375 trace_ssl(hSession,"Unexpected or invalid TLS/SSL verify result %d\n",rv);
367 376 set_ssl_state(hSession,LIB3270_SSL_UNSECURE);
368 377  
369   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security error" );
370   - ((SSL_ERROR_MESSAGE *) message)->text = _( "Can't verify." );
371   - ((SSL_ERROR_MESSAGE *) message)->description = _( "Unexpected or invalid TLS/SSL verify result" );
  378 + static LIB3270_POPUP_DESCRIPTOR popup = {
  379 + .summary = N_( "Can't verify." ),
  380 + .body = N_( "Unexpected or invalid TLS/SSL verify result" )
  381 + };
  382 +
  383 + ((SSL_ERROR_MESSAGE *) message)->popup = &popup;
372 384 return EACCES;
373 385  
374 386 }
... ... @@ -388,9 +400,13 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
388 400 set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED);
389 401  
390 402 #ifdef SSL_ENABLE_SELF_SIGNED_CERT_CHECK
391   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security error" );
392   - ((SSL_ERROR_MESSAGE *) message)->text = _( "The SSL certificate for this host is not trusted." );
393   - ((SSL_ERROR_MESSAGE *) message)->description = _( "The security certificate presented by this host was not issued by a trusted certificate authority." );
  403 + static const LIB3270_POPUP_DESCRIPTOR popup = {
  404 + .name = "SelfSignedCert",
  405 + .type = LIB3270_NOTIFY_SECURE,
  406 + .summary = N_( "The SSL certificate for this host is not trusted." ),
  407 + .body = N_( "The security certificate presented by this host was not issued by a trusted certificate authority." )
  408 + }
  409 + ((SSL_ERROR_MESSAGE *) message)->popup = &popup;
394 410 return EACCES;
395 411 #else
396 412 break;
... ... @@ -399,21 +415,15 @@ static int background_ssl_negotiation(H3270 *hSession, void *message)
399 415 default:
400 416 trace_ssl(hSession,"TLS/SSL verify result was %d (%s)\n", rv, msg->body);
401 417  
402   - debug("message: %s",msg->summary);
403   - debug("description: %s",msg->body);
  418 + ((SSL_ERROR_MESSAGE *) message)->popup = (LIB3270_POPUP_DESCRIPTOR *) msg;
404 419  
405   - ((SSL_ERROR_MESSAGE *) message)->text = gettext(msg->summary);
406   - ((SSL_ERROR_MESSAGE *) message)->description = gettext(msg->body);
  420 + debug("message: %s",((SSL_ERROR_MESSAGE *) message)->popup->summary);
  421 + debug("description: %s",((SSL_ERROR_MESSAGE *) message)->popup->body);
407 422  
408 423 set_ssl_state(hSession,LIB3270_SSL_NEGOTIATED);
409 424  
410 425 if(msg->type == LIB3270_NOTIFY_ERROR)
411   - {
412   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security error" );
413 426 return EACCES;
414   - }
415   -
416   - ((SSL_ERROR_MESSAGE *) message)->title = _( "Security warning" );
417 427  
418 428 }
419 429  
... ... @@ -448,45 +458,41 @@ int ssl_negotiate(H3270 *hSession)
448 458  
449 459 rc = lib3270_run_task(hSession, background_ssl_negotiation, &msg);
450 460  
451   - if(rc == EACCES)
  461 + if(rc && msg.popup)
452 462 {
453   - // SSL validation has failed
454   -
455   - int abort = -1;
456   -
457   - if(msg.description)
458   - abort = popup_ssl_error(hSession,rc,msg.title,msg.text,msg.description);
459   - else
460   - abort = popup_ssl_error(hSession,rc,msg.title,msg.text,ERR_reason_error_string(msg.error));
  463 + // SSL Negotiation has failed.
  464 + host_disconnect(hSession,1); // Disconnect with "failed" status.
461 465  
462   - if(abort)
  466 + if(popup_ssl_error(hSession,rc,&msg))
463 467 {
464 468 host_disconnect(hSession,1); // Disconnect with "failed" status.
465 469 return rc;
466 470 }
467 471  
468   - }
469   - else if(rc)
470   - {
471   - // SSL Negotiation has failed.
472   - host_disconnect(hSession,1); // Disconnect with "failed" status.
  472 + } else if(rc) {
473 473  
474   - if(msg.description)
475   - lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, msg.title, msg.text, "%s", msg.description);
476   - else
477   - lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, msg.title, msg.text, "%s", ERR_reason_error_string(msg.error));
  474 + // SSL Negotiation has failed, no popup to present.
  475 + const LIB3270_POPUP_DESCRIPTOR popup = {
  476 + .summary = N_("SSL negotiation has failed")
  477 + };
478 478  
479   - return rc;
  479 + msg.popup = &popup;
  480 + if(popup_ssl_error(hSession,rc,&msg))
  481 + {
  482 + host_disconnect(hSession,1); // Disconnect with "failed" status.
  483 + return rc;
  484 + }
480 485  
481 486 }
482 487  
483   - /* Tell the world that we are (still) connected, now in secure mode. */
  488 + // Tell the world that we are (still) connected, now in secure mode.
484 489 lib3270_set_connected_initial(hSession);
485 490 non_blocking(hSession,True);
486 491  
487 492 return 0;
488 493 }
489 494  
  495 +
490 496 int ssl_init(H3270 *hSession) {
491 497  
492 498 int rc;
... ... @@ -502,10 +508,25 @@ int ssl_init(H3270 *hSession) {
502 508 // SSL init has failed.
503 509 host_disconnect(hSession,1); // Disconnect with "failed" status.
504 510  
505   - if(msg.description)
506   - lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, msg.title, msg.text, "%s", msg.description);
  511 + if(msg.popup)
  512 + {
  513 + ssl_popup_message(hSession,&msg);
  514 + }
507 515 else
508   - lib3270_popup_dialog(hSession, LIB3270_NOTIFY_ERROR, msg.title, msg.text, "%s", ERR_reason_error_string(msg.error));
  516 + {
  517 + LIB3270_POPUP_DESCRIPTOR popup = {
  518 + .summary = N_("Unexpected error on SSL initialization")
  519 + };
  520 +
  521 + lib3270_autoptr(char) body = lib3270_strdup_printf("%s (rc=%d)",strerror(rc),rc);
  522 + popup.body = body;
  523 +
  524 + msg.popup = &popup;
  525 + ssl_popup_message(hSession,&msg);
  526 + msg.popup = NULL;
  527 +
  528 + }
  529 +
509 530  
510 531 }
511 532  
... ...
src/ssl/notify.c
... ... @@ -43,16 +43,76 @@
43 43  
44 44 #include <openssl/err.h>
45 45  
46   -int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const char GNUC_UNUSED(*title), const char *summary, const char *body)
  46 +/**
  47 + * @brief Translate strings from ssl error message.
  48 + *
  49 + * @param msg SSL error message descriptor.
  50 + * @param rc Value of errno.
  51 + *
  52 + * @return Dynamically allocated popup description.
  53 + *
  54 + */
  55 +static LIB3270_POPUP_DESCRIPTOR * translate_ssl_error_message(const SSL_ERROR_MESSAGE *msg, int rc)
47 56 {
  57 + LIB3270_POPUP_DESCRIPTOR * popup;
  58 +
  59 + if(msg->popup->body)
  60 + {
  61 + popup = lib3270_malloc(sizeof(LIB3270_POPUP_DESCRIPTOR));
  62 + memcpy(popup,msg->popup,sizeof(LIB3270_POPUP_DESCRIPTOR));
  63 + popup->body = dgettext(GETTEXT_PACKAGE,msg->popup->body);
  64 + }
  65 + else
  66 + {
  67 + lib3270_autoptr(char) body = NULL;
  68 + if(msg->code)
  69 + {
  70 + body = lib3270_strdup_printf(_( "%s (SSL error %d)" ),ERR_reason_error_string(msg->code),msg->code);
  71 + }
  72 +#ifdef _WIN32
  73 + else if(msg->lasterror)
  74 + {
  75 + lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(msg->lasterror);
  76 + body = lib3270_strdup_printf(_( "Windows error was \"%s\" (%u)" ), windows_error,(unsigned int) msg->lasterror);
  77 + }
  78 +#endif
  79 + else if(rc) {
  80 + body = lib3270_strdup_printf(_( "%s (rc=%d)" ),strerror(rc),rc);
  81 + }
  82 +
  83 + popup = lib3270_malloc(sizeof(LIB3270_POPUP_DESCRIPTOR)+strlen(body)+1);
  84 + memcpy(popup,msg->popup,sizeof(LIB3270_POPUP_DESCRIPTOR));
  85 + popup->body = (char *) (popup+1);
  86 + strcpy((char *) (popup+1),body);
  87 +
  88 + }
  89 +
  90 + if(popup->summary)
  91 + popup->summary = dgettext(GETTEXT_PACKAGE,popup->summary);
  92 +
  93 + if(popup->title)
  94 + popup->title = dgettext(GETTEXT_PACKAGE,popup->title);
  95 + else
  96 + popup->title = _("Security alert");
  97 +
  98 + return popup;
  99 +}
  100 +
  101 +
  102 +int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const SSL_ERROR_MESSAGE *msg)
  103 +{
  104 + int response = 0;
  105 +
  106 + LIB3270_POPUP_DESCRIPTOR * popup = translate_ssl_error_message(msg,0);
  107 +
48 108 #ifdef _WIN32
49 109  
50 110 lib3270_autoptr(char) rcMessage = lib3270_strdup_printf("The error code was %d",rc);
51 111  
52 112 const char *outMsg[] = {
53   - title,
54   - summary,
55   - (body ? body : ""),
  113 + popup->title,
  114 + popup->summary,
  115 + (popup->body ? popup->body : ""),
56 116 rcMessage
57 117 };
58 118  
... ... @@ -70,63 +130,42 @@ int popup_ssl_error(H3270 GNUC_UNUSED(*hSession), int rc, const char GNUC_UNUSED
70 130  
71 131 #else
72 132  
73   - lib3270_write_log(hSession, "SSL", "%s %s (rc=%d)", summary, (body ? body : ""), rc);
  133 + lib3270_write_log(hSession, "SSL", "%s %s (rc=%d)", popup->summary, (popup->body ? popup->body : ""), rc);
74 134  
75 135 #endif // _WIN32
76 136  
77 137 #ifdef SSL_ENABLE_NOTIFICATION_WHEN_FAILED
78 138  
79   - return hSession->cbk.popup_ssl_error(hSession,rc,title,summary,body);
80   -
81   -#else
  139 + response = hSession->cbk.popup_ssl_error(
  140 + hSession,
  141 + rc,
  142 + popup->title,
  143 + popup->summary,
  144 + popup->body
  145 + );
82 146  
83   - return 0;
84 147  
85 148 #endif // SSL_ENABLE_NOTIFICATION_WHEN_FAILED
86   -}
87 149  
88   -int notify_ssl_error(H3270 *hSession, int rc, const SSL_ERROR_MESSAGE *message)
89   -{
90   - lib3270_write_log(
91   - hSession,
92   - "SSL-CRL-GET",
93   - "CRL GET error: %s (rc=%d ssl_error=%d)",
94   - message->title,
95   - rc,
96   - message->error
97   - );
  150 + lib3270_free(popup);
  151 + return response;
98 152  
99   - if(message->description)
100   - {
101   - if(popup_ssl_error(hSession,rc,message->title,message->text,message->description))
102   - return rc;
103   - }
104   -#ifdef _WIN32
105   - else if(message->lasterror)
106   - {
107   - lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(message->lasterror);
108   - lib3270_autoptr(char) formatted_error = lib3270_strdup_printf(_( "Windows error was \"%s\" (%u)" ), windows_error,(unsigned int) message->lasterror);
  153 +}
109 154  
110   - if(popup_ssl_error(hSession,rc,message->title,message->text,formatted_error))
111   - return rc;
  155 +void ssl_popup_message(H3270 *hSession, const SSL_ERROR_MESSAGE *msg) {
112 156  
113   - }
114   -#endif // WIN32
115   - else if(message->error)
116   - {
117   - lib3270_autoptr(char) formatted_error = lib3270_strdup_printf(_( "%s (SSL error %d)" ),ERR_reason_error_string(message->error),message->error);
118   - lib3270_write_log(hSession,"SSL-CRL-GET","%s",formatted_error);
  157 + LIB3270_POPUP_DESCRIPTOR * popup = translate_ssl_error_message(msg,0);
119 158  
120   - if(popup_ssl_error(hSession,rc,message->title,message->text,formatted_error))
121   - return rc;
122   - }
123   - else
124   - {
125   - if(popup_ssl_error(hSession,rc,message->title,message->text,""))
126   - return rc;
127   - }
  159 + lib3270_popup_dialog(
  160 + hSession,
  161 + popup->type,
  162 + popup->title,
  163 + popup->summary,
  164 + "%s", popup->body
  165 + );
  166 +
  167 + lib3270_free(popup);
128 168  
129   - return 0;
130 169 }
131 170  
132 171 #endif // defined(HAVE_LIBSSL)
... ...