aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2017-10-07 10:37:42 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2017-10-07 10:37:42 +0200
commitfd111326e7c91616593ff361bdad61deea337aa9 (patch)
treea33bbf22f30a1ddbdf359e5b0b0d1a1f3385a3ab /src
parent58d4e0f0447ae4efc6b3f4ba8a3d612c22f7cbb4 (diff)
downloadgnunet-fd111326e7c91616593ff361bdad61deea337aa9.tar.gz
gnunet-fd111326e7c91616593ff361bdad61deea337aa9.zip
-finish revocation in service, cleanup
Diffstat (limited to 'src')
-rw-r--r--src/identity-provider/gnunet-service-identity-provider.c244
-rw-r--r--src/identity-provider/identity_provider.h21
-rw-r--r--src/include/gnunet_protocols.h16
3 files changed, 201 insertions, 80 deletions
diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c
index dd78dd9aa..62955b5da 100644
--- a/src/identity-provider/gnunet-service-identity-provider.c
+++ b/src/identity-provider/gnunet-service-identity-provider.c
@@ -314,6 +314,17 @@ struct IdpClient
314 * Tail of DLL of ticket iteration ops 314 * Tail of DLL of ticket iteration ops
315 */ 315 */
316 struct TicketIteration *ticket_iter_tail; 316 struct TicketIteration *ticket_iter_tail;
317
318
319 /**
320 * Head of DLL of ticket revocation ops
321 */
322 struct TicketRevocationHandle *revocation_list_head;
323
324 /**
325 * Tail of DLL of ticket revocation ops
326 */
327 struct TicketRevocationHandle *revocation_list_tail;
317}; 328};
318 329
319 330
@@ -446,6 +457,15 @@ struct ParallelLookup
446 */ 457 */
447struct TicketRevocationHandle 458struct TicketRevocationHandle
448{ 459{
460 /**
461 * DLL
462 */
463 struct TicketRevocationHandle *next;
464
465 /**
466 * DLL
467 */
468 struct TicketRevocationHandle *prev;
449 469
450 /** 470 /**
451 * Client connection 471 * Client connection
@@ -1135,15 +1155,104 @@ ticket_reissue_proc (void *cls,
1135} 1155}
1136 1156
1137 1157
1158/**********************************************************
1159 * Revocation
1160 **********************************************************/
1161
1162/**
1163 * Cleanup revoke handle
1164 */
1165static void
1166cleanup_revoke_ticket_handle (struct TicketRevocationHandle *handle)
1167{
1168 if (NULL != handle->attrs)
1169 attribute_list_destroy (handle->attrs);
1170 if (NULL != handle->abe_key)
1171 GNUNET_free (handle->abe_key);
1172 if (NULL != handle->ns_qe)
1173 GNUNET_NAMESTORE_cancel (handle->ns_qe);
1174 GNUNET_free (handle);
1175}
1176
1177/**
1178 * Send revocation result
1179 */
1180static void
1181send_revocation_finished (struct TicketRevocationHandle *rh,
1182 uint32_t success)
1183{
1184 struct GNUNET_MQ_Envelope *env;
1185 struct RevokeTicketResultMessage *trm;
1186
1187 env = GNUNET_MQ_msg (trm,
1188 GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT);
1189 trm->id = htonl (rh->r_id);
1190 trm->success = htonl (success);
1191 GNUNET_MQ_send (rh->client->mq,
1192 env);
1193 GNUNET_CONTAINER_DLL_remove (rh->client->revocation_list_head,
1194 rh->client->revocation_list_tail,
1195 rh);
1196 cleanup_revoke_ticket_handle (rh);
1197}
1198
1199/* Prototype for below function */
1138static void 1200static void
1139attr_reenc_cont (void *cls, 1201attr_reenc_cont (void *cls,
1140 int32_t success, 1202 int32_t success,
1141 const char *emsg) 1203 const char *emsg);
1204
1205/**
1206 * Revoke next attribte by reencryption with
1207 * new ABE master
1208 */
1209static void
1210reenc_next_attribute (struct TicketRevocationHandle *rh)
1142{ 1211{
1143 struct TicketRevocationHandle *rh = cls;
1144 struct GNUNET_GNSRECORD_Data rd[1]; 1212 struct GNUNET_GNSRECORD_Data rd[1];
1213 char* buf;
1145 size_t buf_size; 1214 size_t buf_size;
1146 char *buf; 1215
1216 buf_size = attribute_serialize_get_size (rh->attrs->list_head->attribute);
1217 buf = GNUNET_malloc (buf_size);
1218
1219 attribute_serialize (rh->attrs->list_head->attribute,
1220 buf);
1221
1222 /**
1223 * Encrypt the attribute value and store in namestore
1224 */
1225 rd[0].data_size = GNUNET_CRYPTO_cpabe_encrypt (buf,
1226 buf_size,
1227 rh->attrs->list_head->attribute->name, //Policy
1228 rh->abe_key,
1229 (void**)&rd[0].data);
1230 GNUNET_free (buf);
1231 rd[0].record_type = GNUNET_GNSRECORD_TYPE_ID_ATTR;
1232 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1233 rd[0].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; //TODO sane?
1234 rh->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
1235 &rh->identity,
1236 rh->attrs->list_head->attribute->name,
1237 1,
1238 rd,
1239 &attr_reenc_cont,
1240 rh);
1241 GNUNET_free ((void*)rd[0].data);
1242
1243}
1244
1245/**
1246 * Namestore callback after revoked attribute
1247 * is stored
1248 */
1249static void
1250attr_reenc_cont (void *cls,
1251 int32_t success,
1252 const char *emsg)
1253{
1254 struct TicketRevocationHandle *rh = cls;
1255 struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
1147 int ret; 1256 int ret;
1148 1257
1149 if (GNUNET_SYSERR == success) 1258 if (GNUNET_SYSERR == success)
@@ -1154,9 +1263,13 @@ attr_reenc_cont (void *cls,
1154 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1263 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1155 return; 1264 return;
1156 } 1265 }
1266 le = rh->attrs->list_head;
1157 GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head, 1267 GNUNET_CONTAINER_DLL_remove (rh->attrs->list_head,
1158 rh->attrs->list_tail, 1268 rh->attrs->list_tail,
1159 rh->attrs->list_head); 1269 rh->attrs->list_head);
1270 GNUNET_free (le->attribute);
1271 GNUNET_free (le);
1272
1160 if (NULL == rh->attrs->list_head) 1273 if (NULL == rh->attrs->list_head)
1161 { 1274 {
1162 /* Done, issue new keys */ 1275 /* Done, issue new keys */
@@ -1175,98 +1288,54 @@ attr_reenc_cont (void *cls,
1175 return; 1288 return;
1176 } 1289 }
1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1178 "Re-encrypting attribute\n"); 1291 "Re-encrypting next attribute\n");
1179 buf_size = attribute_serialize_get_size (rh->attrs->list_head->attribute); 1292 reenc_next_attribute (rh);
1180 buf = GNUNET_malloc (buf_size);
1181
1182 attribute_serialize (rh->attrs->list_head->attribute,
1183 buf);
1184
1185 /**
1186 * Encrypt the attribute value and store in namestore
1187 */
1188 rd[0].data_size = GNUNET_CRYPTO_cpabe_encrypt (buf,
1189 buf_size,
1190 rh->attrs->list_head->attribute->name, //Policy
1191 rh->abe_key,
1192 (void**)&rd[0].data);
1193 GNUNET_free (buf);
1194 rd[0].record_type = GNUNET_GNSRECORD_TYPE_ID_ATTR;
1195 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1196 rd[0].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; //TODO sane?
1197 rh->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
1198 &rh->identity,
1199 rh->attrs->list_head->attribute->name,
1200 1,
1201 rd,
1202 &attr_reenc_cont,
1203 rh);
1204 GNUNET_free ((void*)rd[0].data);
1205
1206} 1293}
1207 1294
1208 1295
1296/**
1297 * Start reencryption with newly generated ABE master
1298 */
1209static void 1299static void
1210reenc_after_abe_bootstrap (void *cls, 1300reenc_after_abe_bootstrap (void *cls,
1211 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 1301 struct GNUNET_CRYPTO_AbeMasterKey *abe_key)
1212{ 1302{
1213 struct TicketRevocationHandle *rh = cls; 1303 struct TicketRevocationHandle *rh = cls;
1214 struct GNUNET_GNSRECORD_Data rd[1]; 1304 GNUNET_free (rh->abe_key);
1215 char* buf;
1216 size_t buf_size;
1217
1218
1219 rh->abe_key = abe_key;
1220 GNUNET_assert (NULL != abe_key); 1305 GNUNET_assert (NULL != abe_key);
1306 rh->abe_key = abe_key;
1221 1307
1222 if (NULL == rh->attrs->list_head) 1308 if (NULL == rh->attrs->list_head)
1223 { 1309 {
1224 /* No attributes to reencrypt, this is odd... */ 1310 /* No attributes to reencrypt */
1225 GNUNET_break (0); 1311 send_revocation_finished (rh, GNUNET_OK);
1312 cleanup_revoke_ticket_handle (rh);
1313 return;
1226 } else { 1314 } else {
1227 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, 1315 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1228 "Revocation Phase III: Re-encrypting attributes\n"); 1316 "Revocation Phase III: Re-encrypting attributes\n");
1229 buf_size = attribute_serialize_get_size (rh->attrs->list_head->attribute); 1317 reenc_next_attribute (rh);
1230 buf = GNUNET_malloc (buf_size);
1231
1232 attribute_serialize (rh->attrs->list_head->attribute,
1233 buf);
1234
1235 /**
1236 * Encrypt the attribute value and store in namestore
1237 */
1238 rd[0].data_size = GNUNET_CRYPTO_cpabe_encrypt (buf,
1239 buf_size,
1240 rh->attrs->list_head->attribute->name, //Policy
1241 rh->abe_key,
1242 (void**)&rd[0].data);
1243 GNUNET_free (buf);
1244 rd[0].record_type = GNUNET_GNSRECORD_TYPE_ID_ATTR;
1245 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1246 rd[0].expiration_time = GNUNET_TIME_UNIT_HOURS.rel_value_us; //TODO sane?
1247 rh->ns_qe = GNUNET_NAMESTORE_records_store (ns_handle,
1248 &rh->identity,
1249 rh->attrs->list_head->attribute->name,
1250 1,
1251 rd,
1252 &attr_reenc_cont,
1253 rh);
1254 GNUNET_free ((void*)rd[0].data);
1255
1256 } 1318 }
1257} 1319}
1258 1320
1259 1321
1322/**
1323 * Collecting attributes failed... abort.
1324 */
1260static void 1325static void
1261revoke_collect_iter_error (void *cls) 1326revoke_collect_iter_error (void *cls)
1262{ 1327{
1263 //struct AttributeIterator *ai = cls; 1328 struct TicketRevocationHandle *rh = cls;
1264 //TODO 1329
1265 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1266 "Failed to iterate over attributes\n"); 1331 "Failed to iterate over attributes\n");
1267 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1332 send_revocation_finished (rh, GNUNET_SYSERR);
1333 cleanup_revoke_ticket_handle (rh);
1268} 1334}
1269 1335
1336/**
1337 * Done decrypting existing attributes.
1338 */
1270static void 1339static void
1271revoke_collect_iter_finished (void *cls) 1340revoke_collect_iter_finished (void *cls)
1272{ 1341{
@@ -1277,6 +1346,10 @@ revoke_collect_iter_finished (void *cls)
1277 bootstrap_abe (&rh->identity, &reenc_after_abe_bootstrap, rh, GNUNET_YES); 1346 bootstrap_abe (&rh->identity, &reenc_after_abe_bootstrap, rh, GNUNET_YES);
1278} 1347}
1279 1348
1349/**
1350 * Decrypt existing attribute and store it
1351 * We will revoke it by reencrypting it with a new ABE master key.
1352 */
1280static void 1353static void
1281revoke_collect_iter_cb (void *cls, 1354revoke_collect_iter_cb (void *cls,
1282 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1355 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
@@ -1320,7 +1393,9 @@ revoke_collect_iter_cb (void *cls,
1320 GNUNET_NAMESTORE_zone_iterator_next (rh->ns_it); 1393 GNUNET_NAMESTORE_zone_iterator_next (rh->ns_it);
1321} 1394}
1322 1395
1323 1396/**
1397 * Start attribute collection for revocation
1398 */
1324static void 1399static void
1325collect_after_abe_bootstrap (void *cls, 1400collect_after_abe_bootstrap (void *cls,
1326 struct GNUNET_CRYPTO_AbeMasterKey *abe_key) 1401 struct GNUNET_CRYPTO_AbeMasterKey *abe_key)
@@ -1395,6 +1470,9 @@ handle_revoke_ticket_message (void *cls,
1395 rh->identity = rm->identity; 1470 rh->identity = rm->identity;
1396 GNUNET_CRYPTO_ecdsa_key_get_public (&rh->identity, 1471 GNUNET_CRYPTO_ecdsa_key_get_public (&rh->identity,
1397 &rh->ticket.identity); 1472 &rh->ticket.identity);
1473 GNUNET_CONTAINER_DLL_insert (idp->revocation_list_head,
1474 idp->revocation_list_tail,
1475 rh);
1398 bootstrap_abe (&rh->identity, &collect_after_abe_bootstrap, rh, GNUNET_NO); 1476 bootstrap_abe (&rh->identity, &collect_after_abe_bootstrap, rh, GNUNET_NO);
1399 GNUNET_SERVICE_client_continue (idp->client); 1477 GNUNET_SERVICE_client_continue (idp->client);
1400 1478
@@ -2046,7 +2124,11 @@ struct TicketIterationProcResult
2046 2124
2047}; 2125};
2048 2126
2049 2127static void
2128cleanup_ticket_iter_handle (struct TicketIteration *ti)
2129{
2130 GNUNET_free (ti);
2131}
2050 2132
2051/** 2133/**
2052 * Process ticket from database 2134 * Process ticket from database
@@ -2125,7 +2207,7 @@ run_ticket_iteration_round (struct TicketIteration *ti)
2125 GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head, 2207 GNUNET_CONTAINER_DLL_remove (ti->client->ticket_iter_head,
2126 ti->client->ticket_iter_tail, 2208 ti->client->ticket_iter_tail,
2127 ti); 2209 ti);
2128 GNUNET_free (ti); 2210 cleanup_ticket_iter_handle (ti);
2129} 2211}
2130 2212
2131/** 2213/**
@@ -2188,7 +2270,7 @@ handle_ticket_iteration_stop (void *cls,
2188 GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head, 2270 GNUNET_CONTAINER_DLL_remove (client->ticket_iter_head,
2189 client->ticket_iter_tail, 2271 client->ticket_iter_tail,
2190 ti); 2272 ti);
2191 GNUNET_free (ti); 2273 cleanup_ticket_iter_handle (ti);
2192 GNUNET_SERVICE_client_continue (client->client); 2274 GNUNET_SERVICE_client_continue (client->client);
2193} 2275}
2194 2276
@@ -2319,6 +2401,8 @@ client_disconnect_cb (void *cls,
2319{ 2401{
2320 struct IdpClient *idp = app_ctx; 2402 struct IdpClient *idp = app_ctx;
2321 struct AttributeIterator *ai; 2403 struct AttributeIterator *ai;
2404 struct TicketIteration *ti;
2405 struct TicketRevocationHandle *rh;
2322 2406
2323 //TODO other operations 2407 //TODO other operations
2324 2408
@@ -2333,6 +2417,20 @@ client_disconnect_cb (void *cls,
2333 ai); 2417 ai);
2334 GNUNET_free (ai); 2418 GNUNET_free (ai);
2335 } 2419 }
2420 while (NULL != (rh = idp->revocation_list_head))
2421 {
2422 GNUNET_CONTAINER_DLL_remove (idp->revocation_list_head,
2423 idp->revocation_list_tail,
2424 rh);
2425 cleanup_revoke_ticket_handle (rh);
2426 }
2427 while (NULL != (ti = idp->ticket_iter_head))
2428 {
2429 GNUNET_CONTAINER_DLL_remove (idp->ticket_iter_head,
2430 idp->ticket_iter_tail,
2431 ti);
2432 cleanup_ticket_iter_handle (ti);
2433 }
2336 GNUNET_free (idp); 2434 GNUNET_free (idp);
2337} 2435}
2338 2436
diff --git a/src/identity-provider/identity_provider.h b/src/identity-provider/identity_provider.h
index a4cdd694e..cb0f1591d 100644
--- a/src/identity-provider/identity_provider.h
+++ b/src/identity-provider/identity_provider.h
@@ -303,6 +303,27 @@ struct RevokeTicketMessage
303 //Followed by a ticket and serialized attribute list 303 //Followed by a ticket and serialized attribute list
304}; 304};
305 305
306/**
307 * Ticket revoke message
308 */
309struct RevokeTicketResultMessage
310{
311 /**
312 * Type will be #GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ISSUE
313 */
314 struct GNUNET_MessageHeader header;
315
316 /**
317 * Unique identifier for this request (for key collisions).
318 */
319 uint32_t id GNUNET_PACKED;
320
321 /**
322 * Revocation result
323 */
324 uint32_t success GNUNET_PACKED;
325};
326
306 327
307/** 328/**
308 * Ticket result message 329 * Ticket result message
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index bf643a9fd..6710d749f 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -2634,19 +2634,21 @@ extern "C"
2634 2634
2635#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET 967 2635#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_TICKET 967
2636 2636
2637#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET 968 2637#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT 968
2638 2638
2639#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_RESULT 969 2639#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET 969
2640 2640
2641#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET 970 2641#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_REVOKE_TICKET_RESULT 970
2642 2642
2643#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT 971 2643#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET 971
2644 2644
2645#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START 972 2645#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_CONSUME_TICKET_RESULT 972
2646 2646
2647#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP 973 2647#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_START 973
2648 2648
2649#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT 974 2649#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_STOP 974
2650
2651#define GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_TICKET_ITERATION_NEXT 975
2650 2652
2651/************************************************** 2653/**************************************************
2652 * 2654 *