aboutsummaryrefslogtreecommitdiff
path: root/src/lib/anastasis_recovery.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/anastasis_recovery.c')
-rw-r--r--src/lib/anastasis_recovery.c80
1 files changed, 30 insertions, 50 deletions
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index c9f8c0e..e844737 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -624,8 +624,8 @@ policy_lookup_cb (void *cls,
624 void *plaintext; 624 void *plaintext;
625 size_t size_plaintext; 625 size_t size_plaintext;
626 json_error_t json_error; 626 json_error_t json_error;
627 json_t *dec_policies; 627 const json_t *dec_policies;
628 json_t *esc_methods; 628 const json_t *esc_methods;
629 629
630 r->plo = NULL; 630 r->plo = NULL;
631 switch (http_status) 631 switch (http_status)
@@ -761,10 +761,10 @@ policy_lookup_cb (void *cls,
761 { 761 {
762 const char *secret_name = NULL; 762 const char *secret_name = NULL;
763 struct GNUNET_JSON_Specification spec[] = { 763 struct GNUNET_JSON_Specification spec[] = {
764 GNUNET_JSON_spec_json ("policies", 764 GNUNET_JSON_spec_array_const ("policies",
765 &dec_policies), 765 &dec_policies),
766 GNUNET_JSON_spec_json ("escrow_methods", 766 GNUNET_JSON_spec_array_const ("escrow_methods",
767 &esc_methods), 767 &esc_methods),
768 GNUNET_JSON_spec_mark_optional ( 768 GNUNET_JSON_spec_mark_optional (
769 GNUNET_JSON_spec_string ("secret_name", 769 GNUNET_JSON_spec_string ("secret_name",
770 &secret_name), 770 &secret_name),
@@ -848,8 +848,6 @@ policy_lookup_cb (void *cls,
848 NULL, NULL)) 848 NULL, NULL))
849 { 849 {
850 GNUNET_break_op (0); 850 GNUNET_break_op (0);
851 json_decref (esc_methods);
852 json_decref (dec_policies);
853 r->csc (r->csc_cls, 851 r->csc (r->csc_cls,
854 ANASTASIS_RS_POLICY_MALFORMED_JSON, 852 ANASTASIS_RS_POLICY_MALFORMED_JSON,
855 NULL, 853 NULL,
@@ -864,13 +862,11 @@ policy_lookup_cb (void *cls,
864 cs->instructions = GNUNET_strdup (instructions); 862 cs->instructions = GNUNET_strdup (instructions);
865 cs->ci.instructions = cs->instructions; 863 cs->ci.instructions = cs->instructions;
866 } 864 }
867 json_decref (esc_methods);
868 865
869 for (unsigned int j = 0; j < r->ri.dps_len; j++) 866 for (unsigned int j = 0; j < r->ri.dps_len; j++)
870 { 867 {
871 struct DecryptionPolicy *dp = &r->dps[j]; 868 struct DecryptionPolicy *dp = &r->dps[j];
872 869 const json_t *uuids;
873 json_t *uuids = NULL;
874 json_t *uuid; 870 json_t *uuid;
875 size_t n_index; 871 size_t n_index;
876 struct GNUNET_JSON_Specification spec[] = { 872 struct GNUNET_JSON_Specification spec[] = {
@@ -879,22 +875,19 @@ policy_lookup_cb (void *cls,
879 &dp->emk_size), 875 &dp->emk_size),
880 GNUNET_JSON_spec_fixed_auto ("master_salt", 876 GNUNET_JSON_spec_fixed_auto ("master_salt",
881 &dp->master_salt), 877 &dp->master_salt),
882 GNUNET_JSON_spec_json ("uuids", 878 GNUNET_JSON_spec_array_const ("uuids",
883 &uuids), 879 &uuids),
884 GNUNET_JSON_spec_end () 880 GNUNET_JSON_spec_end ()
885 }; 881 };
886 882
887 r->ri.dps[j] = &r->dps[j].pub_details; 883 r->ri.dps[j] = &r->dps[j].pub_details;
888 if ( (GNUNET_OK != 884 if (GNUNET_OK !=
889 GNUNET_JSON_parse (json_array_get (dec_policies, 885 GNUNET_JSON_parse (json_array_get (dec_policies,
890 j), 886 j),
891 spec, 887 spec,
892 NULL, NULL)) || 888 NULL, NULL))
893 (! json_is_array (uuids)) )
894 { 889 {
895 GNUNET_break_op (0); 890 GNUNET_break_op (0);
896 json_decref (uuids);
897 json_decref (dec_policies);
898 r->csc (r->csc_cls, 891 r->csc (r->csc_cls,
899 ANASTASIS_RS_POLICY_MALFORMED_JSON, 892 ANASTASIS_RS_POLICY_MALFORMED_JSON,
900 NULL, 893 NULL,
@@ -925,8 +918,6 @@ policy_lookup_cb (void *cls,
925 sizeof (uuid))) ) 918 sizeof (uuid))) )
926 { 919 {
927 GNUNET_break_op (0); 920 GNUNET_break_op (0);
928 json_decref (dec_policies);
929 json_decref (uuids);
930 r->csc (r->csc_cls, 921 r->csc (r->csc_cls,
931 ANASTASIS_RS_POLICY_MALFORMED_JSON, 922 ANASTASIS_RS_POLICY_MALFORMED_JSON,
932 NULL, 923 NULL,
@@ -947,8 +938,6 @@ policy_lookup_cb (void *cls,
947 if (! found) 938 if (! found)
948 { 939 {
949 GNUNET_break_op (0); 940 GNUNET_break_op (0);
950 json_decref (dec_policies);
951 json_decref (uuids);
952 r->csc (r->csc_cls, 941 r->csc (r->csc_cls,
953 ANASTASIS_RS_POLICY_MALFORMED_JSON, 942 ANASTASIS_RS_POLICY_MALFORMED_JSON,
954 NULL, 943 NULL,
@@ -957,9 +946,7 @@ policy_lookup_cb (void *cls,
957 return; 946 return;
958 } 947 }
959 } 948 }
960 json_decref (uuids);
961 } 949 }
962 json_decref (dec_policies);
963 r->pc (r->pc_cls, 950 r->pc (r->pc_cls,
964 &r->ri); 951 &r->ri);
965} 952}
@@ -1134,7 +1121,7 @@ ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r)
1134 */ 1121 */
1135static enum GNUNET_GenericReturnValue 1122static enum GNUNET_GenericReturnValue
1136parse_cs_array (struct ANASTASIS_Recovery *r, 1123parse_cs_array (struct ANASTASIS_Recovery *r,
1137 json_t *cs_arr) 1124 const json_t *cs_arr)
1138{ 1125{
1139 json_t *cs; 1126 json_t *cs;
1140 unsigned int n_index; 1127 unsigned int n_index;
@@ -1220,7 +1207,7 @@ parse_cs_array (struct ANASTASIS_Recovery *r,
1220 */ 1207 */
1221static enum GNUNET_GenericReturnValue 1208static enum GNUNET_GenericReturnValue
1222parse_dps_array (struct ANASTASIS_Recovery *r, 1209parse_dps_array (struct ANASTASIS_Recovery *r,
1223 json_t *dps_arr) 1210 const json_t *dps_arr)
1224{ 1211{
1225 json_t *dps; 1212 json_t *dps;
1226 unsigned int n_index; 1213 unsigned int n_index;
@@ -1239,15 +1226,15 @@ parse_dps_array (struct ANASTASIS_Recovery *r,
1239 json_array_foreach (dps_arr, n_index, dps) 1226 json_array_foreach (dps_arr, n_index, dps)
1240 { 1227 {
1241 struct DecryptionPolicy *dp = &r->dps[n_index]; 1228 struct DecryptionPolicy *dp = &r->dps[n_index];
1242 json_t *challenges; 1229 const json_t *challenges;
1243 struct GNUNET_JSON_Specification spec[] = { 1230 struct GNUNET_JSON_Specification spec[] = {
1244 GNUNET_JSON_spec_varsize ("encrypted_master_key", 1231 GNUNET_JSON_spec_varsize ("encrypted_master_key",
1245 &dp->emk, 1232 &dp->emk,
1246 &dp->emk_size), 1233 &dp->emk_size),
1247 GNUNET_JSON_spec_fixed_auto ("master_salt", 1234 GNUNET_JSON_spec_fixed_auto ("master_salt",
1248 &dp->master_salt), 1235 &dp->master_salt),
1249 GNUNET_JSON_spec_json ("challenges", 1236 GNUNET_JSON_spec_array_const ("challenges",
1250 &challenges), 1237 &challenges),
1251 GNUNET_JSON_spec_end () 1238 GNUNET_JSON_spec_end ()
1252 }; 1239 };
1253 const char *err_json_name; 1240 const char *err_json_name;
@@ -1270,12 +1257,6 @@ parse_dps_array (struct ANASTASIS_Recovery *r,
1270 } 1257 }
1271 GNUNET_assert (NULL != dp->emk); 1258 GNUNET_assert (NULL != dp->emk);
1272 GNUNET_assert (dp->emk_size > 0); 1259 GNUNET_assert (dp->emk_size > 0);
1273 if (! json_is_array (challenges))
1274 {
1275 GNUNET_break_op (0);
1276 GNUNET_JSON_parse_free (spec);
1277 return GNUNET_SYSERR;
1278 }
1279 dp->pub_details.challenges_length = json_array_size (challenges); 1260 dp->pub_details.challenges_length = json_array_size (challenges);
1280 dp->pub_details.challenges = GNUNET_new_array ( 1261 dp->pub_details.challenges = GNUNET_new_array (
1281 dp->pub_details.challenges_length, 1262 dp->pub_details.challenges_length,
@@ -1320,8 +1301,7 @@ parse_dps_array (struct ANASTASIS_Recovery *r,
1320 } 1301 }
1321 } 1302 }
1322 } 1303 }
1323 /* We don't free the spec, since we're still using dp->ems. */ 1304 /* Do NOT free the spec: we are still using dp->ems. */
1324 json_decref (challenges);
1325 } 1305 }
1326 return GNUNET_OK; 1306 return GNUNET_OK;
1327} 1307}
@@ -1363,9 +1343,9 @@ ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx,
1363 const char *err_json_name; 1343 const char *err_json_name;
1364 unsigned int err_line; 1344 unsigned int err_line;
1365 uint32_t version; 1345 uint32_t version;
1366 json_t *dps_arr; 1346 const json_t *dps_arr;
1367 json_t *cs_arr; 1347 const json_t *cs_arr;
1368 json_t *id_data; 1348 const json_t *id_data;
1369 const char *provider_url; 1349 const char *provider_url;
1370 const char *secret_name; 1350 const char *secret_name;
1371 void *ecs; 1351 void *ecs;
@@ -1381,12 +1361,12 @@ ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx,
1381 NULL), 1361 NULL),
1382 GNUNET_JSON_spec_uint32 ("version", 1362 GNUNET_JSON_spec_uint32 ("version",
1383 &version), 1363 &version),
1384 GNUNET_JSON_spec_json ("decryption_policies", 1364 GNUNET_JSON_spec_array_const ("decryption_policies",
1385 &dps_arr), 1365 &dps_arr),
1386 GNUNET_JSON_spec_json ("challenges", 1366 GNUNET_JSON_spec_array_const ("challenges",
1387 &cs_arr), 1367 &cs_arr),
1388 GNUNET_JSON_spec_json ("id_data", 1368 GNUNET_JSON_spec_object_const ("id_data",
1389 &id_data), 1369 &id_data),
1390 GNUNET_JSON_spec_varsize ("encrypted_core_secret", 1370 GNUNET_JSON_spec_varsize ("encrypted_core_secret",
1391 &ecs, 1371 &ecs,
1392 &ecs_size), 1372 &ecs_size),
@@ -1420,7 +1400,7 @@ ANASTASIS_recovery_deserialize (struct GNUNET_CURL_Context *ctx,
1420 GNUNET_JSON_parse_free (spec); 1400 GNUNET_JSON_parse_free (spec);
1421 return NULL; 1401 return NULL;
1422 } 1402 }
1423 r->id_data = json_incref (id_data); 1403 r->id_data = json_incref ((json_t *) id_data);
1424 r->provider_url = GNUNET_strdup (provider_url); 1404 r->provider_url = GNUNET_strdup (provider_url);
1425 if (NULL != secret_name) 1405 if (NULL != secret_name)
1426 r->secret_name = GNUNET_strdup (secret_name); 1406 r->secret_name = GNUNET_strdup (secret_name);