completed support of AUTHZ_CA_CERT and AUTHZ_CA_CERT_NAME attributes
[strongswan.git] / src / charon / plugins / stroke / stroke_list.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "stroke_list.h"
19
20 #include <daemon.h>
21 #include <utils/linked_list.h>
22 #include <credentials/certificates/x509.h>
23 #include <credentials/certificates/ac.h>
24 #include <credentials/certificates/crl.h>
25 #include <config/peer_cfg.h>
26
27 /* warning intervals for list functions */
28 #define CERT_WARNING_INTERVAL 30 /* days */
29 #define CRL_WARNING_INTERVAL 7 /* days */
30 #define AC_WARNING_INTERVAL 1 /* day */
31
32 typedef struct private_stroke_list_t private_stroke_list_t;
33
34 /**
35 * private data of stroke_list
36 */
37 struct private_stroke_list_t {
38
39 /**
40 * public functions
41 */
42 stroke_list_t public;
43
44 /**
45 * timestamp of daemon start
46 */
47 time_t uptime;
48 };
49
50 /**
51 * get the authentication class of a config
52 */
53 auth_class_t get_auth_class(peer_cfg_t *config)
54 {
55 auth_class_t *class;
56 auth_info_t *auth_info;
57
58 auth_info = config->get_auth(config);
59 if (auth_info->get_item(auth_info, AUTHN_AUTH_CLASS, (void**)&class))
60 {
61 return *class;
62 }
63 /* fallback to pubkey authentication */
64 return AUTH_CLASS_PUBKEY;
65 }
66
67 /**
68 * log an IKE_SA to out
69 */
70 static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)
71 {
72 ike_sa_id_t *id = ike_sa->get_id(ike_sa);
73
74 fprintf(out, "%12s[%d]: %N, %H[%D]...%H[%D]\n",
75 ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
76 ike_sa_state_names, ike_sa->get_state(ike_sa),
77 ike_sa->get_my_host(ike_sa), ike_sa->get_my_id(ike_sa),
78 ike_sa->get_other_host(ike_sa), ike_sa->get_other_id(ike_sa));
79
80 if (all)
81 {
82 char *ike_proposal = ike_sa->get_proposal(ike_sa);
83
84 fprintf(out, "%12s[%d]: IKE SPIs: %.16llx_i%s %.16llx_r%s",
85 ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
86 id->get_initiator_spi(id), id->is_initiator(id) ? "*" : "",
87 id->get_responder_spi(id), id->is_initiator(id) ? "" : "*");
88
89
90 if (ike_sa->get_state(ike_sa) == IKE_ESTABLISHED)
91 {
92 u_int32_t rekey = ike_sa->get_statistic(ike_sa, STAT_REKEY_TIME);
93 u_int32_t reauth = ike_sa->get_statistic(ike_sa, STAT_REAUTH_TIME);
94
95 if (rekey)
96 {
97 fprintf(out, ", rekeying in %V", &rekey);
98 }
99 if (reauth)
100 {
101 fprintf(out, ", %N reauthentication in %V", auth_class_names,
102 get_auth_class(ike_sa->get_peer_cfg(ike_sa)), &reauth);
103 }
104 if (!rekey && !reauth)
105 {
106 fprintf(out, ", rekeying disabled");
107 }
108 }
109 fprintf(out, "\n");
110
111 if (ike_proposal)
112 {
113 fprintf(out, "%12s[%d]: IKE proposal: %s\n",
114 ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
115 ike_proposal);
116 }
117 }
118 }
119
120 /**
121 * log an CHILD_SA to out
122 */
123 static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
124 {
125 u_int32_t rekey, now = time(NULL);
126 u_int32_t use_in, use_out, use_fwd;
127 encryption_algorithm_t encr_alg;
128 integrity_algorithm_t int_alg;
129 size_t encr_len, int_len;
130 mode_t mode;
131
132 child_sa->get_stats(child_sa, &mode, &encr_alg, &encr_len,
133 &int_alg, &int_len, &rekey, &use_in, &use_out,
134 &use_fwd);
135
136 fprintf(out, "%12s{%d}: %N, %N",
137 child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
138 child_sa_state_names, child_sa->get_state(child_sa),
139 mode_names, mode);
140
141 if (child_sa->get_state(child_sa) == CHILD_INSTALLED)
142 {
143 u_int16_t my_cpi = child_sa->get_cpi(child_sa, TRUE);
144 u_int16_t other_cpi = child_sa->get_cpi(child_sa, FALSE);
145
146 fprintf(out, ", %N SPIs: %.8x_i %.8x_o",
147 protocol_id_names, child_sa->get_protocol(child_sa),
148 ntohl(child_sa->get_spi(child_sa, TRUE)),
149 ntohl(child_sa->get_spi(child_sa, FALSE)));
150
151 /* Is IPCOMP activated ? */
152 if (my_cpi && other_cpi)
153 {
154 fprintf(out, ", IPCOMP CPIs: %.4x_i %.4x_o",
155 ntohs(my_cpi), ntohs(other_cpi));
156 }
157
158 if (all)
159 {
160 fprintf(out, "\n%12s{%d}: ", child_sa->get_name(child_sa),
161 child_sa->get_reqid(child_sa));
162
163
164 if (child_sa->get_protocol(child_sa) == PROTO_ESP)
165 {
166 fprintf(out, "%N", encryption_algorithm_names, encr_alg);
167
168 if (encr_len)
169 {
170 fprintf(out, "-%d", encr_len);
171 }
172 if (int_alg != AUTH_UNDEFINED)
173 {
174 fprintf(out, "/");
175 }
176 }
177
178 if (int_alg != AUTH_UNDEFINED)
179 {
180 fprintf(out, "%N", integrity_algorithm_names, int_alg);
181 if (int_len)
182 {
183 fprintf(out, "-%d", int_len);
184 }
185 }
186 fprintf(out, ", rekeying ");
187
188 if (rekey)
189 {
190 fprintf(out, "in %#V", &now, &rekey);
191 }
192 else
193 {
194 fprintf(out, "disabled");
195 }
196
197 fprintf(out, ", last use: ");
198 use_in = max(use_in, use_fwd);
199 if (use_in)
200 {
201 fprintf(out, "%ds_i ", now - use_in);
202 }
203 else
204 {
205 fprintf(out, "no_i ");
206 }
207 if (use_out)
208 {
209 fprintf(out, "%ds_o ", now - use_out);
210 }
211 else
212 {
213 fprintf(out, "no_o ");
214 }
215 }
216 }
217
218 fprintf(out, "\n%12s{%d}: %#R=== %#R\n",
219 child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
220 child_sa->get_traffic_selectors(child_sa, TRUE),
221 child_sa->get_traffic_selectors(child_sa, FALSE));
222 }
223
224 /**
225 * Implementation of stroke_list_t.status.
226 */
227 static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bool all)
228 {
229 enumerator_t *enumerator, *children;
230 iterator_t *iterator;
231 ike_cfg_t *ike_cfg;
232 child_cfg_t *child_cfg;
233 ike_sa_t *ike_sa;
234 bool found = FALSE;
235 char *name = msg->status.name;
236
237 if (all)
238 {
239 peer_cfg_t *peer_cfg;
240 char *plugin;
241 host_t *host;
242 u_int32_t dpd;
243 time_t uptime = time(NULL) - this->uptime;
244
245 fprintf(out, "Performance:\n");
246 fprintf(out, " uptime: %V, since %#T\n", &uptime, &this->uptime, FALSE);
247 fprintf(out, " worker threads: %d idle of %d,",
248 charon->processor->get_idle_threads(charon->processor),
249 charon->processor->get_total_threads(charon->processor));
250 fprintf(out, " job queue load: %d,",
251 charon->processor->get_job_load(charon->processor));
252 fprintf(out, " scheduled events: %d\n",
253 charon->scheduler->get_job_load(charon->scheduler));
254 fprintf(out, " loaded plugins: ");
255 enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
256 while (enumerator->enumerate(enumerator, &plugin))
257 {
258 fprintf(out, "%s ", plugin);
259 }
260 enumerator->destroy(enumerator);
261 fprintf(out, "\n");
262
263 iterator = charon->kernel_interface->create_address_iterator(
264 charon->kernel_interface);
265 fprintf(out, "Listening IP addresses:\n");
266 while (iterator->iterate(iterator, (void**)&host))
267 {
268 fprintf(out, " %H\n", host);
269 }
270 iterator->destroy(iterator);
271
272 fprintf(out, "Connections:\n");
273 enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends);
274 while (enumerator->enumerate(enumerator, (void**)&peer_cfg))
275 {
276 void *ptr;
277 certificate_t *cert;
278 auth_item_t item;
279 auth_info_t *auth;
280 enumerator_t *auth_enumerator;
281 identification_t *my_ca = NULL, *other_ca = NULL;
282
283 if (peer_cfg->get_ike_version(peer_cfg) != 2 ||
284 (name && !streq(name, peer_cfg->get_name(peer_cfg))))
285 {
286 continue;
287 }
288
289 /* determine any required CAs */
290 auth = peer_cfg->get_auth(peer_cfg);
291 auth_enumerator = auth->create_item_enumerator(auth);
292 while (auth_enumerator->enumerate(auth_enumerator, &item, &ptr))
293 {
294 switch (item)
295 {
296 case AUTHN_CA_CERT:
297 cert = (certificate_t *)ptr;
298 my_ca = cert->get_subject(cert);
299 break;
300 case AUTHN_CA_CERT_NAME:
301 my_ca = (identification_t *)ptr;
302 break;
303 case AUTHZ_CA_CERT:
304 cert = (certificate_t *)ptr;
305 other_ca = cert->get_subject(cert);
306 break;
307 case AUTHZ_CA_CERT_NAME:
308 other_ca = (identification_t *)ptr;
309 break;
310 default:
311 break;
312 }
313 }
314 auth_enumerator->destroy(auth_enumerator);
315
316 ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
317 fprintf(out, "%12s: %s[%D]...%s[%D]\n", peer_cfg->get_name(peer_cfg),
318 ike_cfg->get_my_addr(ike_cfg), peer_cfg->get_my_id(peer_cfg),
319 ike_cfg->get_other_addr(ike_cfg), peer_cfg->get_other_id(peer_cfg));
320 if (my_ca || other_ca)
321 {
322 fprintf(out, "%12s: CAs: ", peer_cfg->get_name(peer_cfg));
323 if (my_ca)
324 {
325 fprintf(out, "\"%D\"...", my_ca);
326 }
327 else
328 {
329 fprintf(out, "%%any...");
330 }
331 if (other_ca)
332 {
333 fprintf(out, "\"%D\"\n", other_ca);
334 }
335 else
336 {
337 fprintf(out, "%%any\n");
338 }
339 }
340 fprintf(out, "%12s: %N authentication", peer_cfg->get_name(peer_cfg),
341 auth_class_names, get_auth_class(peer_cfg));
342 dpd = peer_cfg->get_dpd(peer_cfg);
343 if (dpd)
344 {
345 fprintf(out, ", dpddelay=%us", dpd);
346 }
347 fprintf(out, "\n");
348
349 /* TODO: list groups */
350
351 children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
352 while (children->enumerate(children, &child_cfg))
353 {
354 linked_list_t *my_ts, *other_ts;
355
356 my_ts = child_cfg->get_traffic_selectors(child_cfg, TRUE, NULL, NULL);
357 other_ts = child_cfg->get_traffic_selectors(child_cfg, FALSE, NULL, NULL);
358 fprintf(out, "%12s: %#R=== %#R", child_cfg->get_name(child_cfg),
359 my_ts, other_ts);
360 my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
361 other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
362
363 if (dpd)
364 {
365 fprintf(out, ", dpdaction=%N", action_names,
366 child_cfg->get_dpd_action(child_cfg));
367 }
368 fprintf(out, "\n");
369 }
370 children->destroy(children);
371 }
372 enumerator->destroy(enumerator);
373 }
374
375 fprintf(out, "Security Associations:\n");
376 enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
377 while (enumerator->enumerate(enumerator, &ike_sa))
378 {
379 bool ike_printed = FALSE;
380 child_sa_t *child_sa;
381 iterator_t *children = ike_sa->create_child_sa_iterator(ike_sa);
382
383 if (name == NULL || streq(name, ike_sa->get_name(ike_sa)))
384 {
385 log_ike_sa(out, ike_sa, all);
386 found = TRUE;
387 ike_printed = TRUE;
388 }
389
390 while (children->iterate(children, (void**)&child_sa))
391 {
392 if (name == NULL || streq(name, child_sa->get_name(child_sa)))
393 {
394 if (!ike_printed)
395 {
396 log_ike_sa(out, ike_sa, all);
397 found = TRUE;
398 ike_printed = TRUE;
399 }
400 log_child_sa(out, child_sa, all);
401 }
402 }
403 children->destroy(children);
404 }
405 enumerator->destroy(enumerator);
406
407 if (!found)
408 {
409 if (name)
410 {
411 fprintf(out, " no match\n");
412 }
413 else
414 {
415 fprintf(out, " none\n");
416 }
417 }
418 }
419
420 /**
421 * create a unique certificate list without duplicates
422 * certicates having the same issuer are grouped together.
423 */
424 static linked_list_t* create_unique_cert_list(certificate_type_t type)
425 {
426 linked_list_t *list = linked_list_create();
427 enumerator_t *enumerator = charon->credentials->create_cert_enumerator(
428 charon->credentials, type, KEY_ANY,
429 NULL, FALSE);
430 certificate_t *cert;
431
432 while (enumerator->enumerate(enumerator, (void**)&cert))
433 {
434 iterator_t *iterator = list->create_iterator(list, TRUE);
435 identification_t *issuer = cert->get_issuer(cert);
436 bool previous_same, same = FALSE, last = TRUE;
437 certificate_t *list_cert;
438
439 while (iterator->iterate(iterator, (void**)&list_cert))
440 {
441 /* exit if we have a duplicate? */
442 if (list_cert->equals(list_cert, cert))
443 {
444 last = FALSE;
445 break;
446 }
447 /* group certificates with same issuer */
448 previous_same = same;
449 same = list_cert->has_issuer(list_cert, issuer);
450 if (previous_same && !same)
451 {
452 iterator->insert_before(iterator, (void *)cert->get_ref(cert));
453 last = FALSE;
454 break;
455 }
456 }
457 iterator->destroy(iterator);
458
459 if (last)
460 {
461 list->insert_last(list, (void *)cert->get_ref(cert));
462 }
463 }
464 enumerator->destroy(enumerator);
465 return list;
466 }
467
468 /**
469 * list all X.509 certificates matching the flags
470 */
471 static void stroke_list_certs(linked_list_t *list, char *label,
472 x509_flag_t flags, bool utc, FILE *out)
473 {
474 bool first = TRUE;
475 time_t now = time(NULL);
476 enumerator_t *enumerator = list->create_enumerator(list);
477 certificate_t *cert;
478
479 while (enumerator->enumerate(enumerator, (void**)&cert))
480 {
481 x509_t *x509 = (x509_t*)cert;
482 x509_flag_t x509_flags = x509->get_flags(x509);
483
484 /* list only if flag is set, or flags == 0 (ignoring self-signed) */
485 if ((x509_flags & flags) || (flags == (x509_flags & ~X509_SELF_SIGNED)))
486 {
487 enumerator_t *enumerator;
488 identification_t *altName;
489 bool first_altName = TRUE;
490 chunk_t serial = x509->get_serial(x509);
491 identification_t *authkey = x509->get_authKeyIdentifier(x509);
492 time_t notBefore, notAfter;
493 public_key_t *public = cert->get_public_key(cert);
494
495 if (first)
496 {
497 fprintf(out, "\n");
498 fprintf(out, "List of %s:\n", label);
499 first = FALSE;
500 }
501 fprintf(out, "\n");
502
503 /* list subjectAltNames */
504 enumerator = x509->create_subjectAltName_enumerator(x509);
505 while (enumerator->enumerate(enumerator, (void**)&altName))
506 {
507 if (first_altName)
508 {
509 fprintf(out, " altNames: ");
510 first_altName = FALSE;
511 }
512 else
513 {
514 fprintf(out, ", ");
515 }
516 fprintf(out, "%D", altName);
517 }
518 if (!first_altName)
519 {
520 fprintf(out, "\n");
521 }
522 enumerator->destroy(enumerator);
523
524 fprintf(out, " subject: \"%D\"\n", cert->get_subject(cert));
525 fprintf(out, " issuer: \"%D\"\n", cert->get_issuer(cert));
526 fprintf(out, " serial: %#B\n", &serial);
527
528 /* list validity */
529 cert->get_validity(cert, &now, &notBefore, &notAfter);
530 fprintf(out, " validity: not before %#T, ", &notBefore, utc);
531 if (now < notBefore)
532 {
533 fprintf(out, "not valid yet (valid in %#V)\n", &now, &notBefore);
534 }
535 else
536 {
537 fprintf(out, "ok\n");
538 }
539 fprintf(out, " not after %#T, ", &notAfter, utc);
540 if (now > notAfter)
541 {
542 fprintf(out, "expired (%#V ago)\n", &now, &notAfter);
543 }
544 else
545 {
546 fprintf(out, "ok");
547 if (now > notAfter - CERT_WARNING_INTERVAL * 60 * 60 * 24)
548 {
549 fprintf(out, " (expires in %#V)", &now, &notAfter);
550 }
551 fprintf(out, " \n");
552 }
553
554 /* list public key information */
555 if (public)
556 {
557 private_key_t *private = NULL;
558 identification_t *id, *keyid;
559
560 id = public->get_id(public, ID_PUBKEY_SHA1);
561 keyid = public->get_id(public, ID_PUBKEY_INFO_SHA1);
562
563 private = charon->credentials->get_private(
564 charon->credentials,
565 public->get_type(public), keyid, NULL);
566 fprintf(out, " pubkey: %N %d bits%s\n",
567 key_type_names, public->get_type(public),
568 public->get_keysize(public) * 8,
569 private ? ", has private key" : "");
570 fprintf(out, " keyid: %D\n", keyid);
571 fprintf(out, " subjkey: %D\n", id);
572 DESTROY_IF(private);
573 public->destroy(public);
574 }
575
576 /* list optional authorityKeyIdentifier */
577 if (authkey)
578 {
579 fprintf(out, " authkey: %D\n", authkey);
580 }
581 }
582 }
583 enumerator->destroy(enumerator);
584 }
585
586 /**
587 * list all X.509 attribute certificates
588 */
589 static void stroke_list_acerts(linked_list_t *list, bool utc, FILE *out)
590 {
591 bool first = TRUE;
592 time_t thisUpdate, nextUpdate, now = time(NULL);
593 enumerator_t *enumerator = list->create_enumerator(list);
594 certificate_t *cert;
595
596 while (enumerator->enumerate(enumerator, (void**)&cert))
597 {
598 ac_t *ac = (ac_t*)cert;
599 chunk_t serial = ac->get_serial(ac);
600 chunk_t holderSerial = ac->get_holderSerial(ac);
601 identification_t *holderIssuer = ac->get_holderIssuer(ac);
602 identification_t *authkey = ac->get_authKeyIdentifier(ac);
603 identification_t *entityName = cert->get_subject(cert);
604
605 if (first)
606 {
607 fprintf(out, "\n");
608 fprintf(out, "List of X.509 Attribute Certificates:\n");
609 first = FALSE;
610 }
611 fprintf(out, "\n");
612
613 if (entityName)
614 {
615 fprintf(out, " holder: \"%D\"\n", entityName);
616 }
617 if (holderIssuer)
618 {
619 fprintf(out, " hissuer: \"%D\"\n", holderIssuer);
620 }
621 if (holderSerial.ptr)
622 {
623 fprintf(out, " hserial: %#B\n", &holderSerial);
624 }
625 fprintf(out, " issuer: \"%D\"\n", cert->get_issuer(cert));
626 fprintf(out, " serial: %#B\n", &serial);
627
628 /* list validity */
629 cert->get_validity(cert, &now, &thisUpdate, &nextUpdate);
630 fprintf(out, " updates: this %#T\n", &thisUpdate, utc);
631 fprintf(out, " next %#T, ", &nextUpdate, utc);
632 if (now > nextUpdate)
633 {
634 fprintf(out, "expired (%#V ago)\n", &now, &nextUpdate);
635 }
636 else
637 {
638 fprintf(out, "ok");
639 if (now > nextUpdate - AC_WARNING_INTERVAL * 60 * 60 * 24)
640 {
641 fprintf(out, " (expires in %#V)", &now, &nextUpdate);
642 }
643 fprintf(out, " \n");
644 }
645
646 /* list optional authorityKeyIdentifier */
647 if (authkey)
648 {
649 fprintf(out, " authkey: %D\n", authkey);
650 }
651 }
652 enumerator->destroy(enumerator);
653 }
654
655 /**
656 * list all X.509 CRLs
657 */
658 static void stroke_list_crls(linked_list_t *list, bool utc, FILE *out)
659 {
660 bool first = TRUE;
661 time_t thisUpdate, nextUpdate, now = time(NULL);
662 enumerator_t *enumerator = list->create_enumerator(list);
663 certificate_t *cert;
664
665 while (enumerator->enumerate(enumerator, (void**)&cert))
666 {
667 crl_t *crl = (crl_t*)cert;
668 chunk_t serial = crl->get_serial(crl);
669 identification_t *authkey = crl->get_authKeyIdentifier(crl);
670
671 if (first)
672 {
673 fprintf(out, "\n");
674 fprintf(out, "List of X.509 CRLs:\n");
675 first = FALSE;
676 }
677 fprintf(out, "\n");
678
679 fprintf(out, " issuer: \"%D\"\n", cert->get_issuer(cert));
680
681 /* list optional crlNumber */
682 if (serial.ptr)
683 {
684 fprintf(out, " serial: %#B\n", &serial);
685 }
686
687 /* count the number of revoked certificates */
688 {
689 int count = 0;
690 enumerator_t *enumerator = crl->create_enumerator(crl);
691
692 while (enumerator->enumerate(enumerator, NULL, NULL, NULL))
693 {
694 count++;
695 }
696 fprintf(out, " revoked: %d certificate%s\n", count,
697 (count == 1)? "" : "s");
698 enumerator->destroy(enumerator);
699 }
700
701 /* list validity */
702 cert->get_validity(cert, &now, &thisUpdate, &nextUpdate);
703 fprintf(out, " updates: this %#T\n", &thisUpdate, utc);
704 fprintf(out, " next %#T, ", &nextUpdate, utc);
705 if (now > nextUpdate)
706 {
707 fprintf(out, "expired (%#V ago)\n", &now, &nextUpdate);
708 }
709 else
710 {
711 fprintf(out, "ok");
712 if (now > nextUpdate - CRL_WARNING_INTERVAL * 60 * 60 * 24)
713 {
714 fprintf(out, " (expires in %#V)", &now, &nextUpdate);
715 }
716 fprintf(out, " \n");
717 }
718
719 /* list optional authorityKeyIdentifier */
720 if (authkey)
721 {
722 fprintf(out, " authkey: %D\n", authkey);
723 }
724 }
725 enumerator->destroy(enumerator);
726 }
727
728 /**
729 * list all OCSP responses
730 */
731 static void stroke_list_ocsp(linked_list_t* list, bool utc, FILE *out)
732 {
733 bool first = TRUE;
734 enumerator_t *enumerator = list->create_enumerator(list);
735 certificate_t *cert;
736
737 while (enumerator->enumerate(enumerator, (void**)&cert))
738 {
739 if (first)
740 {
741 fprintf(out, "\n");
742 fprintf(out, "List of OCSP responses:\n");
743 fprintf(out, "\n");
744 first = FALSE;
745 }
746
747 fprintf(out, " signer: \"%D\"\n", cert->get_issuer(cert));
748 }
749 enumerator->destroy(enumerator);
750 }
751
752 /**
753 * Implementation of stroke_list_t.list.
754 */
755 static void list(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out)
756 {
757 linked_list_t *cert_list = NULL;
758
759 if (msg->list.flags & (LIST_CERTS | LIST_CACERTS | LIST_OCSPCERTS | LIST_AACERTS))
760 {
761 cert_list = create_unique_cert_list(CERT_X509);
762 }
763 if (msg->list.flags & LIST_CERTS)
764 {
765 stroke_list_certs(cert_list, "X.509 End Entity Certificates",
766 0, msg->list.utc, out);
767 }
768 if (msg->list.flags & LIST_CACERTS)
769 {
770 stroke_list_certs(cert_list, "X.509 CA Certificates",
771 X509_CA, msg->list.utc, out);
772 }
773 if (msg->list.flags & LIST_OCSPCERTS)
774 {
775 stroke_list_certs(cert_list, "X.509 OCSP Signer Certificates",
776 X509_OCSP_SIGNER, msg->list.utc, out);
777 }
778 if (msg->list.flags & LIST_AACERTS)
779 {
780 stroke_list_certs(cert_list, "X.509 AA Certificates",
781 X509_AA, msg->list.utc, out);
782 }
783 if (msg->list.flags & LIST_ACERTS)
784 {
785 linked_list_t *ac_list = create_unique_cert_list(CERT_X509_AC);
786
787 stroke_list_acerts(ac_list, msg->list.utc, out);
788 ac_list->destroy_offset(ac_list, offsetof(certificate_t, destroy));
789 }
790 if (msg->list.flags & LIST_CRLS)
791 {
792 linked_list_t *crl_list = create_unique_cert_list(CERT_X509_CRL);
793
794 stroke_list_crls(crl_list, msg->list.utc, out);
795 crl_list->destroy_offset(crl_list, offsetof(certificate_t, destroy));
796 }
797 if (msg->list.flags & LIST_OCSP)
798 {
799 linked_list_t *ocsp_list = create_unique_cert_list(CERT_X509_OCSP_RESPONSE);
800
801 stroke_list_ocsp(ocsp_list, msg->list.utc, out);
802 ocsp_list->destroy_offset(ocsp_list, offsetof(certificate_t, destroy));
803 }
804 DESTROY_OFFSET_IF(cert_list, offsetof(certificate_t, destroy));
805 }
806
807 /**
808 * Implementation of stroke_list_t.destroy
809 */
810 static void destroy(private_stroke_list_t *this)
811 {
812 free(this);
813 }
814
815 /*
816 * see header file
817 */
818 stroke_list_t *stroke_list_create()
819 {
820 private_stroke_list_t *this = malloc_thing(private_stroke_list_t);
821
822 this->public.list = (void(*)(stroke_list_t*, stroke_msg_t *msg, FILE *out))list;
823 this->public.status = (void(*)(stroke_list_t*, stroke_msg_t *msg, FILE *out,bool))status;
824 this->public.destroy = (void(*)(stroke_list_t*))destroy;
825
826 this->uptime = time(NULL);
827
828 return &this->public;
829 }
830