Commit 249d32fd838529744b397e27a190cb4863581cc9
1 parent
3414cdc2
Exists in
master
and in
5 other branches
Incluindo caixa de diálogo com o estado da conexão SSL
Showing
8 changed files
with
345 additions
and
5 deletions
Show diff stats
src/include/lib3270.h
... | ... | @@ -699,7 +699,8 @@ |
699 | 699 | #define lib3270_is_connected(h) lib3270_in_tn3270e(h) |
700 | 700 | #define lib3270_is_ready(h) lib3270_get_program_message(h) == LIB3270_MESSAGE_NONE |
701 | 701 | |
702 | - LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session); | |
702 | + LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session); | |
703 | + LIB3270_EXPORT long lib3270_get_SSL_verify_result(H3270 *session); | |
703 | 704 | |
704 | 705 | |
705 | 706 | /** | ... | ... |
src/include/pw3270.h
... | ... | @@ -53,6 +53,8 @@ |
53 | 53 | |
54 | 54 | LIB3270_EXPORT GtkWidget * pw3270_new(const gchar *host, const gchar *systype, unsigned short colors); |
55 | 55 | LIB3270_EXPORT void pw3270_set_host(GtkWidget *widget, const gchar *uri); |
56 | + LIB3270_EXPORT const gchar * pw3270_get_host(GtkWidget *widget); | |
57 | + | |
56 | 58 | LIB3270_EXPORT gboolean pw3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix); |
57 | 59 | LIB3270_EXPORT H3270 * pw3270_get_session(GtkWidget *widget); |
58 | 60 | LIB3270_EXPORT GtkWidget * pw3270_get_terminal_widget(GtkWidget *widget); | ... | ... |
src/include/pw3270/v3270.h
... | ... | @@ -194,6 +194,7 @@ |
194 | 194 | LIB3270_EXPORT void v3270_set_session_options(GtkWidget *widget, LIB3270_OPTION options); |
195 | 195 | LIB3270_EXPORT int v3270_set_session_color_type(GtkWidget *widget, unsigned short colortype); |
196 | 196 | LIB3270_EXPORT void v3270_set_host(GtkWidget *widget, const gchar *uri); |
197 | + LIB3270_EXPORT const gchar * v3270_get_host(GtkWidget *widget); | |
197 | 198 | |
198 | 199 | // Keyboard & Mouse special actions |
199 | 200 | LIB3270_EXPORT gboolean v3270_set_keyboard_action(GtkWidget *widget, const gchar *key_name, GtkAction *action); | ... | ... |
src/lib3270/telnet.c
... | ... | @@ -3325,4 +3325,12 @@ LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session) |
3325 | 3325 | return session->secure; |
3326 | 3326 | } |
3327 | 3327 | |
3328 | - | |
3328 | +LIB3270_EXPORT long lib3270_get_SSL_verify_result(H3270 *hSession) | |
3329 | +{ | |
3330 | + CHECK_SESSION_HANDLE(hSession); | |
3331 | +#if defined(HAVE_LIBSSL) | |
3332 | + if(hSession->ssl_con) | |
3333 | + return SSL_get_verify_result(hSession->ssl_con); | |
3334 | +#endif // HAVE_LIBSSL | |
3335 | + return -1; | |
3336 | +} | ... | ... |
src/pw3270/dialog.c
... | ... | @@ -29,9 +29,15 @@ |
29 | 29 | * |
30 | 30 | */ |
31 | 31 | |
32 | + #include <lib3270/config.h> | |
32 | 33 | #include "globals.h" |
33 | 34 | #include <pw3270/v3270.h> |
34 | 35 | |
36 | + #if defined(HAVE_LIBSSL) | |
37 | + #include <openssl/ssl.h> | |
38 | + #include <openssl/err.h> | |
39 | + #endif | |
40 | + | |
35 | 41 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
36 | 42 | |
37 | 43 | static const struct _charset |
... | ... | @@ -49,6 +55,235 @@ |
49 | 55 | }; |
50 | 56 | |
51 | 57 | |
58 | + static const struct _sslerror | |
59 | + { | |
60 | + long id; | |
61 | + const gchar * icon; | |
62 | + const gchar * title; | |
63 | + const gchar * text; | |
64 | + } | |
65 | + sslerror[] = | |
66 | + { | |
67 | + // http://www.openssl.org/docs/apps/verify.html | |
68 | + { | |
69 | + X509_V_OK, | |
70 | + GTK_STOCK_DIALOG_AUTHENTICATION, | |
71 | + N_( "Secure connection was successful." ), | |
72 | + N_( "This connection is secure and signed." ) | |
73 | + }, | |
74 | + | |
75 | + { | |
76 | + X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT, | |
77 | + GTK_STOCK_DIALOG_ERROR, | |
78 | + N_( "Unable to get issuer certificate" ), | |
79 | + N_( "The issuer certificate of a looked up certificate could not be found. This normally means the list of trusted certificates is not complete." ), | |
80 | + }, | |
81 | + | |
82 | + { | |
83 | + X509_V_ERR_UNABLE_TO_GET_CRL, | |
84 | + GTK_STOCK_DIALOG_ERROR, | |
85 | + N_( "Unable to get certificate CRL" ), | |
86 | + N_( "The CRL of a certificate could not be found." ), | |
87 | + }, | |
88 | + | |
89 | + { | |
90 | + X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE, | |
91 | + GTK_STOCK_DIALOG_ERROR, | |
92 | + N_( "Unable to decrypt certificate's signature" ), | |
93 | + N_( "The certificate signature could not be decrypted. This means that the actual signature value could not be determined rather than it not matching the expected value, this is only meaningful for RSA keys." ), | |
94 | + }, | |
95 | + | |
96 | + { | |
97 | + X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE, | |
98 | + GTK_STOCK_DIALOG_ERROR, | |
99 | + N_( "Unable to decrypt CRL's signature" ), | |
100 | + N_( "The CRL signature could not be decrypted: this means that the actual signature value could not be determined rather than it not matching the expected value. Unused." ), | |
101 | + }, | |
102 | + | |
103 | + { | |
104 | + X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY, | |
105 | + GTK_STOCK_DIALOG_ERROR, | |
106 | + N_( "Unable to decode issuer public key" ), | |
107 | + N_( "The public key in the certificate SubjectPublicKeyInfo could not be read." ), | |
108 | + }, | |
109 | + | |
110 | + { | |
111 | + X509_V_ERR_CERT_SIGNATURE_FAILURE, | |
112 | + GTK_STOCK_DIALOG_ERROR, | |
113 | + N_( "Certificate signature failure" ), | |
114 | + N_( "The signature of the certificate is invalid." ), | |
115 | + }, | |
116 | + | |
117 | + { | |
118 | + X509_V_ERR_CRL_SIGNATURE_FAILURE, | |
119 | + GTK_STOCK_DIALOG_ERROR, | |
120 | + N_( "CRL signature failure" ), | |
121 | + N_( "The signature of the certificate is invalid." ), | |
122 | + }, | |
123 | + | |
124 | + { | |
125 | + X509_V_ERR_CERT_NOT_YET_VALID, | |
126 | + GTK_STOCK_DIALOG_WARNING, | |
127 | + N_( "Certificate is not yet valid" ), | |
128 | + N_( "The certificate is not yet valid: the notBefore date is after the current time." ), | |
129 | + }, | |
130 | + | |
131 | + { | |
132 | + X509_V_ERR_CERT_HAS_EXPIRED, | |
133 | + GTK_STOCK_DIALOG_ERROR, | |
134 | + N_( "Certificate has expired" ), | |
135 | + N_( "The certificate has expired: that is the notAfter date is before the current time." ), | |
136 | + }, | |
137 | + | |
138 | + { | |
139 | + X509_V_ERR_CRL_NOT_YET_VALID, | |
140 | + GTK_STOCK_DIALOG_WARNING, | |
141 | + N_( "CRL is not yet valid" ), | |
142 | + N_( "The CRL is not yet valid." ), | |
143 | + }, | |
144 | + | |
145 | + { | |
146 | + X509_V_ERR_CRL_HAS_EXPIRED, | |
147 | + GTK_STOCK_DIALOG_ERROR, | |
148 | + N_( "CRL has expired" ), | |
149 | + N_( "The CRL has expired." ), | |
150 | + }, | |
151 | + | |
152 | + { | |
153 | + X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD, | |
154 | + GTK_STOCK_DIALOG_ERROR, | |
155 | + N_( "Format error in certificate's notBefore field" ), | |
156 | + N_( "The certificate notBefore field contains an invalid time." ), | |
157 | + }, | |
158 | + | |
159 | + { | |
160 | + X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD, | |
161 | + GTK_STOCK_DIALOG_ERROR, | |
162 | + N_( "Format error in certificate's notAfter field" ), | |
163 | + N_( "The certificate notAfter field contains an invalid time." ), | |
164 | + }, | |
165 | + | |
166 | + { | |
167 | + X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD, | |
168 | + GTK_STOCK_DIALOG_ERROR, | |
169 | + N_( "Format error in CRL's lastUpdate field" ), | |
170 | + N_( "The CRL lastUpdate field contains an invalid time." ), | |
171 | + }, | |
172 | + | |
173 | + { | |
174 | + X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD, | |
175 | + GTK_STOCK_DIALOG_ERROR, | |
176 | + N_( "Format error in CRL's nextUpdate field" ), | |
177 | + N_( "The CRL nextUpdate field contains an invalid time." ), | |
178 | + }, | |
179 | + | |
180 | + { | |
181 | + X509_V_ERR_OUT_OF_MEM, | |
182 | + GTK_STOCK_DIALOG_ERROR, | |
183 | + N_( "Out of memory" ), | |
184 | + N_( "An error occurred trying to allocate memory. This should never happen." ), | |
185 | + }, | |
186 | + | |
187 | + { | |
188 | + X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT, | |
189 | + GTK_STOCK_DIALOG_WARNING, | |
190 | + N_( "Self signed certificate" ), | |
191 | + N_( "The passed certificate is self signed and the same certificate cannot be found in the list of trusted certificates." ), | |
192 | + }, | |
193 | + | |
194 | + { | |
195 | + X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN, | |
196 | + GTK_STOCK_DIALOG_WARNING, | |
197 | + N_( "Self signed certificate in certificate chain" ), | |
198 | + N_( "The certificate chain could be built up using the untrusted certificates but the root could not be found locally." ), | |
199 | + }, | |
200 | + | |
201 | + { | |
202 | + X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, | |
203 | + GTK_STOCK_DIALOG_WARNING, | |
204 | + N_( "Unable to get local issuer certificate" ), | |
205 | + N_( "The issuer certificate could not be found: this occurs if the issuer certificate of an untrusted certificate cannot be found." ), | |
206 | + }, | |
207 | + | |
208 | + { | |
209 | + X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE, | |
210 | + GTK_STOCK_DIALOG_ERROR, | |
211 | + N_( "Unable to verify the first certificate" ), | |
212 | + N_( "No signatures could be verified because the chain contains only one certificate and it is not self signed." ), | |
213 | + }, | |
214 | + | |
215 | + { | |
216 | + X509_V_ERR_CERT_REVOKED, | |
217 | + GTK_STOCK_DIALOG_ERROR, | |
218 | + N_( "Certificate revoked" ), | |
219 | + N_( "The certificate has been revoked." ), | |
220 | + }, | |
221 | + | |
222 | + { | |
223 | + X509_V_ERR_INVALID_CA, | |
224 | + GTK_STOCK_DIALOG_ERROR, | |
225 | + N_( "Invalid CA certificate" ), | |
226 | + N_( "A CA certificate is invalid. Either it is not a CA or its extensions are not consistent with the supplied purpose." ), | |
227 | + }, | |
228 | + | |
229 | + { | |
230 | + X509_V_ERR_PATH_LENGTH_EXCEEDED, | |
231 | + GTK_STOCK_DIALOG_ERROR, | |
232 | + N_( "Path length constraint exceeded" ), | |
233 | + N_( "The basicConstraints pathlength parameter has been exceeded." ), | |
234 | + }, | |
235 | + | |
236 | + { | |
237 | + X509_V_ERR_INVALID_PURPOSE, | |
238 | + GTK_STOCK_DIALOG_ERROR, | |
239 | + N_( "Unsupported certificate purpose" ), | |
240 | + N_( "The supplied certificate cannot be used for the specified purpose." ), | |
241 | + }, | |
242 | + | |
243 | + { | |
244 | + X509_V_ERR_CERT_UNTRUSTED, | |
245 | + GTK_STOCK_DIALOG_WARNING, | |
246 | + N_( "Certificate not trusted" ), | |
247 | + N_( "The root CA is not marked as trusted for the specified purpose." ), | |
248 | + }, | |
249 | + | |
250 | + { | |
251 | + X509_V_ERR_CERT_REJECTED, | |
252 | + GTK_STOCK_DIALOG_ERROR, | |
253 | + N_( "Certificate rejected" ), | |
254 | + N_( "The root CA is marked to reject the specified purpose." ), | |
255 | + }, | |
256 | + | |
257 | + { | |
258 | + X509_V_ERR_SUBJECT_ISSUER_MISMATCH, | |
259 | + GTK_STOCK_DIALOG_ERROR, | |
260 | + N_( "Subject issuer mismatch" ), | |
261 | + N_( "The current candidate issuer certificate was rejected because its subject name did not match the issuer name of the current certificate. Only displayed when the -issuer_checks option is set." ), | |
262 | + }, | |
263 | + | |
264 | + { | |
265 | + X509_V_ERR_AKID_SKID_MISMATCH, | |
266 | + GTK_STOCK_DIALOG_ERROR, | |
267 | + N_( "Authority and subject key identifier mismatch" ), | |
268 | + N_( "The current candidate issuer certificate was rejected because its subject key identifier was present and did not match the authority key identifier current certificate. Only displayed when the -issuer_checks option is set." ), | |
269 | + }, | |
270 | + | |
271 | + { | |
272 | + X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH, | |
273 | + GTK_STOCK_DIALOG_ERROR, | |
274 | + N_( "Authority and issuer serial number mismatch" ), | |
275 | + N_( "The current candidate issuer certificate was rejected because its issuer name and serial number was present and did not match the authority key identifier of the current certificate. Only displayed when the -issuer_checks option is set." ), | |
276 | + }, | |
277 | + | |
278 | + { | |
279 | + X509_V_ERR_KEYUSAGE_NO_CERTSIGN, | |
280 | + GTK_STOCK_DIALOG_ERROR, | |
281 | + N_( "Key usage does not include certificate signing" ), | |
282 | + N_( "The current candidate issuer certificate was rejected because its keyUsage extension does not permit certificate signing." ), | |
283 | + } | |
284 | + | |
285 | + }; | |
286 | + | |
52 | 287 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
53 | 288 | |
54 | 289 | |
... | ... | @@ -491,3 +726,81 @@ |
491 | 726 | |
492 | 727 | g_free(info); |
493 | 728 | } |
729 | + | |
730 | + G_GNUC_INTERNAL void run_security_dialog(GtkWidget *widget) | |
731 | + { | |
732 | + GtkWidget * dialog; | |
733 | + H3270 * hSession = pw3270_get_session(widget); | |
734 | + | |
735 | + trace("%s(%p)",__FUNCTION__,widget); | |
736 | + | |
737 | +#ifdef HAVE_LIBSSL | |
738 | + if(lib3270_get_secure(hSession) == LIB3270_SSL_UNSECURE) | |
739 | +#endif // HAVE_LIBSSL | |
740 | + { | |
741 | + // Connection is insecure, show simple dialog with host and info | |
742 | + | |
743 | + dialog = gtk_message_dialog_new( | |
744 | + GTK_WINDOW(widget), | |
745 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
746 | + GTK_MESSAGE_INFO, | |
747 | + GTK_BUTTONS_CLOSE, | |
748 | + pw3270_get_host(widget) | |
749 | + ); | |
750 | + | |
751 | + gtk_message_dialog_format_secondary_markup( | |
752 | + GTK_MESSAGE_DIALOG(dialog), | |
753 | + "%s", _( "<b>Identity not verified</b>\nThe connection is insecure" )); | |
754 | + | |
755 | + } | |
756 | +#ifdef HAVE_LIBSSL | |
757 | + else | |
758 | + { | |
759 | + long id = lib3270_get_SSL_verify_result(hSession); | |
760 | + const gchar * title = N_( "Unexpected SSL error"); | |
761 | + const gchar * text = NULL; | |
762 | + const gchar * icon = GTK_STOCK_DIALOG_ERROR; | |
763 | + int f; | |
764 | + | |
765 | + for(f=0;f<G_N_ELEMENTS(sslerror);f++) | |
766 | + { | |
767 | + if(sslerror[f].id == id) | |
768 | + { | |
769 | + title = sslerror[f].title; | |
770 | + icon = sslerror[f].icon; | |
771 | + text = sslerror[f].text; | |
772 | + break; | |
773 | + } | |
774 | + } | |
775 | + | |
776 | + dialog = gtk_message_dialog_new( | |
777 | + GTK_WINDOW(widget), | |
778 | + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
779 | + GTK_MESSAGE_OTHER, | |
780 | + GTK_BUTTONS_CLOSE, | |
781 | + "%s",gettext(title) | |
782 | + ); | |
783 | + | |
784 | + gtk_message_dialog_set_image(GTK_MESSAGE_DIALOG(dialog),gtk_image_new_from_stock(icon,GTK_ICON_SIZE_DIALOG)); | |
785 | + | |
786 | + if(text) | |
787 | + { | |
788 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),text); | |
789 | + } | |
790 | + else | |
791 | + { | |
792 | + gchar *str = g_strdup_printf("Unexpected SSL error <b>%ld</b>",id); | |
793 | + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),text); | |
794 | + g_free(str); | |
795 | + } | |
796 | + | |
797 | + } | |
798 | +#endif // HAVE_LIBSSL | |
799 | + | |
800 | + gtk_window_set_title(GTK_WINDOW(dialog),_("About security")); | |
801 | + | |
802 | + gtk_widget_show_all(GTK_WIDGET(dialog)); | |
803 | + gtk_dialog_run(GTK_DIALOG(dialog)); | |
804 | + gtk_widget_destroy(GTK_WIDGET(dialog)); | |
805 | + | |
806 | + } | ... | ... |
src/pw3270/globals.h
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | G_GNUC_INTERNAL void load_color_schemes(GtkWidget *widget, gchar *active); |
63 | 63 | G_GNUC_INTERNAL GtkWidget * color_scheme_new(const GdkColor *current); |
64 | 64 | G_GNUC_INTERNAL LIB3270_OPTION pw3270_options_by_hosttype(const gchar *systype); |
65 | - | |
65 | + G_GNUC_INTERNAL void run_security_dialog(GtkWidget *widget); | |
66 | 66 | |
67 | 67 | // actions |
68 | 68 | G_GNUC_INTERNAL void paste_file_action(GtkAction *action, GtkWidget *widget); | ... | ... |
src/pw3270/v3270/widget.c
... | ... | @@ -1432,6 +1432,12 @@ void v3270_set_host(GtkWidget *widget, const gchar *uri) |
1432 | 1432 | lib3270_set_host(GTK_V3270(widget)->host,uri); |
1433 | 1433 | } |
1434 | 1434 | |
1435 | +const gchar * v3270_get_host(GtkWidget *widget) | |
1436 | +{ | |
1437 | + g_return_val_if_fail(GTK_IS_V3270(widget),""); | |
1438 | + return lib3270_get_host(GTK_V3270(widget)->host); | |
1439 | +} | |
1440 | + | |
1435 | 1441 | const gchar * v3270_get_session_name(GtkWidget *widget) |
1436 | 1442 | { |
1437 | 1443 | if(!GTK_IS_V3270(widget) || GTK_V3270(widget)->session_name == NULL) | ... | ... |
src/pw3270/window.c
... | ... | @@ -226,6 +226,12 @@ |
226 | 226 | v3270_set_host(GTK_PW3270(widget)->terminal,uri); |
227 | 227 | } |
228 | 228 | |
229 | + const gchar * pw3270_get_host(GtkWidget *widget) | |
230 | + { | |
231 | + g_return_val_if_fail(GTK_IS_PW3270(widget),""); | |
232 | + return v3270_get_host(GTK_PW3270(widget)->terminal); | |
233 | + } | |
234 | + | |
229 | 235 | gboolean pw3270_get_toggle(GtkWidget *widget, LIB3270_TOGGLE ix) |
230 | 236 | { |
231 | 237 | g_return_val_if_fail(GTK_IS_PW3270(widget),FALSE); |
... | ... | @@ -471,15 +477,16 @@ |
471 | 477 | |
472 | 478 | } |
473 | 479 | |
474 | - static gboolean field_clicked(GtkWidget *terminal, gboolean connected, V3270_OIA_FIELD field, GdkEventButton *event) | |
480 | + static gboolean field_clicked(GtkWidget *widget, gboolean connected, V3270_OIA_FIELD field, GdkEventButton *event, GtkWidget *window) | |
475 | 481 | { |
476 | - trace("%s: %s field=%d event=%p",__FUNCTION__,connected ? "Connected" : "Disconnected", field, event); | |
482 | + trace("%s: %s field=%d event=%p window=%p",__FUNCTION__,connected ? "Connected" : "Disconnected", field, event, window); | |
477 | 483 | |
478 | 484 | if(!connected) |
479 | 485 | return FALSE; |
480 | 486 | |
481 | 487 | if(field == V3270_OIA_SSL) |
482 | 488 | { |
489 | + run_security_dialog(window); | |
483 | 490 | trace("%s: Show SSL connection info dialog",__FUNCTION__); |
484 | 491 | return TRUE; |
485 | 492 | } |
... | ... | @@ -512,6 +519,8 @@ |
512 | 519 | GtkAction **action = g_new0(GtkAction *,ACTION_COUNT); |
513 | 520 | H3270 * host; |
514 | 521 | |
522 | + trace("%s(%p)",__FUNCTION__,widget); | |
523 | + | |
515 | 524 | // Initialize terminal widget |
516 | 525 | widget->terminal = v3270_new(); |
517 | 526 | host = v3270_get_session(widget->terminal); | ... | ... |