diff options
author | jospaeth <spaethj@in.tum.de> | 2020-07-15 16:28:26 +0200 |
---|---|---|
committer | jospaeth <spaethj@in.tum.de> | 2020-07-15 16:28:26 +0200 |
commit | 3192c1c84a8cf6aa81e55ac647adf125cbd88904 (patch) | |
tree | cf8c0505b36ac3a5c7d86d6a683b6651c1917dce /src/escrow/escrow_api.c | |
parent | 122f2979146c6068cbaf189560f196e4a3323801 (diff) | |
download | gnunet-3192c1c84a8cf6aa81e55ac647adf125cbd88904.tar.gz gnunet-3192c1c84a8cf6aa81e55ac647adf125cbd88904.zip |
changes to the escrow api [not compiling]
Diffstat (limited to 'src/escrow/escrow_api.c')
-rw-r--r-- | src/escrow/escrow_api.c | 103 |
1 files changed, 89 insertions, 14 deletions
diff --git a/src/escrow/escrow_api.c b/src/escrow/escrow_api.c index b293c05a5..6d4d6531b 100644 --- a/src/escrow/escrow_api.c +++ b/src/escrow/escrow_api.c | |||
@@ -25,12 +25,37 @@ | |||
25 | * @brief api to interact with the escrow component | 25 | * @brief api to interact with the escrow component |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_escrow_lib.h" | 30 | #include "gnunet_escrow_lib.h" |
30 | #include "gnunet_escrow_plugin.h" | 31 | #include "gnunet_escrow_plugin.h" |
31 | 32 | ||
32 | 33 | ||
33 | /** | 34 | /** |
35 | * Handle for the escrow component. | ||
36 | */ | ||
37 | struct GNUNET_ESCROW_Handle | ||
38 | { | ||
39 | /** | ||
40 | * Configuration to use. | ||
41 | */ | ||
42 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
43 | }; | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Handle for an operation with the escrow component. | ||
48 | */ | ||
49 | struct GNUNET_ESCROW_Operation | ||
50 | { | ||
51 | /** | ||
52 | * Main escrow handle. | ||
53 | */ | ||
54 | struct GNUNET_ESCROW_Handle *h; | ||
55 | }; | ||
56 | |||
57 | |||
58 | /** | ||
34 | * Init canary for the plaintext plugin | 59 | * Init canary for the plaintext plugin |
35 | */ | 60 | */ |
36 | static int plaintext_initialized; | 61 | static int plaintext_initialized; |
@@ -74,7 +99,8 @@ static struct GNUNET_ESCROW_KeyPluginFunctions *anastasis_api; | |||
74 | * @return pointer to the escrow plugin API | 99 | * @return pointer to the escrow plugin API |
75 | */ | 100 | */ |
76 | struct GNUNET_ESCROW_KeyPluginFunctions * | 101 | struct GNUNET_ESCROW_KeyPluginFunctions * |
77 | init_plugin (enum GNUNET_ESCROW_Key_Escrow_Method method) | 102 | init_plugin (struct GNUNET_ESCROW_Handle *h, |
103 | enum GNUNET_ESCROW_Key_Escrow_Method method) | ||
78 | { | 104 | { |
79 | switch (method) | 105 | switch (method) |
80 | { | 106 | { |
@@ -85,7 +111,7 @@ init_plugin (enum GNUNET_ESCROW_Key_Escrow_Method method) | |||
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
86 | "Loading PLAINTEXT escrow plugin\n"); | 112 | "Loading PLAINTEXT escrow plugin\n"); |
87 | plaintext_api = GNUNET_PLUGIN_load ("libgnunet_plugin_escrow_plaintext", | 113 | plaintext_api = GNUNET_PLUGIN_load ("libgnunet_plugin_escrow_plaintext", |
88 | NULL); | 114 | (void *)h->cfg); |
89 | return plaintext_api; | 115 | return plaintext_api; |
90 | case GNUNET_ESCROW_KEY_GNS: | 116 | case GNUNET_ESCROW_KEY_GNS: |
91 | if (GNUNET_YES == gns_initialized) | 117 | if (GNUNET_YES == gns_initialized) |
@@ -94,7 +120,7 @@ init_plugin (enum GNUNET_ESCROW_Key_Escrow_Method method) | |||
94 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
95 | "Loading GNS escrow plugin\n"); | 121 | "Loading GNS escrow plugin\n"); |
96 | gns_api = GNUNET_PLUGIN_load ("libgnunet_plugin_escrow_gns", | 122 | gns_api = GNUNET_PLUGIN_load ("libgnunet_plugin_escrow_gns", |
97 | NULL); | 123 | (void *)h->cfg); |
98 | return gns_api; | 124 | return gns_api; |
99 | case GNUNET_ESCROW_KEY_ANASTASIS: | 125 | case GNUNET_ESCROW_KEY_ANASTASIS: |
100 | if (GNUNET_YES == anastasis_initialized) | 126 | if (GNUNET_YES == anastasis_initialized) |
@@ -103,7 +129,7 @@ init_plugin (enum GNUNET_ESCROW_Key_Escrow_Method method) | |||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
104 | "Loading ANASTASIS escrow plugin\n"); | 130 | "Loading ANASTASIS escrow plugin\n"); |
105 | anastasis_api = GNUNET_PLUGIN_load ("libgnunet_plugin_escrow_anastasis", | 131 | anastasis_api = GNUNET_PLUGIN_load ("libgnunet_plugin_escrow_anastasis", |
106 | NULL); | 132 | (void *)h->cfg); |
107 | return anastasis_api; | 133 | return anastasis_api; |
108 | } | 134 | } |
109 | // should never be reached | 135 | // should never be reached |
@@ -112,11 +138,32 @@ init_plugin (enum GNUNET_ESCROW_Key_Escrow_Method method) | |||
112 | 138 | ||
113 | 139 | ||
114 | /** | 140 | /** |
141 | * Initialize the escrow component. | ||
142 | * | ||
143 | * @param cfg the configuration to use | ||
144 | * | ||
145 | * @return handle to use | ||
146 | */ | ||
147 | struct GNUNET_ESCROW_Handle * | ||
148 | GNUNET_ESCROW_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
149 | { | ||
150 | struct GNUNET_ESCROW_Handle *h; | ||
151 | |||
152 | h = GNUNET_new (struct GNUNET_ESCROW_Handle); | ||
153 | h->cfg = cfg; | ||
154 | return h; | ||
155 | } | ||
156 | |||
157 | |||
158 | /** | ||
115 | * Unload all loaded plugins on destruction. | 159 | * Unload all loaded plugins on destruction. |
160 | * | ||
161 | * @param h the escrow handle | ||
116 | */ | 162 | */ |
117 | void __attribute__ ((destructor)) | 163 | void |
118 | GNUNET_ESCROW_fini_plugins () | 164 | GNUNET_ESCROW_fini (struct GNUNET_ESCROW_Handle *h) |
119 | { | 165 | { |
166 | /* unload all loaded plugins */ | ||
120 | if (GNUNET_YES == plaintext_initialized) | 167 | if (GNUNET_YES == plaintext_initialized) |
121 | { | 168 | { |
122 | plaintext_initialized = GNUNET_NO; | 169 | plaintext_initialized = GNUNET_NO; |
@@ -143,6 +190,9 @@ GNUNET_ESCROW_fini_plugins () | |||
143 | anastasis_api)); | 190 | anastasis_api)); |
144 | anastasis_api = NULL; | 191 | anastasis_api = NULL; |
145 | } | 192 | } |
193 | |||
194 | /* freee the escrow handle */ | ||
195 | GNUNET_free (h); | ||
146 | } | 196 | } |
147 | 197 | ||
148 | 198 | ||
@@ -155,12 +205,13 @@ GNUNET_ESCROW_fini_plugins () | |||
155 | * @return the escrow anchor needed to get the data back | 205 | * @return the escrow anchor needed to get the data back |
156 | */ | 206 | */ |
157 | void * | 207 | void * |
158 | GNUNET_ESCROW_put (const struct GNUNET_IDENTITY_Ego *ego, | 208 | GNUNET_ESCROW_put (struct GNUNET_ESCROW_Handle *h, |
209 | const struct GNUNET_IDENTITY_Ego *ego, | ||
159 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 210 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
160 | { | 211 | { |
161 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 212 | struct GNUNET_ESCROW_KeyPluginFunctions *api; |
162 | 213 | ||
163 | api = init_plugin (method); | 214 | api = init_plugin (h, method); |
164 | return api->start_key_escrow (ego); | 215 | return api->start_key_escrow (ego); |
165 | } | 216 | } |
166 | 217 | ||
@@ -174,12 +225,13 @@ GNUNET_ESCROW_put (const struct GNUNET_IDENTITY_Ego *ego, | |||
174 | * @return the escrow anchor needed to get the data back | 225 | * @return the escrow anchor needed to get the data back |
175 | */ | 226 | */ |
176 | void * | 227 | void * |
177 | GNUNET_ESCROW_renew (void *escrowAnchor, | 228 | GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h, |
229 | void *escrowAnchor, | ||
178 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 230 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
179 | { | 231 | { |
180 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 232 | struct GNUNET_ESCROW_KeyPluginFunctions *api; |
181 | 233 | ||
182 | api = init_plugin (method); | 234 | api = init_plugin (h, method); |
183 | return api->renew_key_escrow (escrowAnchor); | 235 | return api->renew_key_escrow (escrowAnchor); |
184 | } | 236 | } |
185 | 237 | ||
@@ -194,13 +246,14 @@ GNUNET_ESCROW_renew (void *escrowAnchor, | |||
194 | * @return a new identity ego restored from the escrow | 246 | * @return a new identity ego restored from the escrow |
195 | */ | 247 | */ |
196 | const struct GNUNET_IDENTITY_Ego * | 248 | const struct GNUNET_IDENTITY_Ego * |
197 | GNUNET_ESCROW_get (void *escrowAnchor, | 249 | GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h, |
250 | void *escrowAnchor, | ||
198 | char *egoName, | 251 | char *egoName, |
199 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 252 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
200 | { | 253 | { |
201 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 254 | struct GNUNET_ESCROW_KeyPluginFunctions *api; |
202 | 255 | ||
203 | api = init_plugin (method); | 256 | api = init_plugin (h, method); |
204 | return api->restore_key (escrowAnchor, egoName); | 257 | return api->restore_key (escrowAnchor, egoName); |
205 | } | 258 | } |
206 | 259 | ||
@@ -217,12 +270,34 @@ GNUNET_ESCROW_get (void *escrowAnchor, | |||
217 | * GNUNET_ESCROW_INVALID otherwise | 270 | * GNUNET_ESCROW_INVALID otherwise |
218 | */ | 271 | */ |
219 | int | 272 | int |
220 | GNUNET_ESCROW_verify (const struct GNUNET_IDENTITY_Ego *ego, | 273 | GNUNET_ESCROW_verify (struct GNUNET_ESCROW_Handle *h, |
274 | const struct GNUNET_IDENTITY_Ego *ego, | ||
221 | void *escrowAnchor, | 275 | void *escrowAnchor, |
222 | enum GNUNET_ESCROW_Key_Escrow_Method method) | 276 | enum GNUNET_ESCROW_Key_Escrow_Method method) |
223 | { | 277 | { |
224 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | 278 | struct GNUNET_ESCROW_KeyPluginFunctions *api; |
225 | 279 | ||
226 | api = init_plugin (method); | 280 | api = init_plugin (h, method); |
227 | return api->verify_key_escrow (ego, escrowAnchor); | 281 | return api->verify_key_escrow (ego, escrowAnchor); |
228 | } | 282 | } |
283 | |||
284 | |||
285 | /** | ||
286 | * Deserialize an escrow anchor string (e.g. from command line) into a | ||
287 | * GNUNET_ESCROW_Anchor struct | ||
288 | * | ||
289 | * @param anchorString the encoded escrow anchor string | ||
290 | * @param method the escrow method to use | ||
291 | * | ||
292 | * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct | ||
293 | */ | ||
294 | const struct GNUNET_ESCROW_Anchor * | ||
295 | GNUNET_ESCROW_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h, | ||
296 | char *anchorString, | ||
297 | enum GNUNET_ESCROW_Key_Escrow_Method method) | ||
298 | { | ||
299 | struct GNUNET_ESCROW_KeyPluginFunctions *api; | ||
300 | |||
301 | api = init_plugin (h, method); | ||
302 | return api->anchor_string_to_data (anchorString); | ||
303 | } | ||