diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-14 22:31:38 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-15 12:11:19 +0200 |
commit | 25eb1fb2acbe92b418d8643c06107ce0ab2bfb9a (patch) | |
tree | 97ba1f700217697979449cec7528b4eab5e22a22 /src/gnsrecord | |
parent | 96c802b46be51e5c45f34e2de823f787d26c2929 (diff) | |
download | gnunet-25eb1fb2acbe92b418d8643c06107ce0ab2bfb9a.tar.gz gnunet-25eb1fb2acbe92b418d8643c06107ce0ab2bfb9a.zip |
- better wire format for rrblocks
Diffstat (limited to 'src/gnsrecord')
-rw-r--r-- | src/gnsrecord/gnsrecord_crypto.c | 86 | ||||
-rw-r--r-- | src/gnsrecord/gnsrecord_misc.c | 54 | ||||
-rw-r--r-- | src/gnsrecord/gnunet-gnsrecord-tvg.c | 9 |
3 files changed, 104 insertions, 45 deletions
diff --git a/src/gnsrecord/gnsrecord_crypto.c b/src/gnsrecord/gnsrecord_crypto.c index b32b148fe..5c7330998 100644 --- a/src/gnsrecord/gnsrecord_crypto.c +++ b/src/gnsrecord/gnsrecord_crypto.c | |||
@@ -81,16 +81,17 @@ derive_block_aes_key (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
81 | * @return NULL on error (block too large) | 81 | * @return NULL on error (block too large) |
82 | */ | 82 | */ |
83 | static struct GNUNET_GNSRECORD_Block * | 83 | static struct GNUNET_GNSRECORD_Block * |
84 | block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 84 | block_create_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
85 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, | 85 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, |
86 | struct GNUNET_TIME_Absolute expire, | 86 | struct GNUNET_TIME_Absolute expire, |
87 | const char *label, | 87 | const char *label, |
88 | const struct GNUNET_GNSRECORD_Data *rd, | 88 | const struct GNUNET_GNSRECORD_Data *rd, |
89 | unsigned int rd_count) | 89 | unsigned int rd_count) |
90 | { | 90 | { |
91 | ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, | 91 | ssize_t payload_len = GNUNET_GNSRECORD_records_get_size (rd_count, |
92 | rd); | 92 | rd); |
93 | struct GNUNET_GNSRECORD_Block *block; | 93 | struct GNUNET_GNSRECORD_Block *block; |
94 | struct GNUNET_GNSRECORD_EcdsaBlock *ecblock; | ||
94 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; | 95 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dkey; |
95 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 96 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
96 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 97 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
@@ -140,20 +141,21 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
140 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) | 141 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) |
141 | + sizeof(uint32_t) | 142 | + sizeof(uint32_t) |
142 | + payload_len); | 143 | + payload_len); |
143 | block->purpose.size = htonl (sizeof(uint32_t) | 144 | ecblock = &block->ecdsa_block; |
145 | block->type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
146 | ecblock->purpose.size = htonl (sizeof(uint32_t) | ||
144 | + payload_len | 147 | + payload_len |
145 | + sizeof(struct | 148 | + sizeof(struct |
146 | GNUNET_CRYPTO_EccSignaturePurpose) | 149 | GNUNET_CRYPTO_EccSignaturePurpose) |
147 | + sizeof(struct GNUNET_TIME_AbsoluteNBO)); | 150 | + sizeof(struct GNUNET_TIME_AbsoluteNBO)); |
148 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | 151 | ecblock->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); |
149 | block->expiration_time = GNUNET_TIME_absolute_hton (expire); | 152 | ecblock->expiration_time = GNUNET_TIME_absolute_hton (expire); |
150 | /* encrypt and sign */ | 153 | /* encrypt and sign */ |
151 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, | 154 | dkey = GNUNET_CRYPTO_ecdsa_private_key_derive (key, |
152 | label, | 155 | label, |
153 | "gns"); | 156 | "gns"); |
154 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, | 157 | GNUNET_CRYPTO_ecdsa_key_get_public (dkey, |
155 | &block->derived_key.ecdsa_key); | 158 | &ecblock->derived_key); |
156 | block->derived_key.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
157 | derive_block_aes_key (&iv, | 159 | derive_block_aes_key (&iv, |
158 | &skey, | 160 | &skey, |
159 | label, | 161 | label, |
@@ -164,12 +166,12 @@ block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
164 | + sizeof(uint32_t), | 166 | + sizeof(uint32_t), |
165 | &skey, | 167 | &skey, |
166 | &iv, | 168 | &iv, |
167 | &block[1])); | 169 | &ecblock[1])); |
168 | } | 170 | } |
169 | if (GNUNET_OK != | 171 | if (GNUNET_OK != |
170 | GNUNET_CRYPTO_ecdsa_sign_ (dkey, | 172 | GNUNET_CRYPTO_ecdsa_sign_ (dkey, |
171 | &block->purpose, | 173 | &ecblock->purpose, |
172 | &block->signature)) | 174 | &ecblock->signature)) |
173 | { | 175 | { |
174 | GNUNET_break (0); | 176 | GNUNET_break (0); |
175 | GNUNET_free (dkey); | 177 | GNUNET_free (dkey); |
@@ -205,12 +207,12 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
205 | case GNUNET_GNSRECORD_TYPE_PKEY: | 207 | case GNUNET_GNSRECORD_TYPE_PKEY: |
206 | GNUNET_CRYPTO_ecdsa_key_get_public (&key->ecdsa_key, | 208 | GNUNET_CRYPTO_ecdsa_key_get_public (&key->ecdsa_key, |
207 | &pkey); | 209 | &pkey); |
208 | return block_create (&key->ecdsa_key, | 210 | return block_create_ecdsa (&key->ecdsa_key, |
209 | &pkey, | 211 | &pkey, |
210 | expire, | 212 | expire, |
211 | label, | 213 | label, |
212 | rd, | 214 | rd, |
213 | rd_count); | 215 | rd_count); |
214 | default: | 216 | default: |
215 | GNUNET_assert (0); | 217 | GNUNET_assert (0); |
216 | } | 218 | } |
@@ -258,7 +260,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *pkey, | |||
258 | 260 | ||
259 | if (GNUNET_IDENTITY_TYPE_ECDSA != ntohl (pkey->type)) | 261 | if (GNUNET_IDENTITY_TYPE_ECDSA != ntohl (pkey->type)) |
260 | { | 262 | { |
261 | return NULL; //FIXME | 263 | return NULL; // FIXME |
262 | } | 264 | } |
263 | key = &pkey->ecdsa_key; | 265 | key = &pkey->ecdsa_key; |
264 | #define CSIZE 64 | 266 | #define CSIZE 64 |
@@ -276,12 +278,12 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *pkey, | |||
276 | &line->pkey); | 278 | &line->pkey); |
277 | } | 279 | } |
278 | #undef CSIZE | 280 | #undef CSIZE |
279 | return block_create (key, | 281 | return block_create_ecdsa (key, |
280 | &line->pkey, | 282 | &line->pkey, |
281 | expire, | 283 | expire, |
282 | label, | 284 | label, |
283 | rd, | 285 | rd, |
284 | rd_count); | 286 | rd_count); |
285 | } | 287 | } |
286 | 288 | ||
287 | 289 | ||
@@ -296,28 +298,30 @@ enum GNUNET_GenericReturnValue | |||
296 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block) | 298 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block) |
297 | { | 299 | { |
298 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key; | 300 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key; |
301 | const struct GNUNET_GNSRECORD_EcdsaBlock *ecblock; | ||
299 | 302 | ||
300 | if (GNUNET_GNSRECORD_TYPE_PKEY != ntohl (block->derived_key.type)) | 303 | if (GNUNET_GNSRECORD_TYPE_PKEY != ntohl (block->type)) |
301 | { | 304 | { |
302 | GNUNET_break (0); | 305 | GNUNET_break (0); |
303 | return GNUNET_NO; | 306 | return GNUNET_NO; |
304 | } | 307 | } |
305 | key = &block->derived_key.ecdsa_key; | 308 | ecblock = &block->ecdsa_block; |
309 | key = &ecblock->derived_key; | ||
306 | 310 | ||
307 | return GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, | 311 | return GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, |
308 | &block->purpose, | 312 | &ecblock->purpose, |
309 | &block->signature, | 313 | &ecblock->signature, |
310 | key); | 314 | key); |
311 | } | 315 | } |
312 | 316 | ||
313 | 317 | ||
314 | enum GNUNET_GenericReturnValue | 318 | enum GNUNET_GenericReturnValue |
315 | block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | 319 | block_decrypt_ecdsa (const struct GNUNET_GNSRECORD_EcdsaBlock *block, |
316 | const struct | 320 | const struct |
317 | GNUNET_CRYPTO_EcdsaPublicKey *zone_key, | 321 | GNUNET_CRYPTO_EcdsaPublicKey *zone_key, |
318 | const char *label, | 322 | const char *label, |
319 | GNUNET_GNSRECORD_RecordCallback proc, | 323 | GNUNET_GNSRECORD_RecordCallback proc, |
320 | void *proc_cls) | 324 | void *proc_cls) |
321 | { | 325 | { |
322 | size_t payload_len = ntohl (block->purpose.size) | 326 | size_t payload_len = ntohl (block->purpose.size) |
323 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 327 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
@@ -465,12 +469,12 @@ GNUNET_GNSRECORD_block_decrypt (const struct GNUNET_GNSRECORD_Block *block, | |||
465 | } | 469 | } |
466 | key = &zone_key->ecdsa_key; | 470 | key = &zone_key->ecdsa_key; |
467 | 471 | ||
468 | return block_decrypt (block, key, label, proc, proc_cls); | 472 | return block_decrypt_ecdsa (&block->ecdsa_block, |
473 | key, label, proc, proc_cls); | ||
469 | 474 | ||
470 | } | 475 | } |
471 | 476 | ||
472 | 477 | ||
473 | |||
474 | /** | 478 | /** |
475 | * Calculate the DHT query for a given @a label in a given @a zone. | 479 | * Calculate the DHT query for a given @a label in a given @a zone. |
476 | * | 480 | * |
@@ -524,8 +528,8 @@ GNUNET_GNSRECORD_query_from_public_key (const struct | |||
524 | label, | 528 | label, |
525 | "gns", | 529 | "gns", |
526 | &pd.ecdsa_key); | 530 | &pd.ecdsa_key); |
527 | GNUNET_CRYPTO_hash (&pd, | 531 | GNUNET_CRYPTO_hash (&pd.ecdsa_key, |
528 | sizeof(pd), | 532 | sizeof (pd.ecdsa_key), |
529 | query); | 533 | query); |
530 | break; | 534 | break; |
531 | default: | 535 | default: |
diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 8b590e35f..baf13e963 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c | |||
@@ -272,4 +272,58 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | |||
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | size_t | ||
276 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block) | ||
277 | { | ||
278 | switch (ntohl (block->type)) | ||
279 | { | ||
280 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
281 | return sizeof (uint32_t) /* zone type */ | ||
282 | + sizeof (block->ecdsa_block) /* EcdsaBlock */ | ||
283 | + ntohl (block->ecdsa_block.purpose.size) /* Length of signed data */ | ||
284 | - sizeof (block->ecdsa_block.purpose); /* Purpose already in EcdsaBlock */ | ||
285 | break; | ||
286 | default: | ||
287 | return 0; | ||
288 | } | ||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | |||
293 | struct GNUNET_TIME_Absolute | ||
294 | GNUNET_GNSRECORD_block_get_expiration (const struct | ||
295 | GNUNET_GNSRECORD_Block *block) | ||
296 | { | ||
297 | |||
298 | switch (ntohl (block->type)) | ||
299 | { | ||
300 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
301 | return GNUNET_TIME_absolute_ntoh (block->ecdsa_block.expiration_time); | ||
302 | default: | ||
303 | return GNUNET_TIME_absolute_get_zero_ (); | ||
304 | } | ||
305 | return GNUNET_TIME_absolute_get_zero_ (); | ||
306 | |||
307 | } | ||
308 | |||
309 | |||
310 | enum GNUNET_GenericReturnValue | ||
311 | GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | ||
312 | struct GNUNET_HashCode *query) | ||
313 | { | ||
314 | switch (ntohl (block->type)) | ||
315 | { | ||
316 | case GNUNET_GNSRECORD_TYPE_PKEY: | ||
317 | GNUNET_CRYPTO_hash (&block->ecdsa_block.derived_key, | ||
318 | sizeof (block->ecdsa_block.derived_key), | ||
319 | query); | ||
320 | return GNUNET_OK; | ||
321 | default: | ||
322 | return GNUNET_SYSERR; | ||
323 | } | ||
324 | return GNUNET_SYSERR; | ||
325 | |||
326 | } | ||
327 | |||
328 | |||
275 | /* end of gnsrecord_misc.c */ | 329 | /* end of gnsrecord_misc.c */ |
diff --git a/src/gnsrecord/gnunet-gnsrecord-tvg.c b/src/gnsrecord/gnunet-gnsrecord-tvg.c index 31f077722..7c28a18d0 100644 --- a/src/gnsrecord/gnunet-gnsrecord-tvg.c +++ b/src/gnsrecord/gnunet-gnsrecord-tvg.c | |||
@@ -149,19 +149,20 @@ run (void *cls, | |||
149 | TEST_RECORD_LABEL, | 149 | TEST_RECORD_LABEL, |
150 | rd, | 150 | rd, |
151 | TEST_RRCOUNT); | 151 | TEST_RRCOUNT); |
152 | size_t bdata_size = ntohl (rrblock->purpose.size) | 152 | size_t bdata_size = ntohl (rrblock->ecdsa_block.purpose.size) |
153 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 153 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) |
154 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | 154 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); |
155 | size_t rrblock_size = ntohl (rrblock->purpose.size) | 155 | size_t ecblock_size = ntohl (rrblock->ecdsa_block.purpose.size) |
156 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 156 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) |
157 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 157 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); |
158 | size_t block_size = ecblock_size + sizeof (uint32_t); | ||
158 | 159 | ||
159 | bdata = (char*) &rrblock[1]; | 160 | bdata = (char*) &(&rrblock->ecdsa_block)[1]; |
160 | fprintf (stdout, "BDATA:\n"); | 161 | fprintf (stdout, "BDATA:\n"); |
161 | print_bytes (bdata, bdata_size, 8); | 162 | print_bytes (bdata, bdata_size, 8); |
162 | fprintf (stdout, "\n"); | 163 | fprintf (stdout, "\n"); |
163 | fprintf (stdout, "RRBLOCK:\n"); | 164 | fprintf (stdout, "RRBLOCK:\n"); |
164 | print_bytes (rrblock, rrblock_size, 8); | 165 | print_bytes (rrblock, block_size, 8); |
165 | fprintf (stdout, "\n"); | 166 | fprintf (stdout, "\n"); |
166 | 167 | ||
167 | } | 168 | } |