aboutsummaryrefslogtreecommitdiff
path: root/src/escrow
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-07-18 14:35:59 +0200
committerjospaeth <spaethj@in.tum.de>2020-07-18 14:35:59 +0200
commit15ad508b20fbca46d8b9a8682a723b34098545bf (patch)
tree7800b9fd2cf6e6b36797bb8dc29356ae00a6f497 /src/escrow
parent646beac5ca85327b150affa034a5e9d1559382b1 (diff)
downloadgnunet-15ad508b20fbca46d8b9a8682a723b34098545bf.tar.gz
gnunet-15ad508b20fbca46d8b9a8682a723b34098545bf.zip
pass only ESCROW_Operation to the plugins
Diffstat (limited to 'src/escrow')
-rw-r--r--src/escrow/Makefile.am19
-rw-r--r--src/escrow/escrow_api.c35
-rw-r--r--src/escrow/escrow_plugin_helper.c4
-rw-r--r--src/escrow/gnunet-escrow.c52
-rw-r--r--src/escrow/plugin_escrow_anastasis.c76
-rw-r--r--src/escrow/plugin_escrow_gns.c78
-rw-r--r--src/escrow/plugin_escrow_plaintext.c150
7 files changed, 256 insertions, 158 deletions
diff --git a/src/escrow/Makefile.am b/src/escrow/Makefile.am
index 78acfbb16..2f3ada944 100644
--- a/src/escrow/Makefile.am
+++ b/src/escrow/Makefile.am
@@ -1,7 +1,7 @@
1# This Makefile.am is in the public domain 1# This Makefile.am is in the public domain
2AM_CPPFLAGS = -I$(top_srcdir)/src/include 2AM_CPPFLAGS = -I$(top_srcdir)/src/include
3 3
4 plugindir = $(libdir)/gnunet 4plugindir = $(libdir)/gnunet
5 5
6if USE_COVERAGE 6if USE_COVERAGE
7 AM_CFLAGS = --coverage -O0 7 AM_CFLAGS = --coverage -O0
@@ -46,9 +46,10 @@ libgnunet_plugin_escrow_plaintext_la_SOURCES = \
46 escrow_plugin_helper.c \ 46 escrow_plugin_helper.c \
47 escrow_plugin_helper.h 47 escrow_plugin_helper.h
48libgnunet_plugin_escrow_plaintext_la_LIBADD = \ 48libgnunet_plugin_escrow_plaintext_la_LIBADD = \
49 $(top_builddir)/src/util/libgnunetutil.la \ 49 libgnunetescrow.la \
50 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
50 $(top_builddir)/src/identity/libgnunetidentity.la \ 51 $(top_builddir)/src/identity/libgnunetidentity.la \
51 $(LTLIBINTL) 52 $(LTLIBINTL) $(MHD_LIBS)
52libgnunet_plugin_escrow_plaintext_la_LDFLAGS = \ 53libgnunet_plugin_escrow_plaintext_la_LDFLAGS = \
53 $(GN_PLUGIN_LDFLAGS) 54 $(GN_PLUGIN_LDFLAGS)
54 55
@@ -57,10 +58,11 @@ libgnunet_plugin_escrow_gns_la_SOURCES = \
57 escrow_plugin_helper.c \ 58 escrow_plugin_helper.c \
58 escrow_plugin_helper.h 59 escrow_plugin_helper.h
59libgnunet_plugin_escrow_gns_la_LIBADD = \ 60libgnunet_plugin_escrow_gns_la_LIBADD = \
60 $(top_builddir)/src/util/libgnunetutil.la \ 61 libgnunetescrow.la \
62 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
61 $(top_builddir)/src/identity/libgnunetidentity.la \ 63 $(top_builddir)/src/identity/libgnunetidentity.la \
62 -lsss \ 64 -lsss \
63 $(LTLIBINTL) 65 $(LTLIBINTL) $(MHD_LIBS)
64libgnunet_plugin_escrow_gns_la_LDFLAGS = \ 66libgnunet_plugin_escrow_gns_la_LDFLAGS = \
65 $(GN_PLUGIN_LDFLAGS) 67 $(GN_PLUGIN_LDFLAGS)
66 68
@@ -69,9 +71,10 @@ libgnunet_plugin_escrow_anastasis_la_SOURCES = \
69 escrow_plugin_helper.c \ 71 escrow_plugin_helper.c \
70 escrow_plugin_helper.h 72 escrow_plugin_helper.h
71libgnunet_plugin_escrow_anastasis_la_LIBADD = \ 73libgnunet_plugin_escrow_anastasis_la_LIBADD = \
72 $(top_builddir)/src/util/libgnunetutil.la \ 74 libgnunetescrow.la \
75 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
73 $(top_builddir)/src/identity/libgnunetidentity.la \ 76 $(top_builddir)/src/identity/libgnunetidentity.la \
74 $(LTLIBINTL) 77 $(LTLIBINTL) $(MHD_LIBS)
75libgnunet_plugin_escrow_anastasis_la_LDFLAGS = \ 78libgnunet_plugin_escrow_anastasis_la_LDFLAGS = \
76 $(GN_PLUGIN_LDFLAGS) 79 $(GN_PLUGIN_LDFLAGS)
77 80
@@ -79,9 +82,9 @@ libgnunet_plugin_escrow_anastasis_la_LDFLAGS = \
79gnunet_escrow_SOURCES = \ 82gnunet_escrow_SOURCES = \
80 gnunet-escrow.c 83 gnunet-escrow.c
81gnunet_escrow_LDADD = \ 84gnunet_escrow_LDADD = \
85 libgnunetescrow.la \
82 $(top_builddir)/src/util/libgnunetutil.la \ 86 $(top_builddir)/src/util/libgnunetutil.la \
83 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 87 $(top_builddir)/src/namestore/libgnunetnamestore.la \
84 libgnunetescrow.la \
85 $(top_builddir)/src/identity/libgnunetidentity.la \ 88 $(top_builddir)/src/identity/libgnunetidentity.la \
86 $(GN_LIBINTL) 89 $(GN_LIBINTL)
87 90
diff --git a/src/escrow/escrow_api.c b/src/escrow/escrow_api.c
index 1706d2a5a..ccd314db1 100644
--- a/src/escrow/escrow_api.c
+++ b/src/escrow/escrow_api.c
@@ -197,9 +197,10 @@ GNUNET_ESCROW_put (struct GNUNET_ESCROW_Handle *h,
197 op = GNUNET_new (struct GNUNET_ESCROW_Operation); 197 op = GNUNET_new (struct GNUNET_ESCROW_Operation);
198 op->h = h; 198 op->h = h;
199 op->cb_put = cb; 199 op->cb_put = cb;
200 op->cb_cls = cb_cls;
200 201
201 api = init_plugin (h, method); 202 api = init_plugin (h, method);
202 api->start_key_escrow (h, ego, cb, cb_cls); 203 api->start_key_escrow (op, ego);
203 204
204 return op; 205 return op;
205} 206}
@@ -231,7 +232,7 @@ GNUNET_ESCROW_renew (struct GNUNET_ESCROW_Handle *h,
231 op->cb_renew = cb; 232 op->cb_renew = cb;
232 233
233 api = init_plugin (h, method); 234 api = init_plugin (h, method);
234 api->renew_key_escrow (h, escrowAnchor, cb, cb_cls); 235 api->renew_key_escrow (op, escrowAnchor);
235 236
236 return op; 237 return op;
237} 238}
@@ -265,7 +266,7 @@ GNUNET_ESCROW_get (struct GNUNET_ESCROW_Handle *h,
265 op->cb_get = cb; 266 op->cb_get = cb;
266 267
267 api = init_plugin (h, method); 268 api = init_plugin (h, method);
268 api->restore_key (h, escrowAnchor, egoName, cb, cb_cls); 269 api->restore_key (op, escrowAnchor, egoName);
269 270
270 return op; 271 return op;
271} 272}
@@ -299,7 +300,7 @@ GNUNET_ESCROW_verify (struct GNUNET_ESCROW_Handle *h,
299 op->cb_verify = cb; 300 op->cb_verify = cb;
300 301
301 api = init_plugin (h, method); 302 api = init_plugin (h, method);
302 api->verify_key_escrow (h, ego, escrowAnchor, cb, cb_cls); 303 api->verify_key_escrow (op, ego, escrowAnchor);
303 304
304 return op; 305 return op;
305} 306}
@@ -323,5 +324,29 @@ GNUNET_ESCROW_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
323 struct GNUNET_ESCROW_KeyPluginFunctions *api; 324 struct GNUNET_ESCROW_KeyPluginFunctions *api;
324 325
325 api = init_plugin (h, method); 326 api = init_plugin (h, method);
326 return api->anchor_string_to_data (anchorString); 327 return api->anchor_string_to_data (h, anchorString);
327} 328}
329
330
331/**
332 * Serialize an escrow anchor (struct GNUNET_ESCROW_Anchor) into a string
333 *
334 * @param h the handle for the escrow component
335 * @param escrowAnchor the escrow anchor struct
336 * @param method the escrow method to use
337 *
338 * @return the encoded escrow anchor string
339 */
340char *
341GNUNET_ESCROW_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
342 struct GNUNET_ESCROW_Anchor *escrowAnchor,
343 enum GNUNET_ESCROW_Key_Escrow_Method method)
344{
345 struct GNUNET_ESCROW_KeyPluginFunctions *api;
346
347 api = init_plugin (h, method);
348 return api->anchor_data_to_string (h, escrowAnchor);
349}
350
351
352/* end of escrow_api.c */
diff --git a/src/escrow/escrow_plugin_helper.c b/src/escrow/escrow_plugin_helper.c
index ba177b252..05c5be90b 100644
--- a/src/escrow/escrow_plugin_helper.c
+++ b/src/escrow/escrow_plugin_helper.c
@@ -71,14 +71,14 @@ ESCROW_list_ego (void *cls,
71 void **ctx, 71 void **ctx,
72 const char *identifier) 72 const char *identifier)
73{ 73{
74 struct EscrowPluginHandle *ph = cls;
74 struct EgoEntry *ego_entry; 75 struct EgoEntry *ego_entry;
75 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 76 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
76 struct EscrowPluginHandle *ph = cls;
77 77
78 if ((NULL == ego) && (ESCROW_PLUGIN_STATE_INIT == ph->state)) 78 if ((NULL == ego) && (ESCROW_PLUGIN_STATE_INIT == ph->state))
79 { 79 {
80 ph->state = ESCROW_PLUGIN_STATE_POST_INIT; 80 ph->state = ESCROW_PLUGIN_STATE_POST_INIT;
81 /* call ContinueIdentityInitFunction */ 81 /* call IdentityInitContinuation */
82 ph->cont (); 82 ph->cont ();
83 return; 83 return;
84 } 84 }
diff --git a/src/escrow/gnunet-escrow.c b/src/escrow/gnunet-escrow.c
index c1d43b80e..1651d96ed 100644
--- a/src/escrow/gnunet-escrow.c
+++ b/src/escrow/gnunet-escrow.c
@@ -28,6 +28,7 @@
28 28
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_escrow_lib.h" 30#include "gnunet_escrow_lib.h"
31#include "../identity/identity.h"
31 32
32/** 33/**
33 * return value 34 * return value
@@ -145,10 +146,14 @@ static void
145put_cb (void *cls, 146put_cb (void *cls,
146 struct GNUNET_ESCROW_Anchor *escrowAnchor) 147 struct GNUNET_ESCROW_Anchor *escrowAnchor)
147{ 148{
148 struct GNUNET_ESCROW_Operation *op = cls; 149 char *anchorString;
149 150
150 // TODO: implement 151 anchorString = GNUNET_ESCROW_anchor_data_to_string (escrow_handle,
151 return; 152 escrowAnchor,
153 method);
154
155 fprintf (stdout, "Escrow finished! Please keep the following anchor \
156 in order to restore the key later!\n%s\n", anchorString);
152} 157}
153 158
154 159
@@ -156,10 +161,20 @@ static void
156verify_cb (void *cls, 161verify_cb (void *cls,
157 int verificationResult) 162 int verificationResult)
158{ 163{
159 struct GNUNET_ESCROW_Operation *op = cls; 164 switch (verificationResult)
160 165 {
161 // TODO: implement 166 case GNUNET_ESCROW_VALID:
162 return; 167 fprintf (stdout, "Escrow is valid!\n");
168 break;
169 case GNUNET_ESCROW_INVALID:
170 fprintf (stdout, "Escrow is INvalid! Please perform a new escrow.\n");
171 break;
172 case GNUNET_ESCROW_RENEW_NEEDED:
173 fprintf (stdout, "Escrow needs a renew!\n");
174 break;
175 default:
176 fprintf (stderr, "invalid verificationResult!\n");
177 }
163} 178}
164 179
165 180
@@ -167,10 +182,13 @@ static void
167get_cb (void *cls, 182get_cb (void *cls,
168 const struct GNUNET_IDENTITY_Ego *ego) 183 const struct GNUNET_IDENTITY_Ego *ego)
169{ 184{
170 struct GNUNET_ESCROW_Operation *op = cls; 185 if (NULL == ego)
171 186 {
172 // TODO: implement 187 ret = 1;
173 return; 188 fprintf (stderr, _ ("escrow failed!"));
189 return;
190 }
191 fprintf (stdout, "Ego %s could successfully be restored!", ego->name);
174} 192}
175 193
176 194
@@ -190,7 +208,7 @@ start_process ()
190 ego, 208 ego,
191 method, 209 method,
192 &put_cb, 210 &put_cb,
193 escrow_op); 211 NULL);
194 return; 212 return;
195 } 213 }
196 /* verify */ 214 /* verify */
@@ -207,7 +225,7 @@ start_process ()
207 anchor, 225 anchor,
208 method, 226 method,
209 &verify_cb, 227 &verify_cb,
210 escrow_op); 228 NULL);
211 return; 229 return;
212 } 230 }
213 /* get */ 231 /* get */
@@ -224,7 +242,7 @@ start_process ()
224 get_ego, 242 get_ego,
225 method, 243 method,
226 &get_cb, 244 &get_cb,
227 escrow_op); 245 NULL);
228 return; 246 return;
229 } 247 }
230} 248}
@@ -309,11 +327,11 @@ run (void *cls,
309 } 327 }
310 328
311 /* determine method */ 329 /* determine method */
312 if (strncmp (plaintext_string, method_name, strlen (plaintext_string))) 330 if (!strncmp (plaintext_string, method_name, strlen (plaintext_string)))
313 method = GNUNET_ESCROW_KEY_PLAINTEXT; 331 method = GNUNET_ESCROW_KEY_PLAINTEXT;
314 else if (strncmp (gns_string, method_name, strlen (gns_string))) 332 else if (!strncmp (gns_string, method_name, strlen (gns_string)))
315 method = GNUNET_ESCROW_KEY_GNS; 333 method = GNUNET_ESCROW_KEY_GNS;
316 else if (strncmp (anastasis_string, method_name, strlen (anastasis_string))) 334 else if (!strncmp (anastasis_string, method_name, strlen (anastasis_string)))
317 method = GNUNET_ESCROW_KEY_ANASTASIS; 335 method = GNUNET_ESCROW_KEY_ANASTASIS;
318 else 336 else
319 { 337 {
diff --git a/src/escrow/plugin_escrow_anastasis.c b/src/escrow/plugin_escrow_anastasis.c
index 9543f3cef..c4b4ce1ef 100644
--- a/src/escrow/plugin_escrow_anastasis.c
+++ b/src/escrow/plugin_escrow_anastasis.c
@@ -45,83 +45,64 @@ struct EscrowPluginHandle ph;
45/** 45/**
46 * Start the Anastasis escrow of the key 46 * Start the Anastasis escrow of the key
47 * 47 *
48 * @param h the handle for the escrow component 48 * @param op the escrow operation
49 * @param ego the identity ego containing the private key 49 * @param ego the identity ego containing the private key
50 * @param cb function to call with the escrow anchor on completion
51 * @param cb_cls closure for @a cb
52 */ 50 */
53void 51void
54start_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 52start_anastasis_key_escrow (struct GNUNET_ESCROW_Operation *op,
55 const struct GNUNET_IDENTITY_Ego *ego, 53 const struct GNUNET_IDENTITY_Ego *ego)
56 GNUNET_ESCROW_AnchorContinuation cb,
57 void *cb_cls)
58{ 54{
59 // TODO: implement 55 // TODO: implement
60 cb (cb_cls, NULL); 56 op->cb_put (op->cb_cls, NULL);
61} 57}
62 58
63 59
64/** 60/**
65 * Renew the Anastasis escrow of the key 61 * Renew the Anastasis escrow of the key
66 * 62 *
67 * @param h the handle for the escrow component 63 * @param op the escrow operation
68 * @param escrowAnchor the the escrow anchor returned by the start method 64 * @param escrowAnchor the the escrow anchor returned by the start method
69 * @param cb function to call with the (new) escrow anchor on completion
70 * @param cb_cls closure for @a cb
71 */ 65 */
72void 66void
73renew_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 67renew_anastasis_key_escrow (struct GNUNET_ESCROW_Operation *op,
74 struct GNUNET_ESCROW_Anchor *escrowAnchor, 68 struct GNUNET_ESCROW_Anchor *escrowAnchor)
75 GNUNET_ESCROW_AnchorContinuation cb,
76 void *cb_cls)
77{ 69{
78 // TODO: implement 70 // TODO: implement
79 cb (cb_cls, NULL); 71 op->cb_renew (op->cb_cls, NULL);
80} 72}
81 73
82 74
83/** 75/**
84 * Verify the Anastasis escrow of the key 76 * Verify the Anastasis escrow of the key
85 * 77 *
86 * @param h the handle for the escrow component 78 * @param op the escrow operation
87 * @param ego the identity ego containing the private key 79 * @param ego the identity ego containing the private key
88 * @param escrowAnchor the escrow anchor needed to restore the key 80 * @param escrowAnchor the escrow anchor needed to restore the key
89 * @param cb function to call with the verification result on completion, i.e.
90 * GNUNET_ESCROW_VALID if the escrow could successfully by restored,
91 * GNUNET_ESCROW_RENEW_NEEDED if the escrow needs to be renewed,
92 * GNUNET_ESCROW_INVALID otherwise
93 * @param cb_cls closure for @a cb
94 */ 81 */
95void 82void
96verify_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 83verify_anastasis_key_escrow (struct GNUNET_ESCROW_Operation *op,
97 const struct GNUNET_IDENTITY_Ego *ego, 84 const struct GNUNET_IDENTITY_Ego *ego,
98 struct GNUNET_ESCROW_Anchor *escrowAnchor, 85 struct GNUNET_ESCROW_Anchor *escrowAnchor)
99 GNUNET_ESCROW_VerifyContinuation cb,
100 void *cb_cls)
101{ 86{
102 // TODO: implement 87 // TODO: implement
103 cb (cb_cls, GNUNET_ESCROW_INVALID); 88 op->cb_verify (op->cb_cls, GNUNET_ESCROW_INVALID);
104} 89}
105 90
106 91
107/** 92/**
108 * Restore the key from Anastasis escrow 93 * Restore the key from Anastasis escrow
109 * 94 *
110 * @param h the handle for the escrow component 95 * @param op the escrow operation
111 * @param escrowAnchor the escrow anchor needed to restore the key 96 * @param escrowAnchor the escrow anchor needed to restore the key
112 * @param egoName the name of the ego to restore 97 * @param egoName the name of the ego to restore
113 * @param cb function to call with the restored ego on completion
114 * @param cb_cls closure for @a cb
115 */ 98 */
116void 99void
117restore_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h, 100restore_anastasis_key_escrow (struct GNUNET_ESCROW_Operation *op,
118 struct GNUNET_ESCROW_Anchor *escrowAnchor, 101 struct GNUNET_ESCROW_Anchor *escrowAnchor,
119 char *egoName, 102 char *egoName)
120 GNUNET_ESCROW_EgoContinuation cb,
121 void *cb_cls)
122{ 103{
123 // TODO: implement 104 // TODO: implement
124 cb (cb_cls, NULL); 105 op->cb_get (op->cb_cls, NULL);
125} 106}
126 107
127 108
@@ -129,10 +110,12 @@ restore_anastasis_key_escrow (struct GNUNET_ESCROW_Handle *h,
129 * Deserialize an escrow anchor string into a GNUNET_ESCROW_Anchor struct 110 * Deserialize an escrow anchor string into a GNUNET_ESCROW_Anchor struct
130 * 111 *
131 * @param anchorString the encoded escrow anchor string 112 * @param anchorString the encoded escrow anchor string
113 *
132 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 114 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct
133 */ 115 */
134struct GNUNET_ESCROW_Anchor * 116struct GNUNET_ESCROW_Anchor *
135anastasis_anchor_string_to_data (char *anchorString) 117anastasis_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
118 char *anchorString)
136{ 119{
137 struct GNUNET_ESCROW_Anchor *anchor; 120 struct GNUNET_ESCROW_Anchor *anchor;
138 uint32_t data_size; 121 uint32_t data_size;
@@ -149,7 +132,24 @@ anastasis_anchor_string_to_data (char *anchorString)
149 132
150 133
151/** 134/**
152 * ContinueIdentityInitFunction for the Anastasis plugin 135 * Serialize an escrow anchor struct into a string
136 *
137 * @param h the handle for the escrow component
138 * @param escrowAnchor the escrow anchor struct
139 *
140 * @return the encoded escrow anchor string
141 */
142char *
143anastasis_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
144 struct GNUNET_ESCROW_Anchor *escrowAnchor)
145{
146 // TODO: implement
147 return NULL;
148}
149
150
151/**
152 * IdentityInitContinuation for the Anastasis plugin
153 */ 153 */
154void 154void
155anastasis_cont_init () 155anastasis_cont_init ()
@@ -162,6 +162,7 @@ anastasis_cont_init ()
162 * Entry point for the plugin. 162 * Entry point for the plugin.
163 * 163 *
164 * @param cls Config info 164 * @param cls Config info
165 *
165 * @return the exported block API 166 * @return the exported block API
166 */ 167 */
167void * 168void *
@@ -191,6 +192,7 @@ libgnunet_plugin_escrow_anastasis_init (void *cls)
191 * Exit point from the plugin. 192 * Exit point from the plugin.
192 * 193 *
193 * @param cls the return value from #libgnunet_plugin_block_test_init() 194 * @param cls the return value from #libgnunet_plugin_block_test_init()
195 *
194 * @return NULL 196 * @return NULL
195 */ 197 */
196void * 198void *
diff --git a/src/escrow/plugin_escrow_gns.c b/src/escrow/plugin_escrow_gns.c
index 70f327fb4..f6b2822da 100644
--- a/src/escrow/plugin_escrow_gns.c
+++ b/src/escrow/plugin_escrow_gns.c
@@ -50,16 +50,12 @@ struct EscrowPluginHandle ph;
50/** 50/**
51 * Start the GNS escrow of the key 51 * Start the GNS escrow of the key
52 * 52 *
53 * @param h the handle for the escrow component 53 * @param op the escrow operation
54 * @param ego the identity ego containing the private key 54 * @param ego the identity ego containing the private key
55 * @param cb function to call with the escrow anchor on completion
56 * @param cb_cls closure for @a cb
57 */ 55 */
58void 56void
59start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 57start_gns_key_escrow (struct GNUNET_ESCROW_Operation *op,
60 const struct GNUNET_IDENTITY_Ego *ego, 58 const struct GNUNET_IDENTITY_Ego *ego)
61 GNUNET_ESCROW_AnchorContinuation cb,
62 void *cb_cls)
63{ 59{
64 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 60 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
65 sss_Keyshare keyshares; 61 sss_Keyshare keyshares;
@@ -68,7 +64,7 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
68 64
69 if (NULL == ego) 65 if (NULL == ego)
70 { 66 {
71 cb (cb_cls, NULL); 67 op->cb_put (op->cb_cls, NULL);
72 return; 68 return;
73 } 69 }
74 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 70 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
@@ -87,71 +83,56 @@ start_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
87 // TODO: implement 83 // TODO: implement
88 anchorDataSize = 0; // TODO! 84 anchorDataSize = 0; // TODO!
89 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize); 85 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize);
90 cb (cb_cls, anchor); 86 op->cb_put (op->cb_cls, anchor);
91} 87}
92 88
93 89
94/** 90/**
95 * Renew the GNS escrow of the key 91 * Renew the GNS escrow of the key
96 * 92 *
97 * @param h the handle for the escrow component 93 * @param op the escrow operation
98 * @param escrowAnchor the the escrow anchor returned by the start method 94 * @param escrowAnchor the the escrow anchor returned by the start method
99 * @param cb function to call with the (new) escrow anchor on completion
100 * @param cb_cls closure for @a cb
101 */ 95 */
102void 96void
103renew_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 97renew_gns_key_escrow (struct GNUNET_ESCROW_Operation *op,
104 struct GNUNET_ESCROW_Anchor *escrowAnchor, 98 struct GNUNET_ESCROW_Anchor *escrowAnchor)
105 GNUNET_ESCROW_AnchorContinuation cb,
106 void *cb_cls)
107{ 99{
108 // TODO: implement 100 // TODO: implement
109 cb (cb_cls, NULL); 101 op->cb_renew (op->cb_cls, NULL);
110} 102}
111 103
112 104
113/** 105/**
114 * Verify the GNS escrow of the key 106 * Verify the GNS escrow of the key
115 * 107 *
116 * @param h the handle for the escrow component 108 * @param op the escrow operation
117 * @param ego the identity ego containing the private key 109 * @param ego the identity ego containing the private key
118 * @param escrowAnchor the escrow anchor needed to restore the key 110 * @param escrowAnchor the escrow anchor needed to restore the key
119 * @param cb function to call with the verification result on completion, i.e.
120 * GNUNET_ESCROW_VALID if the escrow could successfully by restored,
121 * GNUNET_ESCROW_RENEW_NEEDED if the escrow needs to be renewed,
122 * GNUNET_ESCROW_INVALID otherwise
123 * @param cb_cls closure for @a cb
124 */ 111 */
125void 112void
126verify_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 113verify_gns_key_escrow (struct GNUNET_ESCROW_Operation *op,
127 const struct GNUNET_IDENTITY_Ego *ego, 114 const struct GNUNET_IDENTITY_Ego *ego,
128 struct GNUNET_ESCROW_Anchor *escrowAnchor, 115 struct GNUNET_ESCROW_Anchor *escrowAnchor)
129 GNUNET_ESCROW_VerifyContinuation cb,
130 void *cb_cls)
131{ 116{
132 // TODO: implement 117 // TODO: implement
133 cb (cb_cls, GNUNET_ESCROW_INVALID); 118 op->cb_verify (op->cb_cls, GNUNET_ESCROW_INVALID);
134} 119}
135 120
136 121
137/** 122/**
138 * Restore the key from GNS escrow 123 * Restore the key from GNS escrow
139 * 124 *
140 * @param h the handle for the escrow component 125 * @param op the escrow operation
141 * @param escrowAnchor the escrow anchor needed to restore the key 126 * @param escrowAnchor the escrow anchor needed to restore the key
142 * @param egoName the name of the ego to restore 127 * @param egoName the name of the ego to restore
143 * @param cb function to call with the restored ego on completion
144 * @param cb_cls closure for @a cb
145 */ 128 */
146void 129void
147restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h, 130restore_gns_key_escrow (struct GNUNET_ESCROW_Operation *op,
148 struct GNUNET_ESCROW_Anchor *escrowAnchor, 131 struct GNUNET_ESCROW_Anchor *escrowAnchor,
149 char *egoName, 132 char *egoName)
150 GNUNET_ESCROW_EgoContinuation cb,
151 void *cb_cls)
152{ 133{
153 // TODO: implement 134 // TODO: implement
154 cb (cb_cls, NULL); 135 op->cb_get (op->cb_cls, NULL);
155} 136}
156 137
157 138
@@ -159,10 +140,12 @@ restore_gns_key_escrow (struct GNUNET_ESCROW_Handle *h,
159 * Deserialize an escrow anchor string into a GNUNET_ESCROW_Anchor struct 140 * Deserialize an escrow anchor string into a GNUNET_ESCROW_Anchor struct
160 * 141 *
161 * @param anchorString the encoded escrow anchor string 142 * @param anchorString the encoded escrow anchor string
143 *
162 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 144 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct
163 */ 145 */
164struct GNUNET_ESCROW_Anchor * 146struct GNUNET_ESCROW_Anchor *
165gns_anchor_string_to_data (char *anchorString) 147gns_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
148 char *anchorString)
166{ 149{
167 struct GNUNET_ESCROW_Anchor *anchor; 150 struct GNUNET_ESCROW_Anchor *anchor;
168 uint32_t data_size; 151 uint32_t data_size;
@@ -179,7 +162,24 @@ gns_anchor_string_to_data (char *anchorString)
179 162
180 163
181/** 164/**
182 * ContinueIdentityInitFunction for the GNS plugin 165 * Serialize an escrow anchor struct into a string
166 *
167 * @param h the handle for the escrow component
168 * @param escrowAnchor the escrow anchor struct
169 *
170 * @return the encoded escrow anchor string
171 */
172char *
173gns_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
174 struct GNUNET_ESCROW_Anchor *escrowAnchor)
175{
176 // TODO: implement
177 return NULL;
178}
179
180
181/**
182 * IdentityInitContinuation for the GNS plugin
183 */ 183 */
184void 184void
185gns_cont_init () 185gns_cont_init ()
@@ -192,6 +192,7 @@ gns_cont_init ()
192 * Entry point for the plugin. 192 * Entry point for the plugin.
193 * 193 *
194 * @param cls Config info 194 * @param cls Config info
195 *
195 * @return the exported block API 196 * @return the exported block API
196 */ 197 */
197void * 198void *
@@ -221,6 +222,7 @@ libgnunet_plugin_escrow_gns_init (void *cls)
221 * Exit point from the plugin. 222 * Exit point from the plugin.
222 * 223 *
223 * @param cls the return value from #libgnunet_plugin_block_test_init() 224 * @param cls the return value from #libgnunet_plugin_block_test_init()
225 *
224 * @return NULL 226 * @return NULL
225 */ 227 */
226void * 228void *
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c
index e1df6bf77..c3680b625 100644
--- a/src/escrow/plugin_escrow_plaintext.c
+++ b/src/escrow/plugin_escrow_plaintext.c
@@ -29,6 +29,7 @@
29#include "gnunet_escrow_plugin.h" 29#include "gnunet_escrow_plugin.h"
30#include "escrow_plugin_helper.h" 30#include "escrow_plugin_helper.h"
31#include "gnunet_identity_service.h" 31#include "gnunet_identity_service.h"
32#include "../identity/identity.h"
32#include <inttypes.h> 33#include <inttypes.h>
33 34
34 35
@@ -46,16 +47,12 @@ struct EscrowPluginHandle ph;
46/** 47/**
47 * Start the plaintext escrow of the key, i.e. simply hand out the key 48 * Start the plaintext escrow of the key, i.e. simply hand out the key
48 * 49 *
49 * @param h the handle for the escrow component 50 * @param op the escrow operation
50 * @param ego the identity ego containing the private key 51 * @param ego the identity ego containing the private key
51 * @param cb function to call with the escrow anchor on completion
52 * @param cb_cls closure for @a cb
53 */ 52 */
54void 53void
55start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 54start_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op,
56 const struct GNUNET_IDENTITY_Ego *ego, 55 const struct GNUNET_IDENTITY_Ego *ego)
57 GNUNET_ESCROW_AnchorContinuation cb,
58 void *cb_cls)
59{ 56{
60 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 57 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
61 struct GNUNET_ESCROW_Anchor *anchor; 58 struct GNUNET_ESCROW_Anchor *anchor;
@@ -64,7 +61,7 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
64 61
65 if (NULL == ego) 62 if (NULL == ego)
66 { 63 {
67 cb (cb_cls, NULL); 64 op->cb_put (op->cb_cls, NULL);
68 return; 65 return;
69 } 66 }
70 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 67 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
@@ -76,46 +73,35 @@ start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
76 anchor->size = anchorDataSize; 73 anchor->size = anchorDataSize;
77 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize); 74 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize);
78 75
79 cb (cb_cls, anchor); 76 op->cb_put (op->cb_cls, anchor);
80} 77}
81 78
82 79
83/** 80/**
84 * Renew the plaintext escrow of the key, i.e. simply hand out the key 81 * Renew the plaintext escrow of the key, i.e. simply hand out the key
85 * 82 *
86 * @param h the handle for the escrow component 83 * @param op the escrow operation
87 * @param escrowAnchor the the escrow anchor returned by the start method 84 * @param escrowAnchor the the escrow anchor returned by the start method
88 * @param cb function to call with the (new) escrow anchor on completion
89 * @param cb_cls closure for @a cb
90 */ 85 */
91void 86void
92renew_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 87renew_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op,
93 struct GNUNET_ESCROW_Anchor *escrowAnchor, 88 struct GNUNET_ESCROW_Anchor *escrowAnchor)
94 GNUNET_ESCROW_AnchorContinuation cb,
95 void *cb_cls)
96{ 89{
97 cb (cb_cls, escrowAnchor); 90 op->cb_renew (op->cb_cls, escrowAnchor);
98} 91}
99 92
100 93
101/** 94/**
102 * Verify the plaintext escrow of the key 95 * Verify the plaintext escrow of the key
103 * 96 *
104 * @param h the handle for the escrow component 97 * @param op the escrow operation
105 * @param ego the identity ego containing the private key 98 * @param ego the identity ego containing the private key
106 * @param escrowAnchor the escrow anchor needed to restore the key 99 * @param escrowAnchor the escrow anchor needed to restore the key
107 * @param cb function to call with the verification result on completion, i.e.
108 * GNUNET_ESCROW_VALID if the escrow could successfully by restored,
109 * GNUNET_ESCROW_RENEW_NEEDED if the escrow needs to be renewed,
110 * GNUNET_ESCROW_INVALID otherwise
111 * @param cb_cls closure for @a cb
112 */ 100 */
113void 101void
114verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 102verify_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op,
115 const struct GNUNET_IDENTITY_Ego *ego, 103 const struct GNUNET_IDENTITY_Ego *ego,
116 struct GNUNET_ESCROW_Anchor *escrowAnchor, 104 struct GNUNET_ESCROW_Anchor *escrowAnchor)
117 GNUNET_ESCROW_VerifyContinuation cb,
118 void *cb_cls)
119{ 105{
120 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 106 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
121 char *pkString; 107 char *pkString;
@@ -123,70 +109,108 @@ verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
123 109
124 if (NULL == ego) 110 if (NULL == ego)
125 { 111 {
126 cb (cb_cls, GNUNET_ESCROW_INVALID); 112 op->cb_verify (op->cb_cls, GNUNET_ESCROW_INVALID);
127 return; 113 return;
128 } 114 }
129 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 115 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
130 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 116 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
131 verificationResult = strncmp (pkString, 117 verificationResult = strncmp (pkString,
132 (char *)escrowAnchor, 118 (char *)&escrowAnchor[1],
133 strlen (pkString)) == 0 ? 119 strlen (pkString)) == 0 ?
134 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; 120 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
135 cb (cb_cls, verificationResult); 121 op->cb_verify (op->cb_cls, verificationResult);
122}
123
124
125/**
126 * Creation operation finished.
127 *
128 * @param cls pointer to operation handle
129 * @param pk private key of the ego, or NULL on error
130 * @param emsg error message, NULL on success
131 */
132static void
133create_finished (void *cls,
134 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
135 const char *emsg)
136{
137 struct GNUNET_ESCROW_Operation *op = cls;
138 struct EgoEntry *ego_list;
139
140 if (NULL == pk)
141 {
142 fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg);
143 return;
144 }
145
146 /* find the ego in our ego list */
147 ego_list = ph.ego_head;
148 while (NULL != ego_list)
149 {
150 if (&ego_list->ego->pk == pk)
151 {
152 /* ego found */
153 op->cb_get (op->cb_cls, ego_list->ego);
154 return;
155 }
156 ego_list = ego_list->next;
157 }
158
159 /* ego not found (should not happen!) */
160 op->cb_get (op->cb_cls, NULL);
136} 161}
137 162
138 163
139/** 164/**
140 * Restore the key from plaintext escrow 165 * Restore the key from plaintext escrow
141 * 166 *
142 * @param h the handle for the escrow component 167 * @param op the escrow operation
143 * @param escrowAnchor the escrow anchor needed to restore the key 168 * @param escrowAnchor the escrow anchor needed to restore the key
144 * @param egoName the name of the ego to restore 169 * @param egoName the name of the ego to restore
145 * @param cb function to call with the restored ego on completion
146 * @param cb_cls closure for @a cb
147 */ 170 */
148void 171void
149restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h, 172restore_plaintext_key_escrow (struct GNUNET_ESCROW_Operation *op,
150 struct GNUNET_ESCROW_Anchor *escrowAnchor, 173 struct GNUNET_ESCROW_Anchor *escrowAnchor,
151 char *egoName, 174 char *egoName)
152 GNUNET_ESCROW_EgoContinuation cb,
153 void *cb_cls)
154{ 175{
155 struct GNUNET_CRYPTO_EcdsaPrivateKey pk; 176 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
156 struct GNUNET_IDENTITY_Operation *op; 177 struct GNUNET_IDENTITY_Operation *id_op;
157 178
158 if (NULL == escrowAnchor) 179 if (NULL == escrowAnchor)
159 { 180 {
160 cb (cb_cls, NULL); 181 op->cb_get (op->cb_cls, NULL);
161 return; 182 return;
162 } 183 }
163 if (GNUNET_OK != 184 if (GNUNET_OK !=
164 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)escrowAnchor, 185 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)&escrowAnchor[1],
165 strlen ((char *)escrowAnchor), 186 strlen ((char *)&escrowAnchor[1]),
166 &pk)) 187 &pk))
167 { 188 {
168 cb (cb_cls, NULL); 189 op->cb_get (op->cb_cls, NULL);
169 return; 190 return;
170 } 191 }
171 192
172 // TODO: implement 193 id_op = GNUNET_IDENTITY_create (identity_handle,
173 op = GNUNET_IDENTITY_create (NULL, 194 egoName,
174 egoName, 195 &pk,
175 &pk, 196 &create_finished,
176 NULL, 197 op);
177 NULL); 198
178 cb (cb_cls, NULL); 199 op->id_op = id_op;
179} 200}
180 201
181 202
182/** 203/**
183 * Deserialize an escrow anchor string into a GNUNET_ESCROW_Anchor struct 204 * Deserialize an escrow anchor string into a GNUNET_ESCROW_Anchor struct
184 * 205 *
206 * @param h the handle for the escrow component
185 * @param anchorString the encoded escrow anchor string 207 * @param anchorString the encoded escrow anchor string
208 *
186 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct 209 * @return the deserialized data packed into a GNUNET_ESCROW_Anchor struct
187 */ 210 */
188struct GNUNET_ESCROW_Anchor * 211struct GNUNET_ESCROW_Anchor *
189plaintext_anchor_string_to_data (char *anchorString) 212plaintext_anchor_string_to_data (struct GNUNET_ESCROW_Handle *h,
213 char *anchorString)
190{ 214{
191 struct GNUNET_ESCROW_Anchor *anchor; 215 struct GNUNET_ESCROW_Anchor *anchor;
192 uint32_t data_size; 216 uint32_t data_size;
@@ -203,7 +227,28 @@ plaintext_anchor_string_to_data (char *anchorString)
203 227
204 228
205/** 229/**
206 * ContinueIdentityInitFunction for the plaintext plugin 230 * Serialize an escrow anchor struct into a string
231 *
232 * @param h the handle for the escrow component
233 * @param escrowAnchor the escrow anchor struct
234 *
235 * @return the encoded escrow anchor string
236 */
237char *
238plaintext_anchor_data_to_string (struct GNUNET_ESCROW_Handle *h,
239 struct GNUNET_ESCROW_Anchor *escrowAnchor)
240{
241 char *anchorString;
242
243 anchorString = GNUNET_malloc (escrowAnchor->size);
244 GNUNET_memcpy (anchorString, &escrowAnchor[1], escrowAnchor->size);
245
246 return anchorString;
247}
248
249
250/**
251 * IdentityInitContinuation for the plaintext plugin
207 */ 252 */
208void 253void
209plaintext_cont_init () 254plaintext_cont_init ()
@@ -216,6 +261,7 @@ plaintext_cont_init ()
216 * Entry point for the plugin. 261 * Entry point for the plugin.
217 * 262 *
218 * @param cls Config info 263 * @param cls Config info
264 *
219 * @return the exported block API 265 * @return the exported block API
220 */ 266 */
221void * 267void *
@@ -230,6 +276,7 @@ libgnunet_plugin_escrow_plaintext_init (void *cls)
230 api->verify_key_escrow = &verify_plaintext_key_escrow; 276 api->verify_key_escrow = &verify_plaintext_key_escrow;
231 api->restore_key = &restore_plaintext_key_escrow; 277 api->restore_key = &restore_plaintext_key_escrow;
232 api->anchor_string_to_data = &plaintext_anchor_string_to_data; 278 api->anchor_string_to_data = &plaintext_anchor_string_to_data;
279 api->anchor_data_to_string = &plaintext_anchor_data_to_string;
233 280
234 ph.cont = &plaintext_cont_init; 281 ph.cont = &plaintext_cont_init;
235 282
@@ -245,6 +292,7 @@ libgnunet_plugin_escrow_plaintext_init (void *cls)
245 * Exit point from the plugin. 292 * Exit point from the plugin.
246 * 293 *
247 * @param cls the return value from #libgnunet_plugin_block_test_init() 294 * @param cls the return value from #libgnunet_plugin_block_test_init()
295 *
248 * @return NULL 296 * @return NULL
249 */ 297 */
250void * 298void *