list CA restrictions in ipsec statusall
[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 identification_t *any_issuer = identification_create_from_string("%any");
240 peer_cfg_t *peer_cfg;
241 char *plugin;
242 host_t *host;
243 u_int32_t dpd;
244 time_t uptime = time(NULL) - this->uptime;
245
246 fprintf(out, "Performance:\n");
247 fprintf(out, " uptime: %V, since %#T\n", &uptime, &this->uptime, FALSE);
248 fprintf(out, " worker threads: %d idle of %d,",
249 charon->processor->get_idle_threads(charon->processor),
250 charon->processor->get_total_threads(charon->processor));
251 fprintf(out, " job queue load: %d,",
252 charon->processor->get_job_load(charon->processor));
253 fprintf(out, " scheduled events: %d\n",
254 charon->scheduler->get_job_load(charon->scheduler));
255 fprintf(out, " loaded plugins: ");
256 enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
257 while (enumerator->enumerate(enumerator, &plugin))
258 {
259 fprintf(out, "%s ", plugin);
260 }
261 enumerator->destroy(enumerator);
262 fprintf(out, "\n");
263
264 iterator = charon->kernel_interface->create_address_iterator(
265 charon->kernel_interface);
266 fprintf(out, "Listening IP addresses:\n");
267 while (iterator->iterate(iterator, (void**)&host))
268 {
269 fprintf(out, " %H\n", host);
270 }
271 iterator->destroy(iterator);
272
273 fprintf(out, "Connections:\n");
274 enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends);
275 while (enumerator->enumerate(enumerator, (void**)&peer_cfg))
276 {
277 auth_item_t item;
278 auth_info_t *auth;
279 enumerator_t *auth_enumerator;
280 certificate_t *cert;
281 identification_t *my_issuer = NULL, *other_issuer = 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, &cert))
293 {
294 switch (item)
295 {
296 case AUTHN_CA_CERT:
297 my_issuer = cert->get_subject(cert);
298 break;
299 case AUTHZ_CA_CERT:
300 other_issuer = cert->get_subject(cert);
301 break;
302 default:
303 break;
304 }
305 }
306 auth_enumerator->destroy(auth_enumerator);
307
308 ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
309 fprintf(out, "%12s: %s[%D]...%s[%D]\n", peer_cfg->get_name(peer_cfg),
310 ike_cfg->get_my_addr(ike_cfg), peer_cfg->get_my_id(peer_cfg),
311 ike_cfg->get_other_addr(ike_cfg), peer_cfg->get_other_id(peer_cfg));
312 if (my_issuer || other_issuer)
313 {
314 fprintf(out, "%12s: CAs: \"%D\"...\"%D\"\n", peer_cfg->get_name(peer_cfg),
315 my_issuer? my_issuer:any_issuer,
316 other_issuer? other_issuer:any_issuer);
317 }
318 fprintf(out, "%12s: %N authentication", peer_cfg->get_name(peer_cfg),
319 auth_class_names, get_auth_class(peer_cfg));
320 dpd = peer_cfg->get_dpd(peer_cfg);
321 if (dpd)
322 {
323 fprintf(out, ", dpddelay=%us", dpd);
324 }
325 fprintf(out, "\n");
326
327 /* TODO: list groups */
328
329 children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
330 while (children->enumerate(children, &child_cfg))
331 {
332 linked_list_t *my_ts, *other_ts;
333
334 my_ts = child_cfg->get_traffic_selectors(child_cfg, TRUE, NULL, NULL);
335 other_ts = child_cfg->get_traffic_selectors(child_cfg, FALSE, NULL, NULL);
336 fprintf(out, "%12s: %#R=== %#R", child_cfg->get_name(child_cfg),
337 my_ts, other_ts);
338 my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
339 other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
340
341 if (dpd)
342 {
343 fprintf(out, ", dpdaction=%N", action_names,
344 child_cfg->get_dpd_action(child_cfg));
345 }
346 fprintf(out, "\n");
347 }
348 children->destroy(children);
349 }
350 enumerator->destroy(enumerator);
351 any_issuer->destroy(any_issuer);
352 }
353
354 fprintf(out, "Security Associations:\n");
355 enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
356 while (enumerator->enumerate(enumerator, &ike_sa))
357 {
358 bool ike_printed = FALSE;
359 child_sa_t *child_sa;
360 iterator_t *children = ike_sa->create_child_sa_iterator(ike_sa);
361
362 if (name == NULL || streq(name, ike_sa->get_name(ike_sa)))
363 {
364 log_ike_sa(out, ike_sa, all);
365 found = TRUE;
366 ike_printed = TRUE;
367 }
368
369 while (children->iterate(children, (void**)&child_sa))
370 {
371 if (name == NULL || streq(name, child_sa->get_name(child_sa)))
372 {
373 if (!ike_printed)
374 {
375 log_ike_sa(out, ike_sa, all);
376 found = TRUE;
377 ike_printed = TRUE;
378 }
379 log_child_sa(out, child_sa, all);
380 }
381 }
382 children->destroy(children);
383 }
384 enumerator->destroy(enumerator);
385
386 if (!found)
387 {
388 if (name)
389 {
390 fprintf(out, " no match\n");
391 }
392 else
393 {
394 fprintf(out, " none\n");
395 }
396 }
397 }
398
399 /**
400 * create a unique certificate list without duplicates
401 * certicates having the same issuer are grouped together.
402 */
403 static linked_list_t* create_unique_cert_list(certificate_type_t type)
404 {
405 linked_list_t *list = linked_list_create();
406 enumerator_t *enumerator = charon->credentials->create_cert_enumerator(
407 charon->credentials, type, KEY_ANY,
408 NULL, FALSE);
409 certificate_t *cert;
410
411 while (enumerator->enumerate(enumerator, (void**)&cert))
412 {
413 iterator_t *iterator = list->create_iterator(list, TRUE);
414 identification_t *issuer = cert->get_issuer(cert);
415 bool previous_same, same = FALSE, last = TRUE;
416 certificate_t *list_cert;
417
418 while (iterator->iterate(iterator, (void**)&list_cert))
419 {
420 /* exit if we have a duplicate? */
421 if (list_cert->equals(list_cert, cert))
422 {
423 last = FALSE;
424 break;
425 }
426 /* group certificates with same issuer */
427 previous_same = same;
428 same = list_cert->has_issuer(list_cert, issuer);
429 if (previous_same && !same)
430 {
431 iterator->insert_before(iterator, (void *)cert->get_ref(cert));
432 last = FALSE;
433 break;
434 }
435 }
436 iterator->destroy(iterator);
437
438 if (last)
439 {
440 list->insert_last(list, (void *)cert->get_ref(cert));
441 }
442 }
443 enumerator->destroy(enumerator);
444 return list;
445 }
446
447 /**
448 * list all X.509 certificates matching the flags
449 */
450 static void stroke_list_certs(linked_list_t *list, char *label,
451 x509_flag_t flags, bool utc, FILE *out)
452 {
453 bool first = TRUE;
454 time_t now = time(NULL);
455 enumerator_t *enumerator = list->create_enumerator(list);
456 certificate_t *cert;
457
458 while (enumerator->enumerate(enumerator, (void**)&cert))
459 {
460 x509_t *x509 = (x509_t*)cert;
461 x509_flag_t x509_flags = x509->get_flags(x509);
462
463 /* list only if flag is set, or flags == 0 (ignoring self-signed) */
464 if ((x509_flags & flags) || (flags == (x509_flags & ~X509_SELF_SIGNED)))
465 {
466 enumerator_t *enumerator;
467 identification_t *altName;
468 bool first_altName = TRUE;
469 chunk_t serial = x509->get_serial(x509);
470 identification_t *authkey = x509->get_authKeyIdentifier(x509);
471 time_t notBefore, notAfter;
472 public_key_t *public = cert->get_public_key(cert);
473
474 if (first)
475 {
476 fprintf(out, "\n");
477 fprintf(out, "List of %s:\n", label);
478 first = FALSE;
479 }
480 fprintf(out, "\n");
481
482 /* list subjectAltNames */
483 enumerator = x509->create_subjectAltName_enumerator(x509);
484 while (enumerator->enumerate(enumerator, (void**)&altName))
485 {
486 if (first_altName)
487 {
488 fprintf(out, " altNames: ");
489 first_altName = FALSE;
490 }
491 else
492 {
493 fprintf(out, ", ");
494 }
495 fprintf(out, "%D", altName);
496 }
497 if (!first_altName)
498 {
499 fprintf(out, "\n");
500 }
501 enumerator->destroy(enumerator);
502
503 fprintf(out, " subject: \"%D\"\n", cert->get_subject(cert));
504 fprintf(out, " issuer: \"%D\"\n", cert->get_issuer(cert));
505 fprintf(out, " serial: %#B\n", &serial);
506
507 /* list validity */
508 cert->get_validity(cert, &now, &notBefore, &notAfter);
509 fprintf(out, " validity: not before %#T, ", &notBefore, utc);
510 if (now < notBefore)
511 {
512 fprintf(out, "not valid yet (valid in %#V)\n", &now, &notBefore);
513 }
514 else
515 {
516 fprintf(out, "ok\n");
517 }
518 fprintf(out, " not after %#T, ", &notAfter, utc);
519 if (now > notAfter)
520 {
521 fprintf(out, "expired (%#V ago)\n", &now, &notAfter);
522 }
523 else
524 {
525 fprintf(out, "ok");
526 if (now > notAfter - CERT_WARNING_INTERVAL * 60 * 60 * 24)
527 {
528 fprintf(out, " (expires in %#V)", &now, &notAfter);
529 }
530 fprintf(out, " \n");
531 }
532
533 /* list public key information */
534 if (public)
535 {
536 private_key_t *private = NULL;
537 identification_t *id, *keyid;
538
539 id = public->get_id(public, ID_PUBKEY_SHA1);
540 keyid = public->get_id(public, ID_PUBKEY_INFO_SHA1);
541
542 private = charon->credentials->get_private(
543 charon->credentials,
544 public->get_type(public), keyid, NULL);
545 fprintf(out, " pubkey: %N %d bits%s\n",
546 key_type_names, public->get_type(public),
547 public->get_keysize(public) * 8,
548 private ? ", has private key" : "");
549 fprintf(out, " keyid: %D\n", keyid);
550 fprintf(out, " subjkey: %D\n", id);
551 DESTROY_IF(private);
552 public->destroy(public);
553 }
554
555 /* list optional authorityKeyIdentifier */
556 if (authkey)
557 {
558 fprintf(out, " authkey: %D\n", authkey);
559 }
560 }
561 }
562 enumerator->destroy(enumerator);
563 }
564
565 /**
566 * list all X.509 attribute certificates
567 */
568 static void stroke_list_acerts(linked_list_t *list, bool utc, FILE *out)
569 {
570 bool first = TRUE;
571 time_t thisUpdate, nextUpdate, now = time(NULL);
572 enumerator_t *enumerator = list->create_enumerator(list);
573 certificate_t *cert;
574
575 while (enumerator->enumerate(enumerator, (void**)&cert))
576 {
577 ac_t *ac = (ac_t*)cert;
578 chunk_t serial = ac->get_serial(ac);
579 chunk_t holderSerial = ac->get_holderSerial(ac);
580 identification_t *holderIssuer = ac->get_holderIssuer(ac);
581 identification_t *authkey = ac->get_authKeyIdentifier(ac);
582 identification_t *entityName = cert->get_subject(cert);
583
584 if (first)
585 {
586 fprintf(out, "\n");
587 fprintf(out, "List of X.509 Attribute Certificates:\n");
588 first = FALSE;
589 }
590 fprintf(out, "\n");
591
592 if (entityName)
593 {
594 fprintf(out, " holder: \"%D\"\n", entityName);
595 }
596 if (holderIssuer)
597 {
598 fprintf(out, " hissuer: \"%D\"\n", holderIssuer);
599 }
600 if (holderSerial.ptr)
601 {
602 fprintf(out, " hserial: %#B\n", &holderSerial);
603 }
604 fprintf(out, " issuer: \"%D\"\n", cert->get_issuer(cert));
605 fprintf(out, " serial: %#B\n", &serial);
606
607 /* list validity */
608 cert->get_validity(cert, &now, &thisUpdate, &nextUpdate);
609 fprintf(out, " updates: this %#T\n", &thisUpdate, utc);
610 fprintf(out, " next %#T, ", &nextUpdate, utc);
611 if (now > nextUpdate)
612 {
613 fprintf(out, "expired (%#V ago)\n", &now, &nextUpdate);
614 }
615 else
616 {
617 fprintf(out, "ok");
618 if (now > nextUpdate - AC_WARNING_INTERVAL * 60 * 60 * 24)
619 {
620 fprintf(out, " (expires in %#V)", &now, &nextUpdate);
621 }
622 fprintf(out, " \n");
623 }
624
625 /* list optional authorityKeyIdentifier */
626 if (authkey)
627 {
628 fprintf(out, " authkey: %D\n", authkey);
629 }
630 }
631 enumerator->destroy(enumerator);
632 }
633
634 /**
635 * list all X.509 CRLs
636 */
637 static void stroke_list_crls(linked_list_t *list, bool utc, FILE *out)
638 {
639 bool first = TRUE;
640 time_t thisUpdate, nextUpdate, now = time(NULL);
641 enumerator_t *enumerator = list->create_enumerator(list);
642 certificate_t *cert;
643
644 while (enumerator->enumerate(enumerator, (void**)&cert))
645 {
646 crl_t *crl = (crl_t*)cert;
647 chunk_t serial = crl->get_serial(crl);
648 identification_t *authkey = crl->get_authKeyIdentifier(crl);
649
650 if (first)
651 {
652 fprintf(out, "\n");
653 fprintf(out, "List of X.509 CRLs:\n");
654 first = FALSE;
655 }
656 fprintf(out, "\n");
657
658 fprintf(out, " issuer: \"%D\"\n", cert->get_issuer(cert));
659
660 /* list optional crlNumber */
661 if (serial.ptr)
662 {
663 fprintf(out, " serial: %#B\n", &serial);
664 }
665
666 /* count the number of revoked certificates */
667 {
668 int count = 0;
669 enumerator_t *enumerator = crl->create_enumerator(crl);
670
671 while (enumerator->enumerate(enumerator, NULL, NULL, NULL))
672 {
673 count++;
674 }
675 fprintf(out, " revoked: %d certificate%s\n", count,
676 (count == 1)? "" : "s");
677 enumerator->destroy(enumerator);
678 }
679
680 /* list validity */
681 cert->get_validity(cert, &now, &thisUpdate, &nextUpdate);
682 fprintf(out, " updates: this %#T\n", &thisUpdate, utc);
683 fprintf(out, " next %#T, ", &nextUpdate, utc);
684 if (now > nextUpdate)
685 {
686 fprintf(out, "expired (%#V ago)\n", &now, &nextUpdate);
687 }
688 else
689 {
690 fprintf(out, "ok");
691 if (now > nextUpdate - CRL_WARNING_INTERVAL * 60 * 60 * 24)
692 {
693 fprintf(out, " (expires in %#V)", &now, &nextUpdate);
694 }
695 fprintf(out, " \n");
696 }
697
698 /* list optional authorityKeyIdentifier */
699 if (authkey)
700 {
701 fprintf(out, " authkey: %D\n", authkey);
702 }
703 }
704 enumerator->destroy(enumerator);
705 }
706
707 /**
708 * list all OCSP responses
709 */
710 static void stroke_list_ocsp(linked_list_t* list, bool utc, FILE *out)
711 {
712 bool first = TRUE;
713 enumerator_t *enumerator = list->create_enumerator(list);
714 certificate_t *cert;
715
716 while (enumerator->enumerate(enumerator, (void**)&cert))
717 {
718 if (first)
719 {
720 fprintf(out, "\n");
721 fprintf(out, "List of OCSP responses:\n");
722 fprintf(out, "\n");
723 first = FALSE;
724 }
725
726 fprintf(out, " signer: \"%D\"\n", cert->get_issuer(cert));
727 }
728 enumerator->destroy(enumerator);
729 }
730
731 /**
732 * Implementation of stroke_list_t.list.
733 */
734 static void list(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out)
735 {
736 linked_list_t *cert_list = NULL;
737
738 if (msg->list.flags & (LIST_CERTS | LIST_CACERTS | LIST_OCSPCERTS | LIST_AACERTS))
739 {
740 cert_list = create_unique_cert_list(CERT_X509);
741 }
742 if (msg->list.flags & LIST_CERTS)
743 {
744 stroke_list_certs(cert_list, "X.509 End Entity Certificates",
745 0, msg->list.utc, out);
746 }
747 if (msg->list.flags & LIST_CACERTS)
748 {
749 stroke_list_certs(cert_list, "X.509 CA Certificates",
750 X509_CA, msg->list.utc, out);
751 }
752 if (msg->list.flags & LIST_OCSPCERTS)
753 {
754 stroke_list_certs(cert_list, "X.509 OCSP Signer Certificates",
755 X509_OCSP_SIGNER, msg->list.utc, out);
756 }
757 if (msg->list.flags & LIST_AACERTS)
758 {
759 stroke_list_certs(cert_list, "X.509 AA Certificates",
760 X509_AA, msg->list.utc, out);
761 }
762 if (msg->list.flags & LIST_ACERTS)
763 {
764 linked_list_t *ac_list = create_unique_cert_list(CERT_X509_AC);
765
766 stroke_list_acerts(ac_list, msg->list.utc, out);
767 ac_list->destroy_offset(ac_list, offsetof(certificate_t, destroy));
768 }
769 if (msg->list.flags & LIST_CRLS)
770 {
771 linked_list_t *crl_list = create_unique_cert_list(CERT_X509_CRL);
772
773 stroke_list_crls(crl_list, msg->list.utc, out);
774 crl_list->destroy_offset(crl_list, offsetof(certificate_t, destroy));
775 }
776 if (msg->list.flags & LIST_OCSP)
777 {
778 linked_list_t *ocsp_list = create_unique_cert_list(CERT_X509_OCSP_RESPONSE);
779
780 stroke_list_ocsp(ocsp_list, msg->list.utc, out);
781 ocsp_list->destroy_offset(ocsp_list, offsetof(certificate_t, destroy));
782 }
783 DESTROY_OFFSET_IF(cert_list, offsetof(certificate_t, destroy));
784 }
785
786 /**
787 * Implementation of stroke_list_t.destroy
788 */
789 static void destroy(private_stroke_list_t *this)
790 {
791 free(this);
792 }
793
794 /*
795 * see header file
796 */
797 stroke_list_t *stroke_list_create()
798 {
799 private_stroke_list_t *this = malloc_thing(private_stroke_list_t);
800
801 this->public.list = (void(*)(stroke_list_t*, stroke_msg_t *msg, FILE *out))list;
802 this->public.status = (void(*)(stroke_list_t*, stroke_msg_t *msg, FILE *out,bool))status;
803 this->public.destroy = (void(*)(stroke_list_t*))destroy;
804
805 this->uptime = time(NULL);
806
807 return &this->public;
808 }
809