diff options
-rw-r--r-- | src/include/gnunet_protocols.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_reclaim_service.h | 19 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 114 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 64 | ||||
-rw-r--r-- | src/reclaim/reclaim_api.c | 43 |
5 files changed, 234 insertions, 8 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 8de779ad3..45b3c6728 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -2716,6 +2716,8 @@ extern "C" { | |||
2716 | 2716 | ||
2717 | #define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_STORE 977 | 2717 | #define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_STORE 977 |
2718 | 2718 | ||
2719 | #define GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE 978 | ||
2720 | |||
2719 | /************************************************** | 2721 | /************************************************** |
2720 | * | 2722 | * |
2721 | * ABD MESSAGE TYPES | 2723 | * ABD MESSAGE TYPES |
diff --git a/src/include/gnunet_reclaim_service.h b/src/include/gnunet_reclaim_service.h index a9061d6e8..0f63b0c96 100644 --- a/src/include/gnunet_reclaim_service.h +++ b/src/include/gnunet_reclaim_service.h | |||
@@ -191,7 +191,24 @@ GNUNET_RECLAIM_attribute_delete ( | |||
191 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 191 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
192 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); | 192 | GNUNET_RECLAIM_ContinuationWithStatus cont, void *cont_cls); |
193 | 193 | ||
194 | 194 | /** | |
195 | * Delete an attestation. Tickets used to share this attestation are updated | ||
196 | * accordingly. | ||
197 | * | ||
198 | * @param h handle to the re:claimID service | ||
199 | * @param pkey Private key of the identity to add an attribute to | ||
200 | * @param attr The attestation | ||
201 | * @param cont Continuation to call when done | ||
202 | * @param cont_cls Closure for @a cont | ||
203 | * @return handle Used to to abort the request | ||
204 | */ | ||
205 | struct GNUNET_RECLAIM_Operation * | ||
206 | GNUNET_RECLAIM_attestation_delete ( | ||
207 | struct GNUNET_RECLAIM_Handle *h, | ||
208 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
209 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, | ||
210 | GNUNET_RECLAIM_ContinuationWithStatus cont, | ||
211 | void *cont_cls); | ||
195 | /** | 212 | /** |
196 | * List all attributes for a local identity. | 213 | * List all attributes for a local identity. |
197 | * This MUST lock the `struct GNUNET_RECLAIM_Handle` | 214 | * This MUST lock the `struct GNUNET_RECLAIM_Handle` |
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index d6c93812f..7929d36d9 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -266,6 +266,11 @@ struct AttributeDeleteHandle | |||
266 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; | 266 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; |
267 | 267 | ||
268 | /** | 268 | /** |
269 | * The attestation to delete | ||
270 | */ | ||
271 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; | ||
272 | |||
273 | /** | ||
269 | * Tickets to update | 274 | * Tickets to update |
270 | */ | 275 | */ |
271 | struct TicketRecordsEntry *tickets_to_update_head; | 276 | struct TicketRecordsEntry *tickets_to_update_head; |
@@ -464,6 +469,8 @@ cleanup_adh (struct AttributeDeleteHandle *adh) | |||
464 | GNUNET_free (adh->label); | 469 | GNUNET_free (adh->label); |
465 | if (NULL != adh->claim) | 470 | if (NULL != adh->claim) |
466 | GNUNET_free (adh->claim); | 471 | GNUNET_free (adh->claim); |
472 | if (NULL != adh->attest) | ||
473 | GNUNET_free (adh->attest); | ||
467 | while (NULL != (le = adh->tickets_to_update_head)) | 474 | while (NULL != (le = adh->tickets_to_update_head)) |
468 | { | 475 | { |
469 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, | 476 | GNUNET_CONTAINER_DLL_remove (adh->tickets_to_update_head, |
@@ -1209,12 +1216,15 @@ ticket_iter (void *cls, | |||
1209 | 1216 | ||
1210 | for (int i = 0; i < rd_count; i++) | 1217 | for (int i = 0; i < rd_count; i++) |
1211 | { | 1218 | { |
1212 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 1219 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) && |
1220 | (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[i].record_type)) | ||
1213 | continue; | 1221 | continue; |
1214 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) | 1222 | if (0 != memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t))) |
1215 | continue; | 1223 | continue; |
1224 | if (0 != memcmp (rd[i].data, (&adh->attest->id), sizeof(uint64_t))) | ||
1225 | continue; | ||
1216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1217 | "Attribute to delete found (%s)\n", | 1227 | "Attribute or Attestation to delete found (%s)\n", |
1218 | adh->label); | 1228 | adh->label); |
1219 | has_changed = GNUNET_YES; | 1229 | has_changed = GNUNET_YES; |
1220 | break; | 1230 | break; |
@@ -1276,7 +1286,7 @@ update_tickets (void *cls) | |||
1276 | if (NULL == adh->tickets_to_update_head) | 1286 | if (NULL == adh->tickets_to_update_head) |
1277 | { | 1287 | { |
1278 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1288 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1279 | "Finished updatding tickets, success\n"); | 1289 | "Finished updating tickets, success\n"); |
1280 | send_delete_response (adh, GNUNET_OK); | 1290 | send_delete_response (adh, GNUNET_OK); |
1281 | cleanup_adh (adh); | 1291 | cleanup_adh (adh); |
1282 | return; | 1292 | return; |
@@ -1307,6 +1317,9 @@ update_tickets (void *cls) | |||
1307 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) | 1317 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) |
1308 | && (0 == memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t)))) | 1318 | && (0 == memcmp (rd[i].data, &adh->claim->id, sizeof(uint64_t)))) |
1309 | continue; | 1319 | continue; |
1320 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR == rd[i].record_type) | ||
1321 | && (0 == memcmp (rd[i].data, &adh->attest->id, sizeof(uint64_t)))) | ||
1322 | continue; | ||
1310 | rd_new[j] = rd[i]; | 1323 | rd_new[j] = rd[i]; |
1311 | j++; | 1324 | j++; |
1312 | } | 1325 | } |
@@ -1466,6 +1479,97 @@ handle_attribute_delete_message (void *cls, | |||
1466 | adh); | 1479 | adh); |
1467 | } | 1480 | } |
1468 | 1481 | ||
1482 | /** | ||
1483 | * Attestation deleted callback | ||
1484 | * | ||
1485 | * @param cls our handle | ||
1486 | * @param success success status | ||
1487 | * @param emsg error message (NULL if success=GNUNET_OK) | ||
1488 | */ | ||
1489 | static void | ||
1490 | attest_delete_cont (void *cls, int32_t success, const char *emsg) | ||
1491 | { | ||
1492 | struct AttributeDeleteHandle *adh = cls; | ||
1493 | |||
1494 | adh->ns_qe = NULL; | ||
1495 | if (GNUNET_SYSERR == success) | ||
1496 | { | ||
1497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1498 | "Error deleting attestation %s\n", | ||
1499 | adh->label); | ||
1500 | send_delete_response (adh, GNUNET_SYSERR); | ||
1501 | cleanup_adh (adh); | ||
1502 | return; | ||
1503 | } | ||
1504 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating tickets...\n"); | ||
1505 | GNUNET_SCHEDULER_add_now (&start_ticket_update, adh); | ||
1506 | } | ||
1507 | |||
1508 | /** | ||
1509 | * Check attestation delete message format | ||
1510 | * | ||
1511 | * @cls unused | ||
1512 | * @dam message to check | ||
1513 | */ | ||
1514 | static int | ||
1515 | check_attestation_delete_message (void *cls, | ||
1516 | const struct AttributeDeleteMessage *dam) | ||
1517 | { | ||
1518 | uint16_t size; | ||
1519 | |||
1520 | size = ntohs (dam->header.size); | ||
1521 | if (size <= sizeof(struct AttributeDeleteMessage)) | ||
1522 | { | ||
1523 | GNUNET_break (0); | ||
1524 | return GNUNET_SYSERR; | ||
1525 | } | ||
1526 | return GNUNET_OK; | ||
1527 | } | ||
1528 | |||
1529 | |||
1530 | /** | ||
1531 | * Handle attestation deletion | ||
1532 | * | ||
1533 | * @param cls our client | ||
1534 | * @param dam deletion message | ||
1535 | */ | ||
1536 | static void | ||
1537 | handle_attestation_delete_message (void *cls, | ||
1538 | const struct AttributeDeleteMessage *dam) | ||
1539 | { | ||
1540 | struct AttributeDeleteHandle *adh; | ||
1541 | struct IdpClient *idp = cls; | ||
1542 | size_t data_len; | ||
1543 | |||
1544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTESTATION_DELETE message\n"); | ||
1545 | |||
1546 | data_len = ntohs (dam->attr_len); | ||
1547 | |||
1548 | adh = GNUNET_new (struct AttributeDeleteHandle); | ||
1549 | adh->attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &dam[1], | ||
1550 | data_len); | ||
1551 | |||
1552 | adh->r_id = ntohl (dam->id); | ||
1553 | adh->identity = dam->identity; | ||
1554 | adh->label | ||
1555 | = GNUNET_STRINGS_data_to_string_alloc (&adh->attest->id, sizeof(uint64_t)); | ||
1556 | GNUNET_SERVICE_client_continue (idp->client); | ||
1557 | adh->client = idp; | ||
1558 | GNUNET_CONTAINER_DLL_insert (idp->delete_op_head, idp->delete_op_tail, adh); | ||
1559 | adh->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
1560 | &adh->identity, | ||
1561 | adh->label, | ||
1562 | 0, | ||
1563 | NULL, | ||
1564 | &attest_delete_cont, | ||
1565 | adh); | ||
1566 | } | ||
1567 | |||
1568 | |||
1569 | |||
1570 | |||
1571 | |||
1572 | |||
1469 | 1573 | ||
1470 | /************************************************* | 1574 | /************************************************* |
1471 | * Attrubute iteration | 1575 | * Attrubute iteration |
@@ -1890,6 +1994,10 @@ GNUNET_SERVICE_MAIN ( | |||
1890 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE, | 1994 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE, |
1891 | struct AttributeDeleteMessage, | 1995 | struct AttributeDeleteMessage, |
1892 | NULL), | 1996 | NULL), |
1997 | GNUNET_MQ_hd_var_size (attestation_delete_message, | ||
1998 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE, | ||
1999 | struct AttributeDeleteMessage, | ||
2000 | NULL), | ||
1893 | GNUNET_MQ_hd_fixed_size ( | 2001 | GNUNET_MQ_hd_fixed_size ( |
1894 | iteration_start, | 2002 | iteration_start, |
1895 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, | 2003 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 9290925b8..b847b773c 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -546,15 +546,71 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
546 | return; | 546 | return; |
547 | } | 547 | } |
548 | 548 | ||
549 | /*WIP*/ | 549 | /** |
550 | * Deletes attestation from an identity | ||
551 | * | ||
552 | * @param con_handle the connection handle | ||
553 | * @param url the url | ||
554 | * @param cls the RequestHandle | ||
555 | */ | ||
550 | static void | 556 | static void |
551 | delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 557 | delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, |
552 | const char *url, | 558 | const char *url, |
553 | void *cls) | 559 | void *cls) |
554 | { | 560 | { |
555 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting Attestations not supported\n"); | 561 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
556 | GNUNET_SCHEDULER_add_now (&do_error, cls); | 562 | struct RequestHandle *handle = cls; |
557 | return; | 563 | struct GNUNET_RECLAIM_ATTESTATION_Claim attr; |
564 | struct EgoEntry *ego_entry; | ||
565 | char *identity_id_str; | ||
566 | char *identity; | ||
567 | char *id; | ||
568 | |||
569 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attestation.\n"); | ||
570 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( | ||
571 | handle->url)) | ||
572 | { | ||
573 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
574 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
575 | return; | ||
576 | } | ||
577 | identity_id_str = | ||
578 | strdup (handle->url + strlen ( | ||
579 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1); | ||
580 | identity = strtok (identity_id_str, "/"); | ||
581 | id = strtok (NULL, "/"); | ||
582 | if ((NULL == identity) || (NULL == id)) | ||
583 | { | ||
584 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); | ||
585 | GNUNET_free (identity_id_str); | ||
586 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
587 | return; | ||
588 | } | ||
589 | |||
590 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
591 | ego_entry = ego_entry->next) | ||
592 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
593 | break; | ||
594 | handle->resp_object = json_array (); | ||
595 | if (NULL == ego_entry) | ||
596 | { | ||
597 | // Done | ||
598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | ||
599 | GNUNET_free (identity_id_str); | ||
600 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
601 | return; | ||
602 | } | ||
603 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
604 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
605 | memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim)); | ||
606 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(uint64_t)); | ||
607 | attr.name = ""; | ||
608 | handle->idp_op = GNUNET_RECLAIM_attestation_delete (handle->idp, | ||
609 | priv_key, | ||
610 | &attr, | ||
611 | &delete_finished_cb, | ||
612 | handle); | ||
613 | GNUNET_free (identity_id_str); | ||
558 | } | 614 | } |
559 | 615 | ||
560 | /** | 616 | /** |
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c index 988650450..ed07f78e1 100644 --- a/src/reclaim/reclaim_api.c +++ b/src/reclaim/reclaim_api.c | |||
@@ -973,6 +973,49 @@ GNUNET_RECLAIM_attestation_store ( | |||
973 | } | 973 | } |
974 | 974 | ||
975 | /** | 975 | /** |
976 | * Delete an attestation. Tickets used to share this attestation are updated | ||
977 | * accordingly. | ||
978 | * | ||
979 | * @param h handle to the re:claimID service | ||
980 | * @param pkey Private key of the identity to add an attribute to | ||
981 | * @param attr The attestation | ||
982 | * @param cont Continuation to call when done | ||
983 | * @param cont_cls Closure for @a cont | ||
984 | * @return handle Used to to abort the request | ||
985 | */ | ||
986 | struct GNUNET_RECLAIM_Operation * | ||
987 | GNUNET_RECLAIM_attestation_delete ( | ||
988 | struct GNUNET_RECLAIM_Handle *h, | ||
989 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
990 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, | ||
991 | GNUNET_RECLAIM_ContinuationWithStatus cont, | ||
992 | void *cont_cls) | ||
993 | { | ||
994 | struct GNUNET_RECLAIM_Operation *op; | ||
995 | struct AttributeDeleteMessage *dam; | ||
996 | size_t attr_len; | ||
997 | |||
998 | op = GNUNET_new (struct GNUNET_RECLAIM_Operation); | ||
999 | op->h = h; | ||
1000 | op->as_cb = cont; | ||
1001 | op->cls = cont_cls; | ||
1002 | op->r_id = h->r_id_gen++; | ||
1003 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | ||
1004 | attr_len = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (attr); | ||
1005 | op->env = GNUNET_MQ_msg_extra (dam, | ||
1006 | attr_len, | ||
1007 | GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE); | ||
1008 | dam->identity = *pkey; | ||
1009 | dam->id = htonl (op->r_id); | ||
1010 | GNUNET_RECLAIM_ATTESTATION_serialize (attr, (char *) &dam[1]); | ||
1011 | |||
1012 | dam->attr_len = htons (attr_len); | ||
1013 | if (NULL != h->mq) | ||
1014 | GNUNET_MQ_send_copy (h->mq, op->env); | ||
1015 | return op; | ||
1016 | } | ||
1017 | |||
1018 | /** | ||
976 | * List all attributes for a local identity. | 1019 | * List all attributes for a local identity. |
977 | * This MUST lock the `struct GNUNET_RECLAIM_Handle` | 1020 | * This MUST lock the `struct GNUNET_RECLAIM_Handle` |
978 | * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and | 1021 | * for any other calls than #GNUNET_RECLAIM_get_attributes_next() and |