diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-02-01 13:05:58 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-02-01 13:05:58 +0100 |
commit | 8e8f974d798b20e298de6583e8ad0b07ef9b0992 (patch) | |
tree | f767ac182b6e2111cb1756f1f572d17da4a1b14a | |
parent | 13a46a8f0136d98d52a48b642f2e0d78892d2c80 (diff) | |
download | gnunet-8e8f974d798b20e298de6583e8ad0b07ef9b0992.tar.gz gnunet-8e8f974d798b20e298de6583e8ad0b07ef9b0992.zip |
-make tvs deterministic
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index 96159d4b3..91c6608cd 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -37,6 +37,31 @@ | |||
37 | #define TEST_RECORD_A "1.2.3.4" | 37 | #define TEST_RECORD_A "1.2.3.4" |
38 | #define TEST_RRCOUNT 2 | 38 | #define TEST_RRCOUNT 2 |
39 | 39 | ||
40 | static char *d_pkey = | ||
41 | "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98"; | ||
42 | |||
43 | static char *d_edkey = | ||
44 | "5af7020ee19160328832352bbc6a68a8d71a7cbe1b929969a7c66d415a0d8f65"; | ||
45 | |||
46 | int parsehex(char *src, char *dst, size_t dstlen, int invert) | ||
47 | { | ||
48 | char *line = src; | ||
49 | char *data = line; | ||
50 | int off; | ||
51 | int read_byte; | ||
52 | int data_len = 0; | ||
53 | |||
54 | while (sscanf(data, " %02x%n", &read_byte, &off) == 1) { | ||
55 | if (invert) | ||
56 | dst[dstlen - 1 - data_len++] = read_byte; | ||
57 | else | ||
58 | dst[data_len++] = read_byte; | ||
59 | data += off; | ||
60 | } | ||
61 | return data_len; | ||
62 | } | ||
63 | |||
64 | |||
40 | static void | 65 | static void |
41 | print_bytes_ (void *buf, | 66 | print_bytes_ (void *buf, |
42 | size_t buf_len, | 67 | size_t buf_len, |
@@ -122,15 +147,18 @@ run_pkey (void) | |||
122 | /* | 147 | /* |
123 | * Make two different expiration times | 148 | * Make two different expiration times |
124 | */ | 149 | */ |
125 | delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | 150 | GNUNET_STRINGS_fancy_time_to_absolute ("2048-01-23 10:51:34", |
126 | 420); // 420 years | 151 | &exp1); |
127 | delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | 152 | GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01", |
128 | 777); // 777 years | 153 | &exp2); |
129 | exp1 = GNUNET_TIME_absolute_add (now, delta1); | 154 | |
130 | exp2 = GNUNET_TIME_absolute_add (now, delta2); | ||
131 | 155 | ||
132 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | 156 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
133 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | 157 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
158 | parsehex(d_pkey, | ||
159 | (char*)&id_priv.ecdsa_key, | ||
160 | sizeof (id_priv.ecdsa_key), 1); | ||
161 | |||
134 | GNUNET_IDENTITY_key_get_public (&id_priv, | 162 | GNUNET_IDENTITY_key_get_public (&id_priv, |
135 | &id_pub); | 163 | &id_pub); |
136 | fprintf (stdout, | 164 | fprintf (stdout, |
@@ -165,10 +193,10 @@ run_pkey (void) | |||
165 | fprintf (stdout, "Record #0\n"); | 193 | fprintf (stdout, "Record #0\n"); |
166 | print_record (&rd[0]); | 194 | print_record (&rd[0]); |
167 | 195 | ||
168 | rd[1].data = &pkey_data; | 196 | rd[1].data = "Some nick"; |
169 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); | 197 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); |
170 | rd[1].expiration_time = exp2.abs_value_us; | 198 | rd[1].expiration_time = exp2.abs_value_us; |
171 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_PKEY; | 199 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_NICK; |
172 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; | 200 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; |
173 | fprintf (stdout, "Record #1\n"); | 201 | fprintf (stdout, "Record #1\n"); |
174 | print_record (&rd[1]); | 202 | print_record (&rd[1]); |
@@ -269,12 +297,10 @@ run_edkey (void) | |||
269 | /* | 297 | /* |
270 | * Make two different expiration times | 298 | * Make two different expiration times |
271 | */ | 299 | */ |
272 | delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | 300 | GNUNET_STRINGS_fancy_time_to_absolute ("%2048-01-23 10:51:34", |
273 | 420); // 420 years | 301 | &exp1); |
274 | delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | 302 | GNUNET_STRINGS_fancy_time_to_absolute ("3540-05-22 07:55:01", |
275 | 777); // 777 years | 303 | &exp2); |
276 | exp1 = GNUNET_TIME_absolute_add (now, delta1); | ||
277 | exp2 = GNUNET_TIME_absolute_add (now, delta2); | ||
278 | 304 | ||
279 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | 305 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
280 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | 306 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
@@ -283,6 +309,9 @@ run_edkey (void) | |||
283 | 309 | ||
284 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); | 310 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); |
285 | GNUNET_CRYPTO_eddsa_key_create (&id_priv.eddsa_key); | 311 | GNUNET_CRYPTO_eddsa_key_create (&id_priv.eddsa_key); |
312 | parsehex(d_edkey, | ||
313 | (char*)&id_priv.eddsa_key, | ||
314 | sizeof (id_priv.eddsa_key), 0); | ||
286 | GNUNET_IDENTITY_key_get_public (&id_priv, | 315 | GNUNET_IDENTITY_key_get_public (&id_priv, |
287 | &id_pub); | 316 | &id_pub); |
288 | fprintf (stdout, | 317 | fprintf (stdout, |
@@ -317,10 +346,10 @@ run_edkey (void) | |||
317 | fprintf (stdout, "Record #0\n"); | 346 | fprintf (stdout, "Record #0\n"); |
318 | print_record (&rd[0]); | 347 | print_record (&rd[0]); |
319 | 348 | ||
320 | rd[1].data = &pkey_data; | 349 | rd[1].data = "My Nick"; |
321 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); | 350 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); |
322 | rd[1].expiration_time = exp2.abs_value_us; | 351 | rd[1].expiration_time = exp2.abs_value_us; |
323 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_EDKEY; | 352 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_NICK; |
324 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; | 353 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; |
325 | fprintf (stdout, "Record #1\n"); | 354 | fprintf (stdout, "Record #1\n"); |
326 | print_record (&rd[1]); | 355 | print_record (&rd[1]); |