diff options
Diffstat (limited to 'src/gnsrecord/gnunet-gnsrecord-tvg.c')
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 60 |
1 files changed, 49 insertions, 11 deletions
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index bdb995a50..9e3dea921 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -96,7 +96,12 @@ static void | |||
96 | run_pkey (void) | 96 | run_pkey (void) |
97 | { | 97 | { |
98 | struct GNUNET_GNSRECORD_Data rd[2]; | 98 | struct GNUNET_GNSRECORD_Data rd[2]; |
99 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); | 99 | struct GNUNET_TIME_Absolute expire; |
100 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | ||
101 | struct GNUNET_TIME_Absolute exp1; | ||
102 | struct GNUNET_TIME_Absolute exp2; | ||
103 | struct GNUNET_TIME_Relative delta1; | ||
104 | struct GNUNET_TIME_Relative delta2; | ||
100 | struct GNUNET_GNSRECORD_Block *rrblock; | 105 | struct GNUNET_GNSRECORD_Block *rrblock; |
101 | char *bdata; | 106 | char *bdata; |
102 | struct GNUNET_IDENTITY_PrivateKey id_priv; | 107 | struct GNUNET_IDENTITY_PrivateKey id_priv; |
@@ -110,13 +115,23 @@ run_pkey (void) | |||
110 | uint32_t rd_count_nbo; | 115 | uint32_t rd_count_nbo; |
111 | char ztld[128]; | 116 | char ztld[128]; |
112 | 117 | ||
118 | /* | ||
119 | * Make two different expiration times | ||
120 | */ | ||
121 | delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
122 | 420); //420 years | ||
123 | delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
124 | 777); //777 years | ||
125 | exp1 = GNUNET_TIME_absolute_add (now, delta1); | ||
126 | exp2 = GNUNET_TIME_absolute_add (now, delta2); | ||
127 | |||
113 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | 128 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
114 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | 129 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); |
115 | GNUNET_IDENTITY_key_get_public (&id_priv, | 130 | GNUNET_IDENTITY_key_get_public (&id_priv, |
116 | &id_pub); | 131 | &id_pub); |
117 | fprintf (stdout, | 132 | fprintf (stdout, |
118 | "Zone private key (d, big-endian):\n"); | 133 | "Zone private key (d, big-endian):\n"); |
119 | print_bytes_ (&id_priv.ecdsa_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8, 1); | 134 | print_bytes (&id_priv.ecdsa_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 8); |
120 | fprintf (stdout, "\n"); | 135 | fprintf (stdout, "\n"); |
121 | fprintf (stdout, "Zone identifier (ztype|zkey):\n"); | 136 | fprintf (stdout, "Zone identifier (ztype|zkey):\n"); |
122 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); | 137 | print_bytes (&id_pub, GNUNET_IDENTITY_key_get_length (&id_pub), 8); |
@@ -140,20 +155,20 @@ run_pkey (void) | |||
140 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); | 155 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); |
141 | rd[0].data = data; | 156 | rd[0].data = data; |
142 | rd[0].data_size = data_size; | 157 | rd[0].data_size = data_size; |
143 | rd[0].expiration_time = exp_abs.abs_value_us; | 158 | rd[0].expiration_time = exp1.abs_value_us; |
144 | rd[0].record_type = GNUNET_DNSPARSER_TYPE_A; | 159 | rd[0].record_type = GNUNET_DNSPARSER_TYPE_A; |
145 | fprintf (stdout, "Record #0\n"); | 160 | fprintf (stdout, "Record #0\n"); |
146 | print_record (&rd[0]); | 161 | print_record (&rd[0]); |
147 | 162 | ||
148 | rd[1].data = &pkey_data; | 163 | rd[1].data = &pkey_data; |
149 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); | 164 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); |
150 | rd[1].expiration_time = exp_abs.abs_value_us; | 165 | rd[1].expiration_time = exp2.abs_value_us; |
151 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_PKEY; | 166 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_PKEY; |
152 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; | 167 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; |
153 | fprintf (stdout, "Record #1\n"); | 168 | fprintf (stdout, "Record #1\n"); |
154 | print_record (&rd[1]); | 169 | print_record (&rd[1]); |
155 | 170 | ||
156 | rdata_size = GNUNET_GNSRECORD_records_get_size (2, | 171 | rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, |
157 | rd); | 172 | rd); |
158 | rdata = GNUNET_malloc (rdata_size); | 173 | rdata = GNUNET_malloc (rdata_size); |
159 | rd_count_nbo = htonl(2); | 174 | rd_count_nbo = htonl(2); |
@@ -167,8 +182,9 @@ run_pkey (void) | |||
167 | fprintf (stdout, "RDATA:\n"); | 182 | fprintf (stdout, "RDATA:\n"); |
168 | print_bytes (rdata, rdata_size, 8); | 183 | print_bytes (rdata, rdata_size, 8); |
169 | fprintf (stdout, "\n"); | 184 | fprintf (stdout, "\n"); |
185 | expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, rd); | ||
170 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, | 186 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, |
171 | exp_abs, | 187 | expire, |
172 | TEST_RECORD_LABEL, | 188 | TEST_RECORD_LABEL, |
173 | rd, | 189 | rd, |
174 | TEST_RRCOUNT); | 190 | TEST_RRCOUNT); |
@@ -203,7 +219,12 @@ static void | |||
203 | run_edkey (void) | 219 | run_edkey (void) |
204 | { | 220 | { |
205 | struct GNUNET_GNSRECORD_Data rd[2]; | 221 | struct GNUNET_GNSRECORD_Data rd[2]; |
206 | struct GNUNET_TIME_Absolute exp_abs = GNUNET_TIME_absolute_get (); | 222 | struct GNUNET_TIME_Absolute expire; |
223 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | ||
224 | struct GNUNET_TIME_Absolute exp1; | ||
225 | struct GNUNET_TIME_Absolute exp2; | ||
226 | struct GNUNET_TIME_Relative delta1; | ||
227 | struct GNUNET_TIME_Relative delta2; | ||
207 | struct GNUNET_GNSRECORD_Block *rrblock; | 228 | struct GNUNET_GNSRECORD_Block *rrblock; |
208 | char *bdata; | 229 | char *bdata; |
209 | struct GNUNET_IDENTITY_PrivateKey id_priv; | 230 | struct GNUNET_IDENTITY_PrivateKey id_priv; |
@@ -217,6 +238,21 @@ run_edkey (void) | |||
217 | uint32_t rd_count_nbo; | 238 | uint32_t rd_count_nbo; |
218 | char ztld[128]; | 239 | char ztld[128]; |
219 | 240 | ||
241 | /* | ||
242 | * Make two different expiration times | ||
243 | */ | ||
244 | delta1 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
245 | 420); //420 years | ||
246 | delta2 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_YEARS, | ||
247 | 777); //777 years | ||
248 | exp1 = GNUNET_TIME_absolute_add (now, delta1); | ||
249 | exp2 = GNUNET_TIME_absolute_add (now, delta2); | ||
250 | |||
251 | id_priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
252 | GNUNET_CRYPTO_ecdsa_key_create (&id_priv.ecdsa_key); | ||
253 | GNUNET_IDENTITY_key_get_public (&id_priv, | ||
254 | &id_pub); | ||
255 | |||
220 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); | 256 | id_priv.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); |
221 | GNUNET_CRYPTO_eddsa_key_create (&id_priv.eddsa_key); | 257 | GNUNET_CRYPTO_eddsa_key_create (&id_priv.eddsa_key); |
222 | GNUNET_IDENTITY_key_get_public (&id_priv, | 258 | GNUNET_IDENTITY_key_get_public (&id_priv, |
@@ -247,21 +283,23 @@ run_edkey (void) | |||
247 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); | 283 | GNUNET_DNSPARSER_TYPE_A, TEST_RECORD_A, &data, &data_size)); |
248 | rd[0].data = data; | 284 | rd[0].data = data; |
249 | rd[0].data_size = data_size; | 285 | rd[0].data_size = data_size; |
250 | rd[0].expiration_time = exp_abs.abs_value_us; | 286 | rd[0].expiration_time = exp1.abs_value_us; |
251 | rd[0].record_type = GNUNET_DNSPARSER_TYPE_A; | 287 | rd[0].record_type = GNUNET_DNSPARSER_TYPE_A; |
252 | fprintf (stdout, "Record #0\n"); | 288 | fprintf (stdout, "Record #0\n"); |
253 | print_record (&rd[0]); | 289 | print_record (&rd[0]); |
254 | 290 | ||
255 | rd[1].data = &pkey_data; | 291 | rd[1].data = &pkey_data; |
256 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); | 292 | rd[1].data_size = sizeof (struct GNUNET_IDENTITY_PublicKey); |
257 | rd[1].expiration_time = exp_abs.abs_value_us; | 293 | rd[1].expiration_time = exp2.abs_value_us; |
258 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_EDKEY; | 294 | rd[1].record_type = GNUNET_GNSRECORD_TYPE_EDKEY; |
259 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; | 295 | rd[1].flags = GNUNET_GNSRECORD_RF_PRIVATE; |
260 | fprintf (stdout, "Record #1\n"); | 296 | fprintf (stdout, "Record #1\n"); |
261 | print_record (&rd[1]); | 297 | print_record (&rd[1]); |
262 | 298 | ||
263 | rdata_size = GNUNET_GNSRECORD_records_get_size (2, | 299 | rdata_size = GNUNET_GNSRECORD_records_get_size (TEST_RRCOUNT, |
264 | rd); | 300 | rd); |
301 | expire = GNUNET_GNSRECORD_record_get_expiration_time (TEST_RRCOUNT, | ||
302 | rd); | ||
265 | rdata = GNUNET_malloc (sizeof (uint32_t) + rdata_size); | 303 | rdata = GNUNET_malloc (sizeof (uint32_t) + rdata_size); |
266 | rd_count_nbo = htonl(2); | 304 | rd_count_nbo = htonl(2); |
267 | GNUNET_memcpy (rdata, | 305 | GNUNET_memcpy (rdata, |
@@ -275,7 +313,7 @@ run_edkey (void) | |||
275 | print_bytes (rdata, rdata_size, 8); | 313 | print_bytes (rdata, rdata_size, 8); |
276 | fprintf (stdout, "\n"); | 314 | fprintf (stdout, "\n"); |
277 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, | 315 | rrblock = GNUNET_GNSRECORD_block_create (&id_priv, |
278 | exp_abs, | 316 | expire, |
279 | TEST_RECORD_LABEL, | 317 | TEST_RECORD_LABEL, |
280 | rd, | 318 | rd, |
281 | TEST_RRCOUNT); | 319 | TEST_RRCOUNT); |