aboutsummaryrefslogtreecommitdiff
path: root/src/revocation
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
parent2315ef124c25961fc88eadbf6b9d396de5d8f992 (diff)
downloadgnunet-ad989721684818bee9a0a1f81d5fb085241959ab.tar.gz
gnunet-ad989721684818bee9a0a1f81d5fb085241959ab.zip
-implementing revocation library
Diffstat (limited to 'src/revocation')
-rw-r--r--src/revocation/gnunet-service-revocation.c16
-rw-r--r--src/revocation/revocation.h24
-rw-r--r--src/revocation/revocation_api.c196
3 files changed, 221 insertions, 15 deletions
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index f310429d3..168f8c6ef 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -125,7 +125,7 @@ static unsigned long long revocation_work_required;
125 * #GNUNET_NO if the key/signature don't verify 125 * #GNUNET_NO if the key/signature don't verify
126 */ 126 */
127static int 127static int
128verify_revoke_message (const struct GNUNET_REVOCATION_RevokeMessage *rm) 128verify_revoke_message (const struct RevokeMessage *rm)
129{ 129{
130 if (GNUNET_YES != 130 if (GNUNET_YES !=
131 GNUNET_REVOCATION_check_pow (&rm->public_key, 131 GNUNET_REVOCATION_check_pow (&rm->public_key,
@@ -183,11 +183,11 @@ handle_revoke_message (void *cls,
183 struct GNUNET_SERVER_Client *client, 183 struct GNUNET_SERVER_Client *client,
184 const struct GNUNET_MessageHeader *message) 184 const struct GNUNET_MessageHeader *message)
185{ 185{
186 const struct GNUNET_REVOCATION_RevokeMessage *rm; 186 const struct RevokeMessage *rm;
187 187
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Received REVOKE message from client\n"); 189 "Received REVOKE message from client\n");
190 rm = (const struct GNUNET_REVOCATION_RevokeMessage *) message; 190 rm = (const struct RevokeMessage *) message;
191 if (GNUNET_OK != 191 if (GNUNET_OK !=
192 verify_revoke_message (rm)) 192 verify_revoke_message (rm))
193 { 193 {
@@ -211,12 +211,12 @@ handle_p2p_revoke_message (void *cls,
211 const struct GNUNET_PeerIdentity *peer, 211 const struct GNUNET_PeerIdentity *peer,
212 const struct GNUNET_MessageHeader *message) 212 const struct GNUNET_MessageHeader *message)
213{ 213{
214 const struct GNUNET_REVOCATION_RevokeMessage *rm; 214 const struct RevokeMessage *rm;
215 215
216 216
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "Received REVOKE message from peer\n"); 218 "Received REVOKE message from peer\n");
219 rm = (const struct GNUNET_REVOCATION_RevokeMessage *) message; 219 rm = (const struct RevokeMessage *) message;
220 if (GNUNET_OK != 220 if (GNUNET_OK !=
221 verify_revoke_message (rm)) 221 verify_revoke_message (rm))
222 { 222 {
@@ -375,14 +375,14 @@ run (void *cls,
375{ 375{
376 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 376 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
377 {&handle_query_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY, 377 {&handle_query_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_QUERY,
378 sizeof (struct GNUNET_REVOCATION_QueryMessage)}, 378 sizeof (struct QueryMessage)},
379 {&handle_revoke_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, 379 {&handle_revoke_message, NULL, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE,
380 sizeof (struct GNUNET_REVOCATION_RevokeMessage)}, 380 sizeof (struct RevokeMessage)},
381 {NULL, NULL, 0, 0} 381 {NULL, NULL, 0, 0}
382 }; 382 };
383 static const struct GNUNET_CORE_MessageHandler core_handlers[] = { 383 static const struct GNUNET_CORE_MessageHandler core_handlers[] = {
384 {&handle_p2p_revoke_message, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE, 384 {&handle_p2p_revoke_message, GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE,
385 sizeof (struct GNUNET_REVOCATION_RevokeMessage)}, 385 sizeof (struct RevokeMessage)},
386 {NULL, 0, 0} 386 {NULL, 0, 0}
387 }; 387 };
388 388
diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h
index c6c5d5e76..29235aeee 100644
--- a/src/revocation/revocation.h
+++ b/src/revocation/revocation.h
@@ -33,7 +33,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
33/** 33/**
34 * Query key revocation status. 34 * Query key revocation status.
35 */ 35 */
36struct GNUNET_REVOCATION_QueryMessage 36struct QueryMessage
37{ 37{
38 /** 38 /**
39 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY 39 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY
@@ -56,7 +56,7 @@ struct GNUNET_REVOCATION_QueryMessage
56/** 56/**
57 * Key revocation response. 57 * Key revocation response.
58 */ 58 */
59struct GNUNET_REVOCATION_QueryResponseMessage 59struct QueryResponseMessage
60{ 60{
61 /** 61 /**
62 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE 62 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_QUERY_RESPONSE
@@ -78,7 +78,7 @@ struct GNUNET_REVOCATION_QueryResponseMessage
78 * #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE (which is just 78 * #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE_RESPONSE (which is just
79 * in a `struct GNUNET_MessageHeader`. 79 * in a `struct GNUNET_MessageHeader`.
80 */ 80 */
81struct GNUNET_REVOCATION_RevokeMessage 81struct RevokeMessage
82{ 82{
83 /** 83 /**
84 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE 84 * Type: #GNUNET_MESSAGE_TYPE_REVOCATION_REVOKE
@@ -114,6 +114,24 @@ struct GNUNET_REVOCATION_RevokeMessage
114}; 114};
115 115
116 116
117/**
118 * Key revocation response.
119 */
120struct RevocationResponseMessage
121{
122 /**
123 * Type: #GNUNET_MESSAGE_TYPE_REVOKE_RESPONSE
124 */
125 struct GNUNET_MessageHeader header;
126
127 /**
128 * #GNUNET_NO if revoked, #GNUNET_YES if valid.
129 */
130 uint32_t is_valid GNUNET_PACKED;
131
132};
133
134
117GNUNET_NETWORK_STRUCT_END 135GNUNET_NETWORK_STRUCT_END
118 136
119 137
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) +