2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file revocation/revocation_api.c
22 * @brief API to perform and access key revocations
23 * @author Christian Grothoff
26 #include "gnunet_revocation_service.h"
27 #include "gnunet_signatures.h"
28 #include "gnunet_protocols.h"
29 #include "revocation.h"
33 * Handle for the key revocation query.
35 struct GNUNET_REVOCATION_Query
39 * Connection to the service.
41 struct GNUNET_CLIENT_Connection *client;
46 const struct GNUNET_CONFIGURATION_Handle *cfg;
51 struct GNUNET_CRYPTO_EccPublicSignKey key;
54 * Function to call with the result.
56 GNUNET_REVOCATION_Callback func;
59 * Closure for @e func.
66 * Check if a key was revoked.
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
74 struct GNUNET_REVOCATION_Query *
75 GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
76 const struct GNUNET_CRYPTO_EccPublicSignKey *key,
77 GNUNET_REVOCATION_Callback func, void *func_cls)
79 struct GNUNET_REVOCATION_Query *q;
81 q = GNUNET_new (struct GNUNET_REVOCATION_Query);
82 q->client = GNUNET_CLIENT_connect ("revocation", cfg);
86 q->func_cls = func_cls;
93 * Cancel key revocation check.
95 * @param q query to cancel
98 GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q)
100 GNUNET_CLIENT_disconnect (q->client);
106 * Handle for the key revocation operation.
108 struct GNUNET_REVOCATION_Handle
112 * Connection to the service.
114 struct GNUNET_CLIENT_Connection *client;
119 const struct GNUNET_CONFIGURATION_Handle *cfg;
124 struct GNUNET_CRYPTO_EccPublicSignKey key;
127 * Signature showing that we have the right to revoke.
129 struct GNUNET_CRYPTO_EccSignature sig;
132 * Proof of work showing that we spent enough resources to broadcast revocation.
137 * Function to call once we are done.
139 GNUNET_REVOCATION_Callback func;
142 * Closure for @e func.
150 * Perform key revocation.
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
164 struct GNUNET_REVOCATION_Handle *
165 GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
166 const struct GNUNET_CRYPTO_EccPublicSignKey *key,
167 const struct GNUNET_CRYPTO_EccSignature *sig,
169 GNUNET_REVOCATION_Callback func, void *func_cls)
171 struct GNUNET_REVOCATION_Handle *h;
173 h = GNUNET_new (struct GNUNET_REVOCATION_Handle);
174 h->client = GNUNET_CLIENT_connect ("revocation", cfg);
180 h->func_cls = func_cls;
187 * Cancel key revocation.
189 * @param h operation to cancel
192 GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h)
194 GNUNET_CLIENT_disconnect (h->client);
200 * Check if the given proof-of-work value
201 * would be acceptable for revoking the given key.
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
208 GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EccPublicSignKey *key,
217 * Create a revocation signature.
219 * @param key private key of the key to revoke
220 * @param sig where to write the revocation signature
223 GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EccPrivateKey *key,
224 struct GNUNET_CRYPTO_EccSignature *sig)
226 struct GNUNET_REVOCATION_RevokeMessage rm;
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,
239 /* end of revocation_api.c */