aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/revocation_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-06 07:41:21 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-06 07:41:21 +0000
commitad989721684818bee9a0a1f81d5fb085241959ab (patch)
treed3761d4e3af72e1d9c67565b682271a4801436d6 /src/revocation/revocation_api.c
parent2315ef124c25961fc88eadbf6b9d396de5d8f992 (diff)
downloadgnunet-ad989721684818bee9a0a1f81d5fb085241959ab.tar.gz
gnunet-ad989721684818bee9a0a1f81d5fb085241959ab.zip
-implementing revocation library
Diffstat (limited to 'src/revocation/revocation_api.c')
-rw-r--r--src/revocation/revocation_api.c196
1 files changed, 192 insertions, 4 deletions
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 109d4afc5..858649bbd 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -60,10 +60,82 @@ struct GNUNET_REVOCATION_Query
60 * Closure for @e func. 60 * Closure for @e func.
61 */ 61 */
62 void *func_cls; 62 void *func_cls;
63
64 /**
65 * Transmission handle to the service.
66 */
67 struct GNUNET_CLIENT_TransmitHandle *th;
68
63}; 69};
64 70
65 71
66/** 72/**
73 * Handle response to our revocation query.
74 *
75 * @param cls our `struct GNUNET_REVOCATION_Query` handle
76 * @param msg response we got, NULL on disconnect
77 */
78static void
79handle_revocation_query_response (void *cls,
80 const struct GNUNET_MessageHeader *msg)
81{
82 struct GNUNET_REVOCATION_Query *q = cls;
83 const struct QueryResponseMessage *qrm;
84
85 if ( (NULL == msg) ||
86 (sizeof (struct QueryResponseMessage) != ntohs (msg->size)) ||
87 (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE != ntohs (msg->type)) )
88 {
89 GNUNET_break (NULL == msg);
90 q->func (q->func_cls, GNUNET_SYSERR);
91 GNUNET_REVOCATION_query_cancel (q);
92 return;
93 }
94 qrm = (const struct QueryResponseMessage *) msg;
95 q->func (q->func_cls, ntohl (qrm->is_valid));
96 GNUNET_REVOCATION_query_cancel (q);
97}
98
99
100/**
101 * Transmit our revocation query to the service.
102 *
103 * @param cls our `struct GNUNET_REVOCATION_Query` handle
104 * @param size number of bytes available in @a buf
105 * @param buf where to copy the query
106 * @return number of bytes copied to @a buf
107 */
108static size_t
109send_revocation_query (void *cls,
110 size_t size,
111 void *buf)
112{
113 struct GNUNET_REVOCATION_Query *q = cls;
114 struct QueryMessage qm;
115
116 q->th = NULL;
117 if ( (NULL == buf) ||
118 (sizeof (struct QueryMessage) > size) )
119 {
120 GNUNET_break (0);
121 q->func (q->func_cls, GNUNET_SYSERR);
122 GNUNET_REVOCATION_query_cancel (q);
123 return 0;
124 }
125 qm.header.size = htons (sizeof (struct QueryMessage));
126 qm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY);
127 qm.reserved = htonl (0);
128 qm.key = q->key;
129 memcpy (buf, &qm, sizeof (struct QueryMessage));
130 GNUNET_CLIENT_receive (q->client,
131 &handle_revocation_query_response,
132 q,
133 GNUNET_TIME_UNIT_FOREVER_REL);
134 return sizeof (struct QueryMessage);
135}
136
137
138/**
67 * Check if a key was revoked. 139 * Check if a key was revoked.
68 * 140 *
69 * @param cfg the configuration to use 141 * @param cfg the configuration to use
@@ -81,11 +153,22 @@ GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
81 153
82 q = GNUNET_new (struct GNUNET_REVOCATION_Query); 154 q = GNUNET_new (struct GNUNET_REVOCATION_Query);
83 q->client = GNUNET_CLIENT_connect ("revocation", cfg); 155 q->client = GNUNET_CLIENT_connect ("revocation", cfg);
156 if (NULL == q->client)
157 {
158 GNUNET_break (0);
159 GNUNET_free (q);
160 return NULL;
161 }
84 q->cfg = cfg; 162 q->cfg = cfg;
85 q->key = *key; 163 q->key = *key;
86 q->func = func; 164 q->func = func;
87 q->func_cls = func_cls; 165 q->func_cls = func_cls;
88 GNUNET_break (0); 166 q->th = GNUNET_CLIENT_notify_transmit_ready (q->client,
167 sizeof (struct QueryMessage),
168 GNUNET_TIME_UNIT_FOREVER_REL,
169 GNUNET_YES,
170 &send_revocation_query,
171 q);
89 return q; 172 return q;
90} 173}
91 174
@@ -98,6 +181,11 @@ GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
98void 181void
99GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q) 182GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q)
100{ 183{
184 if (NULL != q->th)
185 {
186 GNUNET_CLIENT_notify_transmit_ready_cancel (q->th);
187 q->th = NULL;
188 }
101 GNUNET_CLIENT_disconnect (q->client); 189 GNUNET_CLIENT_disconnect (q->client);
102 GNUNET_free (q); 190 GNUNET_free (q);
103} 191}
@@ -144,10 +232,87 @@ struct GNUNET_REVOCATION_Handle
144 */ 232 */
145 void *func_cls; 233 void *func_cls;
146 234
235 /**
236 * Transmission handle to the service.
237 */
238 struct GNUNET_CLIENT_TransmitHandle *th;
239
147}; 240};
148 241
149 242
150/** 243/**
244 * Handle response to our revocation query.
245 *
246 * @param cls our `struct GNUNET_REVOCATION_Handle` handle
247 * @param msg response we got, NULL on disconnect
248 */
249static void
250handle_revocation_response (void *cls,
251 const struct GNUNET_MessageHeader *msg)
252{
253 struct GNUNET_REVOCATION_Handle *h = cls;
254 const struct RevocationResponseMessage *rrm;
255
256 if ( (NULL == msg) ||
257 (sizeof (struct RevocationResponseMessage) != ntohs (msg->size)) ||
258 (GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE != ntohs (msg->type)) )
259 {
260 GNUNET_break (NULL == msg);
261 h->func (h->func_cls, GNUNET_SYSERR);
262 GNUNET_REVOCATION_revoke_cancel (h);
263 return;
264 }
265 rrm = (const struct RevocationResponseMessage *) msg;
266 h->func (h->func_cls, ntohl (rrm->is_valid));
267 GNUNET_REVOCATION_revoke_cancel (h);
268
269}
270
271
272/**
273 * Transmit our revocation to the service.
274 *
275 * @param cls our `struct GNUNET_REVOCATION_Handle` handle
276 * @param size number of bytes available in @a buf
277 * @param buf where to copy the query
278 * @return number of bytes copied to @a buf
279 */
280static size_t
281send_revoke (void *cls,
282 size_t size,
283 void *buf)
284{
285 struct GNUNET_REVOCATION_Handle *h = cls;
286 struct RevokeMessage rm;
287
288 h->th = NULL;
289 if ( (NULL == buf) ||
290 (sizeof (struct RevokeMessage) > size) )
291 {
292 GNUNET_break (0);
293 h->func (h->func_cls, GNUNET_SYSERR);
294 GNUNET_REVOCATION_revoke_cancel (h);
295 return 0;
296 }
297 rm.header.size = htons (sizeof (struct QueryMessage));
298 rm.header.type = htons (GNUNET_MESSAGE_TYPE_REVOCATION_QUERY);
299 rm.reserved = htonl (0);
300 rm.proof_of_work = h->pow;
301 rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
302 rm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
303 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey));
304 rm.public_key = h->key;
305 rm.signature = h->sig;
306 memcpy (buf, &rm, sizeof (struct RevokeMessage));
307 GNUNET_CLIENT_receive (h->client,
308 &handle_revocation_response,
309 h,
310 GNUNET_TIME_UNIT_FOREVER_REL);
311 return sizeof (struct RevokeMessage);
312}
313
314
315/**
151 * Perform key revocation. 316 * Perform key revocation.
152 * 317 *
153 * @param cfg the configuration to use 318 * @param cfg the configuration to use
@@ -170,7 +335,20 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
170 GNUNET_REVOCATION_Callback func, void *func_cls) 335 GNUNET_REVOCATION_Callback func, void *func_cls)
171{ 336{
172 struct GNUNET_REVOCATION_Handle *h; 337 struct GNUNET_REVOCATION_Handle *h;
173 338 unsigned long long matching_bits;
339
340 if ( (GNUNET_OK ==
341 GNUNET_CONFIGURATION_get_value_number (cfg,
342 "REVOCATION",
343 "WORKBITS",
344 &matching_bits)) &&
345 (GNUNET_YES !=
346 GNUNET_REVOCATION_check_pow (key, pow,
347 (unsigned int) matching_bits)) )
348 {
349 GNUNET_break (0);
350 return NULL;
351 }
174 h = GNUNET_new (struct GNUNET_REVOCATION_Handle); 352 h = GNUNET_new (struct GNUNET_REVOCATION_Handle);
175 h->client = GNUNET_CLIENT_connect ("revocation", cfg); 353 h->client = GNUNET_CLIENT_connect ("revocation", cfg);
176 h->cfg = cfg; 354 h->cfg = cfg;
@@ -179,7 +357,12 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
179 h->pow = pow; 357 h->pow = pow;
180 h->func = func; 358 h->func = func;
181 h->func_cls = func_cls; 359 h->func_cls = func_cls;
182 GNUNET_break (0); 360 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
361 sizeof (struct RevokeMessage),
362 GNUNET_TIME_UNIT_FOREVER_REL,
363 GNUNET_YES,
364 &send_revoke,
365 h);
183 return h; 366 return h;
184} 367}
185 368
@@ -192,6 +375,11 @@ GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
192void 375void
193GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h) 376GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
194{ 377{
378 if (NULL != h->th)
379 {
380 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
381 h->th = NULL;
382 }
195 GNUNET_CLIENT_disconnect (h->client); 383 GNUNET_CLIENT_disconnect (h->client);
196 GNUNET_free (h); 384 GNUNET_free (h);
197} 385}
@@ -276,7 +464,7 @@ void
276GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EccPrivateKey *key, 464GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EccPrivateKey *key,
277 struct GNUNET_CRYPTO_EccSignature *sig) 465 struct GNUNET_CRYPTO_EccSignature *sig)
278{ 466{
279 struct GNUNET_REVOCATION_RevokeMessage rm; 467 struct RevokeMessage rm;
280 468
281 rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); 469 rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
282 rm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 470 rm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +