diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-29 13:04:16 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-29 13:04:16 +0000 |
commit | dd64a1b6f257887bb3b7d4b44d2c117ff3592b7c (patch) | |
tree | 7622c9e337069df5ed99c2f60b83c90ce94efa5c /src/namestore/test_namestore_api_lookup.c | |
parent | 58b0c3ab02e3212465ca16d987313111d27952b3 (diff) | |
download | gnunet-dd64a1b6f257887bb3b7d4b44d2c117ff3592b7c.tar.gz gnunet-dd64a1b6f257887bb3b7d4b44d2c117ff3592b7c.zip |
- adding sig purpose and test for lookup up
Diffstat (limited to 'src/namestore/test_namestore_api_lookup.c')
-rw-r--r-- | src/namestore/test_namestore_api_lookup.c | 94 |
1 files changed, 72 insertions, 22 deletions
diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c index fafe5f218..d20a1cdaf 100644 --- a/src/namestore/test_namestore_api_lookup.c +++ b/src/namestore/test_namestore_api_lookup.c | |||
@@ -24,6 +24,8 @@ | |||
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_common.h" | 25 | #include "gnunet_common.h" |
26 | #include "gnunet_namestore_service.h" | 26 | #include "gnunet_namestore_service.h" |
27 | #include "namestore.h" | ||
28 | #include "gnunet_signatures.h" | ||
27 | 29 | ||
28 | #define VERBOSE GNUNET_NO | 30 | #define VERBOSE GNUNET_NO |
29 | 31 | ||
@@ -41,10 +43,12 @@ static struct GNUNET_OS_Process *arm; | |||
41 | 43 | ||
42 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; | 44 | static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; |
43 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | 45 | static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
44 | static GNUNET_HashCode zone; | 46 | struct GNUNET_CRYPTO_RsaSignature s_signature; |
45 | static char *name; | 47 | static GNUNET_HashCode s_zone; |
48 | struct GNUNET_NAMESTORE_RecordData *s_rd; | ||
49 | static char *s_name; | ||
50 | |||
46 | 51 | ||
47 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
48 | 52 | ||
49 | static int res; | 53 | static int res; |
50 | 54 | ||
@@ -107,6 +111,11 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
107 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | 111 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; |
108 | } | 112 | } |
109 | 113 | ||
114 | int c; | ||
115 | for (c = 0; c < RECORDS; c++) | ||
116 | GNUNET_free_non_null((void *) s_rd[c].data); | ||
117 | GNUNET_free (s_rd); | ||
118 | |||
110 | if (privkey != NULL) | 119 | if (privkey != NULL) |
111 | GNUNET_CRYPTO_rsa_key_free (privkey); | 120 | GNUNET_CRYPTO_rsa_key_free (privkey); |
112 | privkey = NULL; | 121 | privkey = NULL; |
@@ -128,9 +137,43 @@ void name_lookup_proc (void *cls, | |||
128 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 137 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
129 | { | 138 | { |
130 | static int found = GNUNET_NO; | 139 | static int found = GNUNET_NO; |
140 | int failed = GNUNET_NO; | ||
141 | int c; | ||
131 | 142 | ||
132 | if (n != NULL) | 143 | if (n != NULL) |
133 | { | 144 | { |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n"); | ||
146 | if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) | ||
147 | { | ||
148 | GNUNET_break (0); | ||
149 | failed = GNUNET_YES; | ||
150 | } | ||
151 | |||
152 | if (0 != memcmp (signature, &s_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature))) | ||
153 | { | ||
154 | GNUNET_break (0); | ||
155 | failed = GNUNET_YES; | ||
156 | } | ||
157 | |||
158 | if (0 != strcmp(n, s_name)) | ||
159 | { | ||
160 | GNUNET_break (0); | ||
161 | failed = GNUNET_YES; | ||
162 | } | ||
163 | |||
164 | if (RECORDS != rd_count) | ||
165 | { | ||
166 | GNUNET_break (0); | ||
167 | failed = GNUNET_YES; | ||
168 | } | ||
169 | |||
170 | for (c = 0; c < RECORDS; c++) | ||
171 | { | ||
172 | GNUNET_break (rd[c].expiration.abs_value == s_rd[c].expiration.abs_value); | ||
173 | GNUNET_break (rd[c].record_type == TEST_RECORD_TYPE); | ||
174 | GNUNET_break (rd[c].data_size == TEST_RECORD_DATALEN); | ||
175 | GNUNET_break (0 == memcmp (rd[c].data, s_rd[c].data, TEST_RECORD_DATALEN)); | ||
176 | } | ||
134 | found = GNUNET_YES; | 177 | found = GNUNET_YES; |
135 | res = 0; | 178 | res = 0; |
136 | } | 179 | } |
@@ -138,12 +181,11 @@ void name_lookup_proc (void *cls, | |||
138 | { | 181 | { |
139 | if (found != GNUNET_YES) | 182 | if (found != GNUNET_YES) |
140 | { | 183 | { |
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", name); | 184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name); |
142 | res = 1; | 185 | res = 1; |
143 | } | 186 | } |
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", name); | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name); |
145 | } | 188 | } |
146 | |||
147 | GNUNET_SCHEDULER_add_now(&end, NULL); | 189 | GNUNET_SCHEDULER_add_now(&end, NULL); |
148 | } | 190 | } |
149 | 191 | ||
@@ -156,7 +198,7 @@ put_cont (void *cls, int32_t success, const char *emsg) | |||
156 | if (success == GNUNET_OK) | 198 | if (success == GNUNET_OK) |
157 | { | 199 | { |
158 | res = 0; | 200 | res = 0; |
159 | GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); | 201 | GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_proc, NULL); |
160 | } | 202 | } |
161 | else | 203 | else |
162 | { | 204 | { |
@@ -190,6 +232,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
190 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 232 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
191 | { | 233 | { |
192 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | 234 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); |
235 | char * rd_ser; | ||
236 | size_t rd_ser_len; | ||
193 | 237 | ||
194 | /* load privat key */ | 238 | /* load privat key */ |
195 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); | 239 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); |
@@ -197,10 +241,23 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
197 | /* get public key */ | 241 | /* get public key */ |
198 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); | 242 | GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); |
199 | 243 | ||
200 | /* create random zone hash */ | 244 | /* create record */ |
201 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &zone); | 245 | s_name = "dummy.dummy.gnunet"; |
246 | s_rd = create_record (RECORDS); | ||
247 | rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, RECORDS, s_rd); | ||
248 | |||
249 | /* sign */ | ||
250 | struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + rd_ser_len); | ||
251 | sig_purpose->size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)+ rd_ser_len); | ||
252 | sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
253 | memcpy (&sig_purpose[1], rd_ser, rd_ser_len); | ||
254 | GNUNET_CRYPTO_rsa_sign (privkey, sig_purpose, &s_signature); | ||
202 | 255 | ||
203 | struct GNUNET_CRYPTO_RsaSignature signature; | 256 | GNUNET_free (rd_ser); |
257 | GNUNET_free (sig_purpose); | ||
258 | |||
259 | /* create random zone hash */ | ||
260 | GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); | ||
204 | 261 | ||
205 | start_arm (cfgfile); | 262 | start_arm (cfgfile); |
206 | GNUNET_assert (arm != NULL); | 263 | GNUNET_assert (arm != NULL); |
@@ -208,21 +265,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
208 | nsh = GNUNET_NAMESTORE_connect (cfg); | 265 | nsh = GNUNET_NAMESTORE_connect (cfg); |
209 | GNUNET_break (NULL != nsh); | 266 | GNUNET_break (NULL != nsh); |
210 | 267 | ||
211 | /* create record */ | ||
212 | name = "dummy.dummy.gnunet"; | ||
213 | rd = create_record (RECORDS); | ||
214 | 268 | ||
215 | GNUNET_break (rd != NULL); | ||
216 | GNUNET_break (name != NULL); | ||
217 | 269 | ||
218 | GNUNET_NAMESTORE_record_put (nsh, &pubkey, name, | 270 | GNUNET_break (s_rd != NULL); |
219 | GNUNET_TIME_absolute_get_forever(), | 271 | GNUNET_break (s_name != NULL); |
220 | RECORDS, rd, &signature, put_cont, name); | ||
221 | 272 | ||
222 | int c; | 273 | GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name, |
223 | for (c = 0; c < RECORDS; c++) | 274 | GNUNET_TIME_absolute_get_forever(), |
224 | GNUNET_free_non_null((void *) rd[c].data); | 275 | RECORDS, s_rd, &s_signature, put_cont, s_name); |
225 | GNUNET_free (rd); | ||
226 | 276 | ||
227 | } | 277 | } |
228 | 278 | ||