aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_pseudonym.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_pseudonym.c')
-rw-r--r--src/fs/test_pseudonym.c148
1 files changed, 21 insertions, 127 deletions
diff --git a/src/fs/test_pseudonym.c b/src/fs/test_pseudonym.c
index a6e258038..c3b459420 100644
--- a/src/fs/test_pseudonym.c
+++ b/src/fs/test_pseudonym.c
@@ -33,17 +33,18 @@
33 33
34static struct GNUNET_CONTAINER_MetaData *meta; 34static struct GNUNET_CONTAINER_MetaData *meta;
35 35
36static struct GNUNET_FS_PseudonymIdentifier id1; 36static struct GNUNET_CRYPTO_EccPublicKey id1;
37 37
38 38
39static int 39static int
40iter (void *cls, const struct GNUNET_FS_PseudonymIdentifier * pseudonym, 40iter (void *cls,
41 const struct GNUNET_CRYPTO_EccPublicKey *pseudonym,
41 const char *name, const char *unique_name, 42 const char *name, const char *unique_name,
42 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) 43 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating)
43{ 44{
44 int *ok = cls; 45 int *ok = cls;
45 46
46 if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_FS_PseudonymIdentifier))) && 47 if ((0 == memcmp (pseudonym, &id1, sizeof (struct GNUNET_CRYPTO_EccPublicKey))) &&
47 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta))) 48 (!GNUNET_CONTAINER_meta_data_test_equal (md, meta)))
48 { 49 {
49 *ok = GNUNET_NO; 50 *ok = GNUNET_NO;
@@ -54,7 +55,7 @@ iter (void *cls, const struct GNUNET_FS_PseudonymIdentifier * pseudonym,
54 55
55 56
56static int 57static int
57noti_callback (void *cls, const struct GNUNET_FS_PseudonymIdentifier * pseudonym, 58noti_callback (void *cls, const struct GNUNET_CRYPTO_EccPublicKey *pseudonym,
58 const char *name, const char *unique_name, 59 const char *name, const char *unique_name,
59 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) 60 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating)
60{ 61{
@@ -66,7 +67,8 @@ noti_callback (void *cls, const struct GNUNET_FS_PseudonymIdentifier * pseudonym
66 67
67 68
68static int 69static int
69fake_noti_callback (void *cls, const struct GNUNET_FS_PseudonymIdentifier * pseudonym, 70fake_noti_callback (void *cls,
71 const struct GNUNET_CRYPTO_EccPublicKey * pseudonym,
70 const char *name, const char *unique_name, 72 const char *name, const char *unique_name,
71 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating) 73 const struct GNUNET_CONTAINER_MetaData *md, int32_t rating)
72{ 74{
@@ -78,13 +80,13 @@ fake_noti_callback (void *cls, const struct GNUNET_FS_PseudonymIdentifier * pseu
78 80
79 81
80static void 82static void
81create_pseu (struct GNUNET_FS_PseudonymIdentifier *pseu) 83create_pseu (struct GNUNET_CRYPTO_EccPublicKey *pseu)
82{ 84{
83 struct GNUNET_FS_PseudonymHandle *ph; 85 struct GNUNET_CRYPTO_EccPrivateKey *ph;
84 86
85 ph = GNUNET_FS_pseudonym_create (NULL); 87 ph = GNUNET_CRYPTO_ecc_key_create ();
86 GNUNET_FS_pseudonym_get_identifier (ph, pseu); 88 GNUNET_CRYPTO_ecc_key_get_public (ph, pseu);
87 GNUNET_FS_pseudonym_destroy (ph); 89 GNUNET_CRYPTO_ecc_key_free (ph);
88} 90}
89 91
90 92
@@ -95,11 +97,11 @@ static int
95test_io () 97test_io ()
96{ 98{
97 int ok; 99 int ok;
98 struct GNUNET_FS_PseudonymIdentifier rid1; 100 struct GNUNET_CRYPTO_EccPublicKey rid1;
99 struct GNUNET_FS_PseudonymIdentifier id2; 101 struct GNUNET_CRYPTO_EccPublicKey id2;
100 struct GNUNET_FS_PseudonymIdentifier rid2; 102 struct GNUNET_CRYPTO_EccPublicKey rid2;
101 struct GNUNET_FS_PseudonymIdentifier fid; 103 struct GNUNET_CRYPTO_EccPublicKey fid;
102 struct GNUNET_FS_PseudonymIdentifier id3; 104 struct GNUNET_CRYPTO_EccPublicKey id3;
103 int old; 105 int old;
104 int newVal; 106 int newVal;
105 struct GNUNET_CONFIGURATION_Handle *cfg; 107 struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -112,12 +114,11 @@ test_io ()
112 int noname_is_a_dup; 114 int noname_is_a_dup;
113 int notiCount, fakenotiCount; 115 int notiCount, fakenotiCount;
114 static char m[1024 * 1024 * 10]; 116 static char m[1024 * 1024 * 10];
115 struct GNUNET_FS_pseudonym_DiscoveryHandle *dh1; 117 struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh1;
116 struct GNUNET_FS_pseudonym_DiscoveryHandle *dh2; 118 struct GNUNET_FS_Pseudonym_DiscoveryHandle *dh2;
117 119
118 memset (m, 'b', sizeof (m)); 120 memset (m, 'b', sizeof (m));
119 m[sizeof (m) - 1] = '\0'; 121 m[sizeof (m) - 1] = '\0';
120
121 GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); 122 GNUNET_log_setup ("test-pseudonym", "WARNING", NULL);
122 ok = GNUNET_YES; 123 ok = GNUNET_YES;
123 (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); 124 (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test");
@@ -178,8 +179,8 @@ test_io ()
178 CHECK (GNUNET_SYSERR == GNUNET_FS_pseudonym_name_to_id (cfg, name1, &rid1)); 179 CHECK (GNUNET_SYSERR == GNUNET_FS_pseudonym_name_to_id (cfg, name1, &rid1));
179 CHECK (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, name2_unique, &rid2)); 180 CHECK (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, name2_unique, &rid2));
180 CHECK (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, name1_unique, &rid1)); 181 CHECK (GNUNET_OK == GNUNET_FS_pseudonym_name_to_id (cfg, name1_unique, &rid1));
181 CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_FS_PseudonymIdentifier))); 182 CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_CRYPTO_EccPublicKey)));
182 CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_FS_PseudonymIdentifier))); 183 CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_CRYPTO_EccPublicKey)));
183 184
184 create_pseu (&fid); 185 create_pseu (&fid);
185 GNUNET_log_skip (1, GNUNET_NO); 186 GNUNET_log_skip (1, GNUNET_NO);
@@ -207,119 +208,12 @@ FAILURE:
207} 208}
208 209
209 210
210/**
211 * Use the given input to sign and check the resulting signature.
212 */
213static void
214test_signature (struct GNUNET_FS_PseudonymHandle *ph,
215 struct GNUNET_FS_PseudonymSignaturePurpose *purpose,
216 struct GNUNET_HashCode *seed,
217 struct GNUNET_HashCode *signing_key,
218 char *bit)
219{
220 struct GNUNET_FS_PseudonymSignature signature;
221 struct GNUNET_FS_PseudonymSignature signature2;
222 struct GNUNET_FS_PseudonymIdentifier pseudonym;
223 struct GNUNET_FS_PseudonymIdentifier verification_key;
224
225 GNUNET_FS_pseudonym_sign (ph, purpose, seed, signing_key, &signature);
226 GNUNET_FS_pseudonym_sign (ph, purpose, seed, signing_key, &signature2);
227 /* with seed, two sigs must be identical, without, they must be different! */
228 if (NULL != seed)
229 GNUNET_break (0 == memcmp (&signature, &signature2, sizeof (signature)));
230 else /* crypto not implemented, thus for now 'break' */
231 GNUNET_break (0 != memcmp (&signature, &signature2, sizeof (signature)));
232 GNUNET_FS_pseudonym_get_identifier (ph, &pseudonym);
233 GNUNET_FS_pseudonym_derive_verification_key (&pseudonym,
234 signing_key,
235 &verification_key);
236 GNUNET_break (GNUNET_OK ==
237 GNUNET_FS_pseudonym_verify (purpose, &signature, &verification_key));
238 /* also check that if the data is changed, the signature no longer matches */
239 (*bit)++;
240 GNUNET_log_skip (1, GNUNET_NO);
241 /* crypto not implemented, thus for now 'break' */
242 GNUNET_break (GNUNET_OK !=
243 GNUNET_FS_pseudonym_verify (purpose, &signature, &verification_key));
244 (*bit)--;
245}
246
247
248/**
249 * Test cryptographic operations for a given private key.
250 *
251 * @param ph private key to test
252 */
253static void
254test_crypto_ops (struct GNUNET_FS_PseudonymHandle *ph)
255{
256 char data[16];
257 struct GNUNET_FS_PseudonymSignaturePurpose *purpose;
258 struct GNUNET_HashCode seed;
259 struct GNUNET_HashCode signing_key;
260
261 memset (data, 42, sizeof (data));
262 purpose = (struct GNUNET_FS_PseudonymSignaturePurpose *) data;
263 purpose->size = htonl (sizeof (data));
264 purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
265 memset (&seed, 41, sizeof (seed));
266 memset (&signing_key, 40, sizeof (signing_key));
267 test_signature (ph, purpose, &seed,
268 &signing_key, &data[sizeof (struct GNUNET_FS_PseudonymSignaturePurpose)]);
269 test_signature (ph, purpose, NULL,
270 &signing_key, &data[sizeof (struct GNUNET_FS_PseudonymSignaturePurpose)]);
271}
272
273
274/**
275 * Test cryptographic operations.
276 */
277static int
278test_crypto ()
279{
280 struct GNUNET_FS_PseudonymHandle *ph;
281 struct GNUNET_FS_PseudonymIdentifier pseudonym;
282 struct GNUNET_FS_PseudonymIdentifier pseudonym2;
283
284 /* check writing to and reading from disk */
285 ph = GNUNET_FS_pseudonym_create ("/tmp/gnunet-pseudonym-test/pseu.dsa");
286 GNUNET_FS_pseudonym_get_identifier (ph, &pseudonym);
287 GNUNET_FS_pseudonym_destroy (ph);
288 ph = GNUNET_FS_pseudonym_create ("/tmp/gnunet-pseudonym-test/pseu.dsa");
289 GNUNET_FS_pseudonym_get_identifier (ph, &pseudonym2);
290 test_crypto_ops (ph);
291 GNUNET_FS_pseudonym_destroy (ph);
292 if (0 != memcmp (&pseudonym, &pseudonym2, sizeof (pseudonym)))
293 return 1;
294
295 /* check in-memory generation */
296 ph = GNUNET_FS_pseudonym_create (NULL);
297 GNUNET_FS_pseudonym_get_identifier (ph, &pseudonym2);
298 if (0 == memcmp (&pseudonym, &pseudonym2, sizeof (pseudonym)))
299 return 1;
300 test_crypto_ops (ph);
301 GNUNET_FS_pseudonym_destroy (ph);
302
303 /* check anonymous pseudonym operations generation */
304 fprintf (stderr, "Checking anonymous ops\n");
305 ph = GNUNET_FS_pseudonym_get_anonymous_pseudonym_handle ();
306 GNUNET_FS_pseudonym_get_identifier (ph, &pseudonym2);
307 if (0 == memcmp (&pseudonym, &pseudonym2, sizeof (pseudonym)))
308 return 1;
309 test_crypto_ops (ph);
310 GNUNET_FS_pseudonym_destroy (ph);
311 return 0;
312}
313
314
315int 211int
316main (int argc, char *argv[]) 212main (int argc, char *argv[])
317{ 213{
318 GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); 214 GNUNET_log_setup ("test-pseudonym", "WARNING", NULL);
319 if (0 != test_io ()) 215 if (0 != test_io ())
320 return 1; 216 return 1;
321 if (0 != test_crypto ())
322 return 1;
323 GNUNET_break (GNUNET_OK == 217 GNUNET_break (GNUNET_OK ==
324 GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); 218 GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"));
325 return 0; 219 return 0;