Pulleyback now appears to work
authorRick van Rein <rick@openfortress.nl>
Sat, 25 Jun 2016 20:43:40 +0000 (21:43 +0100)
committerRick van Rein <rick@openfortress.nl>
Sat, 25 Jun 2016 20:43:40 +0000 (21:43 +0100)
 - The test program adds and removes disclose.db and localid.db entries
 - There are some weird interactions with the tool/get_xxx programs
 - This may be due to opening the databases with DB_RECOVER, but I'm not sure
 - Running one program at a time appears to work though
 - Also note there's been no problem interacting with programs and TLS Pool

doc/pulleyscript.md
pulleyback/api.c
pulleyback/connect.c
pulleyback/update.c
test/pulleybacksimu.c
tool/get_disclose.c
tool/get_localid.c
tool/get_trust.c
tool/set_disclose.c
tool/set_localid.c
tool/set_trust.c

index bc3a9ba..88da311 100644 (file)
@@ -244,4 +244,4 @@ the trust database:
     (pgpkeydn == pgpanchordn)
     
     # Send the found results to the TLS Pool backend
-    pgpkey,pgpvalexp,pgprole -> tlspool (config="../etc/tlspool.conf", type="trust", args="cred,valexp,role", subtype="authority,pgp")
+    pgpkey,pgpvalexp,pgprole -> tlspool (config="../etc/tlspool.conf", type="trust", args="cred,valexp,role", subtype="authority,openpgp")
index d839c3e..4158759 100644 (file)
@@ -185,18 +185,16 @@ int pulleyback_commit (void *pbh) {
                ok = 1;
                break;
        case TXN_ACTIVE:
+       case TXN_SUCCESS:
                // The transaction is in full progress; attempt to commit it
                ok = ok && (0 == self->txn->commit (self->txn, 0));
                self->txn = NULL;
-               self->txn_state = ok? TXN_SUCCESS: TXN_ABORT;
+               self->txn_state = TXN_NONE;
                break;
        case TXN_ABORT:
-               // Fake an implicitly started, empty transaction
-               ok = ok && 1;
-               break;
-       case TXN_SUCCESS:
-               // Fake an implicitly started, empty transaction
-               ok = ok && 1;
+               // Preparation fails, then the call should havae been _rollback()
+               assert (self->txn_state != TXN_ABORT);
+               ok = ok && 0;
                break;
        }
        return ok;
