diff options
author | jospaeth <spaethj@in.tum.de> | 2020-08-18 17:26:18 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-08-18 17:26:18 +0200 |
commit | 47f891753197e99ce5af85c18dbf3a00f5db3b62 (patch) | |
tree | b616f02f7a6fd4ecd0db53e797484fa178de66f5 | |
parent | ca94ab81861548e635819836e256aaa796955d4a (diff) | |
download | gnunet-47f891753197e99ce5af85c18dbf3a00f5db3b62.tar.gz gnunet-47f891753197e99ce5af85c18dbf3a00f5db3b62.zip |
implement GNS escrow verify and restore
error handling not yet working
-rw-r--r-- | src/escrow/plugin_escrow_gns.c | 334 |
1 files changed, 268 insertions, 66 deletions
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c index 3254b6633..985449625 100644 --- a/src/escrow/plugin_escrow_gns.c +++ b/src/escrow/plugin_escrow_gns.c | |||
@@ -399,7 +399,8 @@ cleanup_plugin_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
399 | /* cancel identity operation */ | 399 | /* cancel identity operation */ |
400 | if (NULL != p_op->id_op) | 400 | if (NULL != p_op->id_op) |
401 | GNUNET_IDENTITY_cancel (p_op->id_op); | 401 | GNUNET_IDENTITY_cancel (p_op->id_op); |
402 | GNUNET_free (p_op->egoName); | 402 | if (NULL != p_op->egoName) |
403 | GNUNET_free (p_op->egoName); | ||
403 | GNUNET_free (p_op); | 404 | GNUNET_free (p_op); |
404 | GNUNET_free (plugin_op_wrap); | 405 | GNUNET_free (plugin_op_wrap); |
405 | } | 406 | } |
@@ -418,6 +419,32 @@ start_cont (void *cls) | |||
418 | } | 419 | } |
419 | 420 | ||
420 | 421 | ||
422 | void | ||
423 | verify_cont (void *cls) | ||
424 | { | ||
425 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
426 | struct ESCROW_GnsPluginOperation *p_op; | ||
427 | |||
428 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | ||
429 | p_op->cont (p_op->verify_wrap); | ||
430 | |||
431 | cleanup_plugin_operation (plugin_op_wrap); | ||
432 | } | ||
433 | |||
434 | |||
435 | static void | ||
436 | handle_restore_error (void *cls) | ||
437 | { | ||
438 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
439 | struct ESCROW_GnsPluginOperation *p_op; | ||
440 | |||
441 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | ||
442 | p_op->cont (p_op->ego_wrap); | ||
443 | |||
444 | cleanup_plugin_operation (plugin_op_wrap); | ||
445 | } | ||
446 | |||
447 | |||
421 | sss_Keyshare * | 448 | sss_Keyshare * |
422 | split_private_key (struct ESCROW_GnsPluginOperation *p_op) | 449 | split_private_key (struct ESCROW_GnsPluginOperation *p_op) |
423 | { | 450 | { |
@@ -475,6 +502,11 @@ keyshare_distributed (void *cls, | |||
475 | plugin_op_wrap = ns_qe->plugin_op_wrap; | 502 | plugin_op_wrap = ns_qe->plugin_op_wrap; |
476 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 503 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
477 | 504 | ||
505 | // remove qe from our list | ||
506 | GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, | ||
507 | p_op->ns_qes_tail, | ||
508 | ns_qe); | ||
509 | |||
478 | if (GNUNET_SYSERR == success) | 510 | if (GNUNET_SYSERR == success) |
479 | { | 511 | { |
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 512 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -485,12 +517,10 @@ keyshare_distributed (void *cls, | |||
485 | p_op->cont (p_op->anchor_wrap); | 517 | p_op->cont (p_op->anchor_wrap); |
486 | // this also cancels all running namestore operations | 518 | // this also cancels all running namestore operations |
487 | cleanup_plugin_operation (plugin_op_wrap); | 519 | cleanup_plugin_operation (plugin_op_wrap); |
520 | return; | ||
488 | } | 521 | } |
489 | 522 | ||
490 | // remove qe from list, check if all namestore operations are finished | 523 | // check if all namestore operations are finished |
491 | GNUNET_CONTAINER_DLL_remove (p_op->ns_qes_head, | ||
492 | p_op->ns_qes_tail, | ||
493 | ns_qe); | ||
494 | GNUNET_free (ns_qe); | 524 | GNUNET_free (ns_qe); |
495 | if (NULL == p_op->ns_qes_head) | 525 | if (NULL == p_op->ns_qes_head) |
496 | { | 526 | { |
@@ -790,7 +820,7 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
790 | { | 820 | { |
791 | struct ESCROW_GnsPluginOperation *p_op; | 821 | struct ESCROW_GnsPluginOperation *p_op; |
792 | struct GNUNET_CRYPTO_EcdsaPrivateKey *curr_pk; | 822 | struct GNUNET_CRYPTO_EcdsaPrivateKey *curr_pk; |
793 | char *curr_name; | 823 | char *curr_name, *curr_pk_string; |
794 | struct IdentityOperationEntry *curr_id_op; | 824 | struct IdentityOperationEntry *curr_id_op; |
795 | struct PkEntry *curr_pk_entry; | 825 | struct PkEntry *curr_pk_entry; |
796 | int exists_ret; | 826 | int exists_ret; |
@@ -804,6 +834,13 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
804 | curr_pk = derive_private_key (name, p_op->userSecret, i); | 834 | curr_pk = derive_private_key (name, p_op->userSecret, i); |
805 | curr_name = get_escrow_id_name (name, i); | 835 | curr_name = get_escrow_id_name (name, i); |
806 | 836 | ||
837 | // TODO: REMOVE THIS LOGGING BEFORE PRODUCTIONAL USE! | ||
838 | curr_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (curr_pk); | ||
839 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
840 | "derived private key: %s\n", | ||
841 | curr_pk_string); | ||
842 | GNUNET_free (curr_pk_string); | ||
843 | |||
807 | // check if the escrow identity already exists | 844 | // check if the escrow identity already exists |
808 | exists_ret = escrow_id_exists (curr_name, curr_pk); | 845 | exists_ret = escrow_id_exists (curr_name, curr_pk); |
809 | if (GNUNET_SYSERR == exists_ret) | 846 | if (GNUNET_SYSERR == exists_ret) |
@@ -859,47 +896,93 @@ create_escrow_identities (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
859 | } | 896 | } |
860 | 897 | ||
861 | 898 | ||
862 | void | 899 | static void |
863 | continue_start (void *cls) | 900 | handle_config_load_error (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, |
901 | char *emsg) | ||
864 | { | 902 | { |
865 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
866 | struct ESCROW_GnsPluginOperation *p_op; | 903 | struct ESCROW_GnsPluginOperation *p_op; |
867 | unsigned long long shares, share_threshold; | ||
868 | struct GNUNET_TIME_Relative delay; | ||
869 | 904 | ||
870 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 905 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
871 | 906 | ||
872 | if (ESCROW_PLUGIN_STATE_POST_INIT != ph.state) | 907 | if (NULL != p_op->anchor_wrap) |
873 | { | 908 | { |
874 | delay.rel_value_us = 200 * GNUNET_TIME_relative_get_millisecond_().rel_value_us; | 909 | p_op->anchor_wrap->escrowAnchor = NULL; |
875 | GNUNET_SCHEDULER_add_delayed (delay, &continue_start, plugin_op_wrap); | 910 | p_op->anchor_wrap->emsg = emsg; |
911 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | ||
876 | return; | 912 | return; |
877 | } | 913 | } |
878 | 914 | ||
879 | // get config | 915 | if (NULL != p_op->verify_wrap) |
916 | { | ||
917 | p_op->verify_wrap->verificationResult = GNUNET_ESCROW_INVALID; | ||
918 | p_op->verify_wrap->emsg = emsg; | ||
919 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&verify_cont, plugin_op_wrap); | ||
920 | return; | ||
921 | } | ||
922 | |||
923 | if (NULL != p_op->ego_wrap) | ||
924 | { | ||
925 | p_op->ego_wrap->ego = NULL; | ||
926 | p_op->ego_wrap->emsg = emsg; | ||
927 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&handle_restore_error, plugin_op_wrap); | ||
928 | return; | ||
929 | } | ||
930 | } | ||
931 | |||
932 | |||
933 | static int | ||
934 | load_keyshare_config (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | ||
935 | { | ||
936 | struct ESCROW_GnsPluginOperation *p_op; | ||
937 | unsigned long long shares, share_threshold; | ||
938 | |||
939 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
940 | |||
880 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (p_op->h->cfg, | 941 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (p_op->h->cfg, |
881 | "escrow", | 942 | "escrow", |
882 | "gns_shares", | 943 | "gns_shares", |
883 | &shares)) | 944 | &shares)) |
884 | { | 945 | { |
885 | fprintf (stderr, "Number of shares not specified in config!"); | 946 | handle_config_load_error (plugin_op_wrap, |
886 | p_op->anchor_wrap->escrowAnchor = NULL; | 947 | "Number of shares not specified in config!"); |
887 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | 948 | return GNUNET_SYSERR; |
888 | return; | ||
889 | } | 949 | } |
890 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (p_op->h->cfg, | 950 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (p_op->h->cfg, |
891 | "escrow", | 951 | "escrow", |
892 | "gns_share_threshold", | 952 | "gns_share_threshold", |
893 | &share_threshold)) | 953 | &share_threshold)) |
894 | { | 954 | { |
895 | fprintf (stderr, "Share threshold not specified in config"); | 955 | handle_config_load_error (plugin_op_wrap, |
896 | p_op->anchor_wrap->escrowAnchor = NULL; | 956 | "Share threshold not specified in config"); |
897 | p_op->sched_task = GNUNET_SCHEDULER_add_now (&start_cont, plugin_op_wrap); | 957 | return GNUNET_SYSERR; |
898 | return; | ||
899 | } | 958 | } |
900 | p_op->shares = (uint8_t)shares; | 959 | p_op->shares = (uint8_t)shares; |
901 | p_op->share_threshold = (uint8_t)share_threshold; | 960 | p_op->share_threshold = (uint8_t)share_threshold; |
902 | 961 | ||
962 | return GNUNET_OK; | ||
963 | } | ||
964 | |||
965 | |||
966 | static void | ||
967 | continue_start (void *cls) | ||
968 | { | ||
969 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
970 | struct ESCROW_GnsPluginOperation *p_op; | ||
971 | struct GNUNET_TIME_Relative delay; | ||
972 | |||
973 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | ||
974 | |||
975 | if (ESCROW_PLUGIN_STATE_POST_INIT != ph.state) | ||
976 | { | ||
977 | delay.rel_value_us = 100 * GNUNET_TIME_relative_get_millisecond_().rel_value_us; | ||
978 | GNUNET_SCHEDULER_add_delayed (delay, &continue_start, plugin_op_wrap); | ||
979 | return; | ||
980 | } | ||
981 | |||
982 | /* load config */ | ||
983 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | ||
984 | return; | ||
985 | |||
903 | /* create the escrow identities */ | 986 | /* create the escrow identities */ |
904 | create_escrow_identities (plugin_op_wrap, p_op->ego->name); | 987 | create_escrow_identities (plugin_op_wrap, p_op->ego->name); |
905 | 988 | ||
@@ -977,16 +1060,89 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
977 | } | 1060 | } |
978 | 1061 | ||
979 | 1062 | ||
1063 | static uint8_t | ||
1064 | count_keyshares (sss_Keyshare *keyshares, uint8_t n) | ||
1065 | { | ||
1066 | uint8_t i, c; | ||
1067 | sss_Keyshare null_ks; | ||
1068 | |||
1069 | memset (null_ks, 0, sizeof (sss_Keyshare)); | ||
1070 | |||
1071 | c = 0; | ||
1072 | for (i = 0; i < n; i++) | ||
1073 | { | ||
1074 | if (0 != memcmp (keyshares[i], &null_ks, sizeof (sss_Keyshare))) | ||
1075 | c++; | ||
1076 | } | ||
1077 | |||
1078 | return c; | ||
1079 | } | ||
1080 | |||
1081 | |||
980 | static void | 1082 | static void |
981 | process_keyshares (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | 1083 | remove_empty_keyshares (sss_Keyshare *keyshares, uint8_t n) |
982 | { | 1084 | { |
1085 | uint8_t i, j; | ||
1086 | sss_Keyshare null_ks; | ||
1087 | |||
1088 | memset (null_ks, 0, sizeof (sss_Keyshare)); | ||
1089 | |||
1090 | for (i = j = 0; i < n; i++) | ||
1091 | { | ||
1092 | if (0 != memcmp (keyshares[i], &null_ks, sizeof (sss_Keyshare))) | ||
1093 | { | ||
1094 | memcpy (keyshares[j], keyshares[i], sizeof (sss_Keyshare)); | ||
1095 | j++; | ||
1096 | } | ||
1097 | } | ||
1098 | } | ||
1099 | |||
1100 | |||
1101 | static void | ||
1102 | process_keyshares (void *cls) | ||
1103 | { | ||
1104 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
983 | struct ESCROW_GnsPluginOperation *p_op; | 1105 | struct ESCROW_GnsPluginOperation *p_op; |
984 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 1106 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
1107 | uint8_t keyshares_count; | ||
985 | 1108 | ||
986 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 1109 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
987 | 1110 | ||
988 | // TODO: check if enough keyshares have been restored, combine them | 1111 | /* check if enough keyshares have been restored */ |
989 | pk = NULL; | 1112 | keyshares_count = count_keyshares (p_op->restored_keyshares, p_op->shares); |
1113 | if (keyshares_count < p_op->share_threshold) | ||
1114 | { | ||
1115 | /* the key cannot be restored */ | ||
1116 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1117 | "need %hhu shares, but could only get %hhu", | ||
1118 | p_op->share_threshold, | ||
1119 | keyshares_count); | ||
1120 | |||
1121 | if (NULL != p_op->verify_wrap) // this was called by a verify operation | ||
1122 | { | ||
1123 | p_op->verify_wrap->emsg = | ||
1124 | _ ("key could not be restored, failed to get enough keyshares\n"); | ||
1125 | p_op->restore_pk_cont (p_op->restore_pk_cont_cls, NULL); | ||
1126 | return; | ||
1127 | } | ||
1128 | |||
1129 | if (NULL != p_op->ego_wrap) // this was called by a restore operation | ||
1130 | { | ||
1131 | p_op->ego_wrap->emsg = | ||
1132 | _ ("key could not be restored, failed to get enough keyshares\n"); | ||
1133 | p_op->restore_pk_cont (p_op->restore_pk_cont_cls, NULL); | ||
1134 | return; | ||
1135 | } | ||
1136 | } | ||
1137 | |||
1138 | /* combine the shares */ | ||
1139 | if (keyshares_count != p_op->shares) | ||
1140 | remove_empty_keyshares (p_op->restored_keyshares, p_op->shares); | ||
1141 | |||
1142 | pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | ||
1143 | sss_combine_keyshares (pk->d, | ||
1144 | p_op->restored_keyshares, | ||
1145 | keyshares_count); | ||
990 | 1146 | ||
991 | p_op->restore_pk_cont (p_op->restore_pk_cont_cls, pk); | 1147 | p_op->restore_pk_cont (p_op->restore_pk_cont_cls, pk); |
992 | } | 1148 | } |
@@ -1001,17 +1157,57 @@ process_gns_lookup_result (void *cls, | |||
1001 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; | 1157 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap; |
1002 | struct ESCROW_GnsPluginOperation *p_op; | 1158 | struct ESCROW_GnsPluginOperation *p_op; |
1003 | sss_Keyshare keyshare; | 1159 | sss_Keyshare keyshare; |
1160 | char keyshare_string[64], *end; | ||
1004 | 1161 | ||
1005 | plugin_op_wrap = gns_lr->plugin_op_wrap; | 1162 | plugin_op_wrap = gns_lr->plugin_op_wrap; |
1006 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 1163 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
1007 | 1164 | ||
1008 | // TODO: handle result, store keyshare, check if this was the last keyshare | 1165 | // remove gns_lr from our list |
1166 | GNUNET_CONTAINER_DLL_remove (p_op->gns_lrs_head, | ||
1167 | p_op->gns_lrs_tail, | ||
1168 | gns_lr); | ||
1169 | |||
1170 | if (1 != rd_count) | ||
1171 | { | ||
1172 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1173 | "did not get exactly _one_ record from GNS\n"); | ||
1174 | goto END; | ||
1175 | } | ||
1176 | |||
1177 | if (sizeof (sss_Keyshare) != rd[0].data_size) | ||
1178 | { | ||
1179 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1180 | "the size of the GNS record differs from the size of a keyshare\n"); | ||
1181 | goto END; | ||
1182 | } | ||
1183 | |||
1184 | GNUNET_memcpy (&keyshare, | ||
1185 | rd[0].data, | ||
1186 | rd[0].data_size); | ||
1187 | |||
1188 | end = GNUNET_STRINGS_data_to_string (&keyshare, | ||
1189 | sizeof (sss_Keyshare), | ||
1190 | keyshare_string, | ||
1191 | sizeof (keyshare_string)); | ||
1192 | GNUNET_break (NULL != end); | ||
1193 | *end = '\0'; | ||
1194 | |||
1195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1196 | "got keyshare %s from GNS\n", keyshare_string); | ||
1197 | |||
1009 | GNUNET_memcpy (p_op->restored_keyshares[gns_lr->i], | 1198 | GNUNET_memcpy (p_op->restored_keyshares[gns_lr->i], |
1010 | keyshare, | 1199 | &keyshare, |
1011 | sizeof (sss_Keyshare)); | 1200 | sizeof (sss_Keyshare)); |
1012 | 1201 | ||
1013 | if (1) // TODO: last keyshare? | 1202 | END: |
1014 | process_keyshares(plugin_op_wrap); | 1203 | GNUNET_free (gns_lr); |
1204 | |||
1205 | // check if this was the last gns_lr, i.e. our list is empty | ||
1206 | if (NULL == p_op->gns_lrs_head) | ||
1207 | { | ||
1208 | // schedule the further execution, lets GNS clean up its operation list | ||
1209 | GNUNET_SCHEDULER_add_now (&process_keyshares, plugin_op_wrap); | ||
1210 | } | ||
1015 | } | 1211 | } |
1016 | 1212 | ||
1017 | 1213 | ||
@@ -1024,7 +1220,7 @@ restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
1024 | struct ESCROW_GnsPluginOperation *p_op; | 1220 | struct ESCROW_GnsPluginOperation *p_op; |
1025 | struct GNUNET_CRYPTO_EcdsaPrivateKey *curr_escrow_pk; | 1221 | struct GNUNET_CRYPTO_EcdsaPrivateKey *curr_escrow_pk; |
1026 | struct GNUNET_CRYPTO_EcdsaPublicKey curr_escrow_pub; | 1222 | struct GNUNET_CRYPTO_EcdsaPublicKey curr_escrow_pub; |
1027 | char *curr_escrow_name; | 1223 | char *label, *curr_escrow_pk_string; |
1028 | struct GnsLookupRequestEntry *curr_gns_lr; | 1224 | struct GnsLookupRequestEntry *curr_gns_lr; |
1029 | 1225 | ||
1030 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 1226 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
@@ -1033,18 +1229,28 @@ restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
1033 | p_op->restore_pk_cont = cont; | 1229 | p_op->restore_pk_cont = cont; |
1034 | p_op->restore_pk_cont_cls = cont_cls; | 1230 | p_op->restore_pk_cont_cls = cont_cls; |
1035 | p_op->restored_keyshares = GNUNET_malloc (sizeof (sss_Keyshare) * p_op->shares); | 1231 | p_op->restored_keyshares = GNUNET_malloc (sizeof (sss_Keyshare) * p_op->shares); |
1232 | // ensure that the array is initialized with 0, as this is needed for counting the shares | ||
1233 | memset (p_op->restored_keyshares, 0, sizeof (sss_Keyshare) * p_op->shares); | ||
1234 | |||
1235 | label = get_label (p_op->userSecret); | ||
1036 | 1236 | ||
1037 | for (uint8_t i = 0; i < p_op->shares; i++) | 1237 | for (uint8_t i = 0; i < p_op->shares; i++) |
1038 | { | 1238 | { |
1039 | curr_escrow_pk = derive_private_key (p_op->ego->name, p_op->userSecret, i); | 1239 | curr_escrow_pk = derive_private_key (p_op->egoName, p_op->userSecret, i); |
1040 | curr_escrow_name = get_escrow_id_name (p_op->ego->name, i); | 1240 | |
1241 | // TODO: REMOVE THIS LOGGING BEFORE PRODUCTIONAL USE! | ||
1242 | curr_escrow_pk_string = GNUNET_CRYPTO_ecdsa_private_key_to_string (curr_escrow_pk); | ||
1243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1244 | "derived private key: %s\n", | ||
1245 | curr_escrow_pk_string); | ||
1246 | GNUNET_free (curr_escrow_pk_string); | ||
1041 | 1247 | ||
1042 | curr_gns_lr = GNUNET_new (struct GnsLookupRequestEntry); | 1248 | curr_gns_lr = GNUNET_new (struct GnsLookupRequestEntry); |
1043 | curr_gns_lr->plugin_op_wrap = plugin_op_wrap; | 1249 | curr_gns_lr->plugin_op_wrap = plugin_op_wrap; |
1044 | curr_gns_lr->i = i; | 1250 | curr_gns_lr->i = i; |
1045 | GNUNET_CRYPTO_ecdsa_key_get_public (curr_escrow_pk, &curr_escrow_pub); | 1251 | GNUNET_CRYPTO_ecdsa_key_get_public (curr_escrow_pk, &curr_escrow_pub); |
1046 | curr_gns_lr->lr = GNUNET_GNS_lookup (p_op->gns_h, | 1252 | curr_gns_lr->lr = GNUNET_GNS_lookup (p_op->gns_h, |
1047 | NULL, // TODO: name | 1253 | label, |
1048 | &curr_escrow_pub, | 1254 | &curr_escrow_pub, |
1049 | GNUNET_GNSRECORD_TYPE_ESCROW_KEYSHARE, | 1255 | GNUNET_GNSRECORD_TYPE_ESCROW_KEYSHARE, |
1050 | GNUNET_GNS_LO_DEFAULT, | 1256 | GNUNET_GNS_LO_DEFAULT, |
@@ -1054,19 +1260,7 @@ restore_private_key (struct ESCROW_PluginOperationWrapper *plugin_op_wrap, | |||
1054 | p_op->gns_lrs_tail, | 1260 | p_op->gns_lrs_tail, |
1055 | curr_gns_lr); | 1261 | curr_gns_lr); |
1056 | } | 1262 | } |
1057 | } | 1263 | GNUNET_free (label); |
1058 | |||
1059 | |||
1060 | void | ||
1061 | verify_cont (void *cls) | ||
1062 | { | ||
1063 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
1064 | struct ESCROW_GnsPluginOperation *p_op; | ||
1065 | |||
1066 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | ||
1067 | p_op->cont (p_op->verify_wrap); | ||
1068 | |||
1069 | cleanup_plugin_operation (plugin_op_wrap); | ||
1070 | } | 1264 | } |
1071 | 1265 | ||
1072 | 1266 | ||
@@ -1081,11 +1275,16 @@ verify_restored_pk (void *cls, | |||
1081 | 1275 | ||
1082 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; | 1276 | p_op = (struct ESCROW_GnsPluginOperation *)plugin_op_wrap->plugin_op; |
1083 | 1277 | ||
1084 | ego_pk = GNUNET_IDENTITY_ego_get_private_key (p_op->ego); | 1278 | if (NULL == pk) |
1085 | verificationResult = memcmp (pk, | 1279 | verificationResult = GNUNET_ESCROW_INVALID; |
1086 | ego_pk, | 1280 | else |
1087 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) | 1281 | { |
1088 | == 0 ? GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; | 1282 | ego_pk = GNUNET_IDENTITY_ego_get_private_key (p_op->ego); |
1283 | verificationResult = memcmp (pk, | ||
1284 | ego_pk, | ||
1285 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)) | ||
1286 | == 0 ? GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; | ||
1287 | } | ||
1089 | 1288 | ||
1090 | p_op->verify_wrap->verificationResult = verificationResult; | 1289 | p_op->verify_wrap->verificationResult = verificationResult; |
1091 | verify_cont (plugin_op_wrap); | 1290 | verify_cont (plugin_op_wrap); |
@@ -1125,6 +1324,7 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1125 | p_op->h = h; | 1324 | p_op->h = h; |
1126 | p_op->cont = cb; | 1325 | p_op->cont = cb; |
1127 | p_op->ego = ego; | 1326 | p_op->ego = ego; |
1327 | p_op->egoName = GNUNET_strdup (ego->name); | ||
1128 | p_op->userSecret = gns_anchor_data_to_string (h, escrowAnchor); | 1328 | p_op->userSecret = gns_anchor_data_to_string (h, escrowAnchor); |
1129 | 1329 | ||
1130 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); | 1330 | w = GNUNET_new (struct ESCROW_Plugin_VerifyContinuationWrapper); |
@@ -1140,6 +1340,10 @@ verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1140 | return plugin_op_wrap; | 1340 | return plugin_op_wrap; |
1141 | } | 1341 | } |
1142 | 1342 | ||
1343 | /* load config */ | ||
1344 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | ||
1345 | return plugin_op_wrap; | ||
1346 | |||
1143 | restore_private_key (plugin_op_wrap, | 1347 | restore_private_key (plugin_op_wrap, |
1144 | escrowAnchor, | 1348 | escrowAnchor, |
1145 | &verify_restored_pk, | 1349 | &verify_restored_pk, |
@@ -1182,19 +1386,6 @@ ego_created (const struct GNUNET_IDENTITY_Ego *ego) | |||
1182 | 1386 | ||
1183 | 1387 | ||
1184 | static void | 1388 | static void |
1185 | handle_restore_error (void *cls) | ||
1186 | { | ||
1187 | struct ESCROW_PluginOperationWrapper *plugin_op_wrap = cls; | ||
1188 | struct ESCROW_GnsPluginOperation *p_op; | ||
1189 | |||
1190 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | ||
1191 | p_op->cont (p_op->ego_wrap); | ||
1192 | |||
1193 | cleanup_plugin_operation (plugin_op_wrap); | ||
1194 | } | ||
1195 | |||
1196 | |||
1197 | static void | ||
1198 | id_create_finished (void *cls, | 1389 | id_create_finished (void *cls, |
1199 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 1390 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
1200 | const char *emsg) | 1391 | const char *emsg) |
@@ -1235,6 +1426,13 @@ restore_ego_from_pk (void *cls, | |||
1235 | 1426 | ||
1236 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; | 1427 | p_op = (struct ESCROW_GnsPluginOperation*)plugin_op_wrap->plugin_op; |
1237 | 1428 | ||
1429 | if (NULL == pk) | ||
1430 | { | ||
1431 | p_op->ego_wrap->ego = NULL; | ||
1432 | handle_restore_error (plugin_op_wrap); | ||
1433 | return; | ||
1434 | } | ||
1435 | |||
1238 | p_op->id_op = GNUNET_IDENTITY_create (identity_handle, | 1436 | p_op->id_op = GNUNET_IDENTITY_create (identity_handle, |
1239 | p_op->egoName, | 1437 | p_op->egoName, |
1240 | pk, | 1438 | pk, |
@@ -1293,6 +1491,10 @@ restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, | |||
1293 | return plugin_op_wrap; | 1491 | return plugin_op_wrap; |
1294 | } | 1492 | } |
1295 | 1493 | ||
1494 | /* load config */ | ||
1495 | if (GNUNET_OK != load_keyshare_config (plugin_op_wrap)) | ||
1496 | return plugin_op_wrap; | ||
1497 | |||
1296 | restore_private_key (plugin_op_wrap, | 1498 | restore_private_key (plugin_op_wrap, |
1297 | escrowAnchor, | 1499 | escrowAnchor, |
1298 | &restore_ego_from_pk, | 1500 | &restore_ego_from_pk, |
@@ -1394,7 +1596,7 @@ cancel_gns_operation (struct ESCROW_PluginOperationWrapper *plugin_op_wrap) | |||
1394 | void | 1596 | void |
1395 | gns_cont_init () | 1597 | gns_cont_init () |
1396 | { | 1598 | { |
1397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS plugin initialized"); | 1599 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GNS plugin initialized\n"); |
1398 | } | 1600 | } |
1399 | 1601 | ||
1400 | 1602 | ||