diff options
Diffstat (limited to 'src/revocation')
-rw-r--r-- | src/revocation/Makefile.am | 13 | ||||
-rw-r--r-- | src/revocation/revocation.h | 20 | ||||
-rw-r--r-- | src/revocation/revocation_api.c | 240 |
3 files changed, 262 insertions, 11 deletions
diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am index cc0dfd15f..6937ee85c 100644 --- a/src/revocation/Makefile.am +++ b/src/revocation/Makefile.am | |||
@@ -17,4 +17,15 @@ pkgcfg_DATA = \ | |||
17 | revocation.conf | 17 | revocation.conf |
18 | 18 | ||
19 | 19 | ||
20 | EXTRA_DIST = revocation.h \ No newline at end of file | 20 | lib_LTLIBRARIES = libgnunetrevocation.la |
21 | |||
22 | libgnunetrevocation_la_SOURCES = \ | ||
23 | revocation_api.c revocation.h | ||
24 | libgnunetrevocation_la_LIBADD = \ | ||
25 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
26 | $(GN_LIBINTL) $(XLIB) | ||
27 | libgnunetrevocation_la_LDFLAGS = \ | ||
28 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | ||
29 | -version-info 0:0:0 | ||
30 | |||
31 | #EXTRA_DIST = | ||
diff --git a/src/revocation/revocation.h b/src/revocation/revocation.h index aa15fd44a..c6c5d5e76 100644 --- a/src/revocation/revocation.h +++ b/src/revocation/revocation.h | |||
@@ -48,7 +48,7 @@ struct GNUNET_REVOCATION_QueryMessage | |||
48 | /** | 48 | /** |
49 | * Key to check. | 49 | * Key to check. |
50 | */ | 50 | */ |
51 | struct GNUNET_CRYPTO_EccPublicSignKey key GNUNET_PACKED; | 51 | struct GNUNET_CRYPTO_EccPublicSignKey key; |
52 | 52 | ||
53 | }; | 53 | }; |
54 | 54 | ||
@@ -91,25 +91,25 @@ struct GNUNET_REVOCATION_RevokeMessage | |||
91 | uint32_t reserved GNUNET_PACKED; | 91 | uint32_t reserved GNUNET_PACKED; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Signature confirming revocation. | 94 | * Number that causes a hash collision with the @e public_key. |
95 | */ | 95 | */ |
96 | struct GNUNET_CRYPTO_EccSignature signature GNUNET_PACKED; | 96 | uint64_t proof_of_work GNUNET_PACKED; |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * Must have purpose #GNUNET_SIGNATURE_PURPOSE_REVOCATION, | 99 | * Signature confirming revocation. |
100 | * size expands over the key and the proof of work. | ||
101 | */ | 100 | */ |
102 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose GNUNET_PACKED; | 101 | struct GNUNET_CRYPTO_EccSignature signature; |
103 | 102 | ||
104 | /** | 103 | /** |
105 | * Key to revoke. | 104 | * Must have purpose #GNUNET_SIGNATURE_PURPOSE_REVOCATION, |
105 | * size expands over the public key. | ||
106 | */ | 106 | */ |
107 | struct GNUNET_CRYPTO_EccPublicSignKey public_key GNUNET_PACKED; | 107 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * Number that causes a hash collision with the @e public_key. | 110 | * Key to revoke. |
111 | */ | 111 | */ |
112 | uint64_t proof_of_work GNUNET_PACKED; | 112 | struct GNUNET_CRYPTO_EccPublicSignKey public_key; |
113 | 113 | ||
114 | }; | 114 | }; |
115 | 115 | ||
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 | */ | ||
35 | struct 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 | */ | ||
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) | ||
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 | */ | ||
97 | void | ||
98 | GNUNET_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 | */ | ||
108 | struct 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 | */ | ||
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, | ||
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 | */ | ||
191 | void | ||
192 | GNUNET_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 | */ | ||
207 | int | ||
208 | GNUNET_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 | */ | ||
222 | void | ||
223 | GNUNET_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 | |||