index 2f1a3d8..dfc6370 100644 (file)
@@ -108,11 +108,15 @@ static int parse_cfgfile (struct pulleyback_tlspool *self) {
  */
 void close_database (struct pulleyback_tlspool *self) {
        if (self->db != NULL) {
-               self->db->close (self->db, 0);
+               if (0 != self->db->close (self->db, 0)) {
+                       fprintf (stderr, "Failed to close database\n");
+               }
                self->db = NULL;
        }
        if (self->env != NULL) {
-               self->env->close (self->env, 0);
+               if (0 != self->env->close (self->env, 0)) {
+                       fprintf (stderr, "Failed to close database environment\n");
+               }
                self->env = NULL;
        }
 }
index 181f377..69ddf63 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <arpa/inet.h>
 
+#include <db.h>
+
 #include <quick-der/api.h>
 
 #include "api.h"
@@ -129,9 +131,16 @@ static int update_db (struct pulleyback_tlspool *self,
        }
        gotcrs =
        ok = ok && (0 == self->db->cursor (self->db, self->txn, &crs, 0));
-       dbt_init_fixbuf (&db_key, key  ->derptr, key  ->derlen);
-       dbt_init_fixbuf (&db_val, value->derptr, value->derlen);
-       dbt_init_empty  (&db_got);
+       memset (&db_key, 0, sizeof (db_key));
+       db_key.data = key->derptr;
+       db_key.size = key->derlen;
+       memset (&db_val, 0, sizeof (db_val));
+       db_val.data = value->derptr;
+       db_val.size = value->derlen;
+       memset (&db_got, 0, sizeof (db_got));
+       //OLD// dbt_init_fixbuf (&db_key, key  ->derptr, key  ->derlen);
+       //OLD// dbt_init_fixbuf (&db_val, value->derptr, value->derlen);
+       //OLD// dbt_init_empty  (&db_got);
        nomore = crs->get (crs, &db_key, &db_got, DB_SET);
        while (!nomore) {
                int match = 1;
@@ -139,7 +148,11 @@ static int update_db (struct pulleyback_tlspool *self,
                for (i = 0; match && (i < trimlen); i++) {
                        match = match && (i < db_val.size);
                        match = match && (i < db_got.size);
-                       if (match) {
+                       if (!match) {
+                               // Final decision; only match for same sizes
+                               match = (db_val.size == db_got.size);
+                               break;
+                       } else {
                                uint8_t m, a, b;
                                m = (i < 4)? mask4 [i]: 0xff;
                                a = m & ((uint8_t *) db_val.data) [i];
@@ -154,15 +167,17 @@ static int update_db (struct pulleyback_tlspool *self,
        }
        ok = ok && (nomore == DB_NOTFOUND);
        if (gotcrs) {
-               crs->close (crs);
+               if (0 != crs->close (crs)) {
+                       fprintf (stderr, "Failed to close cursor\n");
+               }
        }
        if (!rm) {
                ok = ok && (0 == self->db->put (
-                               self->db, self->txn, &db_key, &db_val, 0));
+                                self->db, self->txn, &db_key, &db_val, 0));
        }
-       dbt_free (&db_got);
-       // Static, so don't free // dbt_free (&db_val);
-       // Static, so don't free // dbt_free (&db_key);
+       //OLD// // Not ours, so don't free // dbt_free (&db_got);
+       //OLD// // Static,   so don't free // dbt_free (&db_val);
+       //OLD// // Static,   so don't free // dbt_free (&db_key);
        return ok;
 }
 
@@ -182,6 +197,7 @@ int update_disclose (struct pulleyback_tlspool *self, uint8_t **data, int rm) {
                // Perhaps length is too small, or DER formatting error
                return 0;
        }
+printf ("Updating disclose.db (%s): %.*s -> %.*s\n", rm?"DEL":"ADD", rid.derlen, rid.derptr, lid.derlen, lid.derptr);
        return update_db (self, &rid, &lid, -1, NULL, rm);
 }
 
index 7975cc8..58165ee 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <time.h>
 #include <unistd.h>
 
 #include <libgen.h>
@@ -45,21 +46,21 @@ void inline testcmd (char *cmd) {
 void showstatus (char *title) {
        printf ("\n\n\n# %s\n", title);
        // testcmd ("db_stat -h ../testdata/tlspool.env -d ../disclose.db");
-       printf ("\n\n\n## Disclosure database\n\n\n");
-       testcmd ("../tool/get_disclose "CONFFILE" "REMOTEID" >/dev/null");
-       testcmd ("../tool/get_disclose "CONFFILE" "REMOTEID_PATN" >/dev/null");
-       testcmd ("../tool/get_disclose "CONFFILE" "LOCALID" >/dev/null");
-       printf ("\n\n\n## LocalID database\n\n\n");
-       testcmd ("../tool/get_localid "CONFFILE" "REMOTEID" X.509,client,server"" >/dev/null");
-       testcmd ("../tool/get_localid "CONFFILE" "LOCALID" X.509,client,server"" >/dev/null");
-       testcmd ("../tool/get_localid "CONFFILE" "REMOTEID" OpenPGP,client,server"" >/dev/null");
-       testcmd ("../tool/get_localid "CONFFILE" "LOCALID" OpenPGP,client,server"" >/dev/null");
-       printf ("\n\n\n## Trust database\n\n\n");
-       testcmd ("../tool/get_trust "CONFFILE" x509,client,server "ANCHOR_HEX" >/dev/null");
-       testcmd ("../tool/get_trust "CONFFILE" x509,client,server "ANCHOR_HEX" >/dev/null");
-       testcmd ("../tool/get_trust "CONFFILE" pgp,client,server "ANCHOR_HEX" >/dev/null");
-       testcmd ("../tool/get_trust "CONFFILE" pgp,client,server "ANCHOR_HEX" >/dev/null");
-       printf ("\nThat was our last test for %s\n\n\n", title);
+       // printf ("\n\n\n## Disclosure database\n\n\n");
+       // testcmd ("../tool/get_disclose "CONFFILE" "REMOTEID" >/dev/null");
+       // testcmd ("../tool/get_disclose "CONFFILE" "REMOTEID_PATN" >/dev/null");
+       // testcmd ("../tool/get_disclose "CONFFILE" "LOCALID" >/dev/null");
+       // printf ("\n\n\n## LocalID database\n\n\n");
+       // testcmd ("../tool/get_localid "CONFFILE" "REMOTEID" X.509,client,server"" >/dev/null");
+       // testcmd ("../tool/get_localid "CONFFILE" "LOCALID" X.509,client,server"" >/dev/null");
+       // testcmd ("../tool/get_localid "CONFFILE" "REMOTEID" OpenPGP,client,server"" >/dev/null");
+       // testcmd ("../tool/get_localid "CONFFILE" "LOCALID" OpenPGP,client,server"" >/dev/null");
+       // printf ("\n\n\n## Trust database\n\n\n");
+       // testcmd ("../tool/get_trust "CONFFILE" x509,client,server "ANCHOR_HEX" >/dev/null");
+       // testcmd ("../tool/get_trust "CONFFILE" x509,client,server "ANCHOR_HEX" >/dev/null");
+       // testcmd ("../tool/get_trust "CONFFILE" pgp,client,server "ANCHOR_HEX" >/dev/null");
+       // testcmd ("../tool/get_trust "CONFFILE" pgp,client,server "ANCHOR_HEX" >/dev/null");
+       // printf ("\nThat was our last test for %s\n\n\n", title);
 }
 
 
@@ -84,7 +85,10 @@ void *open_backend (char *argv []) {
 }
 
 void close_backend (void *backend) {
-       pulleyback_close (backend);
+       struct pulleyback_tlspool *self = backend;
+       if (backend != NULL) {
+               pulleyback_close (backend);
+       }
 }
 
 
@@ -92,9 +96,9 @@ char *test0 [] = { "pulleyback_tlspool", "config=../etc/tlspool.conf", "type=dis
 char *test1 [] = { "pulleyback_tlspool", "config=../etc/tlspool.conf", "type=disclose", "args=remoteid,localid", NULL };
 char *test2 [] = { "pulleyback_tlspool", "config=../etc/tlspool.conf", "type=localid", "args=localid,pkcs11,cred", "subtype=x509,client", NULL };
 
-uint8_t *args0 [2] = { "\x0c\x1alocal@pulleyback.arpa2.lab", "\x0c\x1bremote@pulleyback.arpa2.lab" };
-uint8_t *args1 [2] = { "\x0c\x1bremote@pulleyback.arpa2.lab", "\x0c\x1alocal@pulleyback.arpa2.lab" };
-uint8_t *args2 [3] = { "\x0c\x1alocal@pulleyback.arpa2.lab", "\x0c\x24pkcs11:manuf=OpenFortress;serial=123", "\x0c\x1a-----LIKE A PGP KEY-----\r\n" };
+uint8_t *args0 [2] = { "\x0c\x1clocalid@pulleyback.arpa2.lab", "\x0c\x1dremoteid@pulleyback.arpa2.lab" };
+uint8_t *args1 [2] = { "\x0c\x1dremoteid@pulleyback.arpa2.lab", "\x0c\x1clocalid@pulleyback.arpa2.lab" };
+uint8_t *args2 [3] = { "\x0c\x1clocalid@pulleyback.arpa2.lab", "\x0c\x24pkcs11:manuf=OpenFortress;serial=123", "\x0c\x1a-----LIKE A PGP KEY-----\r\n" };
 
 char **tests [] = { test0, test1, test2, NULL };
 uint8_t **argss [] = { args0, args1, args2, NULL };
@@ -110,19 +114,32 @@ int main (int argc, char *argv []) {
        close (2);
        dup2 (1, 2);
        openlog (basename (argv [0]), LOG_PERROR, LOG_LOCAL0);
-       showstatus ("Initial status");
+       // showstatus ("Initial status");
        for (testp = tests, argsp = argss; *testp != NULL; testp++, argsp++) {
                backend = open_backend (*testp);
                if (backend == NULL) {
                        continue;
                }
-               snprintf (testtitle, 100, "Test number %d\n", testnr++);
+               snprintf (testtitle, 100, "Test number %d\n", testnr);
+               showstatus (testtitle);
+               pulleyback_add (backend, *argsp);
+               if (pulleyback_commit (backend)) {
+                       printf ("Go have a look...\n");
+               } else {
+                       printf ("Failed, so you probably won't find it...\n");
+               }
+               sleep (10);
+               snprintf (testtitle, 100, "Added in test number %d\n", testnr++);
                showstatus (testtitle);
-               // pulleyback_add (backend, *argsp);
-               // pulleyback_del (backend, *argsp);
+               pulleyback_del (backend, *argsp);
+               if (pulleyback_commit (backend)) {
+                       printf ("It should be gone...\n");
+               } else {
+                       printf ("Failed, so it is probably still there...\n");
+               }
                close_backend (backend);
        }
-       showstatus ("Final status");
+       // showstatus ("Final status");
        closelog ();
        exit (0);
 }
index 2b9678c..f6b2df7 100644 (file)
@@ -183,7 +183,6 @@ int main (int argc, char *argv []) {
        //
        // Finally, commit the transaction
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit readonly transaction\n");
                exit (1);
        }
index b9af249..b5c8cb9 100644 (file)
@@ -228,7 +228,6 @@ printf ("Written %d bytes\n", e_binlen);
                goto failure;
        }
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit readonly transaction\n");
                exit (1);
        }
index 0d9ac5d..9887c04 100644 (file)
@@ -247,7 +247,6 @@ printf ("Written %d bytes\n", e_binlen);
                goto failure;
        }
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit readonly transaction\n");
                exit (1);
        }
index b2f8efc..87aa893 100644 (file)
@@ -207,7 +207,6 @@ int main (int argc, char *argv []) {
        //
        // Finally, commit the transaction
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit transaction\n");
                exit (1);
        } else {
index 1cd7512..58c4791 100644 (file)
@@ -258,7 +258,6 @@ int main (int argc, char *argv []) {
                argi += 2;
        }
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit transaction\n");
                exit (1);
        } else {
index 01f81cd..a8b6bfd 100644 (file)
@@ -264,7 +264,6 @@ int main (int argc, char *argv []) {
                printf ("Written the new record\n");
        }
        if (txn->commit (txn, 0) != 0) {
-               txn->abort (txn);
                fprintf (stderr, "Failed to commit transaction\n");
                exit (1);
        } else {