Skip to content

Commit

Permalink
Add new screen for bad X.509 cert
Browse files Browse the repository at this point in the history
  • Loading branch information
bartkessels committed Feb 3, 2018
1 parent 3c6facd commit 2d97565
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/getit-content-response.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -85,6 +87,7 @@ getit_content_response_show_default (GetitContentResponse *self)
FALSE,
FALSE,
FALSE,
FALSE,
FALSE);
}

Expand All @@ -98,6 +101,7 @@ getit_content_response_show_sending (GetitContentResponse *self)
TRUE,
FALSE,
FALSE,
FALSE,
FALSE);
}

Expand Down Expand Up @@ -127,6 +131,7 @@ getit_content_response_show_response (GetitContentResponse *self,
FALSE,
TRUE,
FALSE,
FALSE,
FALSE);

/* Clear headers grid */
Expand Down Expand Up @@ -219,6 +224,7 @@ getit_content_response_show_error (GetitContentResponse *self,
FALSE,
FALSE,
TRUE,
FALSE,
FALSE);

if (error_message == NULL || strlen (error_message) < 1) {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand All @@ -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);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/getit-content-response.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions src/getit-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions src/ui/content_response.glade
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,50 @@
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grd_invalid_x509_cert">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<child>
<object class="GtkLabel" id="lbl_invalid_x509_cert_title">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">&lt;big&gt;Invalid X.509 Certificate&lt;/big&gt;</property>
<property name="use_markup">True</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl_invalid_x509_cert_message">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">The server responded with an invalid X.509 certificate</property>
<property name="use_markup">True</property>
<property name="justify">center</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
</packing>
</child>
</object>
</child>
</template>
Expand Down

0 comments on commit 2d97565

Please sign in to comment.