aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-05-02 01:42:55 +0200
committerChristian Grothoff <christian@grothoff.org>2018-05-02 01:42:55 +0200
commit6a86935d5e69874324a158fa6d418b88df8c575d (patch)
treedde6040a0c0bcace637d8a70a8f2aa5e54c0cf4b /src
parentd2eed41d5637e802c9b8c6a8d0648636c16e5b88 (diff)
downloadgnunet-6a86935d5e69874324a158fa6d418b88df8c575d.tar.gz
gnunet-6a86935d5e69874324a158fa6d418b88df8c575d.zip
add test for query derivation (passed instantly)
Diffstat (limited to 'src')
-rw-r--r--src/gnsrecord/gnsrecord_crypto.c7
-rw-r--r--src/gnsrecord/test_gnsrecord_crypto.c79
-rw-r--r--src/namestore/gnunet-service-namestore.c2
3 files changed, 56 insertions, 32 deletions
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c
index d9fe2ae40..cebc842f3 100644
--- a/src/gnsrecord/gnsrecord_crypto.c
+++ b/src/gnsrecord/gnsrecord_crypto.c
@@ -405,8 +405,11 @@ GNUNET_GNSRECORD_query_from_private_key (const struct GNUNET_CRYPTO_EcdsaPrivate
405{ 405{
406 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 406 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
407 407
408 GNUNET_CRYPTO_ecdsa_key_get_public (zone, &pub); 408 GNUNET_CRYPTO_ecdsa_key_get_public (zone,
409 GNUNET_GNSRECORD_query_from_public_key (&pub, label, query); 409 &pub);
410 GNUNET_GNSRECORD_query_from_public_key (&pub,
411 label,
412 query);
410} 413}
411 414
412 415
diff --git a/src/gnsrecord/test_gnsrecord_crypto.c b/src/gnsrecord/test_gnsrecord_crypto.c
index 24fe2ad36..1df3f3730 100644
--- a/src/gnsrecord/test_gnsrecord_crypto.c
+++ b/src/gnsrecord/test_gnsrecord_crypto.c
@@ -52,11 +52,10 @@ static int res;
52static struct GNUNET_GNSRECORD_Data * 52static struct GNUNET_GNSRECORD_Data *
53create_record (int count) 53create_record (int count)
54{ 54{
55 unsigned int c;
56 struct GNUNET_GNSRECORD_Data *rd; 55 struct GNUNET_GNSRECORD_Data *rd;
57 56
58 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data)); 57 rd = GNUNET_malloc (count * sizeof (struct GNUNET_GNSRECORD_Data));
59 for (c = 0; c < count; c++) 58 for (unsigned int c = 0; c < count; c++)
60 { 59 {
61 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000; 60 rd[c].expiration_time = GNUNET_TIME_absolute_get().abs_value_us + 1000000000;
62 rd[c].record_type = TEST_RECORD_TYPE; 61 rd[c].record_type = TEST_RECORD_TYPE;
@@ -74,17 +73,19 @@ rd_decrypt_cb (void *cls,
74 const struct GNUNET_GNSRECORD_Data *rd) 73 const struct GNUNET_GNSRECORD_Data *rd)
75{ 74{
76 char rd_cmp_data[TEST_RECORD_DATALEN]; 75 char rd_cmp_data[TEST_RECORD_DATALEN];
77 int c;
78 76
79 GNUNET_assert (RECORDS == rd_count); 77 GNUNET_assert (RECORDS == rd_count);
80 GNUNET_assert (NULL != rd); 78 GNUNET_assert (NULL != rd);
81 79 memset (rd_cmp_data,
82 memset (rd_cmp_data, 'a', TEST_RECORD_DATALEN); 80 'a',
83 for (c = 0; c < rd_count; c++) 81 TEST_RECORD_DATALEN);
82 for (unsigned int c = 0; c < rd_count; c++)
84 { 83 {
85 GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type); 84 GNUNET_assert (TEST_RECORD_TYPE == rd[c].record_type);
86 GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size); 85 GNUNET_assert (TEST_RECORD_DATALEN == rd[c].data_size);
87 GNUNET_assert (0 == memcmp (&rd_cmp_data, rd[c].data, TEST_RECORD_DATALEN)); 86 GNUNET_assert (0 == memcmp (&rd_cmp_data,
87 rd[c].data,
88 TEST_RECORD_DATALEN));
88 } 89 }
89 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
90 "Block was decrypted successfully \n"); 91 "Block was decrypted successfully \n");
@@ -93,37 +94,53 @@ rd_decrypt_cb (void *cls,
93} 94}
94 95
95static void 96static void
96run (void *cls, char *const *args, const char *cfgfile, 97run (void *cls,
98 char *const *args,
99 const char *cfgfile,
97 const struct GNUNET_CONFIGURATION_Handle *cfg) 100 const struct GNUNET_CONFIGURATION_Handle *cfg)
98{ 101{
99 struct GNUNET_GNSRECORD_Block *block; 102 struct GNUNET_GNSRECORD_Block *block;
100 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 103 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
104 struct GNUNET_HashCode query_pub;
105 struct GNUNET_HashCode query_priv;
101 106
102 /* load privat key */ 107 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
103 char *hostkey_file; 108 GNUNET_assert (NULL != privkey);
104 GNUNET_asprintf(&hostkey_file,
105 "zonefiles%s%s",
106 DIR_SEPARATOR_STR,
107 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "Using zonekey file `%s'\n",
110 hostkey_file);
111 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file);
112 GNUNET_free (hostkey_file);
113 GNUNET_assert (privkey != NULL);
114 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); 109 struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get();
115 /* get public key */
116 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey);
117 110
111 /* get public key */
112 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
113 &pubkey);
114
115 /* test query derivation */
116 GNUNET_GNSRECORD_query_from_private_key (privkey,
117 "testlabel",
118 &query_priv);
119 GNUNET_GNSRECORD_query_from_public_key (&pubkey,
120 "testlabel",
121 &query_pub);
122 GNUNET_assert (0 == memcmp (&query_priv,
123 &query_pub,
124 sizeof (struct GNUNET_HashCode)));
118 /* create record */ 125 /* create record */
119 s_name = "DUMMY.dummy.gnunet"; 126 s_name = "DUMMY.dummy.gnunet";
120 s_rd = create_record (RECORDS); 127 s_rd = create_record (RECORDS);
121 128
122 /* Create block */ 129 /* Create block */
123 GNUNET_assert (NULL != (block = GNUNET_GNSRECORD_block_create (privkey, expire,s_name, s_rd, RECORDS))); 130 GNUNET_assert (NULL != (block =
124 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_verify (block)); 131 GNUNET_GNSRECORD_block_create (privkey,
125 GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, &pubkey, s_name, &rd_decrypt_cb, s_name)); 132 expire,
126 133 s_name,
134 s_rd,
135 RECORDS)));
136 GNUNET_assert (GNUNET_OK ==
137 GNUNET_GNSRECORD_block_verify (block));
138 GNUNET_assert (GNUNET_OK ==
139 GNUNET_GNSRECORD_block_decrypt (block,
140 &pubkey,
141 s_name,
142 &rd_decrypt_cb,
143 s_name));
127 GNUNET_free (block); 144 GNUNET_free (block);
128} 145}
129 146
@@ -131,7 +148,8 @@ run (void *cls, char *const *args, const char *cfgfile,
131int 148int
132main (int argc, char *argv[]) 149main (int argc, char *argv[])
133{ 150{
134 static char *const argvx[] = { "test-gnsrecord-crypto", 151 static char *const argvx[] = {
152 "test-gnsrecord-crypto",
135 NULL 153 NULL
136 }; 154 };
137 static struct GNUNET_GETOPT_CommandLineOption options[] = { 155 static struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -139,8 +157,11 @@ main (int argc, char *argv[])
139 }; 157 };
140 158
141 res = 1; 159 res = 1;
142 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api", 160 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
143 "nohelp", options, &run, &res); 161 argvx,
162 "test-gnsrecord-crypto",
163 "nohelp", options,
164 &run, &res);
144 return res; 165 return res;
145} 166}
146 167
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 7934ea6ce..fa189dbc3 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1697,7 +1697,7 @@ handle_monitor_start (void *cls,
1697 1697
1698 1698
1699/** 1699/**
1700 * Obtain the next datum during the zone monitor's zone intiial iteration. 1700 * Obtain the next datum during the zone monitor's zone initial iteration.
1701 * 1701 *
1702 * @param cls zone monitor that does its initial iteration 1702 * @param cls zone monitor that does its initial iteration
1703 */ 1703 */