diff options
Diffstat (limited to 'src/fs/fs_publish_ublock.c')
-rw-r--r-- | src/fs/fs_publish_ublock.c | 238 |
1 files changed, 120 insertions, 118 deletions
diff --git a/src/fs/fs_publish_ublock.c b/src/fs/fs_publish_ublock.c index 4dfb4a585..c50e71f0b 100644 --- a/src/fs/fs_publish_ublock.c +++ b/src/fs/fs_publish_ublock.c | |||
@@ -43,21 +43,22 @@ | |||
43 | * @param pub public key to use for key derivation | 43 | * @param pub public key to use for key derivation |
44 | */ | 44 | */ |
45 | static void | 45 | static void |
46 | derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | 46 | derive_ublock_encryption_key (struct GNUNET_CRYPTO_SymmetricSessionKey *skey, |
47 | struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | 47 | struct GNUNET_CRYPTO_SymmetricInitializationVector |
48 | const char *label, | 48 | *iv, |
49 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | 49 | const char *label, |
50 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | ||
50 | { | 51 | { |
51 | struct GNUNET_HashCode key; | 52 | struct GNUNET_HashCode key; |
52 | 53 | ||
53 | /* derive key from 'label' and public key of the namespace */ | 54 | /* derive key from 'label' and public key of the namespace */ |
54 | GNUNET_assert(GNUNET_YES == | 55 | GNUNET_assert (GNUNET_YES == |
55 | GNUNET_CRYPTO_kdf(&key, sizeof(key), | 56 | GNUNET_CRYPTO_kdf (&key, sizeof(key), |
56 | "UBLOCK-ENC", strlen("UBLOCK-ENC"), | 57 | "UBLOCK-ENC", strlen ("UBLOCK-ENC"), |
57 | label, strlen(label), | 58 | label, strlen (label), |
58 | pub, sizeof(*pub), | 59 | pub, sizeof(*pub), |
59 | NULL, 0)); | 60 | NULL, 0)); |
60 | GNUNET_CRYPTO_hash_to_aes_key(&key, skey, iv); | 61 | GNUNET_CRYPTO_hash_to_aes_key (&key, skey, iv); |
61 | } | 62 | } |
62 | 63 | ||
63 | 64 | ||
@@ -71,27 +72,28 @@ derive_ublock_encryption_key(struct GNUNET_CRYPTO_SymmetricSessionKey *skey, | |||
71 | * @param output where to write the result, has input_len bytes | 72 | * @param output where to write the result, has input_len bytes |
72 | */ | 73 | */ |
73 | void | 74 | void |
74 | GNUNET_FS_ublock_decrypt_(const void *input, | 75 | GNUNET_FS_ublock_decrypt_ (const void *input, |
75 | size_t input_len, | 76 | size_t input_len, |
76 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, | 77 | const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, |
77 | const char *label, | 78 | const char *label, |
78 | void *output) | 79 | void *output) |
79 | { | 80 | { |
80 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 81 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
81 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; | 82 | struct GNUNET_CRYPTO_SymmetricSessionKey skey; |
82 | 83 | ||
83 | derive_ublock_encryption_key(&skey, &iv, | 84 | derive_ublock_encryption_key (&skey, &iv, |
84 | label, ns); | 85 | label, ns); |
85 | GNUNET_CRYPTO_symmetric_decrypt(input, input_len, | 86 | GNUNET_CRYPTO_symmetric_decrypt (input, input_len, |
86 | &skey, &iv, | 87 | &skey, &iv, |
87 | output); | 88 | output); |
88 | } | 89 | } |
89 | 90 | ||
90 | 91 | ||
91 | /** | 92 | /** |
92 | * Context for 'ublock_put_cont'. | 93 | * Context for 'ublock_put_cont'. |
93 | */ | 94 | */ |
94 | struct GNUNET_FS_PublishUblockContext { | 95 | struct GNUNET_FS_PublishUblockContext |
96 | { | ||
95 | /** | 97 | /** |
96 | * Function to call when done. | 98 | * Function to call when done. |
97 | */ | 99 | */ |
@@ -110,7 +112,7 @@ struct GNUNET_FS_PublishUblockContext { | |||
110 | /** | 112 | /** |
111 | * Task to run continuation asynchronously. | 113 | * Task to run continuation asynchronously. |
112 | */ | 114 | */ |
113 | struct GNUNET_SCHEDULER_Task * task; | 115 | struct GNUNET_SCHEDULER_Task *task; |
114 | }; | 116 | }; |
115 | 117 | ||
116 | 118 | ||
@@ -127,16 +129,16 @@ struct GNUNET_FS_PublishUblockContext { | |||
127 | * @param msg NULL on success, otherwise an error message | 129 | * @param msg NULL on success, otherwise an error message |
128 | */ | 130 | */ |
129 | static void | 131 | static void |
130 | ublock_put_cont(void *cls, | 132 | ublock_put_cont (void *cls, |
131 | int32_t success, | 133 | int32_t success, |
132 | struct GNUNET_TIME_Absolute min_expiration, | 134 | struct GNUNET_TIME_Absolute min_expiration, |
133 | const char *msg) | 135 | const char *msg) |
134 | { | 136 | { |
135 | struct GNUNET_FS_PublishUblockContext *uc = cls; | 137 | struct GNUNET_FS_PublishUblockContext *uc = cls; |
136 | 138 | ||
137 | uc->qre = NULL; | 139 | uc->qre = NULL; |
138 | uc->cont(uc->cont_cls, msg); | 140 | uc->cont (uc->cont_cls, msg); |
139 | GNUNET_free(uc); | 141 | GNUNET_free (uc); |
140 | } | 142 | } |
141 | 143 | ||
142 | 144 | ||
@@ -146,13 +148,13 @@ ublock_put_cont(void *cls, | |||
146 | * @param cls the `struct GNUNET_FS_PublishUblockContext *` | 148 | * @param cls the `struct GNUNET_FS_PublishUblockContext *` |
147 | */ | 149 | */ |
148 | static void | 150 | static void |
149 | run_cont(void *cls) | 151 | run_cont (void *cls) |
150 | { | 152 | { |
151 | struct GNUNET_FS_PublishUblockContext *uc = cls; | 153 | struct GNUNET_FS_PublishUblockContext *uc = cls; |
152 | 154 | ||
153 | uc->task = NULL; | 155 | uc->task = NULL; |
154 | uc->cont(uc->cont_cls, NULL); | 156 | uc->cont (uc->cont_cls, NULL); |
155 | GNUNET_free(uc); | 157 | GNUNET_free (uc); |
156 | } | 158 | } |
157 | 159 | ||
158 | 160 | ||
@@ -173,16 +175,16 @@ run_cont(void *cls) | |||
173 | * @return NULL on error (@a cont will still be called) | 175 | * @return NULL on error (@a cont will still be called) |
174 | */ | 176 | */ |
175 | struct GNUNET_FS_PublishUblockContext * | 177 | struct GNUNET_FS_PublishUblockContext * |
176 | GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | 178 | GNUNET_FS_publish_ublock_ (struct GNUNET_FS_Handle *h, |
177 | struct GNUNET_DATASTORE_Handle *dsh, | 179 | struct GNUNET_DATASTORE_Handle *dsh, |
178 | const char *label, | 180 | const char *label, |
179 | const char *ulabel, | 181 | const char *ulabel, |
180 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, | 182 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, |
181 | const struct GNUNET_CONTAINER_MetaData *meta, | 183 | const struct GNUNET_CONTAINER_MetaData *meta, |
182 | const struct GNUNET_FS_Uri *uri, | 184 | const struct GNUNET_FS_Uri *uri, |
183 | const struct GNUNET_FS_BlockOptions *bo, | 185 | const struct GNUNET_FS_BlockOptions *bo, |
184 | enum GNUNET_FS_PublishOptions options, | 186 | enum GNUNET_FS_PublishOptions options, |
185 | GNUNET_FS_UBlockContinuation cont, void *cont_cls) | 187 | GNUNET_FS_UBlockContinuation cont, void *cont_cls) |
186 | { | 188 | { |
187 | struct GNUNET_FS_PublishUblockContext *uc; | 189 | struct GNUNET_FS_PublishUblockContext *uc; |
188 | struct GNUNET_HashCode query; | 190 | struct GNUNET_HashCode query; |
@@ -204,101 +206,101 @@ GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | |||
204 | if (NULL == meta) | 206 | if (NULL == meta) |
205 | mdsize = 0; | 207 | mdsize = 0; |
206 | else | 208 | else |
207 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); | 209 | mdsize = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); |
208 | GNUNET_assert(mdsize >= 0); | 210 | GNUNET_assert (mdsize >= 0); |
209 | uris = GNUNET_FS_uri_to_string(uri); | 211 | uris = GNUNET_FS_uri_to_string (uri); |
210 | slen = strlen(uris) + 1; | 212 | slen = strlen (uris) + 1; |
211 | if (NULL == ulabel) | 213 | if (NULL == ulabel) |
212 | ulen = 1; | 214 | ulen = 1; |
213 | else | 215 | else |
214 | ulen = strlen(ulabel) + 1; | 216 | ulen = strlen (ulabel) + 1; |
215 | size = mdsize + sizeof(struct UBlock) + slen + ulen; | 217 | size = mdsize + sizeof(struct UBlock) + slen + ulen; |
216 | if (size > MAX_UBLOCK_SIZE) | 218 | if (size > MAX_UBLOCK_SIZE) |
217 | { | 219 | { |
218 | size = MAX_UBLOCK_SIZE; | 220 | size = MAX_UBLOCK_SIZE; |
219 | mdsize = size - sizeof(struct UBlock) - (slen + ulen); | 221 | mdsize = size - sizeof(struct UBlock) - (slen + ulen); |
220 | } | 222 | } |
221 | ub_plain = GNUNET_malloc(size); | 223 | ub_plain = GNUNET_malloc (size); |
222 | kbe = (char *)&ub_plain[1]; | 224 | kbe = (char *) &ub_plain[1]; |
223 | if (NULL != ulabel) | 225 | if (NULL != ulabel) |
224 | GNUNET_memcpy(kbe, ulabel, ulen); | 226 | GNUNET_memcpy (kbe, ulabel, ulen); |
225 | kbe += ulen; | 227 | kbe += ulen; |
226 | GNUNET_memcpy(kbe, uris, slen); | 228 | GNUNET_memcpy (kbe, uris, slen); |
227 | kbe += slen; | 229 | kbe += slen; |
228 | GNUNET_free(uris); | 230 | GNUNET_free (uris); |
229 | sptr = kbe; | 231 | sptr = kbe; |
230 | if (NULL != meta) | 232 | if (NULL != meta) |
231 | mdsize = | 233 | mdsize = |
232 | GNUNET_CONTAINER_meta_data_serialize(meta, &sptr, mdsize, | 234 | GNUNET_CONTAINER_meta_data_serialize (meta, &sptr, mdsize, |
233 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 235 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
234 | if (-1 == mdsize) | 236 | if (-1 == mdsize) |
235 | { | 237 | { |
236 | GNUNET_break(0); | 238 | GNUNET_break (0); |
237 | GNUNET_free(ub_plain); | 239 | GNUNET_free (ub_plain); |
238 | cont(cont_cls, _("Internal error.")); | 240 | cont (cont_cls, _ ("Internal error.")); |
239 | return NULL; | 241 | return NULL; |
240 | } | 242 | } |
241 | size = sizeof(struct UBlock) + slen + mdsize + ulen; | 243 | size = sizeof(struct UBlock) + slen + mdsize + ulen; |
242 | 244 | ||
243 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
244 | "Publishing under identifier `%s'\n", | 246 | "Publishing under identifier `%s'\n", |
245 | label); | 247 | label); |
246 | /* get public key of the namespace */ | 248 | /* get public key of the namespace */ |
247 | GNUNET_CRYPTO_ecdsa_key_get_public(ns, | 249 | GNUNET_CRYPTO_ecdsa_key_get_public (ns, |
248 | &pub); | 250 | &pub); |
249 | derive_ublock_encryption_key(&skey, &iv, | 251 | derive_ublock_encryption_key (&skey, &iv, |
250 | label, &pub); | 252 | label, &pub); |
251 | 253 | ||
252 | /* encrypt ublock */ | 254 | /* encrypt ublock */ |
253 | ub_enc = GNUNET_malloc(size); | 255 | ub_enc = GNUNET_malloc (size); |
254 | GNUNET_CRYPTO_symmetric_encrypt(&ub_plain[1], | 256 | GNUNET_CRYPTO_symmetric_encrypt (&ub_plain[1], |
255 | ulen + slen + mdsize, | 257 | ulen + slen + mdsize, |
256 | &skey, &iv, | 258 | &skey, &iv, |
257 | &ub_enc[1]); | 259 | &ub_enc[1]); |
258 | GNUNET_free(ub_plain); | 260 | GNUNET_free (ub_plain); |
259 | ub_enc->purpose.size = htonl(ulen + slen + mdsize + | 261 | ub_enc->purpose.size = htonl (ulen + slen + mdsize |
260 | sizeof(struct UBlock) | 262 | + sizeof(struct UBlock) |
261 | - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | 263 | - sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); |
262 | ub_enc->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); | 264 | ub_enc->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_FS_UBLOCK); |
263 | 265 | ||
264 | /* derive signing-key from 'label' and public key of the namespace */ | 266 | /* derive signing-key from 'label' and public key of the namespace */ |
265 | nsd = GNUNET_CRYPTO_ecdsa_private_key_derive(ns, label, "fs-ublock"); | 267 | nsd = GNUNET_CRYPTO_ecdsa_private_key_derive (ns, label, "fs-ublock"); |
266 | GNUNET_CRYPTO_ecdsa_key_get_public(nsd, | 268 | GNUNET_CRYPTO_ecdsa_key_get_public (nsd, |
267 | &ub_enc->verification_key); | 269 | &ub_enc->verification_key); |
268 | GNUNET_assert(GNUNET_OK == | 270 | GNUNET_assert (GNUNET_OK == |
269 | GNUNET_CRYPTO_ecdsa_sign(nsd, | 271 | GNUNET_CRYPTO_ecdsa_sign (nsd, |
270 | &ub_enc->purpose, | 272 | &ub_enc->purpose, |
271 | &ub_enc->signature)); | 273 | &ub_enc->signature)); |
272 | GNUNET_CRYPTO_hash(&ub_enc->verification_key, | 274 | GNUNET_CRYPTO_hash (&ub_enc->verification_key, |
273 | sizeof(ub_enc->verification_key), | 275 | sizeof(ub_enc->verification_key), |
274 | &query); | 276 | &query); |
275 | GNUNET_free(nsd); | 277 | GNUNET_free (nsd); |
276 | 278 | ||
277 | uc = GNUNET_new(struct GNUNET_FS_PublishUblockContext); | 279 | uc = GNUNET_new (struct GNUNET_FS_PublishUblockContext); |
278 | uc->cont = cont; | 280 | uc->cont = cont; |
279 | uc->cont_cls = cont_cls; | 281 | uc->cont_cls = cont_cls; |
280 | if (NULL != dsh) | 282 | if (NULL != dsh) |
281 | { | 283 | { |
282 | uc->qre = | 284 | uc->qre = |
283 | GNUNET_DATASTORE_put(dsh, | 285 | GNUNET_DATASTORE_put (dsh, |
284 | 0, | 286 | 0, |
285 | &query, | 287 | &query, |
286 | ulen + slen + mdsize + sizeof(struct UBlock), | 288 | ulen + slen + mdsize + sizeof(struct UBlock), |
287 | ub_enc, | 289 | ub_enc, |
288 | GNUNET_BLOCK_TYPE_FS_UBLOCK, | 290 | GNUNET_BLOCK_TYPE_FS_UBLOCK, |
289 | bo->content_priority, | 291 | bo->content_priority, |
290 | bo->anonymity_level, | 292 | bo->anonymity_level, |
291 | bo->replication_level, | 293 | bo->replication_level, |
292 | bo->expiration_time, | 294 | bo->expiration_time, |
293 | -2, 1, | 295 | -2, 1, |
294 | &ublock_put_cont, uc); | 296 | &ublock_put_cont, uc); |
295 | } | 297 | } |
296 | else | 298 | else |
297 | { | 299 | { |
298 | uc->task = GNUNET_SCHEDULER_add_now(&run_cont, | 300 | uc->task = GNUNET_SCHEDULER_add_now (&run_cont, |
299 | uc); | 301 | uc); |
300 | } | 302 | } |
301 | GNUNET_free(ub_enc); | 303 | GNUNET_free (ub_enc); |
302 | return uc; | 304 | return uc; |
303 | } | 305 | } |
304 | 306 | ||
@@ -309,13 +311,13 @@ GNUNET_FS_publish_ublock_(struct GNUNET_FS_Handle *h, | |||
309 | * @param uc operation to abort. | 311 | * @param uc operation to abort. |
310 | */ | 312 | */ |
311 | void | 313 | void |
312 | GNUNET_FS_publish_ublock_cancel_(struct GNUNET_FS_PublishUblockContext *uc) | 314 | GNUNET_FS_publish_ublock_cancel_ (struct GNUNET_FS_PublishUblockContext *uc) |
313 | { | 315 | { |
314 | if (NULL != uc->qre) | 316 | if (NULL != uc->qre) |
315 | GNUNET_DATASTORE_cancel(uc->qre); | 317 | GNUNET_DATASTORE_cancel (uc->qre); |
316 | if (NULL != uc->task) | 318 | if (NULL != uc->task) |
317 | GNUNET_SCHEDULER_cancel(uc->task); | 319 | GNUNET_SCHEDULER_cancel (uc->task); |
318 | GNUNET_free(uc); | 320 | GNUNET_free (uc); |
319 | } | 321 | } |
320 | 322 | ||
321 | /* end of fs_publish_ublock.c */ | 323 | /* end of fs_publish_ublock.c */ |