aboutsummaryrefslogtreecommitdiff
path: root/src/escrow/plugin_escrow_plaintext.c
diff options
context:
space:
mode:
authorjospaeth <spaethj@in.tum.de>2020-07-16 13:41:56 +0200
committerjospaeth <spaethj@in.tum.de>2020-07-16 13:41:56 +0200
commita8b7f94fadb36299b55f15faaa5f4fda143ba9bb (patch)
tree5641541a01aba222d1131166baca6e33dfd2d4f4 /src/escrow/plugin_escrow_plaintext.c
parentf6007d417be9f3030dad817151ed39d896d233ba (diff)
downloadgnunet-a8b7f94fadb36299b55f15faaa5f4fda143ba9bb.tar.gz
gnunet-a8b7f94fadb36299b55f15faaa5f4fda143ba9bb.zip
change plugin functions to support async code
Diffstat (limited to 'src/escrow/plugin_escrow_plaintext.c')
-rw-r--r--src/escrow/plugin_escrow_plaintext.c95
1 files changed, 68 insertions, 27 deletions
diff --git a/src/escrow/plugin_escrow_plaintext.c b/src/escrow/plugin_escrow_plaintext.c
index 3d15167b9..f36e33c6b 100644
--- a/src/escrow/plugin_escrow_plaintext.c
+++ b/src/escrow/plugin_escrow_plaintext.c
@@ -46,86 +46,127 @@ struct EscrowPluginHandle ph;
46/** 46/**
47 * Start the plaintext escrow of the key, i.e. simply hand out the key 47 * Start the plaintext escrow of the key, i.e. simply hand out the key
48 * 48 *
49 * @param h the handle for the escrow component
49 * @param ego the identity ego containing the private key 50 * @param ego the identity ego containing the private key
50 * @return the escrow anchor needed to restore the key 51 * @param cb function to call with the escrow anchor on completion
52 * @param cb_cls closure for @a cb
51 */ 53 */
52void * 54void
53start_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego) 55start_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
56 const struct GNUNET_IDENTITY_Ego *ego,
57 GNUNET_ESCROW_AnchorContinuation cb,
58 void *cb_cls)
54{ 59{
55 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 60 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
61 struct GNUNET_ESCROW_Anchor *anchor;
62 char *pkString;
63 uint32_t anchorDataSize;
56 64
57 if (NULL == ego) 65 if (NULL == ego)
58 { 66 {
59 return NULL; 67 cb (cb_cls, NULL);
68 return;
60 } 69 }
61 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 70 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
62 return GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 71 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
72
73 anchorDataSize = strlen (pkString) + 1;
74 anchor = GNUNET_malloc (sizeof (struct GNUNET_ESCROW_Anchor) + anchorDataSize);
75 anchor->method = GNUNET_ESCROW_KEY_PLAINTEXT;
76 anchor->size = anchorDataSize;
77 GNUNET_memcpy (&anchor[1], pkString, anchorDataSize);
78
79 cb (cb_cls, anchor);
63} 80}
64 81
65 82
66/** 83/**
67 * Renew the plaintext escrow of the key, i.e. simply hand out the key 84 * Renew the plaintext escrow of the key, i.e. simply hand out the key
68 * 85 *
86 * @param h the handle for the escrow component
69 * @param escrowAnchor the the escrow anchor returned by the start method 87 * @param escrowAnchor the the escrow anchor returned by the start method
70 * @return the escrow anchor needed to restore the key 88 * @param cb function to call with the (new) escrow anchor on completion
89 * @param cb_cls closure for @a cb
71 */ 90 */
72void * 91void
73renew_plaintext_key_escrow (void *escrowAnchor) 92renew_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
93 struct GNUNET_ESCROW_Anchor *escrowAnchor,
94 GNUNET_ESCROW_AnchorContinuation cb,
95 void *cb_cls)
74{ 96{
75 return escrowAnchor; 97 cb (cb_cls, escrowAnchor);
76} 98}
77 99
78 100
79/** 101/**
80 * Verify the plaintext escrow of the key 102 * Verify the plaintext escrow of the key
81 * 103 *
104 * @param h the handle for the escrow component
82 * @param ego the identity ego containing the private key 105 * @param ego the identity ego containing the private key
83 * @param escrowAnchor the escrow anchor needed to restore the key 106 * @param escrowAnchor the escrow anchor needed to restore the key
84 * @return GNUNET_ESCROW_VALID if the escrow could successfully by restored, 107 * @param cb function to call with the verification result on completion, i.e.
85 * GNUNET_ESCROW_RENEW_NEEDED if the escrow needs to be renewed, 108 * GNUNET_ESCROW_VALID if the escrow could successfully by restored,
86 * GNUNET_ESCROW_INVALID otherwise 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
87 */ 112 */
88int 113void
89verify_plaintext_key_escrow (const struct GNUNET_IDENTITY_Ego *ego, 114verify_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
90 void *escrowAnchor) 115 const struct GNUNET_IDENTITY_Ego *ego,
116 struct GNUNET_ESCROW_Anchor *escrowAnchor,
117 GNUNET_ESCROW_VerifyContinuation cb,
118 void *cb_cls)
91{ 119{
92 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 120 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
93 char *pkString; 121 char *pkString;
122 int verificationResult;
94 123
95 if (NULL == ego) 124 if (NULL == ego)
96 { 125 {
97 return GNUNET_ESCROW_INVALID; 126 cb (cb_cls, GNUNET_ESCROW_INVALID);
127 return;
98 } 128 }
99 pk = GNUNET_IDENTITY_ego_get_private_key (ego); 129 pk = GNUNET_IDENTITY_ego_get_private_key (ego);
100 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); 130 pkString = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk);
101 return strncmp (pkString, (char *)escrowAnchor, strlen (pkString)) == 0 ? 131 verificationResult = strncmp (pkString,
132 (char *)escrowAnchor,
133 strlen (pkString)) == 0 ?
102 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID; 134 GNUNET_ESCROW_VALID : GNUNET_ESCROW_INVALID;
135 cb (cb_cls, verificationResult);
103} 136}
104 137
105 138
106/** 139/**
107 * Restore the key from plaintext escrow 140 * Restore the key from plaintext escrow
108 * 141 *
142 * @param h the handle for the escrow component
109 * @param escrowAnchor the escrow anchor needed to restore the key 143 * @param escrowAnchor the escrow anchor needed to restore the key
110 * @param egoName the name of the ego to restore 144 * @param egoName the name of the ego to restore
111 * @return the identity ego containing the private key 145 * @param cb function to call with the restored ego on completion
146 * @param cb_cls closure for @a cb
112 */ 147 */
113const struct GNUNET_IDENTITY_Ego * 148void
114restore_plaintext_key_escrow (void *escrowAnchor, 149restore_plaintext_key_escrow (struct GNUNET_ESCROW_Handle *h,
115 char *egoName) 150 struct GNUNET_ESCROW_Anchor *escrowAnchor,
151 char *egoName,
152 GNUNET_ESCROW_EgoContinuation cb,
153 void *cb_cls)
116{ 154{
117 struct GNUNET_CRYPTO_EcdsaPrivateKey pk; 155 struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
118 struct GNUNET_IDENTITY_Operation *op; 156 struct GNUNET_IDENTITY_Operation *op;
119 157
120 if (NULL == escrowAnchor) 158 if (NULL == escrowAnchor)
121 { 159 {
122 return NULL; 160 cb (cb_cls, NULL);
161 return;
123 } 162 }
124 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)escrowAnchor, 163 if (GNUNET_OK !=
125 strlen ((char *)escrowAnchor), 164 GNUNET_CRYPTO_ecdsa_private_key_from_string ((char *)escrowAnchor,
126 &pk)) 165 strlen ((char *)escrowAnchor),
166 &pk))
127 { 167 {
128 return NULL; 168 cb (cb_cls, NULL);
169 return;
129 } 170 }
130 171
131 // TODO: implement 172 // TODO: implement
@@ -134,7 +175,7 @@ restore_plaintext_key_escrow (void *escrowAnchor,
134 &pk, 175 &pk,
135 NULL, 176 NULL,
136 NULL); 177 NULL);
137 return NULL; 178 cb (cb_cls, NULL);
138} 179}
139 180
140 181