[rs-commit] r36 - in /redwax-signtext/trunk/src/linux: crypto.c main.c message.c signtext.c signtext.h
rs-commit at redwax.eu
rs-commit at redwax.eu
Mon Sep 5 15:37:26 CEST 2022
Author: minfrin at redwax.eu
Date: Mon Sep 5 15:37:25 2022
New Revision: 36
Log:
Add labels and buttons for the dialog.
Modified:
redwax-signtext/trunk/src/linux/crypto.c
redwax-signtext/trunk/src/linux/main.c
redwax-signtext/trunk/src/linux/message.c
redwax-signtext/trunk/src/linux/signtext.c
redwax-signtext/trunk/src/linux/signtext.h
Modified: redwax-signtext/trunk/src/linux/crypto.c
==============================================================================
--- redwax-signtext/trunk/src/linux/crypto.c (original)
+++ redwax-signtext/trunk/src/linux/crypto.c Mon Sep 5 15:37:25 2022
@@ -316,6 +316,9 @@
GckTokenInfo *token_info = g_object_get_data(G_OBJECT (certificate), "token-info");
if (token_info) {
+
+ gboolean can_sign = FALSE;
+
g_printerr("crypto_selector_changed: token\n");
gtk_entry_set_max_length(instance->pin, token_info->max_pin_len);
@@ -325,33 +328,44 @@
gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), FALSE);
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "Use pinpad to enter PIN");
gtk_entry_set_text(GTK_ENTRY(instance->pin), "");
+
+ can_sign = TRUE;
}
else {
gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-password-symbolic");
gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), TRUE);
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "Enter your PIN");
gtk_entry_set_text(GTK_ENTRY(instance->pin), "");
+
+ can_sign = token_info->min_pin_len ? FALSE : TRUE;
}
if (!(token_info->flags & CKF_USER_PIN_INITIALIZED)) {
gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-error-symbolic");
gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), FALSE);
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN is not initialised");
+
+ can_sign = FALSE;
}
else if (token_info->flags & CKF_USER_PIN_LOCKED) {
gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-error-symbolic");
gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), FALSE);
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN is locked");
+
+ can_sign = FALSE;
}
else if (token_info->flags & CKF_USER_PIN_TO_BE_CHANGED) {
gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-unavailable-symbolic");
gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), FALSE);
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN must be changed before use");
+
+ can_sign = FALSE;
}
else if (token_info->flags & CKF_USER_PIN_FINAL_TRY) {
gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-warning-symbolic");
gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), TRUE);
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "Final try on PIN");
+ gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), TRUE);
}
else if (token_info->flags & CKF_USER_PIN_COUNT_LOW) {
gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-warning-symbolic");
@@ -359,7 +373,41 @@
gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN retries are low");
}
- }
+ gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), can_sign);
+
+ }
+ }
+
+}
+
+void crypto_pin_changed(GcrComboSelector *selector,
+ gpointer user_data)
+{
+ GObject *selected;
+ SignTextInstance *instance = user_data;
+
+ g_printerr("crypto_pin_changed\n");
+
+ if (selected && GCR_IS_PKCS11_CERTIFICATE(selected)) {
+
+ GcrPkcs11Certificate *certificate = GCR_PKCS11_CERTIFICATE(selected);
+
+ GckTokenInfo *token_info = g_object_get_data(G_OBJECT (certificate), "token-info");
+
+ if (token_info) {
+
+ gboolean can_sign = FALSE;
+
+ g_printerr("crypto_pin_changed: token\n");
+
+ if (gtk_entry_get_text_length(instance->pin) >= token_info->min_pin_len) {
+ can_sign = TRUE;
+ }
+
+ gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), can_sign);
+
+ }
+
}
}
@@ -371,6 +419,7 @@
instance->selector = gcr_combo_selector_new(certificates);
g_signal_connect(instance->selector, "changed", (GCallback)crypto_selector_changed, instance);
-
-}
-
+ g_signal_connect(instance->pin, "changed", (GCallback)crypto_pin_changed, instance);
+
+}
+
Modified: redwax-signtext/trunk/src/linux/main.c
==============================================================================
--- redwax-signtext/trunk/src/linux/main.c (original)
+++ redwax-signtext/trunk/src/linux/main.c Mon Sep 5 15:37:25 2022
@@ -59,7 +59,7 @@
signtext->window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (signtext->window), "Redwax SignText");
-// gtk_window_set_default_size (GTK_WINDOW (signtext->window), 200, 200);
+ gtk_window_set_default_size (GTK_WINDOW (signtext->window), -1, -1);
#ifdef HAVE_GTK_WINDOW_SET_CHILD
gtk_window_set_child (GTK_WINDOW(signtext->window), GTK_WIDGET(signtext->box));
#else
@@ -67,7 +67,7 @@
#endif
// gtk_widget_show (GTK_WIDGET(signtext->window));
- gtk_widget_show_all(GTK_WIDGET(signtext->window));
+// gtk_widget_show_all(GTK_WIDGET(signtext->window));
/* go fetch our smartcards */
crypto_start(signtext);
Modified: redwax-signtext/trunk/src/linux/message.c
==============================================================================
--- redwax-signtext/trunk/src/linux/message.c (original)
+++ redwax-signtext/trunk/src/linux/message.c Mon Sep 5 15:37:25 2022
@@ -155,18 +155,28 @@
crypto_instance_start(instance, certificates);
#ifdef HAVE_GTK_BOX_APPEND
+ gtk_box_append (instance->box, GTK_WIDGET(instance->label));
gtk_box_append (instance->box, GTK_WIDGET(instance->textview));
+ gtk_box_append (instance->box, GTK_WIDGET(instance->label_agree));
gtk_box_append (instance->box, GTK_WIDGET(instance->selector));
gtk_box_append (instance->box, GTK_WIDGET(instance->pin));
+ gtk_box_append (instance->box, GTK_WIDGET(instance->buttons));
#else
+ gtk_box_pack_start (instance->box, GTK_WIDGET(instance->label), FALSE, FALSE, 0);
gtk_box_pack_start (instance->box, GTK_WIDGET(instance->textview), TRUE, TRUE, 0);
+ gtk_box_pack_start (instance->box, GTK_WIDGET(instance->label_agree), FALSE, FALSE, 0);
gtk_box_pack_start (instance->box, GTK_WIDGET(instance->selector), FALSE, FALSE, 0);
gtk_box_pack_start (instance->box, GTK_WIDGET(instance->pin), FALSE, FALSE, 0);
+ gtk_box_pack_start (instance->box, GTK_WIDGET(instance->buttons), FALSE, FALSE, 0);
#endif
gtk_stack_add_titled(signtext->stack, GTK_WIDGET (instance->box), instance->uuid, g_uri_get_host(instance->uri));
gtk_widget_show_all (GTK_WIDGET(instance->box));
+
+
+ gtk_widget_show_all(GTK_WIDGET(signtext->window));
+
}
Modified: redwax-signtext/trunk/src/linux/signtext.c
==============================================================================
--- redwax-signtext/trunk/src/linux/signtext.c (original)
+++ redwax-signtext/trunk/src/linux/signtext.c Mon Sep 5 15:37:25 2022
@@ -75,6 +75,14 @@
instance->uuid = g_strdup(uuid);
instance->uri = uri;
+ instance->label = GTK_LABEL(gtk_label_new (NULL));
+ instance->label_text = g_markup_printf_escaped("The site <b>%s</b> has requested you sign the following text message.", g_uri_get_host(instance->uri));
+ gtk_label_set_markup(instance->label, instance->label_text);
+ gtk_label_set_justify(instance->label, GTK_JUSTIFY_LEFT);
+ gtk_label_set_line_wrap(instance->label, TRUE);
+ gtk_label_set_line_wrap_mode(instance->label, PANGO_WRAP_WORD_CHAR);
+ gtk_label_set_selectable(instance->label, TRUE);
+
instance->buffer = gtk_text_buffer_new (gtk_text_tag_table_new ());
instance->textview = GTK_TEXT_VIEW (gtk_text_view_new_with_buffer(instance->buffer));
@@ -83,10 +91,31 @@
gtk_text_view_set_cursor_visible(instance->textview, FALSE);
gtk_text_view_set_wrap_mode(instance->textview, GTK_WRAP_WORD_CHAR);
+ instance->label_agree = GTK_LABEL(gtk_label_new (NULL));
+ gtk_label_set_markup(instance->label_agree, "If you agree with the text message above, and are happy with the identity of the site, select a certificate and enter your PIN.");
+ gtk_label_set_justify(instance->label_agree, GTK_JUSTIFY_LEFT);
+ gtk_label_set_line_wrap(instance->label_agree, TRUE);
+ gtk_label_set_line_wrap_mode(instance->label_agree, PANGO_WRAP_WORD_CHAR);
+ gtk_label_set_selectable(instance->label_agree, TRUE);
+
instance->pin_buffer = gcr_secure_entry_buffer_new();
instance->pin = GTK_ENTRY(gtk_entry_new_with_buffer(instance->pin_buffer));
gtk_entry_set_visibility(GTK_ENTRY(instance->pin), FALSE);
- gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-password-symbolic");
+// gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-password-symbolic");
+
+ instance->buttons = GTK_BUTTON_BOX(gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL));
+ gtk_button_box_set_layout(instance->buttons, GTK_BUTTONBOX_EXPAND);
+ instance->cancel = GTK_BUTTON(gtk_button_new_with_label("Cancel"));
+ instance->sign = GTK_BUTTON(gtk_button_new_with_label("Sign"));
+
+#ifdef HAVE_GTK_BOX_APPEND
+ gtk_box_append (GTK_BOX(instance->buttons), GTK_WIDGET(instance->cancel));
+ gtk_box_append (GTK_BOX(instance->buttons), GTK_WIDGET(instance->sign));
+#else
+ gtk_box_pack_start (GTK_BOX(instance->buttons), GTK_WIDGET(instance->cancel), TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX(instance->buttons), GTK_WIDGET(instance->sign), TRUE, TRUE, 0);
+#endif
+
return instance;
}
@@ -95,9 +124,15 @@
if (instance) {
if (instance->uuid) g_free(instance->uuid);
if (instance->uri) g_uri_unref(instance->uri);
+ if (instance->label) g_object_unref(instance->label);
+ if (instance->label_text) g_free(instance->label_text);
if (instance->textview) g_object_unref(instance->textview);
+ if (instance->label_agree) g_object_unref(instance->label_agree);
if (instance->buffer) g_object_unref(instance->buffer);
if (instance->pin) g_object_unref(instance->pin);
+ if (instance->buttons) g_object_unref(instance->buttons);
+ if (instance->cancel) g_object_unref(instance->cancel);
+ if (instance->sign) g_object_unref(instance->sign);
}
g_free(instance);
}
Modified: redwax-signtext/trunk/src/linux/signtext.h
==============================================================================
--- redwax-signtext/trunk/src/linux/signtext.h (original)
+++ redwax-signtext/trunk/src/linux/signtext.h Mon Sep 5 15:37:25 2022
@@ -71,12 +71,18 @@
gchar *uuid;
gint64 id;
+ GtkLabel *label;
+ gchar *label_text;
GtkBox *box;
GtkTextBuffer *buffer;
GtkTextView *textview;
GcrComboSelector *selector;
+ GtkLabel *label_agree;
GtkEntryBuffer *pin_buffer;
GtkEntry *pin;
+ GtkButtonBox *buttons;
+ GtkButton *cancel;
+ GtkButton *sign;
} SignTextInstance;
SignTextData *signtext_data_new();
More information about the rs-commit
mailing list