aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_plaintext.c
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-07-10 13:45:09 +0200
committerjospaeth <spaethj@in.tum.de>2020-07-10 13:45:09 +0200
commit45016bc5f75a0182db4596df54bf68fe83ecd12a (patch)
tree42040ebd05ec6552f18c1c3d2ace82dc4f319a4a /src/escrow/plugin_escrow_plaintext.c
parent8e22ed9734ca214dae90a0a2f9bf0f2e1f5499bb (diff)
downloadgnunet-45016bc5f75a0182db4596df54bf68fe83ecd12a.tar.gz
gnunet-45016bc5f75a0182db4596df54bf68fe83ecd12a.zip
add escrow API methods, change plugin functions
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r--src/escrow/plugin_escrow_plaintext.c84
1 files changed, 71 insertions, 13 deletions
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c
index 54a5071bc..4b5342c61 100644
--- a/src/escrow/plugin_escrow_plaintext.c
+++ b/src/escrow/plugin_escrow_plaintext.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_escrow_plugin.h" 29#include "gnunet_escrow_plugin.h"
30#include "gnunet_identity_service.h"
30#include <inttypes.h> 31#include <inttypes.h>
31 32
32 33
@@ -34,37 +35,92 @@
34 * Start the plaintext escrow of the key, i.e. simply hand out the key 35 * Start the plaintext escrow of the key, i.e. simply hand out the key
35 * 36 *
36 * @param ego the identity ego containing the private key 37 * @param ego the identity ego containing the private key
37 * @param escrowAnchor the anchor needed to restore the key 38 * @return the escrow anchor needed to restore the key
38 * @return GNUNET_OK if successful
39 */ 39 */
40int 40void *
41start_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego, 41start_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego)
42 void *escrowAnchor)
43{ 42{
44 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 43 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
45 44
46 if (NULL == ego) 45 if (NULL == ego)
47 { 46 {
48 return GNUNET_NO; 47 return NULL;
49 } 48 }
50 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 49 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
51 escrowAnchor = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 50 return GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
52 return GNUNET_OK;
53} 51}
54 52
55 53
56/** 54/**
57 * Renew the plaintext escrow of the key, i.e. simply hand out the key 55 * Renew the plaintext escrow of the key, i.e. simply hand out the key
58 * 56 *
57 * @param escrowAnchor the the escrow anchor returned by the start method
58 * @return the escrow anchor needed to restore the key
59 */
60void *
61renew_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego)
62{
63 return start_plaintext_key_escrow (ego);
64}
65
66
67/**
68 * Verify the plaintext escrow of the key
69 *
59 * @param ego the identity ego containing the private key 70 * @param ego the identity ego containing the private key
60 * @param escrowAnchor the anchor needed to restore the key 71 * @param escrowAnchor the escrow anchor needed to restore the key
61 * @return GNUNET_OK if successful 72 * @return GNUNET_OK if verification is successful
62 */ 73 */
63int 74int
64renew_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego, 75verify_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego,
65 void *escrowAnchor) 76 void *escrowAnchor)
66{ 77{
67 return start_plaintext_key_escrow (ego, escrowAnchor); 78 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
79 char *pkString;
80
81 if (NULL == ego)
82 {
83 return NULL;
84 }
85 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
86 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
87 return strncmp (pkString, (char *)escrowAnchor, strlen (pkString));
88}
89
90
91/**
92 * Restore the key from plaintext escrow
93 *
94 * @param escrowAnchor the escrow anchor needed to restore the key
95 * @param egoName the name of the ego to restore
96 * @return the identity ego containing the private key
97 */
98const struct GNUNET_IDENTITY_Ego *
99restore_plaintext_key_escrow (void *escrowAnchor,
100 char *egoName)
101{
102 const struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
103 struct GNUNET_IDENTITY_Operation *op;
104
105 if (NULL == escrowAnchor)
106 {
107 return NULL;
108 }
109 // TODO: ecdsa method for string -> privkey
110 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)escrowAnchor,
111 strlen ((char *)escrowAnchor),
112 &pk))
113 {
114 return NULL;
115 }
116
117 // TODO: implement
118 op = GNUNET_IDENTITY_create (NULL,
119 egoName,
120 &pk,
121 NULL,
122 NULL);
123 return NULL;
68} 124}
69 125
70 126
@@ -82,6 +138,8 @@ libgnunet_plugin_escrow_plaintext_init (void *cls)
82 api = GNUNET_new (struct GNUNET_ESCROW_KeyPluginFunctions); 138 api = GNUNET_new (struct GNUNET_ESCROW_KeyPluginFunctions);
83 api->start_key_escrow = &start_plaintext_key_escrow; 139 api->start_key_escrow = &start_plaintext_key_escrow;
84 api->renew_key_escrow = &renew_plaintext_key_escrow; 140 api->renew_key_escrow = &renew_plaintext_key_escrow;
141 api->verify_key_escrow = &verify_plaintext_key_escrow;
142 api->restore_key = &restore_plaintext_key_escrow;
85 return api; 143 return api;
86} 144}
87 145