aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_plaintext.c
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/plugin_escrow_plaintext.c
parent646beac5ca85327b150affa034a5e9d1559382b1 (diff)
downloadgnunet-15ad508b20fbca46d8b9a8682a723b34098545bf.tar.gz
gnunet-15ad508b20fbca46d8b9a8682a723b34098545bf.zip
pass only ESCROW_Operation to the plugins
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r--src/escrow/plugin_escrow_plaintext.c150
1 files changed, 99 insertions, 51 deletions
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 *