kee

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

commit 26692fab85a83b13856346cea0f9c6ef49d4b16b
parent 517704ee020b55f77886f170fc5334986613594a
Author: lash <dev@holbrook.no>
Date:   Wed, 15 May 2024 20:02:54 +0100

Apply timestamp from parse item

Diffstat:
Msrc/gtk/kee-entry.c | 2++
Msrc/ledger.c | 41++++++++++++++++++++++++++++++++++++-----
Mtestdata_asn1.py | 1+
3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c @@ -461,6 +461,7 @@ static int process_entry_ledger(KeeEntry *o) { *last_key = DbKeyDN; memcpy(last_key+1, o->ledger.pubkey_bob, 32); key_len = 32; + db_rewind(o->db); r = db_next(o->db, DbKeyDN, &last_key, &key_len, &last_value, &last_value_length); if (r == ERR_DB_NOMATCH) { strcpy(last_value, "cn=johndoe"); @@ -472,6 +473,7 @@ static int process_entry_ledger(KeeEntry *o) { if (r) { return ERR_FAIL; } + db_rewind(o->db); last_value_length = 129; strcpy(last_value, "uid="); diff --git a/src/ledger.c b/src/ledger.c @@ -428,6 +428,7 @@ struct kee_ledger_item_t *kee_ledger_parse_item(struct kee_ledger_t *ledger, con } /// \todo apply timestamp in structure + /// \todo document timestamp size c = 8; r = asn1_read_value(item, "timestamp", tmp, &c); if (r != ASN1_SUCCESS) { @@ -439,6 +440,18 @@ struct kee_ledger_item_t *kee_ledger_parse_item(struct kee_ledger_t *ledger, con if (r != ASN1_SUCCESS) { return NULL; } + if (is_le()) { + r = to_endian(TO_ENDIAN_LITTLE, 4, tmp); + if (r) { + return NULL; + } + r = to_endian(TO_ENDIAN_LITTLE, 4, tmp+4); + if (r) { + return NULL; + } + } + memcpy(&cur->time.tv_sec, tmp, 4); + memcpy(&cur->time.tv_nsec, tmp+4, 4); r = kee_content_init(&(cur->content), tmp, 0); if (r) { @@ -500,7 +513,7 @@ int kee_ledger_parse(struct kee_ledger_t *ledger, const char *data, size_t data_ asn1_node item; int c; char content_key[64]; - int decimals; + //char decimals; memset(&root, 0, sizeof(root)); memset(&item, 0, sizeof(item)); @@ -526,12 +539,12 @@ int kee_ledger_parse(struct kee_ledger_t *ledger, const char *data, size_t data_ return r; } - c = 8; - r = asn1_read_value(item, "uoaDecimals", &decimals, &c); + c = 1; + r = asn1_read_value(item, "uoaDecimals", &ledger->uoa_decimals, &c); if (r != ASN1_SUCCESS) { return r; } - ledger->uoa_decimals = (char)decimals; + //ledger->uoa_decimals = (char)decimals; c = 32; r = asn1_read_value(item, "alicePubKey", ledger->pubkey_alice, &c); @@ -753,6 +766,24 @@ int kee_ledger_item_serialize(struct kee_ledger_item_t *item, char *out, size_t return 0; } +/// \todo verify final state +int kee_ledger_item_serialize_db(struct kee_ledger_item_t *item, char *out, size_t *out_len) { + int r; + + r = kee_ledger_item_serialize(item, out, out_len, KEE_LEDGER_STATE_FINAL); + if (r) { + return ERR_FAIL; + } + + if (item->initiator == BOB) { + *(out+*out_len) = 1; + } else { + *(out+*out_len) = 0; + } + *out_len += 1; + + return ERR_OK; +} int kee_ledger_sign(struct kee_ledger_t *ledger, struct kee_ledger_item_t *item, struct gpg_store *gpg, const char *passphrase) { int r; @@ -1020,7 +1051,7 @@ static int kee_ledger_item_put_buf(struct kee_ledger_t *ledger, struct db_ctx *d //c = 928; c = 2048; - r = kee_ledger_item_serialize(item, v, &c, KEE_LEDGER_STATE_FINAL); + r = kee_ledger_item_serialize_db(item, v, &c); if (r) { return ERR_FAIL; } diff --git a/testdata_asn1.py b/testdata_asn1.py @@ -219,6 +219,7 @@ class LedgerSigner: b = self.signer[keyname].sign(z) + logg.debug('signature material\t{}\n\t{}'.format(msg[:64].hex(), msg[64:].hex())) logg.debug('signature for {}: {}'.format(z.hex(), b.hex())) return b