diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-01-10 14:57:20 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-01-10 14:57:20 +0100 |
commit | bfd4daf8ae1a3c6229ee3a8ca944adb2ef7e8677 (patch) | |
tree | 25aba3b09bbd0f1fdbc8f9295f49e2caffdb950c /src/dhtu/plugin_dhtu_gnunet.c | |
parent | 98edb2e5e83bafe96bb312262fcd9e992589b1d3 (diff) | |
download | gnunet-bfd4daf8ae1a3c6229ee3a8ca944adb2ef7e8677.tar.gz gnunet-bfd4daf8ae1a3c6229ee3a8ca944adb2ef7e8677.zip |
-remove signing from DHTU API: no longer needed
Diffstat (limited to 'src/dhtu/plugin_dhtu_gnunet.c')
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 182 |
1 files changed, 29 insertions, 153 deletions
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index ee78858c8..2163af941 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c | |||
@@ -35,42 +35,6 @@ | |||
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Handle for a private key used by this underlay. | ||
39 | */ | ||
40 | struct GNUNET_DHTU_PrivateKey | ||
41 | { | ||
42 | /** | ||
43 | * GNUnet uses eddsa for peers. | ||
44 | */ | ||
45 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv; | ||
46 | |||
47 | }; | ||
48 | |||
49 | GNUNET_NETWORK_STRUCT_BEGIN | ||
50 | |||
51 | /** | ||
52 | * Handle for a public key used by this underlay. | ||
53 | */ | ||
54 | struct PublicKey | ||
55 | { | ||
56 | |||
57 | /** | ||
58 | * Header. | ||
59 | */ | ||
60 | struct GNUNET_DHTU_PublicKey header; | ||
61 | |||
62 | /** | ||
63 | * GNUnet uses eddsa for peers. | ||
64 | */ | ||
65 | struct GNUNET_PeerIdentity peer_pub; | ||
66 | |||
67 | }; | ||
68 | |||
69 | |||
70 | GNUNET_NETWORK_STRUCT_END | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Handle for a HELLO we're offering the transport. | 38 | * Handle for a HELLO we're offering the transport. |
75 | */ | 39 | */ |
76 | struct HelloHandle | 40 | struct HelloHandle |
@@ -106,19 +70,14 @@ struct GNUNET_DHTU_Source | |||
106 | { | 70 | { |
107 | 71 | ||
108 | /** | 72 | /** |
109 | * Application context for this source. | 73 | * Hash of @e pid, position of this peer in the DHT overlay. |
110 | */ | ||
111 | void *app_ctx; | ||
112 | |||
113 | /** | ||
114 | * Hash position of this peer in the DHT. | ||
115 | */ | 74 | */ |
116 | struct GNUNET_DHTU_Hash my_id; | 75 | struct GNUNET_DHTU_HashKey id; |
117 | 76 | ||
118 | /** | 77 | /** |
119 | * Private key of this peer. | 78 | * Application context for this source. |
120 | */ | 79 | */ |
121 | struct GNUNET_DHTU_PrivateKey pk; | 80 | void *app_ctx; |
122 | 81 | ||
123 | }; | 82 | }; |
124 | 83 | ||
@@ -146,17 +105,6 @@ struct GNUNET_DHTU_Target | |||
146 | struct GNUNET_MQ_Handle *mq; | 105 | struct GNUNET_MQ_Handle *mq; |
147 | 106 | ||
148 | /** | 107 | /** |
149 | * Public key of the peer. | ||
150 | */ | ||
151 | struct PublicKey pk; | ||
152 | |||
153 | /** | ||
154 | * Hash of the @a pk to identify position of the peer | ||
155 | * in the DHT. | ||
156 | */ | ||
157 | struct GNUNET_DHTU_Hash peer_id; | ||
158 | |||
159 | /** | ||
160 | * Head of preferences expressed for this target. | 108 | * Head of preferences expressed for this target. |
161 | */ | 109 | */ |
162 | struct GNUNET_DHTU_PreferenceHandle *ph_head; | 110 | struct GNUNET_DHTU_PreferenceHandle *ph_head; |
@@ -172,6 +120,16 @@ struct GNUNET_DHTU_Target | |||
172 | struct GNUNET_ATS_ConnectivitySuggestHandle *csh; | 120 | struct GNUNET_ATS_ConnectivitySuggestHandle *csh; |
173 | 121 | ||
174 | /** | 122 | /** |
123 | * Identity of this peer. | ||
124 | */ | ||
125 | struct GNUNET_PeerIdentity pid; | ||
126 | |||
127 | /** | ||
128 | * Hash of @e pid, position of this peer in the DHT overlay. | ||
129 | */ | ||
130 | struct GNUNET_DHTU_HashKey id; | ||
131 | |||
132 | /** | ||
175 | * Preference counter, length of the @a ph_head DLL. | 133 | * Preference counter, length of the @a ph_head DLL. |
176 | */ | 134 | */ |
177 | unsigned int ph_count; | 135 | unsigned int ph_count; |
@@ -215,11 +173,6 @@ struct Plugin | |||
215 | struct GNUNET_DHTU_Source src; | 173 | struct GNUNET_DHTU_Source src; |
216 | 174 | ||
217 | /** | 175 | /** |
218 | * My identity. | ||
219 | */ | ||
220 | struct GNUNET_PeerIdentity my_identity; | ||
221 | |||
222 | /** | ||
223 | * Callbacks into the DHT. | 176 | * Callbacks into the DHT. |
224 | */ | 177 | */ |
225 | struct GNUNET_DHTU_PluginEnvironment *env; | 178 | struct GNUNET_DHTU_PluginEnvironment *env; |
@@ -253,76 +206,13 @@ struct Plugin | |||
253 | * Hellos we are offering to transport. | 206 | * Hellos we are offering to transport. |
254 | */ | 207 | */ |
255 | struct HelloHandle *hh_tail; | 208 | struct HelloHandle *hh_tail; |
256 | }; | ||
257 | |||
258 | 209 | ||
259 | /** | 210 | /** |
260 | * Use our private key to sign a message. | 211 | * Identity of this peer. |
261 | * | 212 | */ |
262 | * @param cls closure | 213 | struct GNUNET_PeerIdentity my_identity; |
263 | * @param pk our private key to sign with | ||
264 | * @param purpose what to sign | ||
265 | * @param[out] signature, allocated on heap and returned | ||
266 | * @return -1 on error, otherwise number of bytes in @a sig | ||
267 | */ | ||
268 | static ssize_t | ||
269 | ip_sign (void *cls, | ||
270 | const struct GNUNET_DHTU_PrivateKey *pk, | ||
271 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
272 | void **sig) | ||
273 | { | ||
274 | struct GNUNET_CRYPTO_EddsaSignature *es; | ||
275 | |||
276 | es = GNUNET_new (struct GNUNET_CRYPTO_EddsaSignature); | ||
277 | GNUNET_CRYPTO_eddsa_sign_ (&pk->eddsa_priv, | ||
278 | purpose, | ||
279 | es); | ||
280 | *sig = es; | ||
281 | return sizeof (*es); | ||
282 | } | ||
283 | |||
284 | |||
285 | /** | ||
286 | * Verify signature in @a sig over @a purpose. | ||
287 | * | ||
288 | * @param cls closure | ||
289 | * @param pk public key to verify signature of | ||
290 | * @param purpose what was being signed | ||
291 | * @param sig signature data | ||
292 | * @param sig_size number of bytes in @a sig | ||
293 | * @return #GNUNET_OK if signature is valid | ||
294 | * #GNUNET_NO if signatures are not supported | ||
295 | * #GNUNET_SYSERR if signature is invalid | ||
296 | */ | ||
297 | static enum GNUNET_GenericReturnValue | ||
298 | ip_verify (void *cls, | ||
299 | const struct GNUNET_DHTU_PublicKey *pk, | ||
300 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
301 | const void *sig, | ||
302 | size_t sig_size) | ||
303 | { | ||
304 | const struct GNUNET_CRYPTO_EddsaSignature *es = sig; | ||
305 | const struct PublicKey *pub; | ||
306 | 214 | ||
307 | GNUNET_assert (sizeof (struct PublicKey) == | 215 | }; |
308 | ntohs (pk->size)); | ||
309 | pub = (const struct PublicKey *) pk; | ||
310 | if (sizeof (*es) != sig_size) | ||
311 | { | ||
312 | GNUNET_break_op (0); | ||
313 | return GNUNET_SYSERR; | ||
314 | } | ||
315 | if (GNUNET_OK != | ||
316 | GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose), | ||
317 | purpose, | ||
318 | es, | ||
319 | &pub->peer_pub.public_key)) | ||
320 | { | ||
321 | GNUNET_break_op (0); | ||
322 | return GNUNET_SYSERR; | ||
323 | } | ||
324 | return GNUNET_OK; | ||
325 | } | ||
326 | 216 | ||
327 | 217 | ||
328 | /** | 218 | /** |
@@ -409,7 +299,7 @@ ip_hold (void *cls, | |||
409 | GNUNET_ATS_connectivity_suggest_cancel (target->csh); | 299 | GNUNET_ATS_connectivity_suggest_cancel (target->csh); |
410 | target->csh | 300 | target->csh |
411 | = GNUNET_ATS_connectivity_suggest (plugin->ats, | 301 | = GNUNET_ATS_connectivity_suggest (plugin->ats, |
412 | &target->pk.peer_pub, | 302 | &target->pid, |
413 | target->ph_count); | 303 | target->ph_count); |
414 | return ph; | 304 | return ph; |
415 | } | 305 | } |
@@ -439,7 +329,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | |||
439 | else | 329 | else |
440 | target->csh | 330 | target->csh |
441 | = GNUNET_ATS_connectivity_suggest (plugin->ats, | 331 | = GNUNET_ATS_connectivity_suggest (plugin->ats, |
442 | &target->pk.peer_pub, | 332 | &target->pid, |
443 | target->ph_count); | 333 | target->ph_count); |
444 | } | 334 | } |
445 | 335 | ||
@@ -503,15 +393,13 @@ core_connect_cb (void *cls, | |||
503 | target = GNUNET_new (struct GNUNET_DHTU_Target); | 393 | target = GNUNET_new (struct GNUNET_DHTU_Target); |
504 | target->plugin = plugin; | 394 | target->plugin = plugin; |
505 | target->mq = mq; | 395 | target->mq = mq; |
506 | target->pk.header.size = htons (sizeof (struct PublicKey)); | 396 | target->pid = *peer; |
507 | target->pk.peer_pub = *peer; | ||
508 | GNUNET_CRYPTO_hash (peer, | 397 | GNUNET_CRYPTO_hash (peer, |
509 | sizeof (struct GNUNET_PeerIdentity), | 398 | sizeof (*peer), |
510 | &target->peer_id.hc); | 399 | &target->id.sha512); |
511 | plugin->env->connect_cb (plugin->env->cls, | 400 | plugin->env->connect_cb (plugin->env->cls, |
512 | &target->pk.header, | ||
513 | &target->peer_id, | ||
514 | target, | 401 | target, |
402 | &target->id, | ||
515 | &target->app_ctx); | 403 | &target->app_ctx); |
516 | return target; | 404 | return target; |
517 | } | 405 | } |
@@ -573,12 +461,11 @@ peerinfo_cb (void *cls, | |||
573 | &GPI_plugins_find); | 461 | &GPI_plugins_find); |
574 | if (NULL == addr) | 462 | if (NULL == addr) |
575 | return; | 463 | return; |
576 | GNUNET_CRYPTO_hash (&plugin->my_identity, | 464 | GNUNET_CRYPTO_hash (peer, |
577 | sizeof (struct GNUNET_PeerIdentity), | 465 | sizeof (*peer), |
578 | &plugin->src.my_id.hc); | 466 | &plugin->src.id.sha512); |
579 | plugin->env->address_add_cb (plugin->env->cls, | 467 | plugin->env->address_add_cb (plugin->env->cls, |
580 | &plugin->src.my_id, | 468 | &plugin->src.id, |
581 | &plugin->src.pk, | ||
582 | addr, | 469 | addr, |
583 | &plugin->src, | 470 | &plugin->src, |
584 | &plugin->src.app_ctx); | 471 | &plugin->src.app_ctx); |
@@ -729,22 +616,11 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
729 | NULL), | 616 | NULL), |
730 | GNUNET_MQ_handler_end () | 617 | GNUNET_MQ_handler_end () |
731 | }; | 618 | }; |
732 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | ||
733 | 619 | ||
734 | pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (env->cfg); | ||
735 | if (NULL == pk) | ||
736 | { | ||
737 | GNUNET_break (0); | ||
738 | return NULL; | ||
739 | } | ||
740 | plugin = GNUNET_new (struct Plugin); | 620 | plugin = GNUNET_new (struct Plugin); |
741 | plugin->env = env; | 621 | plugin->env = env; |
742 | plugin->src.pk.eddsa_priv = *pk; | ||
743 | GNUNET_free (pk); | ||
744 | api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); | 622 | api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); |
745 | api->cls = plugin; | 623 | api->cls = plugin; |
746 | api->sign = &ip_sign; | ||
747 | api->verify = &ip_verify; | ||
748 | api->try_connect = &ip_try_connect; | 624 | api->try_connect = &ip_try_connect; |
749 | api->hold = &ip_hold; | 625 | api->hold = &ip_hold; |
750 | api->drop = &ip_drop; | 626 | api->drop = &ip_drop; |