gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 32b2ebbdc17d168f3ab60ff72b6b5ea64951422c
parent ed42d471aa6b5bf42bfc8e9186e69ab4c0ebc6ff
Author: Schanzenbach, Martin <mschanzenbach@posteo.de>
Date:   Sun,  9 Jul 2017 19:16:46 +0200

-add cli

Diffstat:
Msrc/identity-provider/gnunet-idp.c | 47++++++++++++++++++++++++++++++++++++-----------
Asrc/identity-provider/test_idp.conf | 25+++++++++++++++++++++++++
Asrc/identity-provider/test_idp.sh | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/identity-provider/test_idp_defaults.conf | 24++++++++++++++++++++++++
Msrc/util/crypto_abe.c | 68++++++++++++++++++++++++++++----------------------------------------
5 files changed, 154 insertions(+), 51 deletions(-)

diff --git a/src/identity-provider/gnunet-idp.c b/src/identity-provider/gnunet-idp.c @@ -31,6 +31,11 @@ #include "gnunet_signatures.h" /** + * Init flag + */ +static int init; + +/** * List attribute flag */ static int list; @@ -93,6 +98,7 @@ do_cleanup(void *cls) static void ns_error_cb (void *cls) { + ns_qe = NULL; GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Failed."); do_cleanup(NULL); @@ -104,6 +110,7 @@ store_attr_cont (void *cls, int32_t success, const char*emsg) { + ns_qe = NULL; if (GNUNET_SYSERR == success) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); @@ -120,6 +127,7 @@ store_abe_cont (void *cls, int32_t success, const char*emsg) { + ns_qe = NULL; if (GNUNET_SYSERR == success) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); @@ -133,6 +141,7 @@ store_abe_cont (void *cls, static void iter_error (void *cls) { + ns_iterator = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to iterate over attributes\n"); GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); @@ -141,6 +150,7 @@ iter_error (void *cls) static void iter_finished (void *cls) { + ns_iterator = NULL; GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); } @@ -151,16 +161,22 @@ iter_cb (void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) { + struct GNUNET_CRYPTO_AbeKey *key; int i; char *attr_value; - + char* attrs[2]; for (i=0;i<rd_count;i++) { if (GNUNET_GNSRECORD_TYPE_ID_ATTR != rd[i].record_type) continue; - GNUNET_CRYPTO_cpabe_decrypt_master (rd[i].data, - rd[i].data_size, - abe_key, - &attr_value); + attrs[0] = (char*)label; + attrs[1] = 0; + key = GNUNET_CRYPTO_cpabe_create_key (abe_key, + attrs); + GNUNET_CRYPTO_cpabe_decrypt (rd[i].data, + rd[i].data_size, + key, + (void**)&attr_value); + GNUNET_free (key); GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "%s: %s\n", label, attr_value); } @@ -178,7 +194,7 @@ abe_lookup_cb (void *cls, struct GNUNET_CRYPTO_AbeMasterKey *new_key; int i; ssize_t size; - + ns_qe = NULL; for (i=0;i<rd_count;i++) { if (GNUNET_GNSRECORD_TYPE_ABE_MASTER != rd[i].record_type) continue; @@ -202,6 +218,10 @@ abe_lookup_cb (void *cls, NULL); return; } + if (init) { + GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); + return; + } if (list) { ns_iterator = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle, @@ -241,6 +261,8 @@ ego_cb (void *cls, const char *name) { const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey; + if (NULL == name) + return; if (0 != strcmp (name, ego_name)) return; pkey = GNUNET_IDENTITY_ego_get_private_key (ego); @@ -267,11 +289,11 @@ run (void *cls, return; } - if ((NULL == attr_name) && !list) + if ((NULL == attr_name) && !list && !init) { return; } - if ((NULL == attr_value) && !list) + if ((NULL == attr_value) && !list && !init) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _("Value is required\n")); @@ -309,11 +331,14 @@ main(int argc, char *const argv[]) NULL, gettext_noop ("Ego"), &ego_name), - GNUNET_GETOPT_option_flag ('l', - "list", + GNUNET_GETOPT_option_flag ('D', + "dump", gettext_noop ("List attributes for Ego"), &list), - + GNUNET_GETOPT_option_flag ('i', + "init", + gettext_noop ("Initialize attribute store"), + &init), GNUNET_GETOPT_OPTION_END }; return GNUNET_PROGRAM_run (argc, argv, "ct", diff --git a/src/identity-provider/test_idp.conf b/src/identity-provider/test_idp.conf @@ -0,0 +1,25 @@ +@INLINE@ test_idp_defaults.conf + +[PATHS] +GNUNET_TEST_HOME = /tmp/test-gnunet-idp-peer-1/ + +[dht] +AUTOSTART = YES + +[transport] +PLUGINS = + +[identity-provider] +AUTOSTART = YES +PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/idplog + +[gns] +#PREFIX = valgrind --leak-check=full --track-origins=yes +AUTOSTART = YES +AUTO_IMPORT_PKEY = YES +MAX_PARALLEL_BACKGROUND_QUERIES = 10 +DEFAULT_LOOKUP_TIMEOUT = 15 s +RECORD_PUT_INTERVAL = 1 h +ZONE_PUBLISH_TIME_WINDOW = 1 h +DNS_ROOT=PD67SGHF3E0447TU9HADIVU9OM7V4QHTOG0EBU69TFRI2LG63DR0 + diff --git a/src/identity-provider/test_idp.sh b/src/identity-provider/test_idp.sh @@ -0,0 +1,41 @@ +#!/bin/bash +trap "gnunet-arm -e -c test_idp_lookup.conf" SIGINT + +LOCATION=$(which gnunet-config) +if [ -z $LOCATION ] +then + LOCATION="gnunet-config" +fi +$LOCATION --version 1> /dev/null +if test $? != 0 +then + echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX" + exit 77 +fi + +rm -rf `gnunet-config -c test_idp.conf -s PATHS -o GNUNET_HOME -f` + +# (1) PKEY1.user -> PKEY2.resu.user +# (2) PKEY2.resu -> PKEY3 +# (3) PKEY3.user -> PKEY4 + + +which timeout &> /dev/null && DO_TIMEOUT="timeout 30" + +TEST_ATTR="test" +gnunet-arm -s -c test_idp.conf +gnunet-identity -C testego -c test_idp.conf +$DO_TIMEOUT valgrind gnunet-idp -e testego --init -c test_idp.conf +$DO_TIMEOUT valgrind gnunet-idp -e testego -a email -V john@doe.gnu -c test_idp.conf +STATUS=$? +gnunet-namestore -z testego -D -c test_idp.conf +$DO_TIMEOUT valgrind --leak-check=full gnunet-idp -e testego -D -c test_idp.conf + +if test $? != 0 +then + echo "Error issuing..." + exit 1 +fi +#Try import +gnunet-arm -e -c test_idp_lookup.conf +exit $RES diff --git a/src/identity-provider/test_idp_defaults.conf b/src/identity-provider/test_idp_defaults.conf @@ -0,0 +1,24 @@ +@INLINE@ ../../contrib/no_forcestart.conf + +[PATHS] +GNUNET_TEST_HOME = /tmp/test-gnunet-idp-testing/ + +[namestore-sqlite] +FILENAME = $GNUNET_TEST_HOME/namestore/sqlite_test.db + +[namecache-sqlite] +FILENAME=$GNUNET_TEST_HOME/namecache/namecache.db + +[identity] +# Directory where we store information about our egos +EGODIR = $GNUNET_TEST_HOME/identity/egos/ + +[dhtcache] +DATABASE = heap + +[transport] +PLUGINS = tcp + +[transport-tcp] +BINDTO = 127.0.0.1 + diff --git a/src/util/crypto_abe.c b/src/util/crypto_abe.c @@ -156,7 +156,6 @@ GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key, bswabe_pub_t* pub; bswabe_msk_t* msk; bswabe_prv_t* prv; - gchar* pub_data; gsize len; pub = bswabe_pub_unserialize(key->pub, 0); @@ -164,73 +163,62 @@ GNUNET_CRYPTO_cpabe_create_key (struct GNUNET_CRYPTO_AbeMasterKey *key, prv = bswabe_keygen(pub, msk, attrs); prv_key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey); prv_key->prv = bswabe_prv_serialize(prv); - pub_data = g_strndup ((gchar*)key->pub->data, - key->pub->len); + len = key->pub->len; - prv_key->pub = g_byte_array_new_take ((guint8*)pub_data, len); + printf ("Keylen %lu\n", len); + prv_key->pub = bswabe_pub_serialize (pub); GNUNET_assert (NULL != prv_key->prv); return prv_key; } ssize_t write_cpabe (void **result, GByteArray* cph_buf, - int file_len, GByteArray* aes_buf) + uint32_t file_len, GByteArray* aes_buf) { char *ptr; + uint32_t *len; int i; - ssize_t size; - size = aes_buf->len + cph_buf->len + 12; - *result = GNUNET_malloc (size); + *result = GNUNET_malloc (12 + cph_buf->len + aes_buf->len); ptr = *result; - for(i=3; i >= 0; i--) { - *ptr = (file_len & 0xff<<(i*8))>>(i*8); - ptr++; - } - for(i=3; i >= 0; i--) { - *ptr = (aes_buf->len & 0xff<<(i*8))>>(i*8); - ptr++; - } + len = (uint32_t*) ptr; + *len = htonl (file_len); + ptr += 4; + len = (uint32_t*) ptr; + *len = htonl (aes_buf->len); + ptr += 4; memcpy (ptr, aes_buf->data, aes_buf->len); ptr += aes_buf->len; - for(i=3; i >= 0; i--) { - *ptr = (cph_buf->len & 0xff<<(i*8))>>(i*8); - ptr++; - } + len = (uint32_t*) ptr; + *len = htonl (cph_buf->len); + ptr += 4; memcpy (ptr, cph_buf->data, cph_buf->len); - return size; + return 12 + cph_buf->len + aes_buf->len; } ssize_t read_cpabe (const void *data, GByteArray** cph_buf, GByteArray** aes_buf) { int i; - ssize_t buf_len; - ssize_t tmp_len; + int buf_len; + int tmp_len; char *ptr; + uint32_t *len; *cph_buf = g_byte_array_new(); *aes_buf = g_byte_array_new(); ptr = (char*)data; - - buf_len = 0; - for(i=3; i >= 0; i--) { - buf_len |= *ptr<<(i*8); - ptr++; - } - - tmp_len = 0; - for(i=3; i >= 0; i--) { - tmp_len |= *ptr<<(i*8); - ptr++; - } + len = (uint32_t*)ptr; + buf_len = ntohl (*len); + ptr += 4; + len = (uint32_t*)ptr; + tmp_len = ntohl (*len); + ptr += 4; g_byte_array_set_size(*aes_buf, tmp_len); memcpy((*aes_buf)->data, ptr, tmp_len); ptr += tmp_len; - tmp_len = 0; - for(i=3; i >= 0; i--) { - tmp_len |= *ptr<<(i*8); - ptr++; - } + len = (uint32_t*)ptr; + tmp_len = ntohl (*len); + ptr += 4; g_byte_array_set_size(*cph_buf, tmp_len); memcpy((*cph_buf)->data, ptr, tmp_len);