root / src / sigstatus.c @ 2453
History | View | Annotate | Download (6.8 kB)
| 1 | 1 | hiro | /* sigstatus.h - GTK+ based signature status display
|
|---|---|---|---|
| 2 | 1 | hiro | * Copyright (C) 2001 Werner Koch (dd9jn) |
| 3 | 1 | hiro | * |
| 4 | 1 | hiro | * This program is free software; you can redistribute it and/or modify |
| 5 | 1 | hiro | * it under the terms of the GNU General Public License as published by |
| 6 | 1 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 7 | 1 | hiro | * (at your option) any later version. |
| 8 | 1 | hiro | * |
| 9 | 1 | hiro | * This program is distributed in the hope that it will be useful, |
| 10 | 1 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | 1 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | 1 | hiro | * GNU General Public License for more details. |
| 13 | 1 | hiro | * |
| 14 | 1 | hiro | * You should have received a copy of the GNU General Public License |
| 15 | 1 | hiro | * along with this program; if not, write to the Free Software |
| 16 | 1 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | 1 | hiro | */ |
| 18 | 1 | hiro | |
| 19 | 1 | hiro | #ifdef HAVE_CONFIG_H
|
| 20 | 1 | hiro | # include "config.h" |
| 21 | 1 | hiro | #endif
|
| 22 | 1 | hiro | |
| 23 | 1 | hiro | #if USE_GPGME
|
| 24 | 1 | hiro | |
| 25 | 1 | hiro | #include <glib.h> |
| 26 | 92 | hiro | #include <glib/gi18n.h> |
| 27 | 140 | hiro | #include <gtk/gtkdialog.h> |
| 28 | 1 | hiro | #include <gtk/gtkvbox.h> |
| 29 | 1 | hiro | #include <gtk/gtkhbox.h> |
| 30 | 1 | hiro | #include <gtk/gtklabel.h> |
| 31 | 1 | hiro | #include <gtk/gtkbutton.h> |
| 32 | 36 | hiro | #include <gtk/gtkstock.h> |
| 33 | 1 | hiro | #include <gdk/gdkkeysyms.h> |
| 34 | 1 | hiro | #include <gpgme.h> |
| 35 | 1 | hiro | |
| 36 | 1 | hiro | #include "gtkutils.h" |
| 37 | 1 | hiro | #include "utils.h" |
| 38 | 1 | hiro | #include "sigstatus.h" |
| 39 | 1 | hiro | |
| 40 | 1 | hiro | /* remove the window after 30 seconds to avoid cluttering the deskop
|
| 41 | 1 | hiro | * with too many of them */ |
| 42 | 1 | hiro | #define MY_TIMEOUT (30*1000) |
| 43 | 1 | hiro | |
| 44 | 1 | hiro | struct gpgmegtk_sig_status_s {
|
| 45 | 1 | hiro | GtkWidget *mainwindow; |
| 46 | 1 | hiro | GtkWidget *label; |
| 47 | 1 | hiro | gint running; |
| 48 | 1 | hiro | gint destroy_pending; |
| 49 | 1 | hiro | guint timeout_id; |
| 50 | 1 | hiro | gint timeout_id_valid; |
| 51 | 1 | hiro | }; |
| 52 | 1 | hiro | |
| 53 | 1 | hiro | |
| 54 | 1 | hiro | static void do_destroy(GpgmegtkSigStatus hd) |
| 55 | 1 | hiro | {
|
| 56 | 1 | hiro | if (!hd->running) {
|
| 57 | 140 | hiro | if (hd->timeout_id_valid) {
|
| 58 | 140 | hiro | gtk_timeout_remove(hd->timeout_id); |
| 59 | 140 | hiro | hd->timeout_id_valid = 0;
|
| 60 | 140 | hiro | } |
| 61 | 1 | hiro | if (hd->mainwindow) {
|
| 62 | 1 | hiro | gtk_widget_destroy ( hd->mainwindow ); |
| 63 | 1 | hiro | hd->mainwindow = NULL;
|
| 64 | 1 | hiro | } |
| 65 | 1 | hiro | if (hd->destroy_pending)
|
| 66 | 140 | hiro | g_free(hd); |
| 67 | 1 | hiro | } |
| 68 | 1 | hiro | } |
| 69 | 1 | hiro | |
| 70 | 1 | hiro | static void okay_cb(GtkWidget *widget, gpointer data) |
| 71 | 1 | hiro | {
|
| 72 | 1 | hiro | GpgmegtkSigStatus hd = data; |
| 73 | 1 | hiro | |
| 74 | 1 | hiro | hd->running = 0;
|
| 75 | 1 | hiro | do_destroy(hd); |
| 76 | 1 | hiro | } |
| 77 | 1 | hiro | |
| 78 | 140 | hiro | static gboolean delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
|
| 79 | 1 | hiro | {
|
| 80 | 1 | hiro | GpgmegtkSigStatus hd = data; |
| 81 | 1 | hiro | |
| 82 | 1 | hiro | hd->running = 0;
|
| 83 | 1 | hiro | do_destroy(hd); |
| 84 | 1 | hiro | |
| 85 | 1 | hiro | return TRUE;
|
| 86 | 1 | hiro | } |
| 87 | 1 | hiro | |
| 88 | 1 | hiro | static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
| 89 | 1 | hiro | {
|
| 90 | 1 | hiro | GpgmegtkSigStatus hd = data; |
| 91 | 1 | hiro | |
| 92 | 1 | hiro | if (event && event->keyval == GDK_Escape) {
|
| 93 | 1 | hiro | hd->running = 0;
|
| 94 | 1 | hiro | do_destroy(hd); |
| 95 | 140 | hiro | return TRUE;
|
| 96 | 1 | hiro | } |
| 97 | 1 | hiro | return FALSE;
|
| 98 | 1 | hiro | } |
| 99 | 1 | hiro | |
| 100 | 1 | hiro | GpgmegtkSigStatus gpgmegtk_sig_status_create(void)
|
| 101 | 1 | hiro | {
|
| 102 | 1 | hiro | GtkWidget *window; |
| 103 | 1 | hiro | GtkWidget *vbox; |
| 104 | 1 | hiro | GtkWidget *hbox; |
| 105 | 1 | hiro | GtkWidget *label; |
| 106 | 1 | hiro | GtkWidget *okay_btn; |
| 107 | 1 | hiro | GtkWidget *okay_area; |
| 108 | 1 | hiro | GpgmegtkSigStatus hd; |
| 109 | 1 | hiro | |
| 110 | 1 | hiro | hd = g_malloc0(sizeof *hd);
|
| 111 | 1 | hiro | hd->running = 1;
|
| 112 | 1 | hiro | |
| 113 | 140 | hiro | window = gtk_dialog_new(); |
| 114 | 1 | hiro | hd->mainwindow = window; |
| 115 | 1 | hiro | gtk_widget_set_size_request(window, 400, -1); |
| 116 | 140 | hiro | gtk_window_set_title(GTK_WINDOW(window), _("Signature check result"));
|
| 117 | 140 | hiro | gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); |
| 118 | 1 | hiro | gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); |
| 119 | 140 | hiro | gtk_dialog_set_has_separator(GTK_DIALOG(window), FALSE); |
| 120 | 1 | hiro | g_signal_connect(G_OBJECT(window), "delete_event",
|
| 121 | 1 | hiro | G_CALLBACK(delete_event), hd); |
| 122 | 1 | hiro | g_signal_connect(G_OBJECT(window), "key_press_event",
|
| 123 | 1 | hiro | G_CALLBACK(key_pressed), hd); |
| 124 | 1 | hiro | |
| 125 | 1 | hiro | vbox = gtk_vbox_new(FALSE, 8);
|
| 126 | 140 | hiro | gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
|
| 127 | 140 | hiro | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), |
| 128 | 140 | hiro | vbox, TRUE, TRUE, 0);
|
| 129 | 1 | hiro | gtk_widget_show(vbox); |
| 130 | 1 | hiro | |
| 131 | 1 | hiro | hbox = gtk_hbox_new(FALSE, 0);
|
| 132 | 140 | hiro | gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
|
| 133 | 1 | hiro | gtk_widget_show(hbox); |
| 134 | 1 | hiro | |
| 135 | 1 | hiro | label = gtk_label_new(_("Checking signature"));
|
| 136 | 1 | hiro | hd->label = label; |
| 137 | 1 | hiro | gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
|
| 138 | 140 | hiro | gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
| 139 | 140 | hiro | gtk_label_set_selectable(GTK_LABEL(label), TRUE); |
| 140 | 1 | hiro | gtk_widget_show(label); |
| 141 | 1 | hiro | |
| 142 | 31 | hiro | gtkut_stock_button_set_create(&okay_area, &okay_btn, GTK_STOCK_OK, |
| 143 | 31 | hiro | NULL, NULL, NULL, NULL); |
| 144 | 140 | hiro | gtk_box_pack_end(GTK_BOX(GTK_DIALOG(window)->action_area), |
| 145 | 140 | hiro | okay_area, FALSE, FALSE, 0);
|
| 146 | 140 | hiro | gtk_container_set_border_width(GTK_CONTAINER(okay_area), 5);
|
| 147 | 1 | hiro | gtk_widget_grab_default(okay_btn); |
| 148 | 140 | hiro | gtk_widget_grab_focus(okay_btn); |
| 149 | 1 | hiro | g_signal_connect(G_OBJECT(okay_btn), "clicked",
|
| 150 | 1 | hiro | G_CALLBACK(okay_cb), hd); |
| 151 | 1 | hiro | |
| 152 | 1 | hiro | gtk_widget_show_all(window); |
| 153 | 1 | hiro | |
| 154 | 1 | hiro | while (gtk_events_pending())
|
| 155 | 1 | hiro | gtk_main_iteration(); |
| 156 | 1 | hiro | |
| 157 | 1 | hiro | return hd;
|
| 158 | 1 | hiro | } |
| 159 | 1 | hiro | |
| 160 | 1 | hiro | static gint timeout_cb(gpointer data)
|
| 161 | 1 | hiro | {
|
| 162 | 1 | hiro | GpgmegtkSigStatus hd = data; |
| 163 | 1 | hiro | |
| 164 | 2255 | hiro | gdk_threads_enter(); |
| 165 | 2255 | hiro | |
| 166 | 1 | hiro | hd->running = 0;
|
| 167 | 1 | hiro | hd->timeout_id_valid = 0;
|
| 168 | 1 | hiro | do_destroy(hd); |
| 169 | 1 | hiro | |
| 170 | 2255 | hiro | gdk_threads_leave(); |
| 171 | 2255 | hiro | |
| 172 | 1 | hiro | return FALSE;
|
| 173 | 1 | hiro | } |
| 174 | 1 | hiro | |
| 175 | 1 | hiro | void gpgmegtk_sig_status_destroy(GpgmegtkSigStatus hd)
|
| 176 | 1 | hiro | {
|
| 177 | 1 | hiro | if (hd) {
|
| 178 | 1 | hiro | hd->destroy_pending = 1;
|
| 179 | 1 | hiro | if (hd->running && !hd->timeout_id_valid) {
|
| 180 | 1 | hiro | hd->timeout_id = gtk_timeout_add(MY_TIMEOUT, |
| 181 | 1 | hiro | timeout_cb, hd); |
| 182 | 1 | hiro | hd->timeout_id_valid = 1;
|
| 183 | 1 | hiro | } |
| 184 | 1 | hiro | do_destroy(hd); |
| 185 | 1 | hiro | } |
| 186 | 1 | hiro | } |
| 187 | 1 | hiro | |
| 188 | 56 | hiro | void gpgmegtk_sig_status_update(GpgmegtkSigStatus hd, gpgme_ctx_t ctx)
|
| 189 | 1 | hiro | {
|
| 190 | 56 | hiro | gpgme_verify_result_t result; |
| 191 | 56 | hiro | gpgme_signature_t sig; |
| 192 | 1 | hiro | gchar *text = NULL;
|
| 193 | 1 | hiro | |
| 194 | 1 | hiro | if (!hd || !hd->running || !ctx)
|
| 195 | 1 | hiro | return;
|
| 196 | 56 | hiro | result = gpgme_op_verify_result(ctx); |
| 197 | 1559 | hiro | if (!result)
|
| 198 | 1559 | hiro | return;
|
| 199 | 1559 | hiro | |
| 200 | 56 | hiro | sig = result->signatures; |
| 201 | 56 | hiro | while (sig) {
|
| 202 | 1 | hiro | gchar *tmp; |
| 203 | 1 | hiro | const gchar *userid;
|
| 204 | 56 | hiro | gpgme_key_t key = NULL;
|
| 205 | 1 | hiro | |
| 206 | 56 | hiro | if (!gpgme_get_key(ctx, sig->fpr, &key, 0)) { |
| 207 | 56 | hiro | userid = key->uids->uid; |
| 208 | 56 | hiro | } else {
|
| 209 | 1 | hiro | userid = "[?]";
|
| 210 | 56 | hiro | } |
| 211 | 140 | hiro | tmp = g_strdup_printf |
| 212 | 140 | hiro | (_("%s%s%s from \"%s\""),
|
| 213 | 140 | hiro | text ? text : "", text ? "\n" : "", |
| 214 | 140 | hiro | gpgmegtk_sig_status_to_string(sig, FALSE), userid); |
| 215 | 1 | hiro | g_free (text); |
| 216 | 1 | hiro | text = tmp; |
| 217 | 1 | hiro | gpgme_key_unref (key); |
| 218 | 56 | hiro | sig = sig->next; |
| 219 | 1 | hiro | } |
| 220 | 1 | hiro | gtk_label_set_text(GTK_LABEL(hd->label), text); |
| 221 | 1 | hiro | g_free(text); |
| 222 | 1 | hiro | |
| 223 | 1 | hiro | while (gtk_events_pending())
|
| 224 | 1 | hiro | gtk_main_iteration(); |
| 225 | 1 | hiro | } |
| 226 | 1 | hiro | |
| 227 | 56 | hiro | const gchar *gpgmegtk_sig_status_to_string(gpgme_signature_t signature,
|
| 228 | 140 | hiro | gboolean use_name) |
| 229 | 1 | hiro | {
|
| 230 | 56 | hiro | const gchar *result = "?"; |
| 231 | 140 | hiro | |
| 232 | 216 | hiro | g_return_val_if_fail(signature != NULL, result);
|
| 233 | 216 | hiro | |
| 234 | 140 | hiro | switch (gpg_err_code(signature->status)) {
|
| 235 | 140 | hiro | case GPG_ERR_NO_DATA:
|
| 236 | 1 | hiro | result = _("No signature found");
|
| 237 | 1 | hiro | break;
|
| 238 | 140 | hiro | case GPG_ERR_NO_ERROR:
|
| 239 | 140 | hiro | switch (signature->validity) {
|
| 240 | 140 | hiro | case GPGME_VALIDITY_ULTIMATE:
|
| 241 | 140 | hiro | case GPGME_VALIDITY_FULL:
|
| 242 | 140 | hiro | case GPGME_VALIDITY_MARGINAL:
|
| 243 | 140 | hiro | result = use_name ? _("Good signature from \"%s\"") :
|
| 244 | 140 | hiro | _("Good signature");
|
| 245 | 140 | hiro | break;
|
| 246 | 140 | hiro | default:
|
| 247 | 140 | hiro | result = use_name ? |
| 248 | 140 | hiro | _("Valid signature but the key for \"%s\" is not trusted") :
|
| 249 | 140 | hiro | _("Valid signature (untrusted key)");
|
| 250 | 140 | hiro | break;
|
| 251 | 140 | hiro | } |
| 252 | 1 | hiro | break;
|
| 253 | 140 | hiro | case GPG_ERR_SIG_EXPIRED:
|
| 254 | 140 | hiro | result = use_name ? _("Signature valid but expired for \"%s\"") :
|
| 255 | 140 | hiro | _("Signature valid but expired");
|
| 256 | 140 | hiro | break;
|
| 257 | 140 | hiro | case GPG_ERR_KEY_EXPIRED:
|
| 258 | 140 | hiro | result = use_name ? _("Signature valid but the signing key for \"%s\" has expired") :
|
| 259 | 140 | hiro | _("Signature valid but the signing key has expired");
|
| 260 | 140 | hiro | break;
|
| 261 | 140 | hiro | case GPG_ERR_CERT_REVOKED:
|
| 262 | 140 | hiro | result = use_name ? _("Signature valid but the signing key for \"%s\" has been revoked") :
|
| 263 | 140 | hiro | _("Signature valid but the signing key has been revoked");
|
| 264 | 140 | hiro | break;
|
| 265 | 140 | hiro | case GPG_ERR_BAD_SIGNATURE:
|
| 266 | 56 | hiro | result = use_name ? _("BAD signature from \"%s\"") :
|
| 267 | 140 | hiro | _("BAD signature");
|
| 268 | 1 | hiro | break;
|
| 269 | 140 | hiro | case GPG_ERR_NO_PUBKEY:
|
| 270 | 1 | hiro | result = _("No public key to verify the signature");
|
| 271 | 1 | hiro | break;
|
| 272 | 1 | hiro | default:
|
| 273 | 140 | hiro | result = _("Error verifying the signature");
|
| 274 | 1 | hiro | break;
|
| 275 | 1 | hiro | } |
| 276 | 1 | hiro | |
| 277 | 1 | hiro | return result;
|
| 278 | 1 | hiro | } |
| 279 | 1 | hiro | |
| 280 | 1 | hiro | #endif /* USE_GPGME */ |