d25e95404553330722d126e9607103dbf7220d64
[oweals/gnunet.git] / src / include / gnunet_revocation_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (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., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef GNUNET_REVOCATION_SERVICE_H_
22 #define GNUNET_REVOCATION_SERVICE_H_
23
24 /**
25  * @author Christian Grothoff
26  *
27  * @file
28  * API to perform and access key revocations
29  *
30  * @defgroup revocation  Revocation service
31  * Perform and access key revocations.
32  * @{
33  */
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_util_lib.h"
44
45 /**
46  * Version of the key revocation API.
47  */
48 #define GNUNET_REVOCATION_VERSION 0x00000000
49
50 /**
51  * Handle for the key revocation query.
52  */
53 struct GNUNET_REVOCATION_Query;
54
55 /**
56  * Callback to call with the result of a key revocation query.
57  *
58  * @param cls closure
59  * @param is_valid #GNUNET_NO of the key is/was revoked,
60  *                 #GNUNET_YES if the key is still valid,
61  *                 #GNUNET_SYSERR if we had trouble querying the service
62  *
63  */
64 typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
65                                             int is_valid);
66
67
68 /**
69  * Check if a key was revoked.
70  *
71  * @param cfg the configuration to use
72  * @param key key to check for revocation
73  * @param func funtion to call with the result of the check
74  * @param func_cls closure to pass to @a func
75  * @return handle to use in #GNUNET_REVOCATION_query_cancel to stop REVOCATION from invoking the callback
76  */
77 struct GNUNET_REVOCATION_Query *
78 GNUNET_REVOCATION_query (const struct GNUNET_CONFIGURATION_Handle *cfg,
79                          const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
80                          GNUNET_REVOCATION_Callback func, void *func_cls);
81
82
83 /**
84  * Cancel key revocation check.
85  *
86  * @param q query to cancel
87  */
88 void
89 GNUNET_REVOCATION_query_cancel (struct GNUNET_REVOCATION_Query *q);
90
91
92 /**
93  * Handle for the key revocation operation.
94  */
95 struct GNUNET_REVOCATION_Handle;
96
97
98 /**
99  * Perform key revocation.
100  *
101  * @param cfg the configuration to use
102  * @param key public key of the key to revoke
103  * @param sig signature to use on the revocation (should have been
104  *            created using #GNUNET_REVOCATION_sign_revocation).
105  * @param pow proof of work to use (should have been created by
106  *            iteratively calling #GNUNET_REVOCATION_check_pow)
107  * @param func funtion to call with the result of the check
108  *             (called with `is_valid` being #GNUNET_NO if
109  *              the revocation worked).
110  * @param func_cls closure to pass to @a func
111  * @return handle to use in #GNUNET_REVOCATION_revoke_cancel to stop REVOCATION from invoking the callback
112  */
113 struct GNUNET_REVOCATION_Handle *
114 GNUNET_REVOCATION_revoke (const struct GNUNET_CONFIGURATION_Handle *cfg,
115                           const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
116                           const struct GNUNET_CRYPTO_EcdsaSignature *sig,
117                           uint64_t pow,
118                           GNUNET_REVOCATION_Callback func, void *func_cls);
119
120
121 /**
122  * Cancel key revocation.
123  *
124  * @param h operation to cancel
125  */
126 void
127 GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
128
129
130 /**
131  * Check if the given proof-of-work value
132  * would be acceptable for revoking the given key.
133  *
134  * @param key key to check for
135  * @param pow proof of work value
136  * @param matching_bits how many bits must match (configuration)
137  * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
138  */
139 int
140 GNUNET_REVOCATION_check_pow (const struct GNUNET_CRYPTO_EcdsaPublicKey *key,
141                              uint64_t pow,
142                              unsigned int matching_bits);
143
144
145 /**
146  * Create a revocation signature.
147  *
148  * @param key private key of the key to revoke
149  * @param sig where to write the revocation signature
150  */
151 void
152 GNUNET_REVOCATION_sign_revocation (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
153                                    struct GNUNET_CRYPTO_EcdsaSignature *sig);
154
155
156 #if 0                           /* keep Emacsens' auto-indent happy */
157 {
158 #endif
159 #ifdef __cplusplus
160 }
161 #endif
162
163 #endif /* GNUNET_REVOCATION_SERVICE_H_ */
164
165 /** @} */ /* end of group revocation */