aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-03-07 08:46:28 +0000
committerChristian Grothoff <christian@grothoff.org>2013-03-07 08:46:28 +0000
commit04362fdc4f2829da73b5829e49f262e6401a9b9c (patch)
treee248761a90266be3917fd53856979db3fa2d8bf9
parent69b5a64e31e3ac98e3f78dfefc05ce7a042152fb (diff)
downloadgnunet-04362fdc4f2829da73b5829e49f262e6401a9b9c.tar.gz
gnunet-04362fdc4f2829da73b5829e49f262e6401a9b9c.zip
-expand pseudonym test to cover crypto
-rw-r--r--src/util/test_pseudonym.c102
1 files changed, 94 insertions, 8 deletions
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c
index 2586aadd0..4ca293a9a 100644
--- a/src/util/test_pseudonym.c
+++ b/src/util/test_pseudonym.c
@@ -25,10 +25,8 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_common.h" 27#include "gnunet_common.h"
28#include "gnunet_container_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_crypto_lib.h" 29#include "gnunet_signatures.h"
30#include "gnunet_disk_lib.h"
31#include "gnunet_pseudonym_lib.h"
32 30
33#define CHECK(a) do { if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; } } while (0) 31#define CHECK(a) do { if (!(a)) { ok = GNUNET_NO; GNUNET_break(0); goto FAILURE; } } while (0)
34 32
@@ -204,19 +202,106 @@ FAILURE:
204 GNUNET_PSEUDONYM_discovery_callback_unregister (dh2); 202 GNUNET_PSEUDONYM_discovery_callback_unregister (dh2);
205 GNUNET_CONTAINER_meta_data_destroy (meta); 203 GNUNET_CONTAINER_meta_data_destroy (meta);
206 GNUNET_CONFIGURATION_destroy (cfg); 204 GNUNET_CONFIGURATION_destroy (cfg);
207 GNUNET_break (GNUNET_OK ==
208 GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
209 return (ok == GNUNET_YES) ? 0 : 1; 205 return (ok == GNUNET_YES) ? 0 : 1;
210} 206}
211 207
212 208
209/**
210 * Use the given input to sign and check the resulting signature.
211 */
212static void
213test_signature (struct GNUNET_PseudonymHandle *ph,
214 struct GNUNET_PseudonymSignaturePurpose *purpose,
215 struct GNUNET_HashCode *seed,
216 struct GNUNET_HashCode *signing_key,
217 char *bit)
218{
219 struct GNUNET_PseudonymSignature signature;
220 struct GNUNET_PseudonymSignature signature2;
221 struct GNUNET_PseudonymIdentifier pseudonym;
222 struct GNUNET_PseudonymIdentifier verification_key;
223
224 GNUNET_PSEUDONYM_sign (ph, purpose, seed, signing_key, &signature);
225 GNUNET_PSEUDONYM_sign (ph, purpose, seed, signing_key, &signature2);
226 /* with seed, two sigs must be identical, without, they must be different! */
227 if (NULL != seed)
228 GNUNET_assert (0 == memcmp (&signature, &signature2, sizeof (signature)));
229 else /* crypto not implemented, thus for now 'break' */
230 GNUNET_break (0 != memcmp (&signature, &signature2, sizeof (signature)));
231 GNUNET_PSEUDONYM_get_identifier (ph, &pseudonym);
232 GNUNET_PSEUDONYM_derive_verification_key (&pseudonym,
233 signing_key,
234 &verification_key);
235 GNUNET_assert (GNUNET_OK ==
236 GNUNET_PSEUDONYM_verify (purpose, &signature, &verification_key));
237 /* also check that if the data is changed, the signature no longer matches */
238 (*bit)++;
239 /* crypto not implemented, thus for now 'break' */
240 GNUNET_break (GNUNET_OK !=
241 GNUNET_PSEUDONYM_verify (purpose, &signature, &verification_key));
242 (*bit)--;
243}
244
245
246/**
247 * Test cryptographic operations for a given private key.
248 *
249 * @param ph private key to test
250 */
251static void
252test_crypto_ops (struct GNUNET_PseudonymHandle *ph)
253{
254 char data[16];
255 struct GNUNET_PseudonymSignaturePurpose *purpose;
256 struct GNUNET_HashCode seed;
257 struct GNUNET_HashCode signing_key;
258
259 memset (data, 42, sizeof (data));
260 purpose = (struct GNUNET_PseudonymSignaturePurpose *) data;
261 purpose->size = htonl (sizeof (data));
262 purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
263 memset (&seed, 41, sizeof (seed));
264 memset (&signing_key, 40, sizeof (signing_key));
265 test_signature (ph, purpose, &seed, &signing_key, &data[sizeof (struct GNUNET_PseudonymSignaturePurpose)]);
266 test_signature (ph, purpose, NULL, &signing_key, &data[sizeof (struct GNUNET_PseudonymSignaturePurpose)]);
267}
268
269
270/**
271 * Test cryptographic operations.
272 */
213static int 273static int
214test_crypto () 274test_crypto ()
215{ 275{
216 struct GNUNET_PseudonymHandle *ph; 276 struct GNUNET_PseudonymHandle *ph;
277 struct GNUNET_PseudonymIdentifier pseudonym;
278 struct GNUNET_PseudonymIdentifier pseudonym2;
217 279
280 /* check writing to and reading from disk */
281 ph = GNUNET_PSEUDONYM_create ("/tmp/gnunet-pseudonym-test/pseu.dsa");
282 GNUNET_PSEUDONYM_get_identifier (ph, &pseudonym);
283 GNUNET_PSEUDONYM_destroy (ph);
284 ph = GNUNET_PSEUDONYM_create ("/tmp/gnunet-pseudonym-test/pseu.dsa");
285 GNUNET_PSEUDONYM_get_identifier (ph, &pseudonym2);
286 test_crypto_ops (ph);
287 GNUNET_PSEUDONYM_destroy (ph);
288 if (0 != memcmp (&pseudonym, &pseudonym2, sizeof (pseudonym)))
289 return 1;
290
291 /* check in-memory generation */
218 ph = GNUNET_PSEUDONYM_create (NULL); 292 ph = GNUNET_PSEUDONYM_create (NULL);
219 // FIXME: call sign, verify APIs... 293 GNUNET_PSEUDONYM_get_identifier (ph, &pseudonym2);
294 if (0 == memcmp (&pseudonym, &pseudonym2, sizeof (pseudonym)))
295 return 1;
296 test_crypto_ops (ph);
297 GNUNET_PSEUDONYM_destroy (ph);
298
299 /* check anonymous pseudonym operations generation */
300 ph = GNUNET_PSEUDONYM_get_anonymous_pseudonym_handle ();
301 GNUNET_PSEUDONYM_get_identifier (ph, &pseudonym2);
302 if (0 == memcmp (&pseudonym, &pseudonym2, sizeof (pseudonym)))
303 return 1;
304 test_crypto_ops (ph);
220 GNUNET_PSEUDONYM_destroy (ph); 305 GNUNET_PSEUDONYM_destroy (ph);
221 return 0; 306 return 0;
222} 307}
@@ -229,7 +314,8 @@ main (int argc, char *argv[])
229 return 1; 314 return 1;
230 if (0 != test_crypto ()) 315 if (0 != test_crypto ())
231 return 1; 316 return 1;
232 317 GNUNET_break (GNUNET_OK ==
318 GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
233 return 0; 319 return 0;
234} 320}
235 321