2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
18 #include "stroke_list.h"
23 #include <utils/linked_list.h>
24 #include <credentials/certificates/x509.h>
25 #include <credentials/certificates/ac.h>
26 #include <credentials/certificates/crl.h>
27 #include <config/peer_cfg.h>
29 /* warning intervals for list functions */
30 #define CERT_WARNING_INTERVAL 30 /* days */
31 #define CRL_WARNING_INTERVAL 7 /* days */
32 #define AC_WARNING_INTERVAL 1 /* day */
34 typedef struct private_stroke_list_t private_stroke_list_t
;
37 * private data of stroke_list
39 struct private_stroke_list_t
{
47 * timestamp of daemon start
52 * strokes attribute provider
54 stroke_attribute_t
*attribute
;
58 * get the authentication class of a config
60 auth_class_t
get_auth_class(peer_cfg_t
*config
)
63 auth_info_t
*auth_info
;
65 auth_info
= config
->get_auth(config
);
66 if (auth_info
->get_item(auth_info
, AUTHN_AUTH_CLASS
, (void**)&class))
70 /* fallback to pubkey authentication */
71 return AUTH_CLASS_PUBKEY
;
75 * log an IKE_SA to out
77 static void log_ike_sa(FILE *out
, ike_sa_t
*ike_sa
, bool all
)
79 ike_sa_id_t
*id
= ike_sa
->get_id(ike_sa
);
84 fprintf(out
, "%12s[%d]: %N",
85 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
86 ike_sa_state_names
, ike_sa
->get_state(ike_sa
));
88 if (ike_sa
->get_state(ike_sa
) == IKE_ESTABLISHED
)
90 u_int32_t established
;
92 established
= now
- ike_sa
->get_statistic(ike_sa
, STAT_ESTABLISHED
);
93 fprintf(out
, " %V", &established
);
96 fprintf(out
, ", %H[%D]...%H[%D]\n",
97 ike_sa
->get_my_host(ike_sa
), ike_sa
->get_my_id(ike_sa
),
98 ike_sa
->get_other_host(ike_sa
), ike_sa
->get_other_id(ike_sa
));
102 proposal_t
*ike_proposal
;
104 ike_proposal
= ike_sa
->get_proposal(ike_sa
);
106 fprintf(out
, "%12s[%d]: IKE SPIs: %.16llx_i%s %.16llx_r%s",
107 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
108 id
->get_initiator_spi(id
), id
->is_initiator(id
) ?
"*" : "",
109 id
->get_responder_spi(id
), id
->is_initiator(id
) ?
"" : "*");
112 if (ike_sa
->get_state(ike_sa
) == IKE_ESTABLISHED
)
114 u_int32_t rekey
, reauth
;
116 rekey
= ike_sa
->get_statistic(ike_sa
, STAT_REKEY
);
117 reauth
= ike_sa
->get_statistic(ike_sa
, STAT_REAUTH
);
122 fprintf(out
, ", rekeying in %V", &rekey
);
127 fprintf(out
, ", %N reauthentication in %V", auth_class_names
,
128 get_auth_class(ike_sa
->get_peer_cfg(ike_sa
)), &reauth
);
130 if (!rekey
&& !reauth
)
132 fprintf(out
, ", rekeying disabled");
141 snprintf(buf
, BUF_LEN
, "%P", ike_proposal
);
142 fprintf(out
, "%12s[%d]: IKE proposal: %s\n",
143 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
150 * log an CHILD_SA to out
152 static void log_child_sa(FILE *out
, child_sa_t
*child_sa
, bool all
)
154 u_int32_t rekey
, now
= time(NULL
);
155 u_int32_t use_in
, use_out
;
156 proposal_t
*proposal
;
157 child_cfg_t
*config
= child_sa
->get_config(child_sa
);
159 fprintf(out
, "%12s{%d}: %N, %N%s",
160 child_sa
->get_name(child_sa
), child_sa
->get_reqid(child_sa
),
161 child_sa_state_names
, child_sa
->get_state(child_sa
),
162 ipsec_mode_names
, child_sa
->get_mode(child_sa
),
163 config
->use_proxy_mode(config
) ?
"_PROXY" : "");
165 if (child_sa
->get_state(child_sa
) == CHILD_INSTALLED
)
167 fprintf(out
, ", %N%s SPIs: %.8x_i %.8x_o",
168 protocol_id_names
, child_sa
->get_protocol(child_sa
),
169 child_sa
->has_encap(child_sa
) ?
" in UDP" : "",
170 ntohl(child_sa
->get_spi(child_sa
, TRUE
)),
171 ntohl(child_sa
->get_spi(child_sa
, FALSE
)));
173 if (child_sa
->get_ipcomp(child_sa
) != IPCOMP_NONE
)
175 fprintf(out
, ", IPCOMP CPIs: %.4x_i %.4x_o",
176 ntohs(child_sa
->get_cpi(child_sa
, TRUE
)),
177 ntohs(child_sa
->get_cpi(child_sa
, FALSE
)));
182 fprintf(out
, "\n%12s{%d}: ", child_sa
->get_name(child_sa
),
183 child_sa
->get_reqid(child_sa
));
185 proposal
= child_sa
->get_proposal(child_sa
);
188 u_int16_t encr_alg
= ENCR_UNDEFINED
, int_alg
= AUTH_UNDEFINED
;
189 u_int16_t encr_size
= 0, int_size
= 0;
191 proposal
->get_algorithm(proposal
, ENCRYPTION_ALGORITHM
,
192 &encr_alg
, &encr_size
);
193 proposal
->get_algorithm(proposal
, INTEGRITY_ALGORITHM
,
194 &int_alg
, &int_size
);
196 if (encr_alg
!= ENCR_UNDEFINED
)
198 fprintf(out
, "%N", encryption_algorithm_names
, encr_alg
);
201 fprintf(out
, "-%d", encr_size
);
204 if (int_alg
!= AUTH_UNDEFINED
)
206 fprintf(out
, "/%N", integrity_algorithm_names
, int_alg
);
209 fprintf(out
, "-%d", int_size
);
213 fprintf(out
, ", rekeying ");
215 rekey
= child_sa
->get_lifetime(child_sa
, FALSE
);
218 fprintf(out
, "in %#V", &now
, &rekey
);
222 fprintf(out
, "disabled");
225 fprintf(out
, ", last use: ");
226 use_in
= child_sa
->get_usetime(child_sa
, TRUE
);
229 fprintf(out
, "%ds_i ", now
- use_in
);
233 fprintf(out
, "no_i ");
235 use_out
= child_sa
->get_usetime(child_sa
, FALSE
);
238 fprintf(out
, "%ds_o ", now
- use_out
);
242 fprintf(out
, "no_o ");
247 fprintf(out
, "\n%12s{%d}: %#R=== %#R\n",
248 child_sa
->get_name(child_sa
), child_sa
->get_reqid(child_sa
),
249 child_sa
->get_traffic_selectors(child_sa
, TRUE
),
250 child_sa
->get_traffic_selectors(child_sa
, FALSE
));
254 * Implementation of stroke_list_t.status.
256 static void status(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
, bool all
)
258 enumerator_t
*enumerator
, *children
;
260 child_cfg_t
*child_cfg
;
263 char *name
= msg
->status
.name
;
267 peer_cfg_t
*peer_cfg
;
271 time_t uptime
= time(NULL
) - this->uptime
;
273 u_int size
, online
, offline
;
275 fprintf(out
, "Performance:\n");
276 fprintf(out
, " uptime: %V, since %#T\n", &uptime
, &this->uptime
, FALSE
);
277 fprintf(out
, " worker threads: %d idle of %d,",
278 charon
->processor
->get_idle_threads(charon
->processor
),
279 charon
->processor
->get_total_threads(charon
->processor
));
280 fprintf(out
, " job queue load: %d,",
281 charon
->processor
->get_job_load(charon
->processor
));
282 fprintf(out
, " scheduled events: %d\n",
283 charon
->scheduler
->get_job_load(charon
->scheduler
));
284 fprintf(out
, " loaded plugins: ");
285 enumerator
= lib
->plugins
->create_plugin_enumerator(lib
->plugins
);
286 while (enumerator
->enumerate(enumerator
, &plugin
))
288 fprintf(out
, "%s ", plugin
);
290 enumerator
->destroy(enumerator
);
293 enumerator
= this->attribute
->create_pool_enumerator(this->attribute
);
294 while (enumerator
->enumerate(enumerator
, &name
, &size
, &online
, &offline
))
299 fprintf(out
, "Virtual IP pools (size/online/offline):\n");
301 fprintf(out
, " %s: %lu/%lu/%lu\n", name
, size
, online
, offline
);
303 enumerator
->destroy(enumerator
);
305 enumerator
= charon
->kernel_interface
->create_address_enumerator(
306 charon
->kernel_interface
, FALSE
, FALSE
);
307 fprintf(out
, "Listening IP addresses:\n");
308 while (enumerator
->enumerate(enumerator
, (void**)&host
))
310 fprintf(out
, " %H\n", host
);
312 enumerator
->destroy(enumerator
);
314 fprintf(out
, "Connections:\n");
315 enumerator
= charon
->backends
->create_peer_cfg_enumerator(charon
->backends
);
316 while (enumerator
->enumerate(enumerator
, (void**)&peer_cfg
))
322 enumerator_t
*auth_enumerator
;
323 identification_t
*my_ca
= NULL
, *other_ca
= NULL
;
324 identification_t
*eap_identity
= NULL
;
325 u_int32_t
*eap_type
= NULL
;
326 bool ac_groups
= FALSE
;
328 if (peer_cfg
->get_ike_version(peer_cfg
) != 2 ||
329 (name
&& !streq(name
, peer_cfg
->get_name(peer_cfg
))))
334 /* determine any required CAs, EAP type, EAP identity,
335 * and the presence of AC groups
337 auth
= peer_cfg
->get_auth(peer_cfg
);
338 auth_enumerator
= auth
->create_item_enumerator(auth
);
339 while (auth_enumerator
->enumerate(auth_enumerator
, &item
, &ptr
))
344 eap_type
= (u_int32_t
*)ptr
;
346 case AUTHN_EAP_IDENTITY
:
347 eap_identity
= (identification_t
*)ptr
;
350 cert
= (certificate_t
*)ptr
;
351 my_ca
= cert
->get_subject(cert
);
353 case AUTHN_CA_CERT_NAME
:
354 my_ca
= (identification_t
*)ptr
;
357 cert
= (certificate_t
*)ptr
;
358 other_ca
= cert
->get_subject(cert
);
360 case AUTHZ_CA_CERT_NAME
:
361 other_ca
= (identification_t
*)ptr
;
370 auth_enumerator
->destroy(auth_enumerator
);
372 ike_cfg
= peer_cfg
->get_ike_cfg(peer_cfg
);
373 fprintf(out
, "%12s: %s[%D]...%s[%D]\n", peer_cfg
->get_name(peer_cfg
),
374 ike_cfg
->get_my_addr(ike_cfg
), peer_cfg
->get_my_id(peer_cfg
),
375 ike_cfg
->get_other_addr(ike_cfg
), peer_cfg
->get_other_id(peer_cfg
));
376 if (my_ca
|| other_ca
)
378 fprintf(out
, "%12s: CAs: ", peer_cfg
->get_name(peer_cfg
));
381 fprintf(out
, "\"%D\"...", my_ca
);
385 fprintf(out
, "%%any...");
389 fprintf(out
, "\"%D\"\n", other_ca
);
393 fprintf(out
, "%%any\n");
401 fprintf(out
, "%12s: groups: ", peer_cfg
->get_name(peer_cfg
));
402 auth_enumerator
= auth
->create_item_enumerator(auth
);
403 while (auth_enumerator
->enumerate(auth_enumerator
, &item
, &ptr
))
405 if (item
== AUTHZ_AC_GROUP
)
407 identification_t
*group
= (identification_t
*)ptr
;
409 fprintf(out
, "%s%D", first?
"":", ", group
);
413 auth_enumerator
->destroy(auth_enumerator
);
417 fprintf(out
, "%12s: %N ", peer_cfg
->get_name(peer_cfg
),
418 auth_class_names
, get_auth_class(peer_cfg
));
421 fprintf(out
, "and %N ", eap_type_names
, *eap_type
);
423 fprintf(out
, "authentication");
426 fprintf(out
, ", EAP identity: '%D'", eap_identity
);
428 dpd
= peer_cfg
->get_dpd(peer_cfg
);
431 fprintf(out
, ", dpddelay=%us", dpd
);
435 children
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
436 while (children
->enumerate(children
, &child_cfg
))
438 linked_list_t
*my_ts
, *other_ts
;
440 my_ts
= child_cfg
->get_traffic_selectors(child_cfg
, TRUE
, NULL
, NULL
);
441 other_ts
= child_cfg
->get_traffic_selectors(child_cfg
, FALSE
, NULL
, NULL
);
442 fprintf(out
, "%12s: %#R=== %#R", child_cfg
->get_name(child_cfg
),
444 my_ts
->destroy_offset(my_ts
, offsetof(traffic_selector_t
, destroy
));
445 other_ts
->destroy_offset(other_ts
, offsetof(traffic_selector_t
, destroy
));
449 fprintf(out
, ", dpdaction=%N", action_names
,
450 child_cfg
->get_dpd_action(child_cfg
));
454 children
->destroy(children
);
456 enumerator
->destroy(enumerator
);
459 fprintf(out
, "Security Associations:\n");
460 enumerator
= charon
->controller
->create_ike_sa_enumerator(charon
->controller
);
461 while (enumerator
->enumerate(enumerator
, &ike_sa
))
463 bool ike_printed
= FALSE
;
464 child_sa_t
*child_sa
;
465 iterator_t
*children
= ike_sa
->create_child_sa_iterator(ike_sa
);
467 if (name
== NULL
|| streq(name
, ike_sa
->get_name(ike_sa
)))
469 log_ike_sa(out
, ike_sa
, all
);
474 while (children
->iterate(children
, (void**)&child_sa
))
476 if (name
== NULL
|| streq(name
, child_sa
->get_name(child_sa
)))
480 log_ike_sa(out
, ike_sa
, all
);
484 log_child_sa(out
, child_sa
, all
);
487 children
->destroy(children
);
489 enumerator
->destroy(enumerator
);
495 fprintf(out
, " no match\n");
499 fprintf(out
, " none\n");
505 * create a unique certificate list without duplicates
506 * certicates having the same issuer are grouped together.
508 static linked_list_t
* create_unique_cert_list(certificate_type_t type
)
510 linked_list_t
*list
= linked_list_create();
511 enumerator_t
*enumerator
= charon
->credentials
->create_cert_enumerator(
512 charon
->credentials
, type
, KEY_ANY
,
516 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
518 iterator_t
*iterator
= list
->create_iterator(list
, TRUE
);
519 identification_t
*issuer
= cert
->get_issuer(cert
);
520 bool previous_same
, same
= FALSE
, last
= TRUE
;
521 certificate_t
*list_cert
;
523 while (iterator
->iterate(iterator
, (void**)&list_cert
))
525 /* exit if we have a duplicate? */
526 if (list_cert
->equals(list_cert
, cert
))
531 /* group certificates with same issuer */
532 previous_same
= same
;
533 same
= list_cert
->has_issuer(list_cert
, issuer
);
534 if (previous_same
&& !same
)
536 iterator
->insert_before(iterator
, (void *)cert
->get_ref(cert
));
541 iterator
->destroy(iterator
);
545 list
->insert_last(list
, (void *)cert
->get_ref(cert
));
548 enumerator
->destroy(enumerator
);
553 * list all raw public keys
555 static void stroke_list_pubkeys(linked_list_t
*list
, bool utc
, FILE *out
)
559 enumerator_t
*enumerator
= list
->create_enumerator(list
);
562 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
564 public_key_t
*public = cert
->get_public_key(cert
);
568 private_key_t
*private = NULL
;
569 identification_t
*id
, *keyid
;
574 fprintf(out
, "List of Raw Public Keys:\n");
579 /* list public key information */
580 id
= public->get_id(public, ID_PUBKEY_SHA1
);
581 keyid
= public->get_id(public, ID_PUBKEY_INFO_SHA1
);
583 private = charon
->credentials
->get_private(
585 public->get_type(public), keyid
, NULL
);
586 fprintf(out
, " pubkey: %N %d bits%s\n",
587 key_type_names
, public->get_type(public),
588 public->get_keysize(public) * 8,
589 private ?
", has private key" : "");
590 fprintf(out
, " keyid: %D\n", keyid
);
591 fprintf(out
, " subjkey: %D\n", id
);
593 public->destroy(public);
596 enumerator
->destroy(enumerator
);
600 * list all X.509 certificates matching the flags
602 static void stroke_list_certs(linked_list_t
*list
, char *label
,
603 x509_flag_t flags
, bool utc
, FILE *out
)
606 time_t now
= time(NULL
);
607 enumerator_t
*enumerator
= list
->create_enumerator(list
);
610 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
612 x509_t
*x509
= (x509_t
*)cert
;
613 x509_flag_t x509_flags
= x509
->get_flags(x509
);
615 /* list only if flag is set, or flags == 0 (ignoring self-signed) */
616 if ((x509_flags
& flags
) || (flags
== (x509_flags
& ~X509_SELF_SIGNED
)))
618 enumerator_t
*enumerator
;
619 identification_t
*altName
;
620 bool first_altName
= TRUE
;
621 chunk_t serial
= x509
->get_serial(x509
);
622 identification_t
*authkey
= x509
->get_authKeyIdentifier(x509
);
623 time_t notBefore
, notAfter
;
624 public_key_t
*public = cert
->get_public_key(cert
);
629 fprintf(out
, "List of %s:\n", label
);
634 /* list subjectAltNames */
635 enumerator
= x509
->create_subjectAltName_enumerator(x509
);
636 while (enumerator
->enumerate(enumerator
, (void**)&altName
))
640 fprintf(out
, " altNames: ");
641 first_altName
= FALSE
;
647 fprintf(out
, "%D", altName
);
653 enumerator
->destroy(enumerator
);
655 fprintf(out
, " subject: \"%D\"\n", cert
->get_subject(cert
));
656 fprintf(out
, " issuer: \"%D\"\n", cert
->get_issuer(cert
));
657 fprintf(out
, " serial: %#B\n", &serial
);
660 cert
->get_validity(cert
, &now
, ¬Before
, ¬After
);
661 fprintf(out
, " validity: not before %#T, ", ¬Before
, utc
);
664 fprintf(out
, "not valid yet (valid in %#V)\n", &now
, ¬Before
);
668 fprintf(out
, "ok\n");
670 fprintf(out
, " not after %#T, ", ¬After
, utc
);
673 fprintf(out
, "expired (%#V ago)\n", &now
, ¬After
);
678 if (now
> notAfter
- CERT_WARNING_INTERVAL
* 60 * 60 * 24)
680 fprintf(out
, " (expires in %#V)", &now
, ¬After
);
685 /* list public key information */
688 private_key_t
*private = NULL
;
689 identification_t
*id
, *keyid
;
691 id
= public->get_id(public, ID_PUBKEY_SHA1
);
692 keyid
= public->get_id(public, ID_PUBKEY_INFO_SHA1
);
694 private = charon
->credentials
->get_private(
696 public->get_type(public), keyid
, NULL
);
697 fprintf(out
, " pubkey: %N %d bits%s\n",
698 key_type_names
, public->get_type(public),
699 public->get_keysize(public) * 8,
700 private ?
", has private key" : "");
701 fprintf(out
, " keyid: %D\n", keyid
);
702 fprintf(out
, " subjkey: %D\n", id
);
704 public->destroy(public);
707 /* list optional authorityKeyIdentifier */
710 fprintf(out
, " authkey: %D\n", authkey
);
714 enumerator
->destroy(enumerator
);
718 * list all X.509 attribute certificates
720 static void stroke_list_acerts(linked_list_t
*list
, bool utc
, FILE *out
)
723 time_t thisUpdate
, nextUpdate
, now
= time(NULL
);
724 enumerator_t
*enumerator
= list
->create_enumerator(list
);
727 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
729 ac_t
*ac
= (ac_t
*)cert
;
730 chunk_t serial
= ac
->get_serial(ac
);
731 chunk_t holderSerial
= ac
->get_holderSerial(ac
);
732 identification_t
*holderIssuer
= ac
->get_holderIssuer(ac
);
733 identification_t
*authkey
= ac
->get_authKeyIdentifier(ac
);
734 identification_t
*entityName
= cert
->get_subject(cert
);
739 fprintf(out
, "List of X.509 Attribute Certificates:\n");
746 fprintf(out
, " holder: \"%D\"\n", entityName
);
750 fprintf(out
, " hissuer: \"%D\"\n", holderIssuer
);
752 if (holderSerial
.ptr
)
754 fprintf(out
, " hserial: %#B\n", &holderSerial
);
756 fprintf(out
, " issuer: \"%D\"\n", cert
->get_issuer(cert
));
757 fprintf(out
, " serial: %#B\n", &serial
);
760 cert
->get_validity(cert
, &now
, &thisUpdate
, &nextUpdate
);
761 fprintf(out
, " updates: this %#T\n", &thisUpdate
, utc
);
762 fprintf(out
, " next %#T, ", &nextUpdate
, utc
);
763 if (now
> nextUpdate
)
765 fprintf(out
, "expired (%#V ago)\n", &now
, &nextUpdate
);
770 if (now
> nextUpdate
- AC_WARNING_INTERVAL
* 60 * 60 * 24)
772 fprintf(out
, " (expires in %#V)", &now
, &nextUpdate
);
777 /* list optional authorityKeyIdentifier */
780 fprintf(out
, " authkey: %D\n", authkey
);
783 enumerator
->destroy(enumerator
);
787 * list all X.509 CRLs
789 static void stroke_list_crls(linked_list_t
*list
, bool utc
, FILE *out
)
792 time_t thisUpdate
, nextUpdate
, now
= time(NULL
);
793 enumerator_t
*enumerator
= list
->create_enumerator(list
);
796 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
798 crl_t
*crl
= (crl_t
*)cert
;
799 chunk_t serial
= crl
->get_serial(crl
);
800 identification_t
*authkey
= crl
->get_authKeyIdentifier(crl
);
805 fprintf(out
, "List of X.509 CRLs:\n");
810 fprintf(out
, " issuer: \"%D\"\n", cert
->get_issuer(cert
));
812 /* list optional crlNumber */
815 fprintf(out
, " serial: %#B\n", &serial
);
818 /* count the number of revoked certificates */
821 enumerator_t
*enumerator
= crl
->create_enumerator(crl
);
823 while (enumerator
->enumerate(enumerator
, NULL
, NULL
, NULL
))
827 fprintf(out
, " revoked: %d certificate%s\n", count
,
828 (count
== 1)?
"" : "s");
829 enumerator
->destroy(enumerator
);
833 cert
->get_validity(cert
, &now
, &thisUpdate
, &nextUpdate
);
834 fprintf(out
, " updates: this %#T\n", &thisUpdate
, utc
);
835 fprintf(out
, " next %#T, ", &nextUpdate
, utc
);
836 if (now
> nextUpdate
)
838 fprintf(out
, "expired (%#V ago)\n", &now
, &nextUpdate
);
843 if (now
> nextUpdate
- CRL_WARNING_INTERVAL
* 60 * 60 * 24)
845 fprintf(out
, " (expires in %#V)", &now
, &nextUpdate
);
850 /* list optional authorityKeyIdentifier */
853 fprintf(out
, " authkey: %D\n", authkey
);
856 enumerator
->destroy(enumerator
);
860 * list all OCSP responses
862 static void stroke_list_ocsp(linked_list_t
* list
, bool utc
, FILE *out
)
865 enumerator_t
*enumerator
= list
->create_enumerator(list
);
868 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
873 fprintf(out
, "List of OCSP responses:\n");
878 fprintf(out
, " signer: \"%D\"\n", cert
->get_issuer(cert
));
880 enumerator
->destroy(enumerator
);
884 * List of registered cryptographical algorithms
886 static void list_algs(FILE *out
)
888 enumerator_t
*enumerator
;
889 encryption_algorithm_t encryption
;
890 integrity_algorithm_t integrity
;
891 hash_algorithm_t hash
;
892 pseudo_random_function_t prf
;
893 diffie_hellman_group_t group
;
896 fprintf(out
, "List of registered IKEv2 Algorithms:\n");
897 fprintf(out
, "\n encryption: ");
898 enumerator
= lib
->crypto
->create_crypter_enumerator(lib
->crypto
);
899 while (enumerator
->enumerate(enumerator
, &encryption
))
901 fprintf(out
, "%N ", encryption_algorithm_names
, encryption
);
903 enumerator
->destroy(enumerator
);
904 fprintf(out
, "\n integrity: ");
905 enumerator
= lib
->crypto
->create_signer_enumerator(lib
->crypto
);
906 while (enumerator
->enumerate(enumerator
, &integrity
))
908 fprintf(out
, "%N ", integrity_algorithm_names
, integrity
);
910 enumerator
->destroy(enumerator
);
911 fprintf(out
, "\n hasher: ");
912 enumerator
= lib
->crypto
->create_hasher_enumerator(lib
->crypto
);
913 while (enumerator
->enumerate(enumerator
, &hash
))
915 fprintf(out
, "%N ", hash_algorithm_names
, hash
);
917 enumerator
->destroy(enumerator
);
918 fprintf(out
, "\n prf: ");
919 enumerator
= lib
->crypto
->create_prf_enumerator(lib
->crypto
);
920 while (enumerator
->enumerate(enumerator
, &prf
))
922 fprintf(out
, "%N ", pseudo_random_function_names
, prf
);
924 enumerator
->destroy(enumerator
);
925 fprintf(out
, "\n dh-group: ");
926 enumerator
= lib
->crypto
->create_dh_enumerator(lib
->crypto
);
927 while (enumerator
->enumerate(enumerator
, &group
))
929 fprintf(out
, "%N ", diffie_hellman_group_names
, group
);
931 enumerator
->destroy(enumerator
);
936 * Implementation of stroke_list_t.list.
938 static void list(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
)
940 linked_list_t
*cert_list
= NULL
;
942 if (msg
->list
.flags
& LIST_PUBKEYS
)
944 linked_list_t
*pubkey_list
= create_unique_cert_list(CERT_TRUSTED_PUBKEY
);
946 stroke_list_pubkeys(pubkey_list
, msg
->list
.utc
, out
);
947 pubkey_list
->destroy_offset(pubkey_list
, offsetof(certificate_t
, destroy
));
949 if (msg
->list
.flags
& (LIST_CERTS
| LIST_CACERTS
| LIST_OCSPCERTS
| LIST_AACERTS
))
951 cert_list
= create_unique_cert_list(CERT_X509
);
953 if (msg
->list
.flags
& LIST_CERTS
)
955 stroke_list_certs(cert_list
, "X.509 End Entity Certificates",
956 0, msg
->list
.utc
, out
);
958 if (msg
->list
.flags
& LIST_CACERTS
)
960 stroke_list_certs(cert_list
, "X.509 CA Certificates",
961 X509_CA
, msg
->list
.utc
, out
);
963 if (msg
->list
.flags
& LIST_OCSPCERTS
)
965 stroke_list_certs(cert_list
, "X.509 OCSP Signer Certificates",
966 X509_OCSP_SIGNER
, msg
->list
.utc
, out
);
968 if (msg
->list
.flags
& LIST_AACERTS
)
970 stroke_list_certs(cert_list
, "X.509 AA Certificates",
971 X509_AA
, msg
->list
.utc
, out
);
973 if (msg
->list
.flags
& LIST_ACERTS
)
975 linked_list_t
*ac_list
= create_unique_cert_list(CERT_X509_AC
);
977 stroke_list_acerts(ac_list
, msg
->list
.utc
, out
);
978 ac_list
->destroy_offset(ac_list
, offsetof(certificate_t
, destroy
));
980 if (msg
->list
.flags
& LIST_CRLS
)
982 linked_list_t
*crl_list
= create_unique_cert_list(CERT_X509_CRL
);
984 stroke_list_crls(crl_list
, msg
->list
.utc
, out
);
985 crl_list
->destroy_offset(crl_list
, offsetof(certificate_t
, destroy
));
987 if (msg
->list
.flags
& LIST_OCSP
)
989 linked_list_t
*ocsp_list
= create_unique_cert_list(CERT_X509_OCSP_RESPONSE
);
991 stroke_list_ocsp(ocsp_list
, msg
->list
.utc
, out
);
993 ocsp_list
->destroy_offset(ocsp_list
, offsetof(certificate_t
, destroy
));
995 if (msg
->list
.flags
& LIST_ALGS
)
999 DESTROY_OFFSET_IF(cert_list
, offsetof(certificate_t
, destroy
));
1003 * Implementation of stroke_list_t.destroy
1005 static void destroy(private_stroke_list_t
*this)
1013 stroke_list_t
*stroke_list_create(stroke_attribute_t
*attribute
)
1015 private_stroke_list_t
*this = malloc_thing(private_stroke_list_t
);
1017 this->public.list
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
))list
;
1018 this->public.status
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
,bool))status
;
1019 this->public.destroy
= (void(*)(stroke_list_t
*))destroy
;
1021 this->uptime
= time(NULL
);
1022 this->attribute
= attribute
;
1024 return &this->public;