From 2d975651fd5ad1608de24ae6a707cbfd4ff8406d Mon Sep 17 00:00:00 2001 From: Bart Kessels Date: Sat, 3 Feb 2018 12:07:44 +0100 Subject: [PATCH] Add new screen for bad X.509 cert --- src/getit-content-response.c | 28 ++++++++++++++++++++-- src/getit-content-response.h | 1 + src/getit-window.c | 13 +++++++++++ src/ui/content_response.glade | 44 +++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/getit-content-response.c b/src/getit-content-response.c index eacebe8..056aaeb 100644 --- a/src/getit-content-response.c +++ b/src/getit-content-response.c @@ -33,6 +33,7 @@ struct _GetitContentResponse { GtkScrolledWindow *sw_output_preview; GtkWidget *wv_output_preview; GtkGrid *grd_timeout; + GtkGrid *grd_invalid_x509_cert; }; G_DEFINE_TYPE (GetitContentResponse, getit_content_response, GTK_TYPE_VIEWPORT) @@ -52,7 +53,8 @@ static void getit_content_response_show_screen (GetitContentResponse *self, const gboolean show_sending, const gboolean show_response, const gboolean show_error, - const gboolean show_timeout); + const gboolean show_timeout, + const gboolean show_invalid_x509_cert); /* Callback signatures */ static gboolean getit_content_response_cb_output_paned_destroy (GtkWidget *caller, @@ -85,6 +87,7 @@ getit_content_response_show_default (GetitContentResponse *self) FALSE, FALSE, FALSE, + FALSE, FALSE); } @@ -98,6 +101,7 @@ getit_content_response_show_sending (GetitContentResponse *self) TRUE, FALSE, FALSE, + FALSE, FALSE); } @@ -127,6 +131,7 @@ getit_content_response_show_response (GetitContentResponse *self, FALSE, TRUE, FALSE, + FALSE, FALSE); /* Clear headers grid */ @@ -219,6 +224,7 @@ getit_content_response_show_error (GetitContentResponse *self, FALSE, FALSE, TRUE, + FALSE, FALSE); if (error_message == NULL || strlen (error_message) < 1) { @@ -234,6 +240,21 @@ getit_content_response_show_timeout (GetitContentResponse *self) g_assert (GETIT_IS_CONTENT_RESPONSE (self)); getit_content_response_show_screen (self, + FALSE, + FALSE, + FALSE, + FALSE, + TRUE, + FALSE); +} + +void +getit_content_response_show_invalid_x509_cert (GetitContentResponse *self) +{ + g_assert (GETIT_IS_CONTENT_RESPONSE (self)); + + getit_content_response_show_screen (self, + FALSE, FALSE, FALSE, FALSE, @@ -270,6 +291,7 @@ getit_content_response_class_init (GetitContentResponseClass *klass) gtk_widget_class_bind_template_child (widget_class, GetitContentResponse, sv_output_raw); gtk_widget_class_bind_template_child (widget_class, GetitContentResponse, sw_output_preview); gtk_widget_class_bind_template_child (widget_class, GetitContentResponse, grd_timeout); + gtk_widget_class_bind_template_child (widget_class, GetitContentResponse, grd_invalid_x509_cert); } static void @@ -326,7 +348,8 @@ getit_content_response_show_screen (GetitContentResponse *self, const gboolean show_sending, const gboolean show_response, const gboolean show_error, - const gboolean show_timeout) + const gboolean show_timeout, + const gboolean show_invalid_x509_cert) { g_assert (GETIT_IS_CONTENT_RESPONSE (self)); @@ -335,6 +358,7 @@ getit_content_response_show_screen (GetitContentResponse *self, gtk_widget_set_visible (GTK_WIDGET (self->pnd_output), show_response); gtk_widget_set_visible (GTK_WIDGET (self->grd_error), show_error); gtk_widget_set_visible (GTK_WIDGET (self->grd_timeout), show_timeout); + gtk_widget_set_visible (GTK_WIDGET (self->grd_invalid_x509_cert), show_invalid_x509_cert); } /* diff --git a/src/getit-content-response.h b/src/getit-content-response.h index f1f2c80..297dc91 100644 --- a/src/getit-content-response.h +++ b/src/getit-content-response.h @@ -49,5 +49,6 @@ void getit_content_response_show_response (GetitContentResponse *self, void getit_content_response_show_error (GetitContentResponse *self, const gchar *error_message); void getit_content_response_show_timeout (GetitContentResponse *self); +void getit_content_response_show_invalid_x509_cert (GetitContentResponse *self); G_END_DECLS diff --git a/src/getit-window.c b/src/getit-window.c index c7ce837..3a18d42 100644 --- a/src/getit-window.c +++ b/src/getit-window.c @@ -316,6 +316,8 @@ getit_window_request_finished (SoupSession *session, self = GETIT_WINDOW (user_data); content_response = getit_stack_get_content_response (self->stack); + g_print ("Status code: %d\n", message->status_code); // 6 + /* Check if connection was timed out */ if (message->status_code == 7) { /* Abort session */ @@ -330,6 +332,17 @@ getit_window_request_finished (SoupSession *session, return; } + /* Check if X.509 certificate is accepted */ + if (message->status_code == 6) { + getit_notification_display (_("Invalid X.509 certificate"), + soup_uri_to_string (soup_message_get_uri (message), FALSE), + "network-transmit"); + getit_content_response_show_invalid_x509_cert (content_response); + getit_window_set_loading (self, FALSE); + + return; + } + /* Other checks */ g_return_if_fail (!self->request_canceled); g_return_if_fail (message != NULL); diff --git a/src/ui/content_response.glade b/src/ui/content_response.glade index 0b76798..7683cdb 100644 --- a/src/ui/content_response.glade +++ b/src/ui/content_response.glade @@ -351,6 +351,50 @@ 0 + + + True + False + center + True + + + True + False + center + True + <big>Invalid X.509 Certificate</big> + True + center + + + 0 + 0 + + + + + True + False + center + center + True + The server responded with an invalid X.509 certificate + True + center + True + + + 0 + 1 + + + + + 0 + 5 + +