kee

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

commit db25a88c33706ea91ce730fd359600accd8ad82b
parent 8f0273a3017b1423bde959d587a6b8e950cd3ddc
Author: lash <dev@holbrook.no>
Date:   Sun,  5 May 2024 07:26:46 +0100

Add summary widget after qr scan

Diffstat:
MMakefile | 6+++++-
Msrc/content.c | 6++++++
Msrc/digest.h | 37+++++++++++++++++--------------------
Msrc/gpg.h | 2+-
Msrc/gtk/context.c | 2++
Msrc/gtk/debug.c | 2++
Msrc/gtk/kee-entry-item-store.c | 2++
Msrc/gtk/kee-entry-item.c | 42++++++++++++++++++++++++------------------
Msrc/gtk/kee-entry-item.h | 2++
Msrc/gtk/kee-entry-list.c | 2++
Msrc/gtk/kee-entry-store.c | 2++
Msrc/gtk/kee-entry.c | 121++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Msrc/gtk/kee-import.c | 1+
Msrc/gtk/kee-key.c | 2++
Msrc/gtk/kee-menu.c | 6++++--
Msrc/gtk/menu.c | 1+
16 files changed, 150 insertions(+), 86 deletions(-)

diff --git a/Makefile b/Makefile @@ -17,11 +17,15 @@ clean: run: gtk all - G_DEBUG=3 G_MESSAGES_DEBUG=all ./src/gtk/a.out + G_DEBUG=3 G_MESSAGES_DEBUG=3 ./src/gtk/a.out debug: gtk all + G_DEBUG=all G_MESSAGES_DEBUG=all ./src/gtk/a.out + +gdb: gtk all G_DEBUG=all G_MESSAGES_DEBUG=all gdb ./src/gtk/a.out + #test: gtk all test_src test_gtk test: test_src test_gtk diff --git a/src/content.c b/src/content.c @@ -5,6 +5,8 @@ #include "content.h" #include "err.h" +#include "defs.h" +#include "digest.h" int kee_content_init(struct kee_content_t *content, const char *key, size_t size_hint) { @@ -33,6 +35,10 @@ int kee_content_resolve(struct kee_content_t *content, Cadiz *cadiz) { size_t subject_len; size_t c; + if (!memcmp(content->key, zero_content, DIGEST_LENGTH)) { + return ERR_OK; + } + content->flags = 0; c = content->mem_size - 1; r = cadiz_resolve(cadiz, content->key, content->body, &c); diff --git a/src/digest.h b/src/digest.h @@ -1,28 +1,25 @@ -#ifndef _KEE_DIGEST_H -#define _KEE_DIGEST_H +#ifndef KEE_DIGEST_H_ +#define KEE_DIGEST_H_ + +#include <gcrypt.h> enum DigestErr { ERR_DIGESTFAIL = 1, }; -#ifdef __cplusplus -extern "C" { -#endif - /** - * - * \brief Calculate SHA256 digest over the given input data. - * - * \param in Input data. - * \param in_len Length of input data. - * \param out Contains digest data on success. Must have at least 32 bytes available. - * \return 0 on success, any other value indicates failure. - * - */ - int calculate_digest(const char *in, size_t in_len, char *out); - int calculate_digest_algo(const char *in, size_t in_len, char *out, enum gcry_md_algos algo); +#define DIGEST_LENGTH 64 -#ifdef __cplusplus -} -#endif +/** + * + * \brief Calculate SHA256 digest over the given input data. + * + * \param in Input data. + * \param in_len Length of input data. + * \param out Contains digest data on success. Must have at least 32 bytes available. + * \return 0 on success, any other value indicates failure. + * + */ +int calculate_digest(const char *in, size_t in_len, char *out); +int calculate_digest_algo(const char *in, size_t in_len, char *out, enum gcry_md_algos algo); #endif // _KEE_DIGEST_H diff --git a/src/gpg.h b/src/gpg.h @@ -4,6 +4,7 @@ //#include <string> #include <stddef.h> #include <gcrypt.h> +#include "digest.h" #define GPG_MIN_VERSION "1.10.2" #define CHACHA20_KEY_LENGTH_BYTES 32 @@ -11,7 +12,6 @@ #define PUBKEY_LENGTH 32 #define FINGERPRINT_LENGTH 20 #define SIGNATURE_LENGTH 64 -#define DIGEST_LENGTH 64 #define POINT_LENGTH 32 #ifndef ENCRYPT_BLOCKSIZE diff --git a/src/gtk/context.c b/src/gtk/context.c @@ -7,6 +7,8 @@ #include "gpg.h" #include "db.h" +#define G_LOG_DOMAIN "Kee" + int kee_context_init(struct kee_context *ctx, struct kee_settings *settings) { unsigned char *v; diff --git a/src/gtk/debug.c b/src/gtk/debug.c @@ -2,6 +2,8 @@ #include "debug.h" +#define G_LOG_DOMAIN "Kee" + void debug_log(enum debugLevel level, const char *s) { int loglevel; diff --git a/src/gtk/kee-entry-item-store.c b/src/gtk/kee-entry-item-store.c @@ -8,6 +8,8 @@ #include "db.h" #include "err.h" +#define G_LOG_DOMAIN "Kee" + const size_t entry_ref_len = 65; const size_t entry_key_len = 73; diff --git a/src/gtk/kee-entry-item.c b/src/gtk/kee-entry-item.c @@ -66,22 +66,28 @@ KeeEntryItem* kee_entry_item_new(struct db_ctx *db, struct kee_ledger_t *ledger, return o; } -void kee_entry_item_apply_list_item_widget(KeeEntryItem *o) { +void kee_entry_item_set(KeeEntryItem *o, struct kee_ledger_item_t *item) { + o->item = item; +} + +GtkWidget *list_item_widget(KeeEntryItem *o) { + char *subject; GtkWidget *widget; kee_content_resolve(&o->item->content, o->resolver); - sprintf(o->header, "%s\nalice: %i\nbob: %i\n", o->item->content.subject, o->item->alice_credit_delta, o->item->bob_credit_delta); - - widget = gtk_widget_get_first_child(GTK_WIDGET(o)); - if (widget) { - gtk_box_remove(GTK_BOX(o), widget); + subject = o->item->content.subject; + if (subject == NULL) { + subject = "(no description)"; } + + sprintf(o->header, "%s\nalice: %i\nbob: %i\n", subject, o->item->alice_credit_delta, o->item->bob_credit_delta); + widget = gtk_label_new(o->header); - gtk_box_append(GTK_BOX(o), widget); + + return widget; } -void kee_entry_item_apply_sign_widget(KeeEntryItem *o) { - GtkBox *box; +void kee_entry_item_apply_list_item_widget(KeeEntryItem *o) { GtkWidget *widget; widget = gtk_widget_get_first_child(GTK_WIDGET(o)); @@ -89,18 +95,12 @@ void kee_entry_item_apply_sign_widget(KeeEntryItem *o) { gtk_box_remove(GTK_BOX(o), widget); } - widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_box_append(GTK_BOX(o), widget); - box = GTK_BOX(widget); - - widget = gtk_label_new(o->header); - gtk_box_append(box, widget); + widget = list_item_widget(o); - widget = gtk_entry_new(); - gtk_entry_set_placeholder_text(GTK_ENTRY(widget), "passphrase"); - gtk_box_append(box, widget); + gtk_box_append(GTK_BOX(o), widget); } +/// \todo make interface and function name more intuitive to reflect that this is not operating on the KeeEntryItem object. void kee_entry_item_apply_edit_widget(GtkBox *box, struct kee_entry_item_form_t *form, int first) { GtkWidget *widget; @@ -128,6 +128,12 @@ void kee_entry_item_apply_edit_widget(GtkBox *box, struct kee_entry_item_form_t } +void kee_entry_item_apply_summary_widget(KeeEntryItem *o, GtkBox *box) { + GtkWidget *widget; + widget = list_item_widget(o); + gtk_box_append(box, widget); +} + //KeeEntryItem* kee_entry_item_import(const char *data, size_t data_len) { // KeeEntryItem *item; // diff --git a/src/gtk/kee-entry-item.h b/src/gtk/kee-entry-item.h @@ -36,6 +36,8 @@ void kee_entry_item_set_resolver(KeeEntryItem *o, struct Cadiz *resolver); int kee_entry_item_deserialize(KeeEntryItem *o, const char *data, size_t data_len); void kee_entry_item_apply_list_item_widget(KeeEntryItem *o); void kee_entry_item_apply_edit_widget(GtkBox *box, struct kee_entry_item_form_t *form, int first); +void kee_entry_item_apply_summary_widget(KeeEntryItem *o, GtkBox *box); +void kee_entry_item_set(KeeEntryItem *o, struct kee_ledger_item_t *item); G_END_DECLS diff --git a/src/gtk/kee-entry-list.c b/src/gtk/kee-entry-list.c @@ -6,6 +6,8 @@ #include "kee-menu.h" #include "err.h" +#define G_LOG_DOMAIN "Kee" + typedef struct { } KeeEntryListPrivate; diff --git a/src/gtk/kee-entry-store.c b/src/gtk/kee-entry-store.c @@ -11,6 +11,8 @@ #include "cadiz.h" #include "ledger.h" +#define G_LOG_DOMAIN "Kee" + typedef struct { } KeeEntryStorePrivate; diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c @@ -28,6 +28,8 @@ #include "transport.h" #include "qr.h" +#define G_LOG_DOMAIN "Kee" + typedef struct { } KeeEntryPrivate; @@ -38,6 +40,7 @@ struct _KeeEntryClass { #define ENTRYSTATE_LOAD 0x01 #define ENTRYSTATE_SHORT 0x02 #define ENTRYSTATE_EDIT 0x04 +#define ENTRYSTATE_CONFIRM 0x08 extern const asn1_static_node schema_entry_asn1_tab[]; @@ -245,11 +248,36 @@ static int kee_entry_apply_list_item_widget(KeeEntry *o) { return 1; } +static int kee_entry_apply_summary_widget(KeeEntry *o) { + char b[1024]; + GtkWidget *widget; + KeeEntryItem *item; + GtkWidget *passphrase; + + sprintf(b, "Ledger with %s", o->bob_dn.cn); + widget = gtk_label_new(b); + gtk_box_append(GTK_BOX(o->display), widget); + + item = kee_entry_item_new(o->db, &o->ledger, 0); + kee_entry_item_set(item, o->ledger.last_item); + kee_entry_item_apply_summary_widget(item, o); + + /// \todo DRY - kee-key.c + widget = gtk_label_new("private key passphrase"); + gtk_box_append(GTK_BOX(o->edit), widget); + widget = gtk_entry_new(); + passphrase = GTK_ENTRY(widget); + gtk_entry_set_input_purpose(passphrase, GTK_INPUT_PURPOSE_PASSWORD); + gtk_box_append(GTK_BOX(o->edit), widget); + + return 1; +} + static int kee_entry_apply_display_widget(KeeEntry *o) { char mask; - mask = ENTRYSTATE_SHORT | ENTRYSTATE_EDIT; + mask = ENTRYSTATE_SHORT | ENTRYSTATE_EDIT | ENTRYSTATE_CONFIRM; if ((o->state & mask) == 0) { return 0; } @@ -322,48 +350,6 @@ static int kee_entry_apply_edit_widget(KeeEntry *o) { return 1; } -int kee_entry_modeswitch(KeeEntry *o, enum kee_entry_viewmode_e mode) { - int r; - - if (o->showing != NULL) { - gtk_widget_set_visible(o->showing, false); - gtk_box_remove(GTK_BOX(o), o->showing); - } - switch(mode) { - case KEE_ENTRY_VIEWMODE_SHORT: - r = kee_entry_apply_list_item_widget(o); - break; - case KEE_ENTRY_VIEWMODE_EDIT: - r = kee_entry_apply_edit_widget(o); - break; - case KEE_ENTRY_VIEWMODE_SIGN: - r = kee_entry_apply_display_widget(o); - break; - - default: - r = kee_entry_apply_display_widget(o); - } - gtk_box_append(GTK_BOX(o), o->showing); - gtk_widget_set_visible(o->showing, true); - return r; -} - -KeeEntry* kee_entry_new(struct db_ctx *db) { - KeeEntry *o; - o = KEE_ENTRY(g_object_new(KEE_TYPE_ENTRY, "orientation", GTK_ORIENTATION_VERTICAL, NULL)); - o->db = db; - kee_dn_init(&o->bob_dn, 0); - return o; -} - -void kee_entry_set_resolver(KeeEntry *o, struct Cadiz *resolver) { - o->resolver = resolver; -} - -void kee_entry_set_signer(KeeEntry *o, struct gpg_store *gpg) { - o->gpg = gpg; -} - static void kee_entry_init_list_widget(KeeEntry *o) { GtkSingleSelection *sel; GtkListItemFactory *factory; @@ -380,7 +366,6 @@ static void kee_entry_init_list_widget(KeeEntry *o) { gtk_box_append(GTK_BOX(o->display), GTK_WIDGET(view)); } - static int process_entry_ledger(KeeEntry *o) { int r; size_t key_len; @@ -429,6 +414,54 @@ static int process_entry_ledger(KeeEntry *o) { return ERR_OK; } +/// \todo returns 1 on success, investigate why and change if possible! +int kee_entry_modeswitch(KeeEntry *o, enum kee_entry_viewmode_e mode) { + int r; + + if (o->showing != NULL) { + gtk_widget_set_visible(o->showing, false); + gtk_box_remove(GTK_BOX(o), o->showing); + } + switch(mode) { + case KEE_ENTRY_VIEWMODE_SHORT: + r = kee_entry_apply_list_item_widget(o); + break; + case KEE_ENTRY_VIEWMODE_EDIT: + r = kee_entry_apply_edit_widget(o); + break; + case KEE_ENTRY_VIEWMODE_SIGN: + o->state |= ENTRYSTATE_CONFIRM; + r = kee_entry_apply_display_widget(o); + if (!r) { + return r; + } + r = kee_entry_apply_summary_widget(o); + break; + default: + r = kee_entry_apply_display_widget(o); + } + gtk_box_append(GTK_BOX(o), o->showing); + gtk_widget_set_visible(o->showing, true); + return r; +} + +KeeEntry* kee_entry_new(struct db_ctx *db) { + KeeEntry *o; + o = KEE_ENTRY(g_object_new(KEE_TYPE_ENTRY, "orientation", GTK_ORIENTATION_VERTICAL, NULL)); + o->db = db; + kee_dn_init(&o->bob_dn, 0); + return o; +} + +void kee_entry_set_resolver(KeeEntry *o, struct Cadiz *resolver) { + o->resolver = resolver; +} + +void kee_entry_set_signer(KeeEntry *o, struct gpg_store *gpg) { + o->gpg = gpg; +} + + /// \todo rename "from" to indicate not return new entry but apply on existing int kee_entry_from_ledger(KeeEntry *o, struct kee_ledger_t *ledger) { diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c @@ -204,6 +204,7 @@ static void kee_import_handle_import_data_accept(GtkActionable *actn, void *null // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "checking import data"); //} + /// \todo this fires when unfocusing the import page and creates a warning because stack is not valid. static void kee_import_handle_scan_select(GActionGroup *act, char *action_name, gpointer user_data, GtkStack *stack) { GVariant *v; const char *s; diff --git a/src/gtk/kee-key.c b/src/gtk/kee-key.c @@ -6,6 +6,8 @@ #include "err.h" #include "hex.h" +#define G_LOG_DOMAIN "Kee" + typedef struct { } KeeKeyPrivate; diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c @@ -9,6 +9,8 @@ #include "err.h" #include "context.h" +#define G_LOG_DOMAIN "Kee" + typedef struct { } KeeMenuPrivate; @@ -86,16 +88,16 @@ static void kee_menu_act_import_entry(GAction *act, GVariant *param, KeeMenu *me return; } r = kee_entry_modeswitch(entry, KEE_ENTRY_VIEWMODE_SIGN); - if (r) { + if (!r) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "fail set entry widget view mode"); return; } + kee_menu_next(menu, "entry"); r = kee_menu_set(menu, GTK_WIDGET(entry)); if (r) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "fail replace menu entry content"); return; } - kee_menu_next(menu, "entry"); break; case KEE_LEDGER_STATE_REQUEST: g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "detected request state, ignoring"); diff --git a/src/gtk/menu.c b/src/gtk/menu.c @@ -7,6 +7,7 @@ #include "state.h" #include "menu.h" +#define G_LOG_DOMAIN "Kee" static void act_quit(GAction *act, GVariant *param, GApplication *gapp) { g_application_quit(gapp);