aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim_tickets.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-19 19:05:23 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-20 17:59:01 +0200
commite75869506cc08e08056168383bd4ab02e1f007de (patch)
treeb4617425e38fbd7070f6a6d7cd41544a7f41df5d /src/reclaim/gnunet-service-reclaim_tickets.c
parent1ca1140d4602dcc5c66da0d1ab1b082db9258ead (diff)
downloadgnunet-e75869506cc08e08056168383bd4ab02e1f007de.tar.gz
gnunet-e75869506cc08e08056168383bd4ab02e1f007de.zip
- towards separation between credentials and presentations thereof, wip, ftbfs
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim_tickets.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c194
1 files changed, 102 insertions, 92 deletions
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index af01d8ec7..18b173aaa 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -114,9 +114,9 @@ struct RECLAIM_TICKETS_ConsumeHandle
114 struct GNUNET_RECLAIM_AttributeList *attrs; 114 struct GNUNET_RECLAIM_AttributeList *attrs;
115 115
116 /** 116 /**
117 * Attestations 117 * Credentials
118 */ 118 */
119 struct GNUNET_RECLAIM_AttestationList *attests; 119 struct GNUNET_RECLAIM_CredentialList *credentials;
120 120
121 /** 121 /**
122 * Lookup time 122 * Lookup time
@@ -715,20 +715,20 @@ rvk_move_attr_cb (void *cls,
715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); 715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label);
716 GNUNET_free (claim); 716 GNUNET_free (claim);
717 } 717 }
718 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type) 718 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_CREDENTIAL == rd[i].record_type)
719 { 719 {
720 struct GNUNET_RECLAIM_Attestation *attest; 720 struct GNUNET_RECLAIM_Credential *credential;
721 attest = GNUNET_RECLAIM_attestation_deserialize (rd[i].data, 721 credential = GNUNET_RECLAIM_credential_deserialize (rd[i].data,
722 rd[i].data_size); 722 rd[i].data_size);
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Attestation to update: Name=%s\n", 724 "Credential to update: Name=%s\n",
725 attest->name); 725 credential->name);
726 attest->id = rvk->move_attr->new_id; 726 credential->id = rvk->move_attr->new_id;
727 new_rd[i].data_size = 727 new_rd[i].data_size =
728 GNUNET_RECLAIM_attestation_serialize_get_size (attest); 728 GNUNET_RECLAIM_credential_serialize_get_size (credential);
729 attr_data = GNUNET_malloc (rd[i].data_size); 729 attr_data = GNUNET_malloc (rd[i].data_size);
730 new_rd[i].data_size = GNUNET_RECLAIM_attestation_serialize (attest, 730 new_rd[i].data_size = GNUNET_RECLAIM_credential_serialize (credential,
731 attr_data); 731 attr_data);
732 new_rd[i].data = attr_data; 732 new_rd[i].data = attr_data;
733 new_rd[i].record_type = rd[i].record_type; 733 new_rd[i].record_type = rd[i].record_type;
734 new_rd[i].flags = rd[i].flags; 734 new_rd[i].flags = rd[i].flags;
@@ -736,9 +736,9 @@ rvk_move_attr_cb (void *cls,
736 new_label = 736 new_label =
737 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, 737 GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id,
738 sizeof (rvk->move_attr->new_id)); 738 sizeof (rvk->move_attr->new_id));
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation %s\n", 739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding credential %s\n",
740 new_label); 740 new_label);
741 GNUNET_free (attest); 741 GNUNET_free (credential);
742 } 742 }
743 } 743 }
744 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 744 rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
@@ -981,8 +981,8 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth)
981 981
982 if (NULL != cth->attrs) 982 if (NULL != cth->attrs)
983 GNUNET_RECLAIM_attribute_list_destroy (cth->attrs); 983 GNUNET_RECLAIM_attribute_list_destroy (cth->attrs);
984 if (NULL != cth->attests) 984 if (NULL != cth->credentials)
985 GNUNET_RECLAIM_attestation_list_destroy (cth->attests); 985 GNUNET_RECLAIM_credential_list_destroy (cth->credentials);
986 GNUNET_free (cth); 986 GNUNET_free (cth);
987} 987}
988 988
@@ -1027,40 +1027,20 @@ process_parallel_lookup_result (void *cls,
1027 // REMARK: It is possible now to find rd_count > 1 1027 // REMARK: It is possible now to find rd_count > 1
1028 for (int i = 0; i < rd_count; i++) 1028 for (int i = 0; i < rd_count; i++)
1029 { 1029 {
1030 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type) 1030 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE != rd[i].record_type)
1031 {
1032 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1033 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
1034 &attr_le->attribute);
1035 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1036 cth->attrs->list_tail,
1037 attr_le);
1038 }
1039 else if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION == rd[i].record_type)
1040 {
1041 struct GNUNET_RECLAIM_AttestationListEntry *ale;
1042 ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry);
1043 ale->attestation =
1044 GNUNET_RECLAIM_attestation_deserialize (rd[i].data,
1045 rd[i].data_size);
1046 GNUNET_CONTAINER_DLL_insert (cth->attests->list_head,
1047 cth->attests->list_tail,
1048 ale);
1049 }
1050 else
1051 {
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1053 "Parallel Lookup of Reference without Attestation");
1054 continue; 1031 continue;
1055 } 1032 attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
1056 1033 GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
1057 1034 &attr_le->attribute);
1035 GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
1036 cth->attrs->list_tail,
1037 attr_le);
1058 } 1038 }
1059 if (NULL != cth->parallel_lookups_head) 1039 if (NULL != cth->parallel_lookups_head)
1060 return; // Wait for more 1040 return; // Wait for more
1061 /* Else we are done */ 1041 /* Else we are done */
1062 cth->cb (cth->cb_cls, &cth->ticket.identity, 1042 cth->cb (cth->cb_cls, &cth->ticket.identity,
1063 cth->attrs, cth->attests, GNUNET_OK, NULL); 1043 cth->attrs, cth->credentials, GNUNET_OK, NULL);
1064 cleanup_cth (cth); 1044 cleanup_cth (cth);
1065} 1045}
1066 1046
@@ -1126,26 +1106,45 @@ lookup_authz_cb (void *cls,
1126 1106
1127 for (int i = 0; i < rd_count; i++) 1107 for (int i = 0; i < rd_count; i++)
1128 { 1108 {
1129 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && 1109 /**
1130 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type)) 1110 * Check if record is a credential presentation or an attribute
1131 continue; 1111 * reference.
1132 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); 1112 */
1133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl); 1113 switch (rd[i].record_type)
1134 parallel_lookup = GNUNET_new (struct ParallelLookup); 1114 {
1135 parallel_lookup->handle = cth; 1115 case GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION:
1136 parallel_lookup->label = lbl; 1116 struct GNUNET_RECLAIM_CredentialListEntry *ale;
1137 parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); 1117 ale = GNUNET_new (struct GNUNET_RECLAIM_CredentialListEntry);
1138 parallel_lookup->lookup_request = 1118 ale->credential =
1139 GNUNET_GNS_lookup (gns, 1119 GNUNET_RECLAIM_credential_deserialize (rd[i].data,
1140 lbl, 1120 rd[i].data_size);
1141 &cth->ticket.identity, 1121 GNUNET_CONTAINER_DLL_insert (cth->credentials->list_head,
1142 GNUNET_GNSRECORD_TYPE_ANY, 1122 cth->credentials->list_tail,
1143 GNUNET_GNS_LO_DEFAULT, 1123 ale);
1144 &process_parallel_lookup_result, 1124 break;
1145 parallel_lookup); 1125 case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF:
1146 GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, 1126 lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size);
1147 cth->parallel_lookups_tail, 1127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ticket reference found %s\n", lbl);
1148 parallel_lookup); 1128 parallel_lookup = GNUNET_new (struct ParallelLookup);
1129 parallel_lookup->handle = cth;
1130 parallel_lookup->label = lbl;
1131 parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get ();
1132 parallel_lookup->lookup_request =
1133 GNUNET_GNS_lookup (gns,
1134 lbl,
1135 &cth->ticket.identity,
1136 GNUNET_GNSRECORD_TYPE_ANY,
1137 GNUNET_GNS_LO_DEFAULT,
1138 &process_parallel_lookup_result,
1139 parallel_lookup);
1140 GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head,
1141 cth->parallel_lookups_tail,
1142 parallel_lookup);
1143 break;
1144 default:
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1146 "Ignoring unknown record type %d", rd[i].record_type);
1147 }
1149 } 1148 }
1150 /** 1149 /**
1151 * We started lookups. Add a timeout task. 1150 * We started lookups. Add a timeout task.
@@ -1163,7 +1162,7 @@ lookup_authz_cb (void *cls,
1163 * No references found, return empty attribute list 1162 * No references found, return empty attribute list
1164 */ 1163 */
1165 cth->cb (cth->cb_cls, &cth->ticket.identity, 1164 cth->cb (cth->cb_cls, &cth->ticket.identity,
1166 cth->attrs, cth->attests, GNUNET_OK, NULL); 1165 cth->attrs, cth->credentials, GNUNET_OK, NULL);
1167 cleanup_cth (cth); 1166 cleanup_cth (cth);
1168} 1167}
1169 1168
@@ -1193,7 +1192,7 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id,
1193 cth->identity = *id; 1192 cth->identity = *id;
1194 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub); 1193 GNUNET_CRYPTO_ecdsa_key_get_public (&cth->identity, &cth->identity_pub);
1195 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); 1194 cth->attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
1196 cth->attests = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); 1195 cth->credentials = GNUNET_new (struct GNUNET_RECLAIM_CredentialList);
1197 cth->ticket = *ticket; 1196 cth->ticket = *ticket;
1198 cth->cb = cb; 1197 cth->cb = cb;
1199 cth->cb_cls = cb_cls; 1198 cth->cb_cls = cb_cls;
@@ -1293,7 +1292,7 @@ issue_ticket (struct TicketIssueHandle *ih)
1293 for (le = ih->attrs->list_head; NULL != le; le = le->next) 1292 for (le = ih->attrs->list_head; NULL != le; le = le->next)
1294 attrs_count++; 1293 attrs_count++;
1295 1294
1296 // Worst case we have one attestation per attribute 1295 // Worst case we have one credential per attribute
1297 attrs_record = 1296 attrs_record =
1298 GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data)); 1297 GNUNET_malloc (2 * attrs_count * sizeof(struct GNUNET_GNSRECORD_Data));
1299 i = 0; 1298 i = 0;
@@ -1308,26 +1307,31 @@ issue_ticket (struct TicketIssueHandle *ih)
1308 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF; 1307 attrs_record[i].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF;
1309 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1308 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1310 i++; 1309 i++;
1311 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) 1310 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1312 { 1311 {
1312 struct GNUNET_RECLAIM_Presentation *pres;
1313 int j; 1313 int j;
1314 for (j = 0; j < i; j++) 1314 for (j = 0; j < i; j++)
1315 { 1315 {
1316 if (attrs_record[j].record_type 1316 if (attrs_record[j].record_type
1317 != GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF) 1317 != GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION)
1318 continue; 1318 continue;
1319 if (0 == memcmp (attrs_record[j].data, 1319 pres = attrs_record[j].data;
1320 &le->attribute->attestation, 1320 if (0 == memcmp (pres->credential_id,
1321 sizeof (le->attribute->attestation))) 1321 &le->attribute->credential,
1322 sizeof (le->attribute->credential)))
1322 break; 1323 break;
1323 } 1324 }
1324 if (j < i) 1325 if (j < i)
1325 continue; // Skip as we have already added this attestation. 1326 continue; // Skip as we have already added this credential presentation.
1326 attrs_record[i].data = &le->attribute->attestation; 1327 /**
1327 attrs_record[i].data_size = sizeof(le->attribute->attestation); 1328 * FIXME: Create a new presentation from the credential.
1329 */
1330 attrs_record[i].data = &le->attribute->credential;
1331 attrs_record[i].data_size = sizeof(le->attribute->credential);
1328 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us; 1332 attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
1329 attrs_record[i].record_type = 1333 attrs_record[i].record_type =
1330 GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF; 1334 GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION;
1331 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; 1335 attrs_record[i].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1332 i++; 1336 i++;
1333 } 1337 }
@@ -1401,22 +1405,23 @@ filter_tickets_cb (void *cls,
1401{ 1405{
1402 struct TicketIssueHandle *tih = cls; 1406 struct TicketIssueHandle *tih = cls;
1403 struct GNUNET_RECLAIM_Ticket *ticket = NULL; 1407 struct GNUNET_RECLAIM_Ticket *ticket = NULL;
1408 struct GNUNET_RECLAIM_Presentation *pres;
1404 1409
1405 // figure out the number of requested attributes 1410 // figure out the number of requested attributes
1406 struct GNUNET_RECLAIM_AttributeListEntry *le; 1411 struct GNUNET_RECLAIM_AttributeListEntry *le;
1407 unsigned int attr_cnt = 0; 1412 unsigned int attr_cnt = 0;
1408 unsigned int attest_cnt = 0; 1413 unsigned int cred_cnt = 0;
1409 1414
1410 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1415 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1411 { 1416 {
1412 attr_cnt++; 1417 attr_cnt++;
1413 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->attestation)) 1418 if (GNUNET_NO == GNUNET_RECLAIM_id_is_zero (&le->attribute->credential))
1414 attest_cnt++; 1419 pres_cnt++;
1415 } 1420 }
1416 1421
1417 // ticket search 1422 // ticket search
1418 unsigned int found_attrs_cnt = 0; 1423 unsigned int found_attrs_cnt = 0;
1419 unsigned int found_attests_cnt = 0; 1424 unsigned int found_pres_cnt = 0;
1420 1425
1421 for (int i = 0; i < rd_count; i++) 1426 for (int i = 0; i < rd_count; i++)
1422 { 1427 {
@@ -1436,20 +1441,25 @@ filter_tickets_cb (void *cls,
1436 } 1441 }
1437 1442
1438 // cmp requested attributes with ticket attributes 1443 // cmp requested attributes with ticket attributes
1439 if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF != rd[i].record_type) && 1444 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF == rd[i].record_type)
1440 (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF != rd[i].record_type))
1441 continue;
1442 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1443 { 1445 {
1444 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1446 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1445 &le->attribute->id)) 1447 {
1446 found_attrs_cnt++; 1448 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data,
1449 &le->attribute->id))
1450 found_attrs_cnt++;
1451 }
1447 } 1452 }
1448 for (le = tih->attrs->list_head; NULL != le; le = le->next) 1453 if (GNUNET_GNSRECORD_TYPE_RECLAIM_PRESENTATION == rd[i].record_type)
1449 { 1454 {
1450 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (rd[i].data, 1455 for (le = tih->attrs->list_head; NULL != le; le = le->next)
1451 &le->attribute->attestation)) 1456 {
1452 found_attests_cnt++; 1457 pres = rd[i].data;
1458 if (GNUNET_YES == GNUNET_RECLAIM_id_is_equal (pres->credential_id,
1459 &le->attribute->credential))
1460 found_pres_cnt++;
1461 // FIXME should we store credentials here for later use??
1462 }
1453 } 1463 }
1454 } 1464 }
1455 1465
@@ -1458,7 +1468,7 @@ filter_tickets_cb (void *cls,
1458 * we are done. 1468 * we are done.
1459 */ 1469 */
1460 if ((attr_cnt == found_attrs_cnt) && 1470 if ((attr_cnt == found_attrs_cnt) &&
1461 (attest_cnt == found_attests_cnt) && 1471 (pres_cnt == found_pres_cnt) &&
1462 (NULL != ticket)) 1472 (NULL != ticket))
1463 { 1473 {
1464 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it); 1474 GNUNET_NAMESTORE_zone_iteration_stop (tih->ns_it);