aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/revocation_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/revocation/revocation_api.c')
-rw-r--r--src/revocation/revocation_api.c289
1 files changed, 146 insertions, 143 deletions
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 091f6ae85..fd25050e2 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -33,7 +33,8 @@
33/** 33/**
34 * Handle for the key revocation query. 34 * Handle for the key revocation query.
35 */ 35 */
36struct GNUNET_REVOCATION_Query { 36struct GNUNET_REVOCATION_Query
37{
37 /** 38 /**
38 * Message queue to the service. 39 * Message queue to the service.
39 */ 40 */
@@ -61,16 +62,16 @@ struct GNUNET_REVOCATION_Query {
61 * @param error error code 62 * @param error error code
62 */ 63 */
63static void 64static void
64query_mq_error_handler(void *cls, 65query_mq_error_handler (void *cls,
65 enum GNUNET_MQ_Error error) 66 enum GNUNET_MQ_Error error)
66{ 67{
67 struct GNUNET_REVOCATION_Query *q = cls; 68 struct GNUNET_REVOCATION_Query *q = cls;
68 69
69 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 70 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
70 "Revocation query MQ error\n"); 71 "Revocation query MQ error\n");
71 q->func(q->func_cls, 72 q->func (q->func_cls,
72 GNUNET_SYSERR); 73 GNUNET_SYSERR);
73 GNUNET_REVOCATION_query_cancel(q); 74 GNUNET_REVOCATION_query_cancel (q);
74} 75}
75 76
76 77
@@ -81,17 +82,17 @@ query_mq_error_handler(void *cls,
81 * @param qrm response we got 82 * @param qrm response we got
82 */ 83 */
83static void 84static void
84handle_revocation_query_response(void *cls, 85handle_revocation_query_response (void *cls,
85 const struct QueryResponseMessage *qrm) 86 const struct QueryResponseMessage *qrm)
86{ 87{
87 struct GNUNET_REVOCATION_Query *q = cls; 88 struct GNUNET_REVOCATION_Query *q = cls;
88 89
89 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
90 "Revocation query result: %d\n", 91 "Revocation query result: %d\n",
91 (uint32_t)ntohl(qrm->is_valid)); 92 (uint32_t) ntohl (qrm->is_valid));
92 q->func(q->func_cls, 93 q->func (q->func_cls,
93 ntohl(qrm->is_valid)); 94 ntohl (qrm->is_valid));
94 GNUNET_REVOCATION_query_cancel(q); 95 GNUNET_REVOCATION_query_cancel (q);
95} 96}
96 97
97 98
@@ -105,41 +106,41 @@ handle_revocation_query_response(void *cls,
105 * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback 106 * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback
106 */ 107 */
107struct GNUNET_REVOCATION_Query * 108struct GNUNET_REVOCATION_Query *
108GNUNET_REVOCATION_query(const struct GNUNET_CONFIGURATION_Handle *cfg, 109GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
109 const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 110 const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
110 GNUNET_REVOCATION_Callback func, 111 GNUNET_REVOCATION_Callback func,
111 void *func_cls) 112 void *func_cls)
112{ 113{
113 struct GNUNET_REVOCATION_Query *q 114 struct GNUNET_REVOCATION_Query *q
114 = GNUNET_new(struct GNUNET_REVOCATION_Query); 115 = GNUNET_new (struct GNUNET_REVOCATION_Query);
115 struct GNUNET_MQ_MessageHandler handlers[] = { 116 struct GNUNET_MQ_MessageHandler handlers[] = {
116 GNUNET_MQ_hd_fixed_size(revocation_query_response, 117 GNUNET_MQ_hd_fixed_size (revocation_query_response,
117 GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE, 118 GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE,
118 struct QueryResponseMessage, 119 struct QueryResponseMessage,
119 q), 120 q),
120 GNUNET_MQ_handler_end() 121 GNUNET_MQ_handler_end ()
121 }; 122 };
122 struct QueryMessage *qm; 123 struct QueryMessage *qm;
123 struct GNUNET_MQ_Envelope *env; 124 struct GNUNET_MQ_Envelope *env;
124 125
125 q->mq = GNUNET_CLIENT_connect(cfg, 126 q->mq = GNUNET_CLIENT_connect (cfg,
126 "revocation", 127 "revocation",
127 handlers, 128 handlers,
128 &query_mq_error_handler, 129 &query_mq_error_handler,
129 q); 130 q);
130 if (NULL == q->mq) 131 if (NULL == q->mq)
131 { 132 {
132 GNUNET_free(q); 133 GNUNET_free (q);
133 return NULL; 134 return NULL;
134 } 135 }
135 q->func = func; 136 q->func = func;
136 q->func_cls = func_cls; 137 q->func_cls = func_cls;
137 env = GNUNET_MQ_msg(qm, 138 env = GNUNET_MQ_msg (qm,
138 GNUNET_MESSAGE_TYPE_REVOCATION_QUERY); 139 GNUNET_MESSAGE_TYPE_REVOCATION_QUERY);
139 qm->reserved = htonl(0); 140 qm->reserved = htonl (0);
140 qm->key = *key; 141 qm->key = *key;
141 GNUNET_MQ_send(q->mq, 142 GNUNET_MQ_send (q->mq,
142 env); 143 env);
143 return q; 144 return q;
144} 145}
145 146
@@ -150,21 +151,22 @@ GNUNET_REVOCATION_query(const struct GNUNET_CONFIGURATION_Handle *cfg,
150 * @param q query to cancel 151 * @param q query to cancel
151 */ 152 */
152void 153void
153GNUNET_REVOCATION_query_cancel(struct GNUNET_REVOCATION_Query *q) 154GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q)
154{ 155{
155 if (NULL != q->mq) 156 if (NULL != q->mq)
156 { 157 {
157 GNUNET_MQ_destroy(q->mq); 158 GNUNET_MQ_destroy (q->mq);
158 q->mq = NULL; 159 q->mq = NULL;
159 } 160 }
160 GNUNET_free(q); 161 GNUNET_free (q);
161} 162}
162 163
163 164
164/** 165/**
165 * Handle for the key revocation operation. 166 * Handle for the key revocation operation.
166 */ 167 */
167struct GNUNET_REVOCATION_Handle { 168struct GNUNET_REVOCATION_Handle
169{
168 /** 170 /**
169 * Message queue to the service. 171 * Message queue to the service.
170 */ 172 */
@@ -192,16 +194,16 @@ struct GNUNET_REVOCATION_Handle {
192 * @param error error code 194 * @param error error code
193 */ 195 */
194static void 196static void
195revocation_mq_error_handler(void *cls, 197revocation_mq_error_handler (void *cls,
196 enum GNUNET_MQ_Error error) 198 enum GNUNET_MQ_Error error)
197{ 199{
198 struct GNUNET_REVOCATION_Handle *h = cls; 200 struct GNUNET_REVOCATION_Handle *h = cls;
199 201
200 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 202 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
201 "Revocation MQ error\n"); 203 "Revocation MQ error\n");
202 h->func(h->func_cls, 204 h->func (h->func_cls,
203 GNUNET_SYSERR); 205 GNUNET_SYSERR);
204 GNUNET_REVOCATION_revoke_cancel(h); 206 GNUNET_REVOCATION_revoke_cancel (h);
205} 207}
206 208
207 209
@@ -212,17 +214,17 @@ revocation_mq_error_handler(void *cls,
212 * @param rrm response we got 214 * @param rrm response we got
213 */ 215 */
214static void 216static void
215handle_revocation_response(void *cls, 217handle_revocation_response (void *cls,
216 const struct RevocationResponseMessage *rrm) 218 const struct RevocationResponseMessage *rrm)
217{ 219{
218 struct GNUNET_REVOCATION_Handle *h = cls; 220 struct GNUNET_REVOCATION_Handle *h = cls;
219 221
220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "Revocation transmission result: %d\n", 223 "Revocation transmission result: %d\n",
222 (uint32_t)ntohl(rrm->is_valid)); 224 (uint32_t) ntohl (rrm->is_valid));
223 h->func(h->func_cls, 225 h->func (h->func_cls,
224 ntohl(rrm->is_valid)); 226 ntohl (rrm->is_valid));
225 GNUNET_REVOCATION_revoke_cancel(h); 227 GNUNET_REVOCATION_revoke_cancel (h);
226} 228}
227 229
228 230
@@ -242,64 +244,64 @@ handle_revocation_response(void *cls,
242 * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback 244 * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback
243 */ 245 */
244struct GNUNET_REVOCATION_Handle * 246struct GNUNET_REVOCATION_Handle *
245GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg, 247GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
246 const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 248 const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
247 const struct GNUNET_CRYPTO_EcdsaSignature *sig, 249 const struct GNUNET_CRYPTO_EcdsaSignature *sig,
248 uint64_t pow, 250 uint64_t pow,
249 GNUNET_REVOCATION_Callback func, 251 GNUNET_REVOCATION_Callback func,
250 void *func_cls) 252 void *func_cls)
251{ 253{
252 struct GNUNET_REVOCATION_Handle *h 254 struct GNUNET_REVOCATION_Handle *h
253 = GNUNET_new(struct GNUNET_REVOCATION_Handle); 255 = GNUNET_new (struct GNUNET_REVOCATION_Handle);
254 struct GNUNET_MQ_MessageHandler handlers[] = { 256 struct GNUNET_MQ_MessageHandler handlers[] = {
255 GNUNET_MQ_hd_fixed_size(revocation_response, 257 GNUNET_MQ_hd_fixed_size (revocation_response,
256 GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE, 258 GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE,
257 struct RevocationResponseMessage, 259 struct RevocationResponseMessage,
258 h), 260 h),
259 GNUNET_MQ_handler_end() 261 GNUNET_MQ_handler_end ()
260 }; 262 };
261 unsigned long long matching_bits; 263 unsigned long long matching_bits;
262 struct RevokeMessage *rm; 264 struct RevokeMessage *rm;
263 struct GNUNET_MQ_Envelope *env; 265 struct GNUNET_MQ_Envelope *env;
264 266
265 if ((GNUNET_OK == 267 if ((GNUNET_OK ==
266 GNUNET_CONFIGURATION_get_value_number(cfg, 268 GNUNET_CONFIGURATION_get_value_number (cfg,
267 "REVOCATION", 269 "REVOCATION",
268 "WORKBITS", 270 "WORKBITS",
269 &matching_bits)) && 271 &matching_bits)) &&
270 (GNUNET_YES != 272 (GNUNET_YES !=
271 GNUNET_REVOCATION_check_pow(key, 273 GNUNET_REVOCATION_check_pow (key,
272 pow, 274 pow,
273 (unsigned int)matching_bits))) 275 (unsigned int) matching_bits)))
274 { 276 {
275 GNUNET_break(0); 277 GNUNET_break (0);
276 GNUNET_free(h); 278 GNUNET_free (h);
277 return NULL; 279 return NULL;
278 } 280 }
279 281
280 h->mq = GNUNET_CLIENT_connect(cfg, 282 h->mq = GNUNET_CLIENT_connect (cfg,
281 "revocation", 283 "revocation",
282 handlers, 284 handlers,
283 &revocation_mq_error_handler, 285 &revocation_mq_error_handler,
284 h); 286 h);
285 if (NULL == h->mq) 287 if (NULL == h->mq)
286 { 288 {
287 GNUNET_free(h); 289 GNUNET_free (h);
288 return NULL; 290 return NULL;
289 } 291 }
290 h->func = func; 292 h->func = func;
291 h->func_cls = func_cls; 293 h->func_cls = func_cls;
292 env = GNUNET_MQ_msg(rm, 294 env = GNUNET_MQ_msg (rm,
293 GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE); 295 GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE);
294 rm->reserved = htonl(0); 296 rm->reserved = htonl (0);
295 rm->proof_of_work = pow; 297 rm->proof_of_work = pow;
296 rm->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_REVOCATION); 298 rm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
297 rm->purpose.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 299 rm->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
298 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 300 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
299 rm->public_key = *key; 301 rm->public_key = *key;
300 rm->signature = *sig; 302 rm->signature = *sig;
301 GNUNET_MQ_send(h->mq, 303 GNUNET_MQ_send (h->mq,
302 env); 304 env);
303 return h; 305 return h;
304} 306}
305 307
@@ -310,14 +312,14 @@ GNUNET_REVOCATION_revoke(const struct GNUNET_CONFIGURATION_Handle *cfg,
310 * @param h operation to cancel 312 * @param h operation to cancel
311 */ 313 */
312void 314void
313GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h) 315GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
314{ 316{
315 if (NULL != h->mq) 317 if (NULL != h->mq)
316 { 318 {
317 GNUNET_MQ_destroy(h->mq); 319 GNUNET_MQ_destroy (h->mq);
318 h->mq = NULL; 320 h->mq = NULL;
319 } 321 }
320 GNUNET_free(h); 322 GNUNET_free (h);
321} 323}
322 324
323 325
@@ -329,18 +331,18 @@ GNUNET_REVOCATION_revoke_cancel(struct GNUNET_REVOCATION_Handle *h)
329 * @param result where to write the resulting hash 331 * @param result where to write the resulting hash
330 */ 332 */
331static void 333static void
332pow_hash(const void *buf, 334pow_hash (const void *buf,
333 size_t buf_len, 335 size_t buf_len,
334 struct GNUNET_HashCode *result) 336 struct GNUNET_HashCode *result)
335{ 337{
336 GNUNET_break(0 == 338 GNUNET_break (0 ==
337 gcry_kdf_derive(buf, buf_len, 339 gcry_kdf_derive (buf, buf_len,
338 GCRY_KDF_SCRYPT, 340 GCRY_KDF_SCRYPT,
339 1 /* subalgo */, 341 1 /* subalgo */,
340 "gnunet-revocation-proof-of-work", 342 "gnunet-revocation-proof-of-work",
341 strlen("gnunet-revocation-proof-of-work"), 343 strlen ("gnunet-revocation-proof-of-work"),
342 2 /* iterations; keep cost of individual op small */, 344 2 /* iterations; keep cost of individual op small */,
343 sizeof(struct GNUNET_HashCode), result)); 345 sizeof(struct GNUNET_HashCode), result));
344} 346}
345 347
346 348
@@ -351,12 +353,12 @@ pow_hash(const void *buf,
351 * @return the number of leading zero bits. 353 * @return the number of leading zero bits.
352 */ 354 */
353static unsigned int 355static unsigned int
354count_leading_zeroes(const struct GNUNET_HashCode *hash) 356count_leading_zeroes (const struct GNUNET_HashCode *hash)
355{ 357{
356 unsigned int hash_count; 358 unsigned int hash_count;
357 359
358 hash_count = 0; 360 hash_count = 0;
359 while ((0 == GNUNET_CRYPTO_hash_get_bit(hash, hash_count))) 361 while ((0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count)))
360 hash_count++; 362 hash_count++;
361 return hash_count; 363 return hash_count;
362} 364}
@@ -372,19 +374,19 @@ count_leading_zeroes(const struct GNUNET_HashCode *hash)
372 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not 374 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
373 */ 375 */
374int 376int
375GNUNET_REVOCATION_check_pow(const struct GNUNET_CRYPTO_EcdsaPublicKey *key, 377GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
376 uint64_t pow, 378 uint64_t pow,
377 unsigned int matching_bits) 379 unsigned int matching_bits)
378{ 380{
379 char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) + 381 char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
380 sizeof(pow)] GNUNET_ALIGN; 382 + sizeof(pow)] GNUNET_ALIGN;
381 struct GNUNET_HashCode result; 383 struct GNUNET_HashCode result;
382 384
383 GNUNET_memcpy(buf, &pow, sizeof(pow)); 385 GNUNET_memcpy (buf, &pow, sizeof(pow));
384 GNUNET_memcpy(&buf[sizeof(pow)], key, 386 GNUNET_memcpy (&buf[sizeof(pow)], key,
385 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 387 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
386 pow_hash(buf, sizeof(buf), &result); 388 pow_hash (buf, sizeof(buf), &result);
387 return (count_leading_zeroes(&result) >= 389 return (count_leading_zeroes (&result) >=
388 matching_bits) ? GNUNET_YES : GNUNET_NO; 390 matching_bits) ? GNUNET_YES : GNUNET_NO;
389} 391}
390 392
@@ -396,19 +398,20 @@ GNUNET_REVOCATION_check_pow(const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
396 * @param sig where to write the revocation signature 398 * @param sig where to write the revocation signature
397 */ 399 */
398void 400void
399GNUNET_REVOCATION_sign_revocation(const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 401GNUNET_REVOCATION_sign_revocation (const struct
400 struct GNUNET_CRYPTO_EcdsaSignature *sig) 402 GNUNET_CRYPTO_EcdsaPrivateKey *key,
403 struct GNUNET_CRYPTO_EcdsaSignature *sig)
401{ 404{
402 struct RevokeMessage rm; 405 struct RevokeMessage rm;
403 406
404 rm.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_REVOCATION); 407 rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
405 rm.purpose.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + 408 rm.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
406 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 409 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
407 GNUNET_CRYPTO_ecdsa_key_get_public(key, &rm.public_key); 410 GNUNET_CRYPTO_ecdsa_key_get_public (key, &rm.public_key);
408 GNUNET_assert(GNUNET_OK == 411 GNUNET_assert (GNUNET_OK ==
409 GNUNET_CRYPTO_ecdsa_sign(key, 412 GNUNET_CRYPTO_ecdsa_sign (key,
410 &rm.purpose, 413 &rm.purpose,
411 sig)); 414 sig));
412} 415}
413 416
414 417