kee

Offline IOU signer with QR as transport
git clone git://holbrook.no/kee-gtk4.git
Info | Log | Files | Refs | README | LICENSE

kee-key.c (2279B)


      1 #include <glib-object.h>
      2 #include <gtk/gtk.h>
      3 
      4 #include "kee-key.h"
      5 #include "gpg.h"
      6 #include "err.h"
      7 #include "hex.h"
      8 #include "debug.h"
      9 
     10 
     11 typedef struct {
     12 } KeeKeyPrivate;
     13 
     14 struct _KeeKeyClass {
     15 	GtkWidget parent_class;
     16 };
     17 
     18 struct _KeeKey {
     19 	GtkWidget parent;
     20 	struct gpg_store *gpg;
     21 };
     22 
     23 G_DEFINE_TYPE(KeeKey, kee_key, GTK_TYPE_BOX);
     24 
     25 static guint kee_sigs[KEE_N_KEY_SIGS] = {0,};
     26 
     27 static void kee_key_class_init(KeeKeyClass *kls) {
     28 	GObjectClass *o = G_OBJECT_CLASS(kls);
     29 
     30 	kee_sigs[KEE_S_KEY_UNLOCKED] = g_signal_new("unlock", 
     31 			G_TYPE_FROM_CLASS(o),
     32 			G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
     33 			0,
     34 			NULL,
     35 			NULL,
     36 			NULL,
     37 			G_TYPE_NONE,
     38 			0,
     39 			NULL);
     40 }
     41 
     42 static void kee_key_init(KeeKey *o) {
     43 }
     44 
     45 //static void kee_key_finalize(KeeKey *o) {
     46 //}
     47 
     48 static void kee_key_handle_unlock_click(GtkWidget *button, KeeKey *o) {
     49 	int r;
     50 	GtkEntryBuffer *buf;
     51 	GValue v = G_VALUE_INIT;
     52 	char passphrase[1024];
     53 
     54 	g_value_init(&v, G_TYPE_POINTER);
     55 	buf = g_object_get_data(G_OBJECT(o), "passphrase");
     56 	strcpy(passphrase, gtk_entry_buffer_get_text(buf));
     57 	g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "click");
     58 
     59 	r = gpg_store_check(o->gpg, passphrase);
     60 	if (r) {
     61 		g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "wrong passphrase");
     62 		return;
     63 	}
     64 
     65 	g_signal_emit(o, kee_sigs[KEE_S_KEY_UNLOCKED], 0);
     66 	gtk_entry_buffer_delete_text(buf, 0, gtk_entry_buffer_get_length(buf));
     67 }
     68 
     69 KeeKey* kee_key_new(struct gpg_store *gpg) {
     70 	KeeKey *o;
     71 	GtkWidget *entry;
     72 	GtkWidget *button;
     73 	GtkEntryBuffer *buf;
     74 
     75 	o = g_object_new(KEE_TYPE_KEY, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
     76 	o->gpg = gpg;
     77 
     78 	entry = gtk_entry_new();
     79 	gtk_box_append(GTK_BOX(o), entry);
     80 	buf = gtk_entry_get_buffer(GTK_ENTRY(entry));
     81 	gtk_entry_set_input_purpose(GTK_ENTRY(entry), GTK_INPUT_PURPOSE_PASSWORD);
     82 	gtk_entry_set_visibility(GTK_ENTRY(entry), false);
     83 	g_object_set_data(G_OBJECT(o), "passphrase", buf);
     84 
     85 	button = gtk_button_new_with_label("create");
     86 	gtk_box_append(GTK_BOX(o), button);
     87 	g_signal_connect (button, "clicked", G_CALLBACK (kee_key_handle_unlock_click), o);
     88 
     89 	return o;
     90 }
     91 
     92 const char *kee_key_get_fingerprint(KeeKey *o, char *fingerprint) {
     93 	b2h((unsigned char*)o->gpg->fingerprint, 20, (unsigned char*)fingerprint);
     94 	//strcpy(fingerprint, o->gpg->fingerprint);
     95 	return fingerprint;
     96 }