aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim.c
diff options
context:
space:
mode:
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>2019-10-13 16:31:17 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-01-13 13:31:02 +0100
commit2c65283b0bd97a8719f4c71aee8cc091a491129a (patch)
tree61f1644f36c111342edbd1d19dfd3212b659da04 /src/reclaim/gnunet-service-reclaim.c
parentd5178cdc05a0d91293d9ee2cef45ab9a1c515bac (diff)
downloadgnunet-2c65283b0bd97a8719f4c71aee8cc091a491129a.tar.gz
gnunet-2c65283b0bd97a8719f4c71aee8cc091a491129a.zip
Add Attestations via Reclaim Service
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index a83ea05a6..d6c93812f 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -328,6 +328,11 @@ struct AttributeStoreHandle
328 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim; 328 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
329 329
330 /** 330 /**
331 * The attestation to store
332 */
333 struct GNUNET_RECLAIM_ATTESTATION_Claim *attest;
334
335 /**
331 * The attribute expiration interval 336 * The attribute expiration interval
332 */ 337 */
333 struct GNUNET_TIME_Relative exp; 338 struct GNUNET_TIME_Relative exp;
@@ -486,6 +491,8 @@ cleanup_as_handle (struct AttributeStoreHandle *ash)
486 GNUNET_NAMESTORE_cancel (ash->ns_qe); 491 GNUNET_NAMESTORE_cancel (ash->ns_qe);
487 if (NULL != ash->claim) 492 if (NULL != ash->claim)
488 GNUNET_free (ash->claim); 493 GNUNET_free (ash->claim);
494 if (NULL != ash->attest)
495 GNUNET_free (ash->attest);
489 GNUNET_free (ash); 496 GNUNET_free (ash);
490} 497}
491 498
@@ -1023,6 +1030,139 @@ handle_attribute_store_message (void *cls,
1023 1030
1024 1031
1025/** 1032/**
1033 * Attestation store result handler
1034 *
1035 * @param cls our attribute store handle
1036 * @param success GNUNET_OK if successful
1037 * @param emsg error message (NULL if success=GNUNET_OK)
1038 */
1039static void
1040attest_store_cont (void *cls, int32_t success, const char *emsg)
1041{
1042 struct AttributeStoreHandle *ash = cls;
1043 struct GNUNET_MQ_Envelope *env;
1044 struct SuccessResultMessage *acr_msg;
1045
1046 ash->ns_qe = NULL;
1047 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head,
1048 ash->client->store_op_tail,
1049 ash);
1050
1051 if (GNUNET_SYSERR == success)
1052 {
1053 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1054 "Failed to store attestation %s\n",
1055 emsg);
1056 cleanup_as_handle (ash);
1057 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1058 return;
1059 }
1060
1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1062 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1063 acr_msg->id = htonl (ash->r_id);
1064 acr_msg->op_result = htonl (GNUNET_OK);
1065 GNUNET_MQ_send (ash->client->mq, env);
1066 cleanup_as_handle (ash);
1067}
1068
1069/**
1070 * Add a new attestation
1071 *
1072 * @param cls the AttributeStoreHandle
1073 */
1074static void
1075attest_store_task (void *cls)
1076{
1077 struct AttributeStoreHandle *ash = cls;
1078 struct GNUNET_GNSRECORD_Data rd[1];
1079 char *buf;
1080 char *label;
1081 size_t buf_size;
1082
1083 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attestation\n");
1084 buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest);
1085 buf = GNUNET_malloc (buf_size);
1086 // Give the ash a new id if unset
1087 if (0 == ash->attest->id)
1088 ash->attest->id
1089 = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
1090 GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf);
1091 label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id,
1092 sizeof(uint64_t));
1093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1094
1095 rd[0].data_size = buf_size;
1096 rd[0].data = buf;
1097 rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR;
1098 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1099 rd[0].expiration_time = ash->exp.rel_value_us;
1100 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1101 &ash->identity,
1102 label,
1103 1,
1104 rd,
1105 &attest_store_cont,
1106 ash);
1107 GNUNET_free (buf);
1108 GNUNET_free (label);
1109}
1110
1111/**
1112 * Check an attestation store message
1113 *
1114 * @param cls unused
1115 * @param sam the message to check
1116 */
1117static int
1118check_attestation_store_message (void *cls,
1119 const struct AttributeStoreMessage *sam)
1120{
1121 uint16_t size;
1122
1123 size = ntohs (sam->header.size);
1124 if (size <= sizeof(struct AttributeStoreMessage))
1125 {
1126 GNUNET_break (0);
1127 return GNUNET_SYSERR;
1128 }
1129 return GNUNET_OK;
1130}
1131
1132/**
1133* Handle an attestation store message
1134*
1135* @param cls our client
1136* @param sam the message to handle
1137*/
1138static void
1139handle_attestation_store_message (void *cls,
1140 const struct AttributeStoreMessage *sam)
1141{
1142 struct AttributeStoreHandle *ash;
1143 struct IdpClient *idp = cls;
1144 size_t data_len;
1145
1146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ATTESTATION_STORE message\n");
1147
1148 data_len = ntohs (sam->attr_len);
1149
1150 ash = GNUNET_new (struct AttributeStoreHandle);
1151 ash->attest = GNUNET_RECLAIM_ATTESTATION_deserialize ((char *) &sam[1],
1152 data_len);
1153
1154 ash->r_id = ntohl (sam->id);
1155 ash->identity = sam->identity;
1156 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp);
1157 GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey);
1158
1159 GNUNET_SERVICE_client_continue (idp->client);
1160 ash->client = idp;
1161 GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash);
1162 GNUNET_SCHEDULER_add_now (&attest_store_task, ash);
1163}
1164
1165/**
1026 * Send a deletion success response 1166 * Send a deletion success response
1027 * 1167 *
1028 * @param adh our attribute deletion handle 1168 * @param adh our attribute deletion handle
@@ -1742,6 +1882,10 @@ GNUNET_SERVICE_MAIN (
1742 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE, 1882 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_STORE,
1743 struct AttributeStoreMessage, 1883 struct AttributeStoreMessage,
1744 NULL), 1884 NULL),
1885 GNUNET_MQ_hd_var_size (attestation_store_message,
1886 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_STORE,
1887 struct AttributeStoreMessage,
1888 NULL),
1745 GNUNET_MQ_hd_var_size (attribute_delete_message, 1889 GNUNET_MQ_hd_var_size (attribute_delete_message,
1746 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE, 1890 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_DELETE,
1747 struct AttributeDeleteMessage, 1891 struct AttributeDeleteMessage,