1 /* pulleybacksimu.c -- Simulation of driving the Pulley backend to the TLS Pool
3 * This simulates a series of calls that the SteamWorks Pulley could do on
4 * the backend in ../pulleyback/ -- it links against the library formed there,
5 * and tests the output with the ../test/get_xxx routines.
7 * From: Rick van Rein <rick@openfortress.nl>
22 #include "../pulleyback/api.h"
25 #define REMOTEID "remoteid@tlspool.arpa2.lab"
26 #define REMOTEID_PATN "remoteid@.arpa2.lab"
27 #define LOCALID "localid@tlspool.arpa2.lab"
29 #define CONFFILE "../etc/tlspool.conf"
31 #define X509FILE "tlspool-test-client-cert.der"
32 #define PGPFILE "tlspool-test-client-pubkey.pgp"
34 #define ANCHOR_HEX "aabbccddeeff"
35 #define ANCHOR_BYTES 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
37 void inline testcmd (char *cmd) {
39 printf ("shell$ %s\n", cmd);
40 exitval = system (cmd);
41 printf ("$? = %d\n\n", exitval);
44 //TODO// Calling these subcommands causes trouble with the shared environment
45 //TODO// Note that db_stat does not give that same trouble with -h / -d ?!?
46 void showstatus (char *title) {
47 printf ("\n\n\n# %s\n", title);
48 // testcmd ("db_stat -h ../testdata/tlspool.env -d ../disclose.db");
49 // printf ("\n\n\n## Disclosure database\n\n\n");
50 // testcmd ("../tool/get_disclose "CONFFILE" "REMOTEID" >/dev/null");
51 // testcmd ("../tool/get_disclose "CONFFILE" "REMOTEID_PATN" >/dev/null");
52 // testcmd ("../tool/get_disclose "CONFFILE" "LOCALID" >/dev/null");
53 // printf ("\n\n\n## LocalID database\n\n\n");
54 // testcmd ("../tool/get_localid "CONFFILE" "REMOTEID" X.509,client,server"" >/dev/null");
55 // testcmd ("../tool/get_localid "CONFFILE" "LOCALID" X.509,client,server"" >/dev/null");
56 // testcmd ("../tool/get_localid "CONFFILE" "REMOTEID" OpenPGP,client,server"" >/dev/null");
57 // testcmd ("../tool/get_localid "CONFFILE" "LOCALID" OpenPGP,client,server"" >/dev/null");
58 // printf ("\n\n\n## Trust database\n\n\n");
59 // testcmd ("../tool/get_trust "CONFFILE" x509,client,server "ANCHOR_HEX" >/dev/null");
60 // testcmd ("../tool/get_trust "CONFFILE" x509,client,server "ANCHOR_HEX" >/dev/null");
61 // testcmd ("../tool/get_trust "CONFFILE" pgp,client,server "ANCHOR_HEX" >/dev/null");
62 // testcmd ("../tool/get_trust "CONFFILE" pgp,client,server "ANCHOR_HEX" >/dev/null");
63 // printf ("\nThat was our last test for %s\n\n\n", title);
67 void *open_backend (char *argv []) {
72 for (argc = 0; argv [argc] != NULL; argc++) {
73 if (strncmp (argv [argc], "args=", 5) != 0) {
76 for (argsp = argv [argc]; argsp != NULL; argsp = strchr (argsp + 1, ',')) {
80 backend = pulleyback_open (argc, argv, varc);
81 if (backend == NULL) {
82 printf ("\n\nERROR: BACKEND DID NOT OPEN PROPERLY\n\n");
87 void close_backend (void *backend) {
88 struct pulleyback_tlspool *self = backend;
89 if (backend != NULL) {
90 pulleyback_close (backend);
95 char *test0 [] = { "pulleyback_tlspool", "config=../etc/tlspool.conf", "type=disclose", "args=localid,remoteid", NULL };
96 char *test1 [] = { "pulleyback_tlspool", "config=../etc/tlspool.conf", "type=disclose", "args=remoteid,localid", NULL };
97 char *test2 [] = { "pulleyback_tlspool", "config=../etc/tlspool.conf", "type=localid", "args=localid,pkcs11,cred", "subtype=x509,client", NULL };
99 uint8_t *args0 [2] = { (uint8_t*)"\x0c\x1clocalid@pulleyback.arpa2.lab", (uint8_t*)"\x0c\x1dremoteid@pulleyback.arpa2.lab" };
100 uint8_t *args1 [2] = { (uint8_t*)"\x0c\x1dremoteid@pulleyback.arpa2.lab", (uint8_t*)"\x0c\x1clocalid@pulleyback.arpa2.lab" };
101 uint8_t *args2 [3] = { (uint8_t*)"\x0c\x1clocalid@pulleyback.arpa2.lab", (uint8_t*)"\x0c\x24pkcs11:manuf=OpenFortress;serial=123", (uint8_t*)"\x0c\x1a-----LIKE A PGP KEY-----\r\n" };
103 char **tests [] = { test0, test1, test2, NULL };
104 uint8_t **argss [] = { args0, args1, args2, NULL };
107 int main (int argc, char *argv []) {
110 uint8_t derargs [3] [130];
113 char testtitle [105];
116 openlog (basename (argv [0]), LOG_PERROR, LOG_LOCAL0);
117 // showstatus ("Initial status");
118 for (testp = tests, argsp = argss; *testp != NULL; testp++, argsp++) {
119 backend = open_backend (*testp);
120 if (backend == NULL) {
123 snprintf (testtitle, 100, "Test number %d\n", testnr);
124 showstatus (testtitle);
125 pulleyback_add (backend, *argsp);
126 if (pulleyback_commit (backend)) {
127 printf ("Go have a look...\n");
129 printf ("Failed, so you probably won't find it...\n");
132 snprintf (testtitle, 100, "Added in test number %d\n", testnr++);
133 showstatus (testtitle);
134 pulleyback_del (backend, *argsp);
135 if (pulleyback_commit (backend)) {
136 printf ("It should be gone...\n");
138 printf ("Failed, so it is probably still there...\n");
140 close_backend (backend);
142 // showstatus ("Final status");