diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/plugin_block_gns.c | 5 | ||||
-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 | ||||
-rw-r--r-- | src/include/gnunet_gnsrecord_lib.h | 47 | ||||
-rw-r--r-- | src/namecache/gnunet-service-namecache.c | 47 | ||||
-rw-r--r-- | src/namecache/namecache_api.c | 23 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_flat.c | 16 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_postgres.c | 24 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_sqlite.c | 16 | ||||
-rw-r--r-- | src/namestore/test_plugin_namestore.c | 6 |
11 files changed, 184 insertions, 149 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index aabedcaac..64390c5a0 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -145,10 +145,7 @@ block_plugin_gns_evaluate (void *cls, | |||
145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
146 | } | 146 | } |
147 | block = reply_block; | 147 | block = reply_block; |
148 | if (ntohl (block->purpose.size) + sizeof(struct | 148 | if (ntohl (block->purpose.size) >= reply_block_size) |
149 | GNUNET_CRYPTO_EcdsaSignature) | ||
150 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != | ||
151 | reply_block_size) | ||
152 | { | 149 | { |
153 | GNUNET_break_op (0); | 150 | GNUNET_break_op (0); |
154 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
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 | } |
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 6124b2925..20d8e2517 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -263,21 +263,20 @@ struct GNUNET_GNSRECORD_PlaceData | |||
263 | /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */ | 263 | /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */ |
264 | }; | 264 | }; |
265 | 265 | ||
266 | |||
267 | /** | 266 | /** |
268 | * Information we have in an encrypted block with record data (i.e. in the DHT). | 267 | * Information we have in an encrypted block with record data (i.e. in the DHT). |
269 | */ | 268 | */ |
270 | struct GNUNET_GNSRECORD_Block | 269 | struct GNUNET_GNSRECORD_EcdsaBlock |
271 | { | 270 | { |
272 | /** | 271 | /** |
273 | * Signature of the block. | 272 | * Derived key used for signing; hash of this is the query. |
274 | */ | 273 | */ |
275 | struct GNUNET_CRYPTO_EcdsaSignature signature; | 274 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; |
276 | 275 | ||
277 | /** | 276 | /** |
278 | * Derived key used for signing; hash of this is the query. | 277 | * Signature of the block. |
279 | */ | 278 | */ |
280 | struct GNUNET_IDENTITY_PublicKey derived_key; | 279 | struct GNUNET_CRYPTO_EcdsaSignature signature; |
281 | 280 | ||
282 | /** | 281 | /** |
283 | * Number of bytes signed; also specifies the number of bytes | 282 | * Number of bytes signed; also specifies the number of bytes |
@@ -293,6 +292,17 @@ struct GNUNET_GNSRECORD_Block | |||
293 | /* followed by encrypted data */ | 292 | /* followed by encrypted data */ |
294 | }; | 293 | }; |
295 | 294 | ||
295 | struct GNUNET_GNSRECORD_Block | ||
296 | { | ||
297 | uint32_t type; | ||
298 | |||
299 | union | ||
300 | { | ||
301 | struct GNUNET_GNSRECORD_EcdsaBlock ecdsa_block; | ||
302 | //struct GNUNET_GNSRECORD_EddsaBlock eddsa_block; | ||
303 | }; | ||
304 | }; | ||
305 | |||
296 | 306 | ||
297 | /** | 307 | /** |
298 | * Record type used to box up SRV and TLSA records. For example, a | 308 | * Record type used to box up SRV and TLSA records. For example, a |
@@ -638,6 +648,31 @@ GNUNET_GNSRECORD_record_get_expiration_time ( | |||
638 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); | 648 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd); |
639 | 649 | ||
640 | 650 | ||
651 | /** | ||
652 | * Returns the length of this block in bytes. | ||
653 | * Block length strongly depends on the zone type. | ||
654 | * | ||
655 | * @param block the block. | ||
656 | * @return the length of this block in bytes | ||
657 | */ | ||
658 | size_t | ||
659 | GNUNET_GNSRECORD_block_get_size (const struct GNUNET_GNSRECORD_Block *block); | ||
660 | |||
661 | /** | ||
662 | * Returns the expiration of a block | ||
663 | */ | ||
664 | struct GNUNET_TIME_Absolute | ||
665 | GNUNET_GNSRECORD_block_get_expiration (const struct GNUNET_GNSRECORD_Block *block); | ||
666 | |||
667 | |||
668 | /** | ||
669 | * Builds the query from a block | ||
670 | */ | ||
671 | enum GNUNET_GenericReturnValue | ||
672 | GNUNET_GNSRECORD_query_from_block (const struct GNUNET_GNSRECORD_Block *block, | ||
673 | struct GNUNET_HashCode *query); | ||
674 | |||
675 | |||
641 | #if 0 /* keep Emacsens' auto-indent happy */ | 676 | #if 0 /* keep Emacsens' auto-indent happy */ |
642 | { | 677 | { |
643 | #endif | 678 | #endif |
diff --git a/src/namecache/gnunet-service-namecache.c b/src/namecache/gnunet-service-namecache.c index 7cf216ce3..07bf30de9 100644 --- a/src/namecache/gnunet-service-namecache.c +++ b/src/namecache/gnunet-service-namecache.c | |||
@@ -184,40 +184,24 @@ handle_lookup_block_it (void *cls, | |||
184 | struct LookupBlockContext *lnc = cls; | 184 | struct LookupBlockContext *lnc = cls; |
185 | struct GNUNET_MQ_Envelope *env; | 185 | struct GNUNET_MQ_Envelope *env; |
186 | struct LookupBlockResponseMessage *r; | 186 | struct LookupBlockResponseMessage *r; |
187 | size_t esize; | ||
188 | size_t bsize; | 187 | size_t bsize; |
189 | 188 | ||
190 | bsize = ntohl (block->purpose.size); | 189 | bsize = GNUNET_GNSRECORD_block_get_size (block); |
191 | if (bsize < | ||
192 | (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(struct | ||
193 | GNUNET_TIME_AbsoluteNBO))) | ||
194 | { | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
196 | "Malformed block."); | ||
197 | lnc->status = GNUNET_SYSERR; | ||
198 | return; | ||
199 | } | ||
200 | esize = ntohl (block->purpose.size) | ||
201 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
202 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
203 | env = GNUNET_MQ_msg_extra (r, | 190 | env = GNUNET_MQ_msg_extra (r, |
204 | esize, | 191 | bsize, |
205 | GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE); | 192 | GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE); |
206 | r->gns_header.r_id = htonl (lnc->request_id); | 193 | r->gns_header.r_id = htonl (lnc->request_id); |
207 | r->expire = block->expiration_time; | ||
208 | r->signature = block->signature; | ||
209 | r->derived_key = block->derived_key; | ||
210 | GNUNET_memcpy (&r[1], | 194 | GNUNET_memcpy (&r[1], |
211 | &block[1], | 195 | block, |
212 | esize); | 196 | bsize); |
213 | GNUNET_STATISTICS_update (statistics, | 197 | GNUNET_STATISTICS_update (statistics, |
214 | "blocks found in cache", | 198 | "blocks found in cache", |
215 | 1, | 199 | 1, |
216 | GNUNET_NO); | 200 | GNUNET_NO); |
201 | r->expire = GNUNET_TIME_absolute_hton ( | ||
202 | GNUNET_GNSRECORD_block_get_expiration (block)); | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
218 | "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message with expiration time %s\n", | 204 | "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n"); |
219 | GNUNET_STRINGS_absolute_time_to_string ( | ||
220 | GNUNET_TIME_absolute_ntoh (r->expire))); | ||
221 | GNUNET_MQ_send (lnc->nc->mq, | 205 | GNUNET_MQ_send (lnc->nc->mq, |
222 | env); | 206 | env); |
223 | } | 207 | } |
@@ -314,20 +298,11 @@ handle_block_cache (void *cls, | |||
314 | GNUNET_NO); | 298 | GNUNET_NO); |
315 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct | 299 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct |
316 | BlockCacheMessage); | 300 | BlockCacheMessage); |
317 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) + esize); | 301 | block = GNUNET_malloc (esize); |
318 | block->signature = rp_msg->signature; | 302 | memcpy (block, &rp_msg[1], esize); |
319 | block->derived_key = rp_msg->derived_key; | ||
320 | block->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
321 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
322 | + esize); | ||
323 | block->expiration_time = rp_msg->expire; | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Received NAMECACHE_BLOCK_CACHE message with expiration time %s\n", | 304 | "Received NAMECACHE_BLOCK_CACHE message with type %u\n", |
326 | GNUNET_STRINGS_absolute_time_to_string ( | 305 | htonl (block->type)); |
327 | GNUNET_TIME_absolute_ntoh (block->expiration_time))); | ||
328 | GNUNET_memcpy (&block[1], | ||
329 | &rp_msg[1], | ||
330 | esize); | ||
331 | res = GSN_database->cache_block (GSN_database->cls, | 306 | res = GSN_database->cache_block (GSN_database->cls, |
332 | block); | 307 | block); |
333 | GNUNET_free (block); | 308 | GNUNET_free (block); |
diff --git a/src/namecache/namecache_api.c b/src/namecache/namecache_api.c index 0c904c9ed..fdbf142a7 100644 --- a/src/namecache/namecache_api.c +++ b/src/namecache/namecache_api.c | |||
@@ -225,19 +225,11 @@ handle_lookup_block_response (void *cls, | |||
225 | size = ntohs (msg->gns_header.header.size) | 225 | size = ntohs (msg->gns_header.header.size) |
226 | - sizeof(struct LookupBlockResponseMessage); | 226 | - sizeof(struct LookupBlockResponseMessage); |
227 | { | 227 | { |
228 | char buf[size + sizeof(struct GNUNET_GNSRECORD_Block)] GNUNET_ALIGN; | 228 | char buf[size] GNUNET_ALIGN; |
229 | struct GNUNET_GNSRECORD_Block *block; | 229 | struct GNUNET_GNSRECORD_Block *block; |
230 | 230 | ||
231 | block = (struct GNUNET_GNSRECORD_Block *) buf; | 231 | block = (struct GNUNET_GNSRECORD_Block *) buf; |
232 | block->signature = msg->signature; | 232 | GNUNET_memcpy (block, |
233 | block->derived_key = msg->derived_key; | ||
234 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
235 | block->purpose.size = htonl (size | ||
236 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
237 | + sizeof(struct | ||
238 | GNUNET_CRYPTO_EccSignaturePurpose)); | ||
239 | block->expiration_time = msg->expire; | ||
240 | GNUNET_memcpy (&block[1], | ||
241 | &msg[1], | 233 | &msg[1], |
242 | size); | 234 | size); |
243 | if (GNUNET_OK != | 235 | if (GNUNET_OK != |
@@ -483,11 +475,7 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
483 | 475 | ||
484 | if (NULL == h->mq) | 476 | if (NULL == h->mq) |
485 | return NULL; | 477 | return NULL; |
486 | blen = ntohl (block->purpose.size); | 478 | blen = GNUNET_GNSRECORD_block_get_size (block); |
487 | GNUNET_assert (blen > (sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
488 | + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))); | ||
489 | blen -= (sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
490 | + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
491 | rid = get_op_id (h); | 479 | rid = get_op_id (h); |
492 | qe = GNUNET_new (struct GNUNET_NAMECACHE_QueueEntry); | 480 | qe = GNUNET_new (struct GNUNET_NAMECACHE_QueueEntry); |
493 | qe->nsh = h; | 481 | qe->nsh = h; |
@@ -502,11 +490,8 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
502 | blen, | 490 | blen, |
503 | GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE); | 491 | GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE); |
504 | msg->gns_header.r_id = htonl (rid); | 492 | msg->gns_header.r_id = htonl (rid); |
505 | msg->expire = block->expiration_time; | ||
506 | msg->signature = block->signature; | ||
507 | msg->derived_key = block->derived_key; | ||
508 | GNUNET_memcpy (&msg[1], | 493 | GNUNET_memcpy (&msg[1], |
509 | &block[1], | 494 | block, |
510 | blen); | 495 | blen); |
511 | GNUNET_MQ_send (h->mq, | 496 | GNUNET_MQ_send (h->mq, |
512 | env); | 497 | env); |
diff --git a/src/namecache/plugin_namecache_flat.c b/src/namecache/plugin_namecache_flat.c index 1775561e1..eb7800051 100644 --- a/src/namecache/plugin_namecache_flat.c +++ b/src/namecache/plugin_namecache_flat.c | |||
@@ -207,10 +207,7 @@ store_and_free_entries (void *cls, | |||
207 | struct GNUNET_CRYPTO_HashAsciiEncoded query; | 207 | struct GNUNET_CRYPTO_HashAsciiEncoded query; |
208 | size_t block_size; | 208 | size_t block_size; |
209 | 209 | ||
210 | block_size = ntohl (entry->block->purpose.size) | 210 | block_size = GNUNET_GNSRECORD_block_get_size (entry->block); |
211 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
212 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
213 | |||
214 | GNUNET_STRINGS_base64_encode ((char *) entry->block, | 211 | GNUNET_STRINGS_base64_encode ((char *) entry->block, |
215 | block_size, | 212 | block_size, |
216 | &block_b64); | 213 | &block_b64); |
@@ -277,7 +274,7 @@ expire_blocks (void *cls, | |||
277 | struct GNUNET_TIME_Absolute expiration; | 274 | struct GNUNET_TIME_Absolute expiration; |
278 | 275 | ||
279 | now = GNUNET_TIME_absolute_get (); | 276 | now = GNUNET_TIME_absolute_get (); |
280 | expiration = GNUNET_TIME_absolute_ntoh (entry->block->expiration_time); | 277 | expiration = GNUNET_GNSRECORD_block_get_expiration (entry->block); |
281 | 278 | ||
282 | if (0 == GNUNET_TIME_absolute_get_difference (now, | 279 | if (0 == GNUNET_TIME_absolute_get_difference (now, |
283 | expiration).rel_value_us) | 280 | expiration).rel_value_us) |
@@ -319,12 +316,9 @@ namecache_cache_block (void *cls, | |||
319 | size_t block_size; | 316 | size_t block_size; |
320 | 317 | ||
321 | namecache_expire_blocks (plugin); | 318 | namecache_expire_blocks (plugin); |
322 | GNUNET_CRYPTO_hash (&block->derived_key, | 319 | GNUNET_GNSRECORD_query_from_block (block, |
323 | sizeof(struct GNUNET_IDENTITY_PublicKey), | 320 | &query); |
324 | &query); | 321 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
325 | block_size = ntohl (block->purpose.size) | ||
326 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
327 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
328 | if (block_size > 64 * 65536) | 322 | if (block_size > 64 * 65536) |
329 | { | 323 | { |
330 | GNUNET_break (0); | 324 | GNUNET_break (0); |
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c index 3c8fc4555..ae0f71a1f 100644 --- a/src/namecache/plugin_namecache_postgres.c +++ b/src/namecache/plugin_namecache_postgres.c | |||
@@ -153,11 +153,11 @@ namecache_postgres_expire_blocks (struct Plugin *plugin) | |||
153 | static void | 153 | static void |
154 | delete_old_block (struct Plugin *plugin, | 154 | delete_old_block (struct Plugin *plugin, |
155 | const struct GNUNET_HashCode *query, | 155 | const struct GNUNET_HashCode *query, |
156 | struct GNUNET_TIME_AbsoluteNBO expiration_time) | 156 | struct GNUNET_TIME_Absolute expiration_time) |
157 | { | 157 | { |
158 | struct GNUNET_PQ_QueryParam params[] = { | 158 | struct GNUNET_PQ_QueryParam params[] = { |
159 | GNUNET_PQ_query_param_auto_from_type (query), | 159 | GNUNET_PQ_query_param_auto_from_type (query), |
160 | GNUNET_PQ_query_param_absolute_time_nbo (&expiration_time), | 160 | GNUNET_PQ_query_param_absolute_time (&expiration_time), |
161 | GNUNET_PQ_query_param_end | 161 | GNUNET_PQ_query_param_end |
162 | }; | 162 | }; |
163 | enum GNUNET_DB_QueryStatus res; | 163 | enum GNUNET_DB_QueryStatus res; |
@@ -182,21 +182,20 @@ namecache_postgres_cache_block (void *cls, | |||
182 | { | 182 | { |
183 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
184 | struct GNUNET_HashCode query; | 184 | struct GNUNET_HashCode query; |
185 | size_t block_size = ntohl (block->purpose.size) | 185 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
186 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | 186 | struct GNUNET_TIME_Absolute exp; |
187 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 187 | exp = GNUNET_GNSRECORD_block_get_expiration (block); |
188 | struct GNUNET_PQ_QueryParam params[] = { | 188 | struct GNUNET_PQ_QueryParam params[] = { |
189 | GNUNET_PQ_query_param_auto_from_type (&query), | 189 | GNUNET_PQ_query_param_auto_from_type (&query), |
190 | GNUNET_PQ_query_param_fixed_size (block, block_size), | 190 | GNUNET_PQ_query_param_fixed_size (block, block_size), |
191 | GNUNET_PQ_query_param_absolute_time_nbo (&block->expiration_time), | 191 | GNUNET_PQ_query_param_absolute_time (&exp), |
192 | GNUNET_PQ_query_param_end | 192 | GNUNET_PQ_query_param_end |
193 | }; | 193 | }; |
194 | enum GNUNET_DB_QueryStatus res; | 194 | enum GNUNET_DB_QueryStatus res; |
195 | 195 | ||
196 | namecache_postgres_expire_blocks (plugin); | 196 | namecache_postgres_expire_blocks (plugin); |
197 | GNUNET_CRYPTO_hash (&block->derived_key, | 197 | GNUNET_GNSRECORD_query_from_block (block, |
198 | sizeof(struct GNUNET_IDENTITY_PublicKey), | 198 | &query); |
199 | &query); | ||
200 | if (block_size > 64 * 65536) | 199 | if (block_size > 64 * 65536) |
201 | { | 200 | { |
202 | GNUNET_break (0); | 201 | GNUNET_break (0); |
@@ -204,7 +203,7 @@ namecache_postgres_cache_block (void *cls, | |||
204 | } | 203 | } |
205 | delete_old_block (plugin, | 204 | delete_old_block (plugin, |
206 | &query, | 205 | &query, |
207 | block->expiration_time); | 206 | exp); |
208 | 207 | ||
209 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 208 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, |
210 | "cache_block", | 209 | "cache_block", |
@@ -263,10 +262,7 @@ namecache_postgres_lookup_block (void *cls, | |||
263 | "Ending iteration (no more results)\n"); | 262 | "Ending iteration (no more results)\n"); |
264 | return GNUNET_NO; | 263 | return GNUNET_NO; |
265 | } | 264 | } |
266 | if ((bsize < sizeof(*block)) || | 265 | if ((bsize < sizeof(*block))) |
267 | (bsize != ntohl (block->purpose.size) | ||
268 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
269 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))) | ||
270 | { | 266 | { |
271 | GNUNET_break (0); | 267 | GNUNET_break (0); |
272 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 268 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/namecache/plugin_namecache_sqlite.c b/src/namecache/plugin_namecache_sqlite.c index 33970631b..82008c837 100644 --- a/src/namecache/plugin_namecache_sqlite.c +++ b/src/namecache/plugin_namecache_sqlite.c | |||
@@ -332,9 +332,7 @@ namecache_sqlite_cache_block (void *cls, | |||
332 | struct Plugin *plugin = cls; | 332 | struct Plugin *plugin = cls; |
333 | struct GNUNET_HashCode query; | 333 | struct GNUNET_HashCode query; |
334 | struct GNUNET_TIME_Absolute expiration; | 334 | struct GNUNET_TIME_Absolute expiration; |
335 | size_t block_size = ntohl (block->purpose.size) | 335 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
336 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
337 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
338 | struct GNUNET_SQ_QueryParam del_params[] = { | 336 | struct GNUNET_SQ_QueryParam del_params[] = { |
339 | GNUNET_SQ_query_param_auto_from_type (&query), | 337 | GNUNET_SQ_query_param_auto_from_type (&query), |
340 | GNUNET_SQ_query_param_absolute_time (&expiration), | 338 | GNUNET_SQ_query_param_absolute_time (&expiration), |
@@ -356,10 +354,9 @@ namecache_sqlite_cache_block (void *cls, | |||
356 | last_expire = GNUNET_TIME_absolute_get (); | 354 | last_expire = GNUNET_TIME_absolute_get (); |
357 | namecache_sqlite_expire_blocks (plugin); | 355 | namecache_sqlite_expire_blocks (plugin); |
358 | } | 356 | } |
359 | GNUNET_CRYPTO_hash (&block->derived_key, | 357 | GNUNET_assert (GNUNET_OK == |
360 | sizeof(block->derived_key), | 358 | GNUNET_GNSRECORD_query_from_block (block, &query)); |
361 | &query); | 359 | expiration = GNUNET_GNSRECORD_block_get_expiration (block); |
362 | expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
364 | "Caching new version of block %s (expires %s)\n", | 361 | "Caching new version of block %s (expires %s)\n", |
365 | GNUNET_h2s (&query), | 362 | GNUNET_h2s (&query), |
@@ -498,10 +495,7 @@ namecache_sqlite_lookup_block (void *cls, | |||
498 | GNUNET_break (0); | 495 | GNUNET_break (0); |
499 | ret = GNUNET_SYSERR; | 496 | ret = GNUNET_SYSERR; |
500 | } | 497 | } |
501 | else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block)) || | 498 | else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block))) |
502 | (ntohl (block->purpose.size) | ||
503 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
504 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) != block_size)) | ||
505 | { | 499 | { |
506 | GNUNET_break (0); | 500 | GNUNET_break (0); |
507 | GNUNET_SQ_cleanup_result (rs); | 501 | GNUNET_SQ_cleanup_result (rs); |
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c index 0f9ce97e4..baea0e444 100644 --- a/src/namestore/test_plugin_namestore.c +++ b/src/namestore/test_plugin_namestore.c | |||
@@ -85,14 +85,14 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
85 | static void | 85 | static void |
86 | test_record (void *cls, | 86 | test_record (void *cls, |
87 | uint64_t seq, | 87 | uint64_t seq, |
88 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | 88 | const struct GNUNET_IDENTITY_PrivateKey *private_key, |
89 | const char *label, | 89 | const char *label, |
90 | unsigned int rd_count, | 90 | unsigned int rd_count, |
91 | const struct GNUNET_GNSRECORD_Data *rd) | 91 | const struct GNUNET_GNSRECORD_Data *rd) |
92 | { | 92 | { |
93 | int *idp = cls; | 93 | int *idp = cls; |
94 | int id = *idp; | 94 | int id = *idp; |
95 | struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key; | 95 | struct GNUNET_IDENTITY_PrivateKey tzone_private_key; |
96 | char tname[64]; | 96 | char tname[64]; |
97 | unsigned int trd_count = 1 + (id % 1024); | 97 | unsigned int trd_count = 1 + (id % 1024); |
98 | 98 | ||
@@ -123,7 +123,7 @@ get_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | |||
123 | static void | 123 | static void |
124 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) | 124 | put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) |
125 | { | 125 | { |
126 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; | 126 | struct GNUNET_IDENTITY_PrivateKey zone_private_key; |
127 | char label[64]; | 127 | char label[64]; |
128 | unsigned int rd_count = 1 + (id % 1024); | 128 | unsigned int rd_count = 1 + (id % 1024); |
129 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; | 129 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL (rd_count)]; |