diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-11-29 13:00:18 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:05 +0100 |
commit | 76df96b59f803f9ba68849f452efbeed50d80086 (patch) | |
tree | 774df3681862e922231960ef238aa33b6a219048 | |
parent | 1267dec774294ec2dcc6d2b89bced85eb4fadaa7 (diff) | |
download | gnunet-76df96b59f803f9ba68849f452efbeed50d80086.tar.gz gnunet-76df96b59f803f9ba68849f452efbeed50d80086.zip |
Fixed Adding Attestations
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 166 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 28 |
2 files changed, 140 insertions, 54 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 8b7557090..5727f1ccd 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -1087,44 +1087,144 @@ attest_store_cont (void *cls, int32_t success, const char *emsg) | |||
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | /** | 1089 | /** |
1090 | * Add a new attestation | 1090 | * Send a reference error response |
1091 | * | ||
1092 | * @param ash our attribute store handle | ||
1093 | * @param success the success status | ||
1094 | */ | ||
1095 | static void | ||
1096 | send_ref_error (struct AttributeStoreHandle *ash) | ||
1097 | { | ||
1098 | struct GNUNET_MQ_Envelope *env; | ||
1099 | struct SuccessResultMessage *acr_msg; | ||
1100 | |||
1101 | ash->ns_qe = NULL; | ||
1102 | GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, | ||
1103 | ash->client->store_op_tail, | ||
1104 | ash); | ||
1105 | |||
1106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); | ||
1107 | env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); | ||
1108 | acr_msg->id = htonl (ash->r_id); | ||
1109 | acr_msg->op_result = htonl (GNUNET_SYSERR); | ||
1110 | GNUNET_MQ_send (ash->client->mq, env); | ||
1111 | cleanup_as_handle (ash); | ||
1112 | } | ||
1113 | |||
1114 | /** | ||
1115 | * Error looking up potential attestation. Abort. | ||
1091 | * | 1116 | * |
1092 | * @param cls the AttributeStoreHandle | 1117 | * @param cls our attribute store handle |
1093 | */ | 1118 | */ |
1094 | static void | 1119 | static void |
1095 | attest_store_task (void *cls) | 1120 | attest_error (void *cls) |
1121 | { | ||
1122 | struct AttributeStoreHandle *ash = cls; | ||
1123 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1124 | "Failed to check for existing Attestation\n"); | ||
1125 | cleanup_as_handle (ash); | ||
1126 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
1127 | return; | ||
1128 | } | ||
1129 | |||
1130 | /** | ||
1131 | * Check for existing record before storing reference | ||
1132 | * | ||
1133 | * @param cls our attribute store handle | ||
1134 | * @param zone zone we are iterating | ||
1135 | * @param label label of the records | ||
1136 | * @param rd_count record count | ||
1137 | * @param rd records | ||
1138 | */ | ||
1139 | static void | ||
1140 | attest_add_cb (void *cls, | ||
1141 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
1142 | const char *label, | ||
1143 | unsigned int rd_count, | ||
1144 | const struct GNUNET_GNSRECORD_Data *rd) | ||
1096 | { | 1145 | { |
1097 | struct AttributeStoreHandle *ash = cls; | 1146 | struct AttributeStoreHandle *ash = cls; |
1098 | struct GNUNET_GNSRECORD_Data rd[1]; | ||
1099 | char *buf; | 1147 | char *buf; |
1100 | char *label; | ||
1101 | size_t buf_size; | 1148 | size_t buf_size; |
1102 | |||
1103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attestation\n"); | ||
1104 | buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); | 1149 | buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); |
1105 | buf = GNUNET_malloc (buf_size); | 1150 | buf = GNUNET_malloc (buf_size); |
1106 | // Give the ash a new id if unset | ||
1107 | if (0 == ash->attest->id) | ||
1108 | ash->attest->id | ||
1109 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
1110 | GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); | 1151 | GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); |
1111 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id, | 1152 | if (0 == rd_count ) |
1112 | sizeof(uint64_t)); | 1153 | { |
1154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1155 | "Storing new Attestation\n"); | ||
1156 | struct GNUNET_GNSRECORD_Data rd_new[1]; | ||
1157 | rd_new[0].data_size = buf_size; | ||
1158 | rd_new[0].data = buf; | ||
1159 | rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; | ||
1160 | rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
1161 | rd_new[0].expiration_time = ash->exp.rel_value_us; | ||
1162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | ||
1163 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | ||
1164 | &ash->identity, | ||
1165 | label, | ||
1166 | 1, | ||
1167 | rd_new, | ||
1168 | &attest_store_cont, | ||
1169 | ash); | ||
1170 | GNUNET_free (buf); | ||
1171 | return; | ||
1172 | } | ||
1173 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type) | ||
1174 | { | ||
1175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1176 | "Existing Attestation location is not an Attestation\n"); | ||
1177 | send_ref_error (ash); | ||
1178 | return; | ||
1179 | } | ||
1180 | struct GNUNET_GNSRECORD_Data rd_new[rd_count]; | ||
1181 | for (int i = 0; i<rd_count; i++) | ||
1182 | { | ||
1183 | rd_new[i] = rd[i]; | ||
1184 | } | ||
1185 | rd_new[0].data_size = buf_size; | ||
1186 | rd_new[0].data = buf; | ||
1187 | rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; | ||
1188 | rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
1189 | rd_new[0].expiration_time = ash->exp.rel_value_us; | ||
1113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); | 1190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); |
1114 | |||
1115 | rd[0].data_size = buf_size; | ||
1116 | rd[0].data = buf; | ||
1117 | rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR; | ||
1118 | rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
1119 | rd[0].expiration_time = ash->exp.rel_value_us; | ||
1120 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, | 1191 | ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
1121 | &ash->identity, | 1192 | &ash->identity, |
1122 | label, | 1193 | label, |
1123 | 1, | 1194 | rd_count, |
1124 | rd, | 1195 | rd_new, |
1125 | &attest_store_cont, | 1196 | &attest_store_cont, |
1126 | ash); | 1197 | ash); |
1127 | GNUNET_free (buf); | 1198 | GNUNET_free (buf); |
1199 | } | ||
1200 | |||
1201 | /** | ||
1202 | * Add a new attestation | ||
1203 | * | ||
1204 | * @param cls the AttributeStoreHandle | ||
1205 | */ | ||
1206 | static void | ||
1207 | attest_store_task (void *cls) | ||
1208 | { | ||
1209 | struct AttributeStoreHandle *ash = cls; | ||
1210 | char *label; | ||
1211 | |||
1212 | // Give the ash a new id if unset | ||
1213 | if (0 == ash->attest->id) | ||
1214 | ash->attest->id | ||
1215 | = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); | ||
1216 | label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id, | ||
1217 | sizeof(uint64_t)); | ||
1218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1219 | "Looking up existing data under label %s\n", label); | ||
1220 | // Test for the content of the existing ID | ||
1221 | ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, | ||
1222 | &ash->identity, | ||
1223 | label, | ||
1224 | &attest_error, | ||
1225 | ash, | ||
1226 | &attest_add_cb, | ||
1227 | ash); | ||
1128 | GNUNET_free (label); | 1228 | GNUNET_free (label); |
1129 | } | 1229 | } |
1130 | 1230 | ||
@@ -1250,30 +1350,6 @@ reference_store_cont (void *cls, int32_t success, const char *emsg) | |||
1250 | cleanup_as_handle (ash); | 1350 | cleanup_as_handle (ash); |
1251 | } | 1351 | } |
1252 | 1352 | ||
1253 | /** | ||
1254 | * Send a reference error response | ||
1255 | * | ||
1256 | * @param ash our attribute store handle | ||
1257 | * @param success the success status | ||
1258 | */ | ||
1259 | static void | ||
1260 | send_ref_error (struct AttributeStoreHandle *ash) | ||
1261 | { | ||
1262 | struct GNUNET_MQ_Envelope *env; | ||
1263 | struct SuccessResultMessage *acr_msg; | ||
1264 | |||
1265 | ash->ns_qe = NULL; | ||
1266 | GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head, | ||
1267 | ash->client->store_op_tail, | ||
1268 | ash); | ||
1269 | |||
1270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n"); | ||
1271 | env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE); | ||
1272 | acr_msg->id = htonl (ash->r_id); | ||
1273 | acr_msg->op_result = htonl (GNUNET_SYSERR); | ||
1274 | GNUNET_MQ_send (ash->client->mq, env); | ||
1275 | cleanup_as_handle (ash); | ||
1276 | } | ||
1277 | 1353 | ||
1278 | /** | 1354 | /** |
1279 | * Check for existing record before storing reference | 1355 | * Check for existing record before storing reference |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 71c59ae90..a495c5e85 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -1198,14 +1198,15 @@ parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, | |||
1198 | attest->data_size); | 1198 | attest->data_size); |
1199 | char *jwt_body = strtok (jwt_string, delim); | 1199 | char *jwt_body = strtok (jwt_string, delim); |
1200 | jwt_body = strtok (NULL, delim); | 1200 | jwt_body = strtok (NULL, delim); |
1201 | GNUNET_STRINGS_base64_decode(jwt_body, strlen(jwt_body), (void **) &decoded_jwt); | 1201 | GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body), |
1202 | json_val=json_loads(decoded_jwt, JSON_DECODE_ANY, json_err); | 1202 | (void **) &decoded_jwt); |
1203 | json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err); | ||
1203 | const char *key; | 1204 | const char *key; |
1204 | json_t *value; | 1205 | json_t *value; |
1205 | json_object_foreach(json_val, key, value) { | 1206 | json_object_foreach (json_val, key, value) { |
1206 | if (0 == strcasecmp (key,claim)) | 1207 | if (0 == strcasecmp (key,claim)) |
1207 | { | 1208 | { |
1208 | val_str=json_dumps(value, JSON_ENCODE_ANY); | 1209 | val_str = json_dumps (value, JSON_ENCODE_ANY); |
1209 | } | 1210 | } |
1210 | } | 1211 | } |
1211 | type_str = "String"; | 1212 | type_str = "String"; |
@@ -1216,11 +1217,20 @@ parse_jwt (const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, | |||
1216 | { | 1217 | { |
1217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1218 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1218 | "Attribute value from JWT Parser invalid!\n"); | 1219 | "Attribute value from JWT Parser invalid!\n"); |
1219 | return NULL; | 1220 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, |
1221 | "Error: Referenced Claim Name not Found", | ||
1222 | (void **) &data, | ||
1223 | &data_size); | ||
1224 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (claim, type, data, data_size); | ||
1225 | attr->id = attest->id; | ||
1226 | attr->flag = 1; | ||
1227 | } | ||
1228 | else | ||
1229 | { | ||
1230 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (claim, type, data, data_size); | ||
1231 | attr->id = attest->id; | ||
1232 | attr->flag = 1; | ||
1220 | } | 1233 | } |
1221 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (claim, type, data, data_size); | ||
1222 | attr->id = attest->id; | ||
1223 | attr->flag = 1; | ||
1224 | return attr; | 1234 | return attr; |
1225 | } | 1235 | } |
1226 | 1236 | ||
@@ -1260,13 +1270,13 @@ attr_collect (void *cls, | |||
1260 | } | 1270 | } |
1261 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr2; | 1271 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr2; |
1262 | attr2 = parse_jwt (attest, reference->reference_value); | 1272 | attr2 = parse_jwt (attest, reference->reference_value); |
1263 | attr2->name = reference->name; | ||
1264 | if (NULL == attr2) | 1273 | if (NULL == attr2) |
1265 | { | 1274 | { |
1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1267 | "Attribute Collection with unparsed Attestation\n"); | 1276 | "Attribute Collection with unparsed Attestation\n"); |
1268 | return; | 1277 | return; |
1269 | } | 1278 | } |
1279 | attr2->name = reference->name; | ||
1270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference as attribute: %s\n", | 1280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference as attribute: %s\n", |
1271 | reference->name); | 1281 | reference->name); |
1272 | char *tmp_value; | 1282 | char *tmp_value; |