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
16 #include "stroke_list.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 <credentials/certificates/pgp_certificate.h>
26 #include <credentials/ietf_attributes/ietf_attributes.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 * log an IKE_SA to out
60 static void log_ike_sa(FILE *out
, ike_sa_t
*ike_sa
, bool all
)
62 ike_sa_id_t
*id
= ike_sa
->get_id(ike_sa
);
63 time_t now
= time_monotonic(NULL
);
65 fprintf(out
, "%12s[%d]: %N",
66 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
67 ike_sa_state_names
, ike_sa
->get_state(ike_sa
));
69 if (ike_sa
->get_state(ike_sa
) == IKE_ESTABLISHED
)
73 established
= ike_sa
->get_statistic(ike_sa
, STAT_ESTABLISHED
);
74 fprintf(out
, " %V ago", &now
, &established
);
77 fprintf(out
, ", %H[%Y]...%H[%Y]\n",
78 ike_sa
->get_my_host(ike_sa
), ike_sa
->get_my_id(ike_sa
),
79 ike_sa
->get_other_host(ike_sa
), ike_sa
->get_other_id(ike_sa
));
83 proposal_t
*ike_proposal
;
85 ike_proposal
= ike_sa
->get_proposal(ike_sa
);
87 fprintf(out
, "%12s[%d]: IKE SPIs: %.16llx_i%s %.16llx_r%s",
88 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
89 id
->get_initiator_spi(id
), id
->is_initiator(id
) ?
"*" : "",
90 id
->get_responder_spi(id
), id
->is_initiator(id
) ?
"" : "*");
93 if (ike_sa
->get_state(ike_sa
) == IKE_ESTABLISHED
)
98 rekey
= ike_sa
->get_statistic(ike_sa
, STAT_REKEY
);
99 reauth
= ike_sa
->get_statistic(ike_sa
, STAT_REAUTH
);
100 peer_cfg
= ike_sa
->get_peer_cfg(ike_sa
);
104 fprintf(out
, ", rekeying in %V", &rekey
, &now
);
109 enumerator_t
*enumerator
;
113 enumerator
= peer_cfg
->create_auth_cfg_enumerator(peer_cfg
, TRUE
);
114 while (enumerator
->enumerate(enumerator
, &auth
))
121 fprintf(out
, "%N", auth_class_names
,
122 auth
->get(auth
, AUTH_RULE_AUTH_CLASS
));
124 enumerator
->destroy(enumerator
);
125 fprintf(out
, " reauthentication in %V", &reauth
, &now
);
127 if (!rekey
&& !reauth
)
129 fprintf(out
, ", rekeying disabled");
138 snprintf(buf
, BUF_LEN
, "%P", ike_proposal
);
139 fprintf(out
, "%12s[%d]: IKE proposal: %s\n",
140 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
147 * log an CHILD_SA to out
149 static void log_child_sa(FILE *out
, child_sa_t
*child_sa
, bool all
)
151 time_t use_in
, use_out
, rekey
, now
;
152 u_int64_t bytes_in
, bytes_out
;
153 proposal_t
*proposal
;
154 child_cfg_t
*config
= child_sa
->get_config(child_sa
);
157 fprintf(out
, "%12s{%d}: %N, %N%s",
158 child_sa
->get_name(child_sa
), child_sa
->get_reqid(child_sa
),
159 child_sa_state_names
, child_sa
->get_state(child_sa
),
160 ipsec_mode_names
, child_sa
->get_mode(child_sa
),
161 config
->use_proxy_mode(config
) ?
"_PROXY" : "");
163 if (child_sa
->get_state(child_sa
) == CHILD_INSTALLED
)
165 fprintf(out
, ", %N%s SPIs: %.8x_i %.8x_o",
166 protocol_id_names
, child_sa
->get_protocol(child_sa
),
167 child_sa
->has_encap(child_sa
) ?
" in UDP" : "",
168 ntohl(child_sa
->get_spi(child_sa
, TRUE
)),
169 ntohl(child_sa
->get_spi(child_sa
, FALSE
)));
171 if (child_sa
->get_ipcomp(child_sa
) != IPCOMP_NONE
)
173 fprintf(out
, ", IPCOMP CPIs: %.4x_i %.4x_o",
174 ntohs(child_sa
->get_cpi(child_sa
, TRUE
)),
175 ntohs(child_sa
->get_cpi(child_sa
, FALSE
)));
180 fprintf(out
, "\n%12s{%d}: ", child_sa
->get_name(child_sa
),
181 child_sa
->get_reqid(child_sa
));
183 proposal
= child_sa
->get_proposal(child_sa
);
186 u_int16_t encr_alg
= ENCR_UNDEFINED
, int_alg
= AUTH_UNDEFINED
;
187 u_int16_t encr_size
= 0, int_size
= 0;
189 proposal
->get_algorithm(proposal
, ENCRYPTION_ALGORITHM
,
190 &encr_alg
, &encr_size
);
191 proposal
->get_algorithm(proposal
, INTEGRITY_ALGORITHM
,
192 &int_alg
, &int_size
);
194 if (encr_alg
!= ENCR_UNDEFINED
)
196 fprintf(out
, "%N", encryption_algorithm_names
, encr_alg
);
199 fprintf(out
, "_%u", encr_size
);
202 if (int_alg
!= AUTH_UNDEFINED
)
204 fprintf(out
, "/%N", integrity_algorithm_names
, int_alg
);
207 fprintf(out
, "_%u", int_size
);
212 now
= time_monotonic(NULL
);
213 child_sa
->get_usestats(child_sa
, TRUE
, &use_in
, &bytes_in
);
214 fprintf(out
, ", %llu bytes_i", bytes_in
);
217 fprintf(out
, " (%ds ago)", now
- use_in
);
220 child_sa
->get_usestats(child_sa
, FALSE
, &use_out
, &bytes_out
);
221 fprintf(out
, ", %llu bytes_o", bytes_out
);
224 fprintf(out
, " (%ds ago)", now
- use_out
);
226 fprintf(out
, ", rekeying ");
228 rekey
= child_sa
->get_lifetime(child_sa
, FALSE
);
233 fprintf(out
, "active");
237 fprintf(out
, "in %V", &now
, &rekey
);
242 fprintf(out
, "disabled");
248 fprintf(out
, "\n%12s{%d}: %#R=== %#R\n",
249 child_sa
->get_name(child_sa
), child_sa
->get_reqid(child_sa
),
250 child_sa
->get_traffic_selectors(child_sa
, TRUE
),
251 child_sa
->get_traffic_selectors(child_sa
, FALSE
));
255 * Log a configs local or remote authentication config to out
257 static void log_auth_cfgs(FILE *out
, peer_cfg_t
*peer_cfg
, bool local
)
259 enumerator_t
*enumerator
, *rules
;
262 auth_class_t auth_class
;
263 identification_t
*id
;
265 cert_validation_t valid
;
268 name
= peer_cfg
->get_name(peer_cfg
);
270 enumerator
= peer_cfg
->create_auth_cfg_enumerator(peer_cfg
, local
);
271 while (enumerator
->enumerate(enumerator
, &auth
))
273 fprintf(out
, "%12s: %s [%Y] uses ", name
, local ?
"local: " : "remote:",
274 auth
->get(auth
, AUTH_RULE_IDENTITY
));
276 auth_class
= (uintptr_t)auth
->get(auth
, AUTH_RULE_AUTH_CLASS
);
277 if (auth_class
!= AUTH_CLASS_EAP
)
279 fprintf(out
, "%N authentication\n", auth_class_names
, auth_class
);
283 if ((uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_TYPE
) == EAP_NAK
)
285 fprintf(out
, "EAP authentication");
289 if ((uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_VENDOR
))
291 fprintf(out
, "EAP_%d-%d authentication",
292 (uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_TYPE
),
293 (uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_VENDOR
));
297 fprintf(out
, "%N authentication", eap_type_names
,
298 (uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_TYPE
));
301 id
= auth
->get(auth
, AUTH_RULE_EAP_IDENTITY
);
304 fprintf(out
, " with EAP identity '%Y'", id
);
309 cert
= auth
->get(auth
, AUTH_RULE_CA_CERT
);
312 fprintf(out
, "%12s: ca: \"%Y\"\n", name
, cert
->get_subject(cert
));
315 cert
= auth
->get(auth
, AUTH_RULE_IM_CERT
);
318 fprintf(out
, "%12s: im-ca: \"%Y\"\n", name
, cert
->get_subject(cert
));
321 cert
= auth
->get(auth
, AUTH_RULE_SUBJECT_CERT
);
324 fprintf(out
, "%12s: cert: \"%Y\"\n", name
,
325 cert
->get_subject(cert
));
328 valid
= (uintptr_t)auth
->get(auth
, AUTH_RULE_OCSP_VALIDATION
);
329 if (valid
!= VALIDATION_FAILED
)
331 fprintf(out
, "%12s: ocsp: status must be GOOD%s\n", name
,
332 (valid
== VALIDATION_SKIPPED
) ?
" or SKIPPED" : "");
335 valid
= (uintptr_t)auth
->get(auth
, AUTH_RULE_CRL_VALIDATION
);
336 if (valid
!= VALIDATION_FAILED
)
338 fprintf(out
, "%12s: crl: status must be GOOD%s\n", name
,
339 (valid
== VALIDATION_SKIPPED
) ?
" or SKIPPED" : "");
342 rules
= auth
->create_enumerator(auth
);
343 while (rules
->enumerate(rules
, &rule
, &id
))
345 if (rule
== AUTH_RULE_AC_GROUP
)
347 fprintf(out
, "%12s: group: %Y\n", name
, id
);
350 rules
->destroy(rules
);
352 enumerator
->destroy(enumerator
);
356 * Implementation of stroke_list_t.status.
358 static void status(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
, bool all
)
360 enumerator_t
*enumerator
, *children
;
362 child_cfg_t
*child_cfg
;
363 child_sa_t
*child_sa
;
365 bool first
, found
= FALSE
;
366 char *name
= msg
->status
.name
;
370 peer_cfg_t
*peer_cfg
;
375 u_int size
, online
, offline
;
377 now
= time_monotonic(NULL
);
378 since
= time(NULL
) - (now
- this->uptime
);
380 fprintf(out
, "Status of IKEv2 charon daemon (strongSwan "VERSION
"):\n");
381 fprintf(out
, " uptime: %V, since %T\n", &now
, &this->uptime
, &since
, FALSE
);
382 fprintf(out
, " worker threads: %d idle of %d,",
383 charon
->processor
->get_idle_threads(charon
->processor
),
384 charon
->processor
->get_total_threads(charon
->processor
));
385 fprintf(out
, " job queue load: %d,",
386 charon
->processor
->get_job_load(charon
->processor
));
387 fprintf(out
, " scheduled events: %d\n",
388 charon
->scheduler
->get_job_load(charon
->scheduler
));
389 fprintf(out
, " loaded plugins: ");
390 enumerator
= lib
->plugins
->create_plugin_enumerator(lib
->plugins
);
391 while (enumerator
->enumerate(enumerator
, &plugin
))
393 fprintf(out
, "%s ", plugin
);
395 enumerator
->destroy(enumerator
);
399 enumerator
= this->attribute
->create_pool_enumerator(this->attribute
);
400 while (enumerator
->enumerate(enumerator
, &pool
, &size
, &online
, &offline
))
402 if (name
&& !streq(name
, pool
))
409 fprintf(out
, "Virtual IP pools (size/online/offline):\n");
411 fprintf(out
, " %s: %u/%u/%u\n", pool
, size
, online
, offline
);
413 enumerator
->destroy(enumerator
);
415 enumerator
= charon
->kernel_interface
->create_address_enumerator(
416 charon
->kernel_interface
, FALSE
, FALSE
);
417 fprintf(out
, "Listening IP addresses:\n");
418 while (enumerator
->enumerate(enumerator
, (void**)&host
))
420 fprintf(out
, " %H\n", host
);
422 enumerator
->destroy(enumerator
);
424 fprintf(out
, "Connections:\n");
425 enumerator
= charon
->backends
->create_peer_cfg_enumerator(
426 charon
->backends
, NULL
, NULL
, NULL
, NULL
);
427 while (enumerator
->enumerate(enumerator
, &peer_cfg
))
429 if (peer_cfg
->get_ike_version(peer_cfg
) != 2 ||
430 (name
&& !streq(name
, peer_cfg
->get_name(peer_cfg
))))
435 ike_cfg
= peer_cfg
->get_ike_cfg(peer_cfg
);
436 fprintf(out
, "%12s: %s...%s", peer_cfg
->get_name(peer_cfg
),
437 ike_cfg
->get_my_addr(ike_cfg
), ike_cfg
->get_other_addr(ike_cfg
));
439 dpd
= peer_cfg
->get_dpd(peer_cfg
);
442 fprintf(out
, ", dpddelay=%us", dpd
);
446 log_auth_cfgs(out
, peer_cfg
, TRUE
);
447 log_auth_cfgs(out
, peer_cfg
, FALSE
);
449 children
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
450 while (children
->enumerate(children
, &child_cfg
))
452 linked_list_t
*my_ts
, *other_ts
;
454 my_ts
= child_cfg
->get_traffic_selectors(child_cfg
, TRUE
, NULL
, NULL
);
455 other_ts
= child_cfg
->get_traffic_selectors(child_cfg
, FALSE
, NULL
, NULL
);
456 fprintf(out
, "%12s: child: %#R=== %#R", child_cfg
->get_name(child_cfg
),
458 my_ts
->destroy_offset(my_ts
, offsetof(traffic_selector_t
, destroy
));
459 other_ts
->destroy_offset(other_ts
, offsetof(traffic_selector_t
, destroy
));
463 fprintf(out
, ", dpdaction=%N", action_names
,
464 child_cfg
->get_dpd_action(child_cfg
));
468 children
->destroy(children
);
470 enumerator
->destroy(enumerator
);
474 enumerator
= charon
->traps
->create_enumerator(charon
->traps
);
475 while (enumerator
->enumerate(enumerator
, NULL
, &child_sa
))
479 fprintf(out
, "Routed Connections:\n");
482 log_child_sa(out
, child_sa
, all
);
484 enumerator
->destroy(enumerator
);
486 fprintf(out
, "Security Associations:\n");
487 enumerator
= charon
->controller
->create_ike_sa_enumerator(charon
->controller
);
488 while (enumerator
->enumerate(enumerator
, &ike_sa
))
490 bool ike_printed
= FALSE
;
491 iterator_t
*children
= ike_sa
->create_child_sa_iterator(ike_sa
);
493 if (name
== NULL
|| streq(name
, ike_sa
->get_name(ike_sa
)))
495 log_ike_sa(out
, ike_sa
, all
);
500 while (children
->iterate(children
, (void**)&child_sa
))
502 if (name
== NULL
|| streq(name
, child_sa
->get_name(child_sa
)))
506 log_ike_sa(out
, ike_sa
, all
);
510 log_child_sa(out
, child_sa
, all
);
513 children
->destroy(children
);
515 enumerator
->destroy(enumerator
);
521 fprintf(out
, " no match\n");
525 fprintf(out
, " none\n");
531 * create a unique certificate list without duplicates
532 * certicates having the same issuer are grouped together.
534 static linked_list_t
* create_unique_cert_list(certificate_type_t type
)
536 linked_list_t
*list
= linked_list_create();
537 enumerator_t
*enumerator
= charon
->credentials
->create_cert_enumerator(
538 charon
->credentials
, type
, KEY_ANY
,
542 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
544 iterator_t
*iterator
= list
->create_iterator(list
, TRUE
);
545 identification_t
*issuer
= cert
->get_issuer(cert
);
546 bool previous_same
, same
= FALSE
, last
= TRUE
;
547 certificate_t
*list_cert
;
549 while (iterator
->iterate(iterator
, (void**)&list_cert
))
551 /* exit if we have a duplicate? */
552 if (list_cert
->equals(list_cert
, cert
))
557 /* group certificates with same issuer */
558 previous_same
= same
;
559 same
= list_cert
->has_issuer(list_cert
, issuer
);
560 if (previous_same
&& !same
)
562 iterator
->insert_before(iterator
, (void *)cert
->get_ref(cert
));
567 iterator
->destroy(iterator
);
571 list
->insert_last(list
, (void *)cert
->get_ref(cert
));
574 enumerator
->destroy(enumerator
);
579 * Print a single public key.
581 static void list_public_key(public_key_t
*public, FILE *out
)
583 private_key_t
*private = NULL
;
585 identification_t
*id
;
588 if (public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1
, &keyid
))
590 id
= identification_create_from_encoding(ID_KEY_ID
, keyid
);
591 auth
= auth_cfg_create();
592 private = charon
->credentials
->get_private(charon
->credentials
,
593 public->get_type(public), id
, auth
);
598 fprintf(out
, " pubkey: %N %d bits%s\n",
599 key_type_names
, public->get_type(public),
600 public->get_keysize(public) * 8,
601 private ?
", has private key" : "");
602 if (public->get_fingerprint(public, KEY_ID_PUBKEY_INFO_SHA1
, &keyid
))
604 fprintf(out
, " keyid: %#B\n", &keyid
);
606 if (public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1
, &keyid
))
608 fprintf(out
, " subjkey: %#B\n", &keyid
);
614 * list all raw public keys
616 static void stroke_list_pubkeys(linked_list_t
*list
, bool utc
, FILE *out
)
620 enumerator_t
*enumerator
= list
->create_enumerator(list
);
623 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
625 public_key_t
*public = cert
->get_public_key(cert
);
632 fprintf(out
, "List of Raw Public Keys:\n");
637 list_public_key(public, out
);
638 public->destroy(public);
641 enumerator
->destroy(enumerator
);
645 * list OpenPGP certificates
647 static void stroke_list_pgp(linked_list_t
*list
,bool utc
, FILE *out
)
650 time_t now
= time(NULL
);
651 enumerator_t
*enumerator
= list
->create_enumerator(list
);
654 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
656 time_t created
, until
;
657 public_key_t
*public;
658 pgp_certificate_t
*pgp_cert
= (pgp_certificate_t
*)cert
;
659 chunk_t fingerprint
= pgp_cert
->get_fingerprint(pgp_cert
);
665 fprintf(out
, "List of PGP End Entity Certificates:\n");
669 fprintf(out
, " userid: '%Y'\n", cert
->get_subject(cert
));
671 fprintf(out
, " digest: %#B\n", &fingerprint
);
674 cert
->get_validity(cert
, &now
, &created
, &until
);
675 fprintf(out
, " created: %T\n", &created
, utc
);
676 fprintf(out
, " until: %T%s\n", &until
, utc
,
677 (until
== TIME_32_BIT_SIGNED_MAX
) ?
" (expires never)":"");
679 public = cert
->get_public_key(cert
);
682 list_public_key(public, out
);
683 public->destroy(public);
686 enumerator
->destroy(enumerator
);
690 * list all X.509 certificates matching the flags
692 static void stroke_list_certs(linked_list_t
*list
, char *label
,
693 x509_flag_t flags
, bool utc
, FILE *out
)
696 time_t now
= time(NULL
);
697 enumerator_t
*enumerator
;
699 x509_flag_t flag_mask
;
701 /* mask all auxiliary flags */
702 flag_mask
= ~(X509_SELF_SIGNED
| X509_SERVER_AUTH
| X509_IP_ADDR_BLOCKS
);
704 enumerator
= list
->create_enumerator(list
);
705 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
707 x509_t
*x509
= (x509_t
*)cert
;
708 x509_flag_t x509_flags
= x509
->get_flags(x509
) & flag_mask
;
710 /* list only if flag is set or flag == 0 */
711 if ((x509_flags
& flags
) || (x509_flags
== flags
))
713 enumerator_t
*enumerator
;
714 identification_t
*altName
;
715 bool first_altName
= TRUE
;
717 chunk_t serial
, authkey
;
718 time_t notBefore
, notAfter
;
719 public_key_t
*public;
724 fprintf(out
, "List of %s:\n", label
);
729 /* list subjectAltNames */
730 enumerator
= x509
->create_subjectAltName_enumerator(x509
);
731 while (enumerator
->enumerate(enumerator
, (void**)&altName
))
735 fprintf(out
, " altNames: ");
736 first_altName
= FALSE
;
742 fprintf(out
, "%Y", altName
);
748 enumerator
->destroy(enumerator
);
750 fprintf(out
, " subject: \"%Y\"\n", cert
->get_subject(cert
));
751 fprintf(out
, " issuer: \"%Y\"\n", cert
->get_issuer(cert
));
752 serial
= x509
->get_serial(x509
);
753 fprintf(out
, " serial: %#B\n", &serial
);
756 cert
->get_validity(cert
, &now
, ¬Before
, ¬After
);
757 fprintf(out
, " validity: not before %T, ", ¬Before
, utc
);
760 fprintf(out
, "not valid yet (valid in %V)\n", &now
, ¬Before
);
764 fprintf(out
, "ok\n");
766 fprintf(out
, " not after %T, ", ¬After
, utc
);
769 fprintf(out
, "expired (%V ago)\n", &now
, ¬After
);
774 if (now
> notAfter
- CERT_WARNING_INTERVAL
* 60 * 60 * 24)
776 fprintf(out
, " (expires in %V)", &now
, ¬After
);
781 public = cert
->get_public_key(cert
);
784 list_public_key(public, out
);
785 public->destroy(public);
788 /* list optional authorityKeyIdentifier */
789 authkey
= x509
->get_authKeyIdentifier(x509
);
792 fprintf(out
, " authkey: %#B\n", &authkey
);
795 /* list optional pathLenConstraint */
796 pathlen
= x509
->get_pathLenConstraint(x509
);
797 if (pathlen
!= X509_NO_PATH_LEN_CONSTRAINT
)
799 fprintf(out
, " pathlen: %d\n", pathlen
);
802 /* list optional ipAddrBlocks */
803 if (x509
->get_flags(x509
) & X509_IP_ADDR_BLOCKS
)
805 traffic_selector_t
*ipAddrBlock
;
806 bool first_ipAddrBlock
= TRUE
;
808 fprintf(out
, " addresses: ");
809 enumerator
= x509
->create_ipAddrBlock_enumerator(x509
);
810 while (enumerator
->enumerate(enumerator
, &ipAddrBlock
))
812 if (first_ipAddrBlock
)
814 first_ipAddrBlock
= FALSE
;
820 fprintf(out
, "%R", ipAddrBlock
);
822 enumerator
->destroy(enumerator
);
827 enumerator
->destroy(enumerator
);
831 * list all X.509 attribute certificates
833 static void stroke_list_acerts(linked_list_t
*list
, bool utc
, FILE *out
)
836 time_t thisUpdate
, nextUpdate
, now
= time(NULL
);
837 enumerator_t
*enumerator
= list
->create_enumerator(list
);
840 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
842 ac_t
*ac
= (ac_t
*)cert
;
843 identification_t
*id
;
844 ietf_attributes_t
*groups
;
850 fprintf(out
, "List of X.509 Attribute Certificates:\n");
855 id
= cert
->get_subject(cert
);
858 fprintf(out
, " holder: \"%Y\"\n", id
);
860 id
= ac
->get_holderIssuer(ac
);
863 fprintf(out
, " hissuer: \"%Y\"\n", id
);
865 chunk
= ac
->get_holderSerial(ac
);
868 fprintf(out
, " hserial: %#B\n", &chunk
);
870 groups
= ac
->get_groups(ac
);
873 fprintf(out
, " groups: %s\n", groups
->get_string(groups
));
874 groups
->destroy(groups
);
876 fprintf(out
, " issuer: \"%Y\"\n", cert
->get_issuer(cert
));
877 chunk
= ac
->get_serial(ac
);
878 fprintf(out
, " serial: %#B\n", &chunk
);
881 cert
->get_validity(cert
, &now
, &thisUpdate
, &nextUpdate
);
882 fprintf(out
, " updates: this %T\n", &thisUpdate
, utc
);
883 fprintf(out
, " next %T, ", &nextUpdate
, utc
);
884 if (now
> nextUpdate
)
886 fprintf(out
, "expired (%V ago)\n", &now
, &nextUpdate
);
891 if (now
> nextUpdate
- AC_WARNING_INTERVAL
* 60 * 60 * 24)
893 fprintf(out
, " (expires in %V)", &now
, &nextUpdate
);
898 /* list optional authorityKeyIdentifier */
899 chunk
= ac
->get_authKeyIdentifier(ac
);
902 fprintf(out
, " authkey: %#B\n", &chunk
);
905 enumerator
->destroy(enumerator
);
909 * list all X.509 CRLs
911 static void stroke_list_crls(linked_list_t
*list
, bool utc
, FILE *out
)
914 time_t thisUpdate
, nextUpdate
, now
= time(NULL
);
915 enumerator_t
*enumerator
= list
->create_enumerator(list
);
918 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
920 crl_t
*crl
= (crl_t
*)cert
;
926 fprintf(out
, "List of X.509 CRLs:\n");
931 fprintf(out
, " issuer: \"%Y\"\n", cert
->get_issuer(cert
));
933 /* list optional crlNumber */
934 chunk
= crl
->get_serial(crl
);
937 fprintf(out
, " serial: %#B\n", &chunk
);
940 /* count the number of revoked certificates */
943 enumerator_t
*enumerator
= crl
->create_enumerator(crl
);
945 while (enumerator
->enumerate(enumerator
, NULL
, NULL
, NULL
))
949 fprintf(out
, " revoked: %d certificate%s\n", count
,
950 (count
== 1)?
"" : "s");
951 enumerator
->destroy(enumerator
);
955 cert
->get_validity(cert
, &now
, &thisUpdate
, &nextUpdate
);
956 fprintf(out
, " updates: this %T\n", &thisUpdate
, utc
);
957 fprintf(out
, " next %T, ", &nextUpdate
, utc
);
958 if (now
> nextUpdate
)
960 fprintf(out
, "expired (%V ago)\n", &now
, &nextUpdate
);
965 if (now
> nextUpdate
- CRL_WARNING_INTERVAL
* 60 * 60 * 24)
967 fprintf(out
, " (expires in %V)", &now
, &nextUpdate
);
972 /* list optional authorityKeyIdentifier */
973 chunk
= crl
->get_authKeyIdentifier(crl
);
976 fprintf(out
, " authkey: %#B\n", &chunk
);
979 enumerator
->destroy(enumerator
);
983 * list all OCSP responses
985 static void stroke_list_ocsp(linked_list_t
* list
, bool utc
, FILE *out
)
988 enumerator_t
*enumerator
= list
->create_enumerator(list
);
991 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
996 fprintf(out
, "List of OCSP responses:\n");
1001 fprintf(out
, " signer: \"%Y\"\n", cert
->get_issuer(cert
));
1003 enumerator
->destroy(enumerator
);
1007 * List of registered cryptographical algorithms
1009 static void list_algs(FILE *out
)
1011 enumerator_t
*enumerator
;
1012 encryption_algorithm_t encryption
;
1013 integrity_algorithm_t integrity
;
1014 hash_algorithm_t hash
;
1015 pseudo_random_function_t prf
;
1016 diffie_hellman_group_t group
;
1019 fprintf(out
, "List of registered IKEv2 Algorithms:\n");
1020 fprintf(out
, "\n encryption: ");
1021 enumerator
= lib
->crypto
->create_crypter_enumerator(lib
->crypto
);
1022 while (enumerator
->enumerate(enumerator
, &encryption
))
1024 fprintf(out
, "%N ", encryption_algorithm_names
, encryption
);
1026 enumerator
->destroy(enumerator
);
1027 fprintf(out
, "\n integrity: ");
1028 enumerator
= lib
->crypto
->create_signer_enumerator(lib
->crypto
);
1029 while (enumerator
->enumerate(enumerator
, &integrity
))
1031 fprintf(out
, "%N ", integrity_algorithm_names
, integrity
);
1033 enumerator
->destroy(enumerator
);
1034 fprintf(out
, "\n hasher: ");
1035 enumerator
= lib
->crypto
->create_hasher_enumerator(lib
->crypto
);
1036 while (enumerator
->enumerate(enumerator
, &hash
))
1038 fprintf(out
, "%N ", hash_algorithm_names
, hash
);
1040 enumerator
->destroy(enumerator
);
1041 fprintf(out
, "\n prf: ");
1042 enumerator
= lib
->crypto
->create_prf_enumerator(lib
->crypto
);
1043 while (enumerator
->enumerate(enumerator
, &prf
))
1045 fprintf(out
, "%N ", pseudo_random_function_names
, prf
);
1047 enumerator
->destroy(enumerator
);
1048 fprintf(out
, "\n dh-group: ");
1049 enumerator
= lib
->crypto
->create_dh_enumerator(lib
->crypto
);
1050 while (enumerator
->enumerate(enumerator
, &group
))
1052 fprintf(out
, "%N ", diffie_hellman_group_names
, group
);
1054 enumerator
->destroy(enumerator
);
1059 * Implementation of stroke_list_t.list.
1061 static void list(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
)
1063 linked_list_t
*cert_list
= NULL
;
1065 if (msg
->list
.flags
& LIST_PUBKEYS
)
1067 linked_list_t
*pubkey_list
= create_unique_cert_list(CERT_TRUSTED_PUBKEY
);
1069 stroke_list_pubkeys(pubkey_list
, msg
->list
.utc
, out
);
1070 pubkey_list
->destroy_offset(pubkey_list
, offsetof(certificate_t
, destroy
));
1072 if (msg
->list
.flags
& LIST_CERTS
)
1074 linked_list_t
*pgp_list
= create_unique_cert_list(CERT_GPG
);
1076 stroke_list_pgp(pgp_list
, msg
->list
.utc
, out
);
1077 pgp_list
->destroy_offset(pgp_list
, offsetof(certificate_t
, destroy
));
1079 if (msg
->list
.flags
& (LIST_CERTS
| LIST_CACERTS
| LIST_OCSPCERTS
| LIST_AACERTS
))
1081 cert_list
= create_unique_cert_list(CERT_X509
);
1083 if (msg
->list
.flags
& LIST_CERTS
)
1085 stroke_list_certs(cert_list
, "X.509 End Entity Certificates",
1086 X509_NONE
, msg
->list
.utc
, out
);
1088 if (msg
->list
.flags
& LIST_CACERTS
)
1090 stroke_list_certs(cert_list
, "X.509 CA Certificates",
1091 X509_CA
, msg
->list
.utc
, out
);
1093 if (msg
->list
.flags
& LIST_OCSPCERTS
)
1095 stroke_list_certs(cert_list
, "X.509 OCSP Signer Certificates",
1096 X509_OCSP_SIGNER
, msg
->list
.utc
, out
);
1098 if (msg
->list
.flags
& LIST_AACERTS
)
1100 stroke_list_certs(cert_list
, "X.509 AA Certificates",
1101 X509_AA
, msg
->list
.utc
, out
);
1103 DESTROY_OFFSET_IF(cert_list
, offsetof(certificate_t
, destroy
));
1105 if (msg
->list
.flags
& LIST_ACERTS
)
1107 linked_list_t
*ac_list
= create_unique_cert_list(CERT_X509_AC
);
1109 stroke_list_acerts(ac_list
, msg
->list
.utc
, out
);
1110 ac_list
->destroy_offset(ac_list
, offsetof(certificate_t
, destroy
));
1112 if (msg
->list
.flags
& LIST_CRLS
)
1114 linked_list_t
*crl_list
= create_unique_cert_list(CERT_X509_CRL
);
1116 stroke_list_crls(crl_list
, msg
->list
.utc
, out
);
1117 crl_list
->destroy_offset(crl_list
, offsetof(certificate_t
, destroy
));
1119 if (msg
->list
.flags
& LIST_OCSP
)
1121 linked_list_t
*ocsp_list
= create_unique_cert_list(CERT_X509_OCSP_RESPONSE
);
1123 stroke_list_ocsp(ocsp_list
, msg
->list
.utc
, out
);
1125 ocsp_list
->destroy_offset(ocsp_list
, offsetof(certificate_t
, destroy
));
1127 if (msg
->list
.flags
& LIST_ALGS
)
1134 * Print leases of a single pool
1136 static void pool_leases(private_stroke_list_t
*this, FILE *out
, char *pool
,
1137 host_t
*address
, u_int size
, u_int online
, u_int offline
)
1139 enumerator_t
*enumerator
;
1140 identification_t
*id
;
1145 fprintf(out
, "Leases in pool '%s', usage: %lu/%lu, %lu online\n",
1146 pool
, online
+ offline
, size
, online
);
1147 enumerator
= this->attribute
->create_lease_enumerator(this->attribute
, pool
);
1148 while (enumerator
&& enumerator
->enumerate(enumerator
, &id
, &lease
, &on
))
1150 if (!address
|| address
->ip_equals(address
, lease
))
1152 fprintf(out
, " %15H %s '%Y'\n",
1153 lease
, on ?
"online" : "offline", id
);
1157 enumerator
->destroy(enumerator
);
1160 fprintf(out
, " no matching leases found\n");
1165 * Implementation of stroke_list_t.leases
1167 static void leases(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
)
1169 enumerator_t
*enumerator
;
1170 u_int size
, offline
, online
;
1171 host_t
*address
= NULL
;
1175 if (msg
->leases
.address
)
1177 address
= host_create_from_string(msg
->leases
.address
, 0);
1180 enumerator
= this->attribute
->create_pool_enumerator(this->attribute
);
1181 while (enumerator
->enumerate(enumerator
, &pool
, &size
, &online
, &offline
))
1183 if (!msg
->leases
.pool
|| streq(msg
->leases
.pool
, pool
))
1185 pool_leases(this, out
, pool
, address
, size
, online
, offline
);
1189 enumerator
->destroy(enumerator
);
1192 if (msg
->leases
.pool
)
1194 fprintf(out
, "pool '%s' not found\n", msg
->leases
.pool
);
1198 fprintf(out
, "no pools found\n");
1201 DESTROY_IF(address
);
1205 * Implementation of stroke_list_t.destroy
1207 static void destroy(private_stroke_list_t
*this)
1215 stroke_list_t
*stroke_list_create(stroke_attribute_t
*attribute
)
1217 private_stroke_list_t
*this = malloc_thing(private_stroke_list_t
);
1219 this->public.list
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
))list
;
1220 this->public.status
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
,bool))status
;
1221 this->public.leases
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
))leases
;
1222 this->public.destroy
= (void(*)(stroke_list_t
*))destroy
;
1224 this->uptime
= time_monotonic(NULL
);
1225 this->attribute
= attribute
;
1227 return &this->public;