aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/revocation_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-30 18:27:33 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-30 18:27:33 +0000
commit0314e07406c3860c4dbc76b585000685f3437e09 (patch)
tree6233c519361fe97c2ba6d519c16c09bf10a43027 /src/revocation/revocation_api.c
parent28018959b9afc2a8259f35e074869fd88b31b03e (diff)
downloadgnunet-0314e07406c3860c4dbc76b585000685f3437e09.tar.gz
gnunet-0314e07406c3860c4dbc76b585000685f3437e09.zip
-revocation prototype
Diffstat (limited to 'src/revocation/revocation_api.c')
-rw-r--r--src/revocation/revocation_api.c240
1 files changed, 240 insertions, 0 deletions
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
new file mode 100644
index 000000000..32fe995f7
--- /dev/null
+++ b/src/revocation/revocation_api.c
@@ -0,0 +1,240 @@
1/*
2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public Licerevocation as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public Licerevocation for more details.
14
15 You should have received a copy of the GNU General Public Licerevocation
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20/**
21 * @file revocation/revocation_api.c
22 * @brief API to perform and access key revocations
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_revocation_service.h"
27#include "gnunet_signatures.h"
28#include "gnunet_protocols.h"
29#include "revocation.h"
30
31
32/**
33 * Handle for the key revocation query.
34 */
35struct GNUNET_REVOCATION_Query
36{
37
38 /**
39 * Connection to the service.
40 */
41 struct GNUNET_CLIENT_Connection *client;
42
43 /**
44 * Our configuration.
45 */
46 const struct GNUNET_CONFIGURATION_Handle *cfg;
47
48 /**
49 * Key to check.
50 */
51 struct GNUNET_CRYPTO_EccPublicSignKey key;
52
53 /**
54 * Function to call with the result.
55 */
56 GNUNET_REVOCATION_Callback func;
57
58 /**
59 * Closure for @e func.
60 */
61 void *func_cls;
62};
63
64
65/**
66 * Check if a key was revoked.
67 *
68 * @param cfg the configuration to use
69 * @param key key to check for revocation
70 * @param func funtion to call with the result of the check
71 * @param func_cls closure to pass to @a func
72 * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback
73 */
74struct GNUNET_REVOCATION_Query *
75GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
76 const struct GNUNET_CRYPTO_EccPublicSignKey *key,
77 GNUNET_REVOCATION_Callback func, void *func_cls)
78{
79 struct GNUNET_REVOCATION_Query *q;
80
81 q = GNUNET_new (struct GNUNET_REVOCATION_Query);
82 q->client = GNUNET_CLIENT_connect ("revocation", cfg);
83 q->cfg = cfg;
84 q->key = *key;
85 q->func = func;
86 q->func_cls = func_cls;
87 GNUNET_break (0);
88 return q;
89}
90
91
92/**
93 * Cancel key revocation check.
94 *
95 * @param q query to cancel
96 */
97void
98GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q)
99{
100 GNUNET_CLIENT_disconnect (q->client);
101 GNUNET_free (q);
102}
103
104
105/**
106 * Handle for the key revocation operation.
107 */
108struct GNUNET_REVOCATION_Handle
109{
110
111 /**
112 * Connection to the service.
113 */
114 struct GNUNET_CLIENT_Connection *client;
115
116 /**
117 * Our configuration.
118 */
119 const struct GNUNET_CONFIGURATION_Handle *cfg;
120
121 /**
122 * Key to revoke.
123 */
124 struct GNUNET_CRYPTO_EccPublicSignKey key;
125
126 /**
127 * Signature showing that we have the right to revoke.
128 */
129 struct GNUNET_CRYPTO_EccSignature sig;
130
131 /**
132 * Proof of work showing that we spent enough resources to broadcast revocation.
133 */
134 uint64_t pow;
135
136 /**
137 * Function to call once we are done.
138 */
139 GNUNET_REVOCATION_Callback func;
140
141 /**
142 * Closure for @e func.
143 */
144 void *func_cls;
145
146};
147
148
149/**
150 * Perform key revocation.
151 *
152 * @param cfg the configuration to use
153 * @param key public key of the key to revoke
154 * @param sig signature to use on the revocation (should have been
155 * created using #GNUNET_REVOCATION_sign_revocation).
156 * @param pow proof of work to use (should have been created by
157 * iteratively calling #GNUNET_REVOCATION_check_pow)
158 * @param func funtion to call with the result of the check
159 * (called with `is_valid` being #GNUNET_NO if
160 * the revocation worked).
161 * @param func_cls closure to pass to @a func
162 * @return handle to use in #GNUNET_REVOCATION_cancel to stop REVOCATION from invoking the callback
163 */
164struct GNUNET_REVOCATION_Handle *
165GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
166 const struct GNUNET_CRYPTO_EccPublicSignKey *key,
167 const struct GNUNET_CRYPTO_EccSignature *sig,
168 uint64_t pow,
169 GNUNET_REVOCATION_Callback func, void *func_cls)
170{
171 struct GNUNET_REVOCATION_Handle *h;
172
173 h = GNUNET_new (struct GNUNET_REVOCATION_Handle);
174 h->client = GNUNET_CLIENT_connect ("revocation", cfg);
175 h->cfg = cfg;
176 h->key = *key;
177 h->sig = *sig;
178 h->pow = pow;
179 h->func = func;
180 h->func_cls = func_cls;
181 GNUNET_break (0);
182 return h;
183}
184
185
186/**
187 * Cancel key revocation.
188 *
189 * @param h operation to cancel
190 */
191void
192GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
193{
194 GNUNET_CLIENT_disconnect (h->client);
195 GNUNET_free (h);
196}
197
198
199/**
200 * Check if the given proof-of-work value
201 * would be acceptable for revoking the given key.
202 *
203 * @param key key to check for
204 * @param pow proof of work value
205 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
206 */
207int
208GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EccPublicSignKey *key,
209 uint64_t pow)
210{
211 GNUNET_break (0);
212 return GNUNET_NO;
213}
214
215
216/**
217 * Create a revocation signature.
218 *
219 * @param key private key of the key to revoke
220 * @param sig where to write the revocation signature
221 */
222void
223GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EccPrivateKey *key,
224 struct GNUNET_CRYPTO_EccSignature *sig)
225{
226 struct GNUNET_REVOCATION_RevokeMessage rm;
227
228 rm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
229 rm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
230 sizeof (struct GNUNET_CRYPTO_EccPublicSignKey));
231 GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &rm.public_key);
232 GNUNET_assert (GNUNET_OK ==
233 GNUNET_CRYPTO_ecc_sign (key,
234 &rm.purpose,
235 sig));
236}
237
238
239/* end of revocation_api.c */
240