diff options
Diffstat (limited to 'src/credential/gnunet-credential.c')
-rw-r--r-- | src/credential/gnunet-credential.c | 193 |
1 files changed, 43 insertions, 150 deletions
diff --git a/src/credential/gnunet-credential.c b/src/credential/gnunet-credential.c index 31cd4fd8f..bfd4223ba 100644 --- a/src/credential/gnunet-credential.c +++ b/src/credential/gnunet-credential.c | |||
@@ -24,7 +24,6 @@ | |||
24 | */ | 24 | */ |
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include <gnunet_util_lib.h> | 26 | #include <gnunet_util_lib.h> |
27 | #include <gnunet_identity_service.h> | ||
28 | #include <gnunet_credential_service.h> | 27 | #include <gnunet_credential_service.h> |
29 | 28 | ||
30 | /** | 29 | /** |
@@ -43,31 +42,11 @@ static struct GNUNET_CREDENTIAL_Handle *credential; | |||
43 | static struct GNUNET_TIME_Relative timeout; | 42 | static struct GNUNET_TIME_Relative timeout; |
44 | 43 | ||
45 | /** | 44 | /** |
46 | * Credential to lookup. (-u option) | ||
47 | */ | ||
48 | static char *lookup_credential; | ||
49 | |||
50 | /** | ||
51 | * Handle to verify request | 45 | * Handle to verify request |
52 | */ | 46 | */ |
53 | static struct GNUNET_CREDENTIAL_Request *verify_request; | 47 | static struct GNUNET_CREDENTIAL_Request *verify_request; |
54 | 48 | ||
55 | /** | 49 | /** |
56 | * Lookup an ego with the identity service. | ||
57 | */ | ||
58 | static struct GNUNET_IDENTITY_EgoLookup *el; | ||
59 | |||
60 | /** | ||
61 | * Handle for identity service. | ||
62 | */ | ||
63 | static struct GNUNET_IDENTITY_Handle *identity; | ||
64 | |||
65 | /** | ||
66 | * Active operation on identity service. | ||
67 | */ | ||
68 | static struct GNUNET_IDENTITY_Operation *id_op; | ||
69 | |||
70 | /** | ||
71 | * Task scheduled to handle timeout. | 50 | * Task scheduled to handle timeout. |
72 | */ | 51 | */ |
73 | static struct GNUNET_SCHEDULER_Task *tt; | 52 | static struct GNUNET_SCHEDULER_Task *tt; |
@@ -78,16 +57,19 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
78 | static char *subject_key; | 57 | static char *subject_key; |
79 | 58 | ||
80 | /** | 59 | /** |
81 | * Subject pubkey string | 60 | * Subject credential string |
82 | */ | 61 | */ |
83 | static char *issuer_key; | 62 | static char *subject_credential; |
84 | |||
85 | 63 | ||
64 | /** | ||
65 | * Issuer pubkey string | ||
66 | */ | ||
67 | static char *issuer_key; | ||
86 | 68 | ||
87 | /** | 69 | /** |
88 | * Identity of the zone to use for the lookup (-z option) | 70 | * Issuer attribute |
89 | */ | 71 | */ |
90 | static char *zone_ego_name; | 72 | static char *issuer_attr; |
91 | 73 | ||
92 | 74 | ||
93 | /** | 75 | /** |
@@ -98,26 +80,11 @@ static char *zone_ego_name; | |||
98 | static void | 80 | static void |
99 | do_shutdown (void *cls) | 81 | do_shutdown (void *cls) |
100 | { | 82 | { |
101 | if (NULL != el) | ||
102 | { | ||
103 | GNUNET_IDENTITY_ego_lookup_cancel (el); | ||
104 | el = NULL; | ||
105 | } | ||
106 | if (NULL != id_op) | ||
107 | { | ||
108 | GNUNET_IDENTITY_cancel (id_op); | ||
109 | id_op = NULL; | ||
110 | } | ||
111 | if (NULL != verify_request) | 83 | if (NULL != verify_request) |
112 | { | 84 | { |
113 | GNUNET_CREDENTIAL_verify_cancel (verify_request); | 85 | GNUNET_CREDENTIAL_verify_cancel (verify_request); |
114 | verify_request = NULL; | 86 | verify_request = NULL; |
115 | } | 87 | } |
116 | if (NULL != identity) | ||
117 | { | ||
118 | GNUNET_IDENTITY_disconnect (identity); | ||
119 | identity = NULL; | ||
120 | } | ||
121 | if (NULL != credential) | 88 | if (NULL != credential) |
122 | { | 89 | { |
123 | GNUNET_CREDENTIAL_disconnect (credential); | 90 | GNUNET_CREDENTIAL_disconnect (credential); |
@@ -172,20 +139,39 @@ handle_verify_result (void *cls, | |||
172 | 139 | ||
173 | 140 | ||
174 | /** | 141 | /** |
175 | * Perform the actual resolution, with the subject pkey and | 142 | * Main function that will be run. |
176 | * the issuer public key | ||
177 | * | 143 | * |
178 | * @param pkey public key to use for the zone, can be NULL | 144 | * @param cls closure |
179 | * @param shorten_key private key used for shortening, can be NULL | 145 | * @param args remaining command-line arguments |
146 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
147 | * @param c configuration | ||
180 | */ | 148 | */ |
181 | static void | 149 | static void |
182 | lookup_credentials (struct GNUNET_IDENTITY_Ego *ego) | 150 | run (void *cls, |
151 | char *const *args, | ||
152 | const char *cfgfile, | ||
153 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
183 | { | 154 | { |
184 | 155 | ||
156 | cfg = c; | ||
157 | credential = GNUNET_CREDENTIAL_connect (cfg); | ||
158 | |||
159 | if (NULL == credential) | ||
160 | { | ||
161 | fprintf (stderr, | ||
162 | _("Failed to connect to CREDENTIAL\n")); | ||
163 | return; | ||
164 | } | ||
165 | tt = GNUNET_SCHEDULER_add_delayed (timeout, | ||
166 | &do_timeout, NULL); | ||
167 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
168 | |||
169 | |||
170 | |||
185 | struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey; | 171 | struct GNUNET_CRYPTO_EcdsaPublicKey subject_pkey; |
186 | struct GNUNET_CRYPTO_EcdsaPublicKey issuer_pkey; | 172 | struct GNUNET_CRYPTO_EcdsaPublicKey issuer_pkey; |
187 | 173 | ||
188 | if (NULL != subject_key && NULL != issuer_key && NULL != lookup_credential) | 174 | if (NULL != subject_key && NULL != issuer_key) |
189 | { | 175 | { |
190 | if (GNUNET_OK != | 176 | if (GNUNET_OK != |
191 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_key, | 177 | GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_key, |
@@ -213,9 +199,9 @@ lookup_credentials (struct GNUNET_IDENTITY_Ego *ego) | |||
213 | 199 | ||
214 | verify_request = GNUNET_CREDENTIAL_verify(credential, | 200 | verify_request = GNUNET_CREDENTIAL_verify(credential, |
215 | &issuer_pkey, | 201 | &issuer_pkey, |
216 | "test", //TODO argument | 202 | issuer_attr, //TODO argument |
217 | &subject_pkey, | 203 | &subject_pkey, |
218 | lookup_credential, | 204 | subject_credential, |
219 | &handle_verify_result, | 205 | &handle_verify_result, |
220 | NULL); | 206 | NULL); |
221 | return; | 207 | return; |
@@ -231,93 +217,6 @@ lookup_credentials (struct GNUNET_IDENTITY_Ego *ego) | |||
231 | 217 | ||
232 | 218 | ||
233 | /** | 219 | /** |
234 | * Method called to with the ego we are to use for the lookup, | ||
235 | * when the ego is the one for the default master zone. | ||
236 | * | ||
237 | * @param cls closure (NULL, unused) | ||
238 | * @param ego ego handle, NULL if not found | ||
239 | * @param ctx context for application to store data for this ego | ||
240 | * (during the lifetime of this process, initially NULL) | ||
241 | * @param name name assigned by the user for this ego, | ||
242 | * NULL if the user just deleted the ego and it | ||
243 | * must thus no longer be used | ||
244 | */ | ||
245 | static void | ||
246 | identity_master_cb (void *cls, | ||
247 | struct GNUNET_IDENTITY_Ego *ego, | ||
248 | void **ctx, | ||
249 | const char *name) | ||
250 | { | ||
251 | |||
252 | id_op = NULL; | ||
253 | if (NULL == ego) | ||
254 | { | ||
255 | fprintf (stderr, | ||
256 | _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n")); | ||
257 | GNUNET_SCHEDULER_shutdown (); | ||
258 | return; | ||
259 | } | ||
260 | |||
261 | lookup_credentials(ego); | ||
262 | |||
263 | |||
264 | } | ||
265 | |||
266 | |||
267 | /** | ||
268 | * Main function that will be run. | ||
269 | * | ||
270 | * @param cls closure | ||
271 | * @param args remaining command-line arguments | ||
272 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
273 | * @param c configuration | ||
274 | */ | ||
275 | static void | ||
276 | run (void *cls, | ||
277 | char *const *args, | ||
278 | const char *cfgfile, | ||
279 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
280 | { | ||
281 | |||
282 | cfg = c; | ||
283 | credential = GNUNET_CREDENTIAL_connect (cfg); | ||
284 | identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | ||
285 | |||
286 | |||
287 | |||
288 | |||
289 | if (NULL == credential) | ||
290 | { | ||
291 | fprintf (stderr, | ||
292 | _("Failed to connect to CREDENTIAL\n")); | ||
293 | return; | ||
294 | } | ||
295 | if (NULL == identity) | ||
296 | { | ||
297 | fprintf (stderr, | ||
298 | _("Failed to connect to IDENTITY\n")); | ||
299 | return; | ||
300 | } | ||
301 | tt = GNUNET_SCHEDULER_add_delayed (timeout, | ||
302 | &do_timeout, NULL); | ||
303 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | ||
304 | |||
305 | |||
306 | |||
307 | GNUNET_break (NULL == id_op); | ||
308 | id_op = GNUNET_IDENTITY_get (identity, | ||
309 | "gns-master",//# TODO: Create credential-master | ||
310 | &identity_master_cb, | ||
311 | cls); | ||
312 | GNUNET_assert (NULL != id_op); | ||
313 | |||
314 | |||
315 | |||
316 | |||
317 | } | ||
318 | |||
319 | |||
320 | /** | ||
321 | * The main function for gnunet-gns. | 220 | * The main function for gnunet-gns. |
322 | * | 221 | * |
323 | * @param argc number of arguments from the command line | 222 | * @param argc number of arguments from the command line |
@@ -328,24 +227,18 @@ int | |||
328 | main (int argc, char *const *argv) | 227 | main (int argc, char *const *argv) |
329 | { | 228 | { |
330 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 229 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
331 | {'u', "lookup", "CREDENTIAL", | ||
332 | gettext_noop ("Lookup a record for the given credential"), 1, | ||
333 | &GNUNET_GETOPT_set_string, &lookup_credential}, | ||
334 | /** { 'T', "timeout", "DELAY", | ||
335 | gettext_noop ("Specify timeout for the lookup"), 1, | ||
336 | &GNUNET_GETOPT_set_relative_time, &timeout }, | ||
337 | {'t', "type", "TYPE", | ||
338 | gettext_noop ("Specify the type of the record to lookup"), 1, | ||
339 | &GNUNET_GETOPT_set_string, &lookup_type},**/ | ||
340 | {'z', "zone", "NAME", | ||
341 | gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1, | ||
342 | &GNUNET_GETOPT_set_string, &zone_ego_name}, | ||
343 | {'s', "subject", "PKEY", | 230 | {'s', "subject", "PKEY", |
344 | gettext_noop ("Specify the public key of the subject to lookup the credential for"), 1, | 231 | gettext_noop ("The public key of the subject to lookup the credential for"), 1, |
345 | &GNUNET_GETOPT_set_string, &subject_key}, | 232 | &GNUNET_GETOPT_set_string, &subject_key}, |
233 | {'c', "credential", "CRED", | ||
234 | gettext_noop ("The name of the credential presented by the subject"), 1, | ||
235 | &GNUNET_GETOPT_set_string, &subject_credential}, | ||
346 | {'i', "issuer", "PKEY", | 236 | {'i', "issuer", "PKEY", |
347 | gettext_noop ("Specify the public key of the authority to verify the credential against"), 1, | 237 | gettext_noop ("The public key of the authority to verify the credential against"), 1, |
348 | &GNUNET_GETOPT_set_string, &issuer_key}, | 238 | &GNUNET_GETOPT_set_string, &issuer_key}, |
239 | {'a', "attribute", "ATTR", | ||
240 | gettext_noop ("The issuer attribute to verify against"), 1, | ||
241 | &GNUNET_GETOPT_set_string, &issuer_attr}, | ||
349 | GNUNET_GETOPT_OPTION_END | 242 | GNUNET_GETOPT_OPTION_END |
350 | }; | 243 | }; |
351 | int ret; | 244 | int ret; |