aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>2019-10-25 12:13:25 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-01-13 13:31:03 +0100
commitdf903a80b2681567bf0b1afe9f1e3c89b13efbc2 (patch)
tree872819f349d6bb324215aaf2bfc9cdcbaffc2cd0
parentbb286cb253251e8210ed686dbde3dc8ecee16420 (diff)
downloadgnunet-df903a80b2681567bf0b1afe9f1e3c89b13efbc2.tar.gz
gnunet-df903a80b2681567bf0b1afe9f1e3c89b13efbc2.zip
Adding Reference Type Implemented
-rw-r--r--src/reclaim/gnunet-service-reclaim.c219
1 files changed, 219 insertions, 0 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 45b2a57c5..aea96e61e 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -338,6 +338,11 @@ struct AttributeStoreHandle
338 struct GNUNET_RECLAIM_ATTESTATION_Claim *attest; 338 struct GNUNET_RECLAIM_ATTESTATION_Claim *attest;
339 339
340 /** 340 /**
341 * The reference to store
342 */
343 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference;
344
345 /**
341 * The attribute expiration interval 346 * The attribute expiration interval
342 */ 347 */
343 struct GNUNET_TIME_Relative exp; 348 struct GNUNET_TIME_Relative exp;
@@ -500,6 +505,8 @@ cleanup_as_handle (struct AttributeStoreHandle *ash)
500 GNUNET_free (ash->claim); 505 GNUNET_free (ash->claim);
501 if (NULL != ash->attest) 506 if (NULL != ash->attest)
502 GNUNET_free (ash->attest); 507 GNUNET_free (ash->attest);
508 if (NULL != ash->reference)
509 GNUNET_free (ash->reference);
503 GNUNET_free (ash); 510 GNUNET_free (ash);
504} 511}
505 512
@@ -1170,6 +1177,214 @@ handle_attestation_store_message (void *cls,
1170} 1177}
1171 1178
1172/** 1179/**
1180 * Error looking up potential reference value. Abort.
1181 *
1182 * @param cls our attribute store handle
1183 */
1184static void
1185ref_error (void *cls)
1186{
1187 struct AttributeStoreHandle *ash = cls;
1188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1189 "Failed to find Attestation entry for Attestation reference\n");
1190 cleanup_as_handle (ash);
1191 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1192 return;
1193}
1194
1195/**
1196* Reference store result handler
1197*
1198* @param cls our attribute store handle
1199* @param success GNUNET_OK if successful
1200* @param emsg error message (NULL if success=GNUNET_OK)
1201*/
1202static void
1203reference_store_cont (void *cls, int32_t success, const char *emsg)
1204{
1205 struct AttributeStoreHandle *ash = cls;
1206 struct GNUNET_MQ_Envelope *env;
1207 struct SuccessResultMessage *acr_msg;
1208
1209 ash->ns_qe = NULL;
1210 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head,
1211 ash->client->store_op_tail,
1212 ash);
1213
1214 if (GNUNET_SYSERR == success)
1215 {
1216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1217 "Failed to store reference %s\n",
1218 emsg);
1219 cleanup_as_handle (ash);
1220 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1221 return;
1222 }
1223
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1225 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1226 acr_msg->id = htonl (ash->r_id);
1227 acr_msg->op_result = htonl (GNUNET_OK);
1228 GNUNET_MQ_send (ash->client->mq, env);
1229 cleanup_as_handle (ash);
1230}
1231
1232/**
1233* Check for existing record before storing reference
1234*
1235* @param cls our attribute store handle
1236* @param zone zone we are iterating
1237* @param label label of the records
1238* @param rd_count record count
1239* @param rd records
1240*/
1241static void
1242ref_add_cb (void *cls,
1243 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1244 const char *label,
1245 unsigned int rd_count,
1246 const struct GNUNET_GNSRECORD_Data *rd)
1247{
1248 struct AttributeStoreHandle *ash = cls;
1249 char *buf;
1250 size_t buf_size;
1251 buf_size = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (ash->reference);
1252 buf = GNUNET_malloc (buf_size);
1253 GNUNET_RECLAIM_ATTESTATION_REF_serialize (ash->reference, buf);
1254 if (0 == rd_count )
1255 {
1256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1257 "Failed to find Attestation entry for Attestation reference\n");
1258 cleanup_as_handle (ash);
1259 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1260 return;
1261 }
1262 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type)
1263 {
1264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1265 "Intended Reference storage location is not an attestation\n");
1266 cleanup_as_handle (ash);
1267 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1268 return;
1269 }
1270 struct GNUNET_GNSRECORD_Data rd_new[rd_count + 1];
1271 int i;
1272 for (i = 0; i<rd_count; i++)
1273 {
1274 rd_new[i] = rd[i];
1275 }
1276 rd_new[rd_count].data_size = buf_size;
1277 rd_new[rd_count].data = buf;
1278 rd_new[rd_count].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_REF;
1279 rd_new[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1280 rd_new[rd_count].expiration_time = ash->exp.rel_value_us;
1281 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1282 &ash->identity,
1283 label,
1284 rd_count + 1,
1285 rd_new,
1286 &reference_store_cont,
1287 ash);
1288 GNUNET_free (buf);
1289}
1290
1291/**
1292 * Add a new reference
1293 *
1294 * @param cls the AttributeStoreHandle
1295 */
1296static void
1297reference_store_task (void *cls)
1298{
1299 struct AttributeStoreHandle *ash = cls;
1300 char *label;
1301
1302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing reference\n");
1303
1304 // Give the ash a new id if unset
1305 if (0 == ash->reference->id)
1306 {
1307 if (0 == ash->reference->id_attest)
1308 {
1309 ash->reference->id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
1310 UINT64_MAX);
1311 }
1312 else
1313 {
1314 ash->reference->id = ash->reference->id_attest;
1315 }
1316 }
1317
1318 label = GNUNET_STRINGS_data_to_string_alloc (&ash->reference->id,
1319 sizeof(uint64_t));
1320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1321// Test for the content of the existing ID
1322
1323 ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
1324 &ash->identity,
1325 label,
1326 &ref_error,
1327 ash,
1328 &ref_add_cb,
1329 ash);
1330 GNUNET_free (label);
1331}
1332
1333/**
1334 * Check an attestation reference store message
1335 *
1336 * @param cls unused
1337 * @param sam the message to check
1338 */
1339static int
1340check_reference_store_message (void *cls,
1341 const struct
1342 AttributeStoreMessage *sam)
1343{
1344 uint16_t size;
1345
1346 size = ntohs (sam->header.size);
1347 if (size <= sizeof(struct AttributeStoreMessage))
1348 {
1349 GNUNET_break (0);
1350 return GNUNET_SYSERR;
1351 }
1352 return GNUNET_OK;
1353}
1354
1355
1356/**
1357 * Handle an attestation reference store message
1358 *
1359 * @param cls our client
1360 * @param sam the message to handle
1361 */
1362static void
1363handle_reference_store_message (void *cls,
1364 const struct AttributeStoreMessage *sam)
1365{
1366 struct AttributeStoreHandle *ash;
1367 struct IdpClient *idp = cls;
1368 size_t data_len;
1369
1370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received REFERENCE_STORE message\n");
1371
1372 data_len = ntohs (sam->attr_len);
1373 ash = GNUNET_new (struct AttributeStoreHandle);
1374 ash->reference = GNUNET_RECLAIM_ATTESTATION_REF_deserialize ((char *) &sam[1],
1375 data_len);
1376 ash->r_id = ntohl (sam->id);
1377 ash->identity = sam->identity;
1378 ash->exp.rel_value_us = GNUNET_ntohll (sam->exp);
1379 GNUNET_CRYPTO_ecdsa_key_get_public (&sam->identity, &ash->identity_pkey);
1380
1381
1382 GNUNET_SERVICE_client_continue (idp->client);
1383 ash->client = idp;
1384 GNUNET_CONTAINER_DLL_insert (idp->store_op_head, idp->store_op_tail, ash);
1385 GNUNET_SCHEDULER_add_now (&reference_store_task, ash);
1386}
1387/**
1173 * Send a deletion success response 1388 * Send a deletion success response
1174 * 1389 *
1175 * @param adh our attribute deletion handle 1390 * @param adh our attribute deletion handle
@@ -2019,6 +2234,10 @@ GNUNET_SERVICE_MAIN (
2019 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE, 2234 GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_DELETE,
2020 struct AttributeDeleteMessage, 2235 struct AttributeDeleteMessage,
2021 NULL), 2236 NULL),
2237 GNUNET_MQ_hd_var_size (reference_store_message,
2238 GNUNET_MESSAGE_TYPE_RECLAIM_REFERENCE_STORE,
2239 struct AttributeStoreMessage,
2240 NULL),
2022 GNUNET_MQ_hd_fixed_size ( 2241 GNUNET_MQ_hd_fixed_size (
2023 iteration_start, 2242 iteration_start,
2024 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START, 2243 GNUNET_MESSAGE_TYPE_RECLAIM_ATTRIBUTE_ITERATION_START,