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"
22 #endif /* HAVE_MALLINFO */
25 #include <utils/linked_list.h>
26 #include <credentials/certificates/x509.h>
27 #include <credentials/certificates/ac.h>
28 #include <credentials/certificates/crl.h>
29 #include <credentials/certificates/pgp_certificate.h>
30 #include <credentials/ietf_attributes/ietf_attributes.h>
31 #include <config/peer_cfg.h>
33 /* warning intervals for list functions */
34 #define CERT_WARNING_INTERVAL 30 /* days */
35 #define CRL_WARNING_INTERVAL 7 /* days */
36 #define AC_WARNING_INTERVAL 1 /* day */
38 typedef struct private_stroke_list_t private_stroke_list_t
;
41 * private data of stroke_list
43 struct private_stroke_list_t
{
51 * timestamp of daemon start
56 * strokes attribute provider
58 stroke_attribute_t
*attribute
;
62 * Log tasks of a specific queue to out
64 static void log_task_q(FILE *out
, ike_sa_t
*ike_sa
, task_queue_t q
, char *name
)
66 enumerator_t
*enumerator
;
70 enumerator
= ike_sa
->create_task_enumerator(ike_sa
, q
);
71 while (enumerator
->enumerate(enumerator
, &task
))
75 fprintf(out
, "%12s[%d]: Tasks %s: ", ike_sa
->get_name(ike_sa
),
76 ike_sa
->get_unique_id(ike_sa
), name
);
79 fprintf(out
, "%N ", task_type_names
, task
->get_type(task
));
81 enumerator
->destroy(enumerator
);
89 * log an IKE_SA to out
91 static void log_ike_sa(FILE *out
, ike_sa_t
*ike_sa
, bool all
)
93 ike_sa_id_t
*id
= ike_sa
->get_id(ike_sa
);
94 time_t now
= time_monotonic(NULL
);
96 fprintf(out
, "%12s[%d]: %N",
97 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
98 ike_sa_state_names
, ike_sa
->get_state(ike_sa
));
100 if (ike_sa
->get_state(ike_sa
) == IKE_ESTABLISHED
)
104 established
= ike_sa
->get_statistic(ike_sa
, STAT_ESTABLISHED
);
105 fprintf(out
, " %V ago", &now
, &established
);
108 fprintf(out
, ", %H[%Y]...%H[%Y]\n",
109 ike_sa
->get_my_host(ike_sa
), ike_sa
->get_my_id(ike_sa
),
110 ike_sa
->get_other_host(ike_sa
), ike_sa
->get_other_id(ike_sa
));
114 proposal_t
*ike_proposal
;
116 ike_proposal
= ike_sa
->get_proposal(ike_sa
);
118 fprintf(out
, "%12s[%d]: IKE SPIs: %.16llx_i%s %.16llx_r%s",
119 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
120 id
->get_initiator_spi(id
), id
->is_initiator(id
) ?
"*" : "",
121 id
->get_responder_spi(id
), id
->is_initiator(id
) ?
"" : "*");
124 if (ike_sa
->get_state(ike_sa
) == IKE_ESTABLISHED
)
126 time_t rekey
, reauth
;
127 peer_cfg_t
*peer_cfg
;
129 rekey
= ike_sa
->get_statistic(ike_sa
, STAT_REKEY
);
130 reauth
= ike_sa
->get_statistic(ike_sa
, STAT_REAUTH
);
131 peer_cfg
= ike_sa
->get_peer_cfg(ike_sa
);
135 fprintf(out
, ", rekeying in %V", &rekey
, &now
);
140 enumerator_t
*enumerator
;
144 enumerator
= peer_cfg
->create_auth_cfg_enumerator(peer_cfg
, TRUE
);
145 while (enumerator
->enumerate(enumerator
, &auth
))
152 fprintf(out
, "%N", auth_class_names
,
153 auth
->get(auth
, AUTH_RULE_AUTH_CLASS
));
155 enumerator
->destroy(enumerator
);
156 fprintf(out
, " reauthentication in %V", &reauth
, &now
);
158 if (!rekey
&& !reauth
)
160 fprintf(out
, ", rekeying disabled");
169 snprintf(buf
, BUF_LEN
, "%P", ike_proposal
);
170 fprintf(out
, "%12s[%d]: IKE proposal: %s\n",
171 ike_sa
->get_name(ike_sa
), ike_sa
->get_unique_id(ike_sa
),
175 log_task_q(out
, ike_sa
, TASK_QUEUE_QUEUED
, "queued");
176 log_task_q(out
, ike_sa
, TASK_QUEUE_ACTIVE
, "active");
177 log_task_q(out
, ike_sa
, TASK_QUEUE_PASSIVE
, "passive");
182 * log an CHILD_SA to out
184 static void log_child_sa(FILE *out
, child_sa_t
*child_sa
, bool all
)
186 time_t use_in
, use_out
, rekey
, now
;
187 u_int64_t bytes_in
, bytes_out
;
188 proposal_t
*proposal
;
189 child_cfg_t
*config
= child_sa
->get_config(child_sa
);
192 fprintf(out
, "%12s{%d}: %N, %N%s",
193 child_sa
->get_name(child_sa
), child_sa
->get_reqid(child_sa
),
194 child_sa_state_names
, child_sa
->get_state(child_sa
),
195 ipsec_mode_names
, child_sa
->get_mode(child_sa
),
196 config
->use_proxy_mode(config
) ?
"_PROXY" : "");
198 if (child_sa
->get_state(child_sa
) == CHILD_INSTALLED
)
200 fprintf(out
, ", %N%s SPIs: %.8x_i %.8x_o",
201 protocol_id_names
, child_sa
->get_protocol(child_sa
),
202 child_sa
->has_encap(child_sa
) ?
" in UDP" : "",
203 ntohl(child_sa
->get_spi(child_sa
, TRUE
)),
204 ntohl(child_sa
->get_spi(child_sa
, FALSE
)));
206 if (child_sa
->get_ipcomp(child_sa
) != IPCOMP_NONE
)
208 fprintf(out
, ", IPCOMP CPIs: %.4x_i %.4x_o",
209 ntohs(child_sa
->get_cpi(child_sa
, TRUE
)),
210 ntohs(child_sa
->get_cpi(child_sa
, FALSE
)));
215 fprintf(out
, "\n%12s{%d}: ", child_sa
->get_name(child_sa
),
216 child_sa
->get_reqid(child_sa
));
218 proposal
= child_sa
->get_proposal(child_sa
);
221 u_int16_t encr_alg
= ENCR_UNDEFINED
, int_alg
= AUTH_UNDEFINED
;
222 u_int16_t encr_size
= 0, int_size
= 0;
224 proposal
->get_algorithm(proposal
, ENCRYPTION_ALGORITHM
,
225 &encr_alg
, &encr_size
);
226 proposal
->get_algorithm(proposal
, INTEGRITY_ALGORITHM
,
227 &int_alg
, &int_size
);
229 if (encr_alg
!= ENCR_UNDEFINED
)
231 fprintf(out
, "%N", encryption_algorithm_names
, encr_alg
);
234 fprintf(out
, "_%u", encr_size
);
237 if (int_alg
!= AUTH_UNDEFINED
)
239 fprintf(out
, "/%N", integrity_algorithm_names
, int_alg
);
242 fprintf(out
, "_%u", int_size
);
247 now
= time_monotonic(NULL
);
248 child_sa
->get_usestats(child_sa
, TRUE
, &use_in
, &bytes_in
);
249 fprintf(out
, ", %llu bytes_i", bytes_in
);
252 fprintf(out
, " (%ds ago)", now
- use_in
);
255 child_sa
->get_usestats(child_sa
, FALSE
, &use_out
, &bytes_out
);
256 fprintf(out
, ", %llu bytes_o", bytes_out
);
259 fprintf(out
, " (%ds ago)", now
- use_out
);
261 fprintf(out
, ", rekeying ");
263 rekey
= child_sa
->get_lifetime(child_sa
, FALSE
);
268 fprintf(out
, "active");
272 fprintf(out
, "in %V", &now
, &rekey
);
277 fprintf(out
, "disabled");
283 fprintf(out
, "\n%12s{%d}: %#R=== %#R\n",
284 child_sa
->get_name(child_sa
), child_sa
->get_reqid(child_sa
),
285 child_sa
->get_traffic_selectors(child_sa
, TRUE
),
286 child_sa
->get_traffic_selectors(child_sa
, FALSE
));
290 * Log a configs local or remote authentication config to out
292 static void log_auth_cfgs(FILE *out
, peer_cfg_t
*peer_cfg
, bool local
)
294 enumerator_t
*enumerator
, *rules
;
297 auth_class_t auth_class
;
298 identification_t
*id
;
300 cert_validation_t valid
;
303 name
= peer_cfg
->get_name(peer_cfg
);
305 enumerator
= peer_cfg
->create_auth_cfg_enumerator(peer_cfg
, local
);
306 while (enumerator
->enumerate(enumerator
, &auth
))
308 fprintf(out
, "%12s: %s [%Y] uses ", name
, local ?
"local: " : "remote:",
309 auth
->get(auth
, AUTH_RULE_IDENTITY
));
311 auth_class
= (uintptr_t)auth
->get(auth
, AUTH_RULE_AUTH_CLASS
);
312 if (auth_class
!= AUTH_CLASS_EAP
)
314 fprintf(out
, "%N authentication\n", auth_class_names
, auth_class
);
318 if ((uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_TYPE
) == EAP_NAK
)
320 fprintf(out
, "EAP authentication");
324 if ((uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_VENDOR
))
326 fprintf(out
, "EAP_%d-%d authentication",
327 (uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_TYPE
),
328 (uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_VENDOR
));
332 fprintf(out
, "%N authentication", eap_type_names
,
333 (uintptr_t)auth
->get(auth
, AUTH_RULE_EAP_TYPE
));
336 id
= auth
->get(auth
, AUTH_RULE_EAP_IDENTITY
);
339 fprintf(out
, " with EAP identity '%Y'", id
);
344 cert
= auth
->get(auth
, AUTH_RULE_CA_CERT
);
347 fprintf(out
, "%12s: ca: \"%Y\"\n", name
, cert
->get_subject(cert
));
350 cert
= auth
->get(auth
, AUTH_RULE_IM_CERT
);
353 fprintf(out
, "%12s: im-ca: \"%Y\"\n", name
, cert
->get_subject(cert
));
356 cert
= auth
->get(auth
, AUTH_RULE_SUBJECT_CERT
);
359 fprintf(out
, "%12s: cert: \"%Y\"\n", name
,
360 cert
->get_subject(cert
));
363 valid
= (uintptr_t)auth
->get(auth
, AUTH_RULE_OCSP_VALIDATION
);
364 if (valid
!= VALIDATION_FAILED
)
366 fprintf(out
, "%12s: ocsp: status must be GOOD%s\n", name
,
367 (valid
== VALIDATION_SKIPPED
) ?
" or SKIPPED" : "");
370 valid
= (uintptr_t)auth
->get(auth
, AUTH_RULE_CRL_VALIDATION
);
371 if (valid
!= VALIDATION_FAILED
)
373 fprintf(out
, "%12s: crl: status must be GOOD%s\n", name
,
374 (valid
== VALIDATION_SKIPPED
) ?
" or SKIPPED" : "");
377 rules
= auth
->create_enumerator(auth
);
378 while (rules
->enumerate(rules
, &rule
, &id
))
380 if (rule
== AUTH_RULE_GROUP
)
382 fprintf(out
, "%12s: group: %Y\n", name
, id
);
385 rules
->destroy(rules
);
387 enumerator
->destroy(enumerator
);
391 * Implementation of stroke_list_t.status.
393 static void status(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
, bool all
)
395 enumerator_t
*enumerator
, *children
;
397 child_cfg_t
*child_cfg
;
398 child_sa_t
*child_sa
;
400 bool first
, found
= FALSE
;
401 char *name
= msg
->status
.name
;
405 peer_cfg_t
*peer_cfg
;
410 u_int size
, online
, offline
;
411 now
= time_monotonic(NULL
);
412 since
= time(NULL
) - (now
- this->uptime
);
414 fprintf(out
, "Status of IKEv2 charon daemon (strongSwan "VERSION
"):\n");
415 fprintf(out
, " uptime: %V, since %T\n", &now
, &this->uptime
, &since
, FALSE
);
418 struct mallinfo mi
= mallinfo();
420 fprintf(out
, " malloc: sbrk %d, mmap %d, used %d, free %d\n",
421 mi
.arena
, mi
.hblkhd
, mi
.uordblks
, mi
.fordblks
);
423 #endif /* HAVE_MALLINFO */
424 fprintf(out
, " worker threads: %d idle of %d,",
425 charon
->processor
->get_idle_threads(charon
->processor
),
426 charon
->processor
->get_total_threads(charon
->processor
));
427 fprintf(out
, " job queue load: %d,",
428 charon
->processor
->get_job_load(charon
->processor
));
429 fprintf(out
, " scheduled events: %d\n",
430 charon
->scheduler
->get_job_load(charon
->scheduler
));
431 fprintf(out
, " loaded plugins: ");
432 enumerator
= lib
->plugins
->create_plugin_enumerator(lib
->plugins
);
433 while (enumerator
->enumerate(enumerator
, &plugin
))
435 fprintf(out
, "%s ", plugin
);
437 enumerator
->destroy(enumerator
);
441 enumerator
= this->attribute
->create_pool_enumerator(this->attribute
);
442 while (enumerator
->enumerate(enumerator
, &pool
, &size
, &online
, &offline
))
444 if (name
&& !streq(name
, pool
))
451 fprintf(out
, "Virtual IP pools (size/online/offline):\n");
453 fprintf(out
, " %s: %u/%u/%u\n", pool
, size
, online
, offline
);
455 enumerator
->destroy(enumerator
);
457 enumerator
= charon
->kernel_interface
->create_address_enumerator(
458 charon
->kernel_interface
, FALSE
, FALSE
);
459 fprintf(out
, "Listening IP addresses:\n");
460 while (enumerator
->enumerate(enumerator
, (void**)&host
))
462 fprintf(out
, " %H\n", host
);
464 enumerator
->destroy(enumerator
);
466 fprintf(out
, "Connections:\n");
467 enumerator
= charon
->backends
->create_peer_cfg_enumerator(
468 charon
->backends
, NULL
, NULL
, NULL
, NULL
);
469 while (enumerator
->enumerate(enumerator
, &peer_cfg
))
471 if (peer_cfg
->get_ike_version(peer_cfg
) != 2 ||
472 (name
&& !streq(name
, peer_cfg
->get_name(peer_cfg
))))
477 ike_cfg
= peer_cfg
->get_ike_cfg(peer_cfg
);
478 fprintf(out
, "%12s: %s...%s", peer_cfg
->get_name(peer_cfg
),
479 ike_cfg
->get_my_addr(ike_cfg
), ike_cfg
->get_other_addr(ike_cfg
));
481 dpd
= peer_cfg
->get_dpd(peer_cfg
);
484 fprintf(out
, ", dpddelay=%us", dpd
);
488 log_auth_cfgs(out
, peer_cfg
, TRUE
);
489 log_auth_cfgs(out
, peer_cfg
, FALSE
);
491 children
= peer_cfg
->create_child_cfg_enumerator(peer_cfg
);
492 while (children
->enumerate(children
, &child_cfg
))
494 linked_list_t
*my_ts
, *other_ts
;
496 my_ts
= child_cfg
->get_traffic_selectors(child_cfg
, TRUE
, NULL
, NULL
);
497 other_ts
= child_cfg
->get_traffic_selectors(child_cfg
, FALSE
, NULL
, NULL
);
498 fprintf(out
, "%12s: child: %#R=== %#R", child_cfg
->get_name(child_cfg
),
500 my_ts
->destroy_offset(my_ts
, offsetof(traffic_selector_t
, destroy
));
501 other_ts
->destroy_offset(other_ts
, offsetof(traffic_selector_t
, destroy
));
505 fprintf(out
, ", dpdaction=%N", action_names
,
506 child_cfg
->get_dpd_action(child_cfg
));
510 children
->destroy(children
);
512 enumerator
->destroy(enumerator
);
516 enumerator
= charon
->traps
->create_enumerator(charon
->traps
);
517 while (enumerator
->enumerate(enumerator
, NULL
, &child_sa
))
521 fprintf(out
, "Routed Connections:\n");
524 log_child_sa(out
, child_sa
, all
);
526 enumerator
->destroy(enumerator
);
528 fprintf(out
, "Security Associations:\n");
529 enumerator
= charon
->controller
->create_ike_sa_enumerator(charon
->controller
);
530 while (enumerator
->enumerate(enumerator
, &ike_sa
))
532 bool ike_printed
= FALSE
;
533 iterator_t
*children
= ike_sa
->create_child_sa_iterator(ike_sa
);
535 if (name
== NULL
|| streq(name
, ike_sa
->get_name(ike_sa
)))
537 log_ike_sa(out
, ike_sa
, all
);
542 while (children
->iterate(children
, (void**)&child_sa
))
544 if (name
== NULL
|| streq(name
, child_sa
->get_name(child_sa
)))
548 log_ike_sa(out
, ike_sa
, all
);
552 log_child_sa(out
, child_sa
, all
);
555 children
->destroy(children
);
557 enumerator
->destroy(enumerator
);
563 fprintf(out
, " no match\n");
567 fprintf(out
, " none\n");
573 * create a unique certificate list without duplicates
574 * certicates having the same issuer are grouped together.
576 static linked_list_t
* create_unique_cert_list(certificate_type_t type
)
578 linked_list_t
*list
= linked_list_create();
579 enumerator_t
*enumerator
= charon
->credentials
->create_cert_enumerator(
580 charon
->credentials
, type
, KEY_ANY
,
584 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
586 iterator_t
*iterator
= list
->create_iterator(list
, TRUE
);
587 identification_t
*issuer
= cert
->get_issuer(cert
);
588 bool previous_same
, same
= FALSE
, last
= TRUE
;
589 certificate_t
*list_cert
;
591 while (iterator
->iterate(iterator
, (void**)&list_cert
))
593 /* exit if we have a duplicate? */
594 if (list_cert
->equals(list_cert
, cert
))
599 /* group certificates with same issuer */
600 previous_same
= same
;
601 same
= list_cert
->has_issuer(list_cert
, issuer
);
602 if (previous_same
&& !same
)
604 iterator
->insert_before(iterator
, (void *)cert
->get_ref(cert
));
609 iterator
->destroy(iterator
);
613 list
->insert_last(list
, (void *)cert
->get_ref(cert
));
616 enumerator
->destroy(enumerator
);
621 * Print a single public key.
623 static void list_public_key(public_key_t
*public, FILE *out
)
625 private_key_t
*private = NULL
;
627 identification_t
*id
;
630 if (public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1
, &keyid
))
632 id
= identification_create_from_encoding(ID_KEY_ID
, keyid
);
633 auth
= auth_cfg_create();
634 private = charon
->credentials
->get_private(charon
->credentials
,
635 public->get_type(public), id
, auth
);
640 fprintf(out
, " pubkey: %N %d bits%s\n",
641 key_type_names
, public->get_type(public),
642 public->get_keysize(public) * 8,
643 private ?
", has private key" : "");
644 if (public->get_fingerprint(public, KEY_ID_PUBKEY_INFO_SHA1
, &keyid
))
646 fprintf(out
, " keyid: %#B\n", &keyid
);
648 if (public->get_fingerprint(public, KEY_ID_PUBKEY_SHA1
, &keyid
))
650 fprintf(out
, " subjkey: %#B\n", &keyid
);
656 * list all raw public keys
658 static void stroke_list_pubkeys(linked_list_t
*list
, bool utc
, FILE *out
)
662 enumerator_t
*enumerator
= list
->create_enumerator(list
);
665 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
667 public_key_t
*public = cert
->get_public_key(cert
);
674 fprintf(out
, "List of Raw Public Keys:\n");
679 list_public_key(public, out
);
680 public->destroy(public);
683 enumerator
->destroy(enumerator
);
687 * list OpenPGP certificates
689 static void stroke_list_pgp(linked_list_t
*list
,bool utc
, FILE *out
)
692 time_t now
= time(NULL
);
693 enumerator_t
*enumerator
= list
->create_enumerator(list
);
696 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
698 time_t created
, until
;
699 public_key_t
*public;
700 pgp_certificate_t
*pgp_cert
= (pgp_certificate_t
*)cert
;
701 chunk_t fingerprint
= pgp_cert
->get_fingerprint(pgp_cert
);
707 fprintf(out
, "List of PGP End Entity Certificates:\n");
711 fprintf(out
, " userid: '%Y'\n", cert
->get_subject(cert
));
713 fprintf(out
, " digest: %#B\n", &fingerprint
);
716 cert
->get_validity(cert
, &now
, &created
, &until
);
717 fprintf(out
, " created: %T\n", &created
, utc
);
718 fprintf(out
, " until: %T%s\n", &until
, utc
,
719 (until
== TIME_32_BIT_SIGNED_MAX
) ?
" (expires never)":"");
721 public = cert
->get_public_key(cert
);
724 list_public_key(public, out
);
725 public->destroy(public);
728 enumerator
->destroy(enumerator
);
732 * list all X.509 certificates matching the flags
734 static void stroke_list_certs(linked_list_t
*list
, char *label
,
735 x509_flag_t flags
, bool utc
, FILE *out
)
738 time_t now
= time(NULL
);
739 enumerator_t
*enumerator
;
741 x509_flag_t flag_mask
;
743 /* mask all auxiliary flags */
744 flag_mask
= ~(X509_SERVER_AUTH
| X509_CLIENT_AUTH
|
745 X509_SELF_SIGNED
| X509_IP_ADDR_BLOCKS
);
747 enumerator
= list
->create_enumerator(list
);
748 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
750 x509_t
*x509
= (x509_t
*)cert
;
751 x509_flag_t x509_flags
= x509
->get_flags(x509
) & flag_mask
;
753 /* list only if flag is set or flag == 0 */
754 if ((x509_flags
& flags
) || (x509_flags
== flags
))
756 enumerator_t
*enumerator
;
757 identification_t
*altName
;
758 bool first_altName
= TRUE
;
760 chunk_t serial
, authkey
;
761 time_t notBefore
, notAfter
;
762 public_key_t
*public;
767 fprintf(out
, "List of %s:\n", label
);
772 /* list subjectAltNames */
773 enumerator
= x509
->create_subjectAltName_enumerator(x509
);
774 while (enumerator
->enumerate(enumerator
, (void**)&altName
))
778 fprintf(out
, " altNames: ");
779 first_altName
= FALSE
;
785 fprintf(out
, "%Y", altName
);
791 enumerator
->destroy(enumerator
);
793 fprintf(out
, " subject: \"%Y\"\n", cert
->get_subject(cert
));
794 fprintf(out
, " issuer: \"%Y\"\n", cert
->get_issuer(cert
));
795 serial
= x509
->get_serial(x509
);
796 fprintf(out
, " serial: %#B\n", &serial
);
799 cert
->get_validity(cert
, &now
, ¬Before
, ¬After
);
800 fprintf(out
, " validity: not before %T, ", ¬Before
, utc
);
803 fprintf(out
, "not valid yet (valid in %V)\n", &now
, ¬Before
);
807 fprintf(out
, "ok\n");
809 fprintf(out
, " not after %T, ", ¬After
, utc
);
812 fprintf(out
, "expired (%V ago)\n", &now
, ¬After
);
817 if (now
> notAfter
- CERT_WARNING_INTERVAL
* 60 * 60 * 24)
819 fprintf(out
, " (expires in %V)", &now
, ¬After
);
824 public = cert
->get_public_key(cert
);
827 list_public_key(public, out
);
828 public->destroy(public);
831 /* list optional authorityKeyIdentifier */
832 authkey
= x509
->get_authKeyIdentifier(x509
);
835 fprintf(out
, " authkey: %#B\n", &authkey
);
838 /* list optional pathLenConstraint */
839 pathlen
= x509
->get_pathLenConstraint(x509
);
840 if (pathlen
!= X509_NO_PATH_LEN_CONSTRAINT
)
842 fprintf(out
, " pathlen: %d\n", pathlen
);
845 /* list optional ipAddrBlocks */
846 if (x509
->get_flags(x509
) & X509_IP_ADDR_BLOCKS
)
848 traffic_selector_t
*ipAddrBlock
;
849 bool first_ipAddrBlock
= TRUE
;
851 fprintf(out
, " addresses: ");
852 enumerator
= x509
->create_ipAddrBlock_enumerator(x509
);
853 while (enumerator
->enumerate(enumerator
, &ipAddrBlock
))
855 if (first_ipAddrBlock
)
857 first_ipAddrBlock
= FALSE
;
863 fprintf(out
, "%R", ipAddrBlock
);
865 enumerator
->destroy(enumerator
);
870 enumerator
->destroy(enumerator
);
874 * list all X.509 attribute certificates
876 static void stroke_list_acerts(linked_list_t
*list
, bool utc
, FILE *out
)
879 time_t thisUpdate
, nextUpdate
, now
= time(NULL
);
880 enumerator_t
*enumerator
= list
->create_enumerator(list
);
883 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
885 ac_t
*ac
= (ac_t
*)cert
;
886 identification_t
*id
;
887 ietf_attributes_t
*groups
;
893 fprintf(out
, "List of X.509 Attribute Certificates:\n");
898 id
= cert
->get_subject(cert
);
901 fprintf(out
, " holder: \"%Y\"\n", id
);
903 id
= ac
->get_holderIssuer(ac
);
906 fprintf(out
, " hissuer: \"%Y\"\n", id
);
908 chunk
= ac
->get_holderSerial(ac
);
911 fprintf(out
, " hserial: %#B\n", &chunk
);
913 groups
= ac
->get_groups(ac
);
916 fprintf(out
, " groups: %s\n", groups
->get_string(groups
));
917 groups
->destroy(groups
);
919 fprintf(out
, " issuer: \"%Y\"\n", cert
->get_issuer(cert
));
920 chunk
= ac
->get_serial(ac
);
921 fprintf(out
, " serial: %#B\n", &chunk
);
924 cert
->get_validity(cert
, &now
, &thisUpdate
, &nextUpdate
);
925 fprintf(out
, " updates: this %T\n", &thisUpdate
, utc
);
926 fprintf(out
, " next %T, ", &nextUpdate
, utc
);
927 if (now
> nextUpdate
)
929 fprintf(out
, "expired (%V ago)\n", &now
, &nextUpdate
);
934 if (now
> nextUpdate
- AC_WARNING_INTERVAL
* 60 * 60 * 24)
936 fprintf(out
, " (expires in %V)", &now
, &nextUpdate
);
941 /* list optional authorityKeyIdentifier */
942 chunk
= ac
->get_authKeyIdentifier(ac
);
945 fprintf(out
, " authkey: %#B\n", &chunk
);
948 enumerator
->destroy(enumerator
);
952 * list all X.509 CRLs
954 static void stroke_list_crls(linked_list_t
*list
, bool utc
, FILE *out
)
957 time_t thisUpdate
, nextUpdate
, now
= time(NULL
);
958 enumerator_t
*enumerator
= list
->create_enumerator(list
);
961 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
963 crl_t
*crl
= (crl_t
*)cert
;
969 fprintf(out
, "List of X.509 CRLs:\n");
974 fprintf(out
, " issuer: \"%Y\"\n", cert
->get_issuer(cert
));
976 /* list optional crlNumber */
977 chunk
= crl
->get_serial(crl
);
980 fprintf(out
, " serial: %#B\n", &chunk
);
983 /* count the number of revoked certificates */
986 enumerator_t
*enumerator
= crl
->create_enumerator(crl
);
988 while (enumerator
->enumerate(enumerator
, NULL
, NULL
, NULL
))
992 fprintf(out
, " revoked: %d certificate%s\n", count
,
993 (count
== 1)?
"" : "s");
994 enumerator
->destroy(enumerator
);
998 cert
->get_validity(cert
, &now
, &thisUpdate
, &nextUpdate
);
999 fprintf(out
, " updates: this %T\n", &thisUpdate
, utc
);
1000 fprintf(out
, " next %T, ", &nextUpdate
, utc
);
1001 if (now
> nextUpdate
)
1003 fprintf(out
, "expired (%V ago)\n", &now
, &nextUpdate
);
1008 if (now
> nextUpdate
- CRL_WARNING_INTERVAL
* 60 * 60 * 24)
1010 fprintf(out
, " (expires in %V)", &now
, &nextUpdate
);
1012 fprintf(out
, " \n");
1015 /* list optional authorityKeyIdentifier */
1016 chunk
= crl
->get_authKeyIdentifier(crl
);
1019 fprintf(out
, " authkey: %#B\n", &chunk
);
1022 enumerator
->destroy(enumerator
);
1026 * list all OCSP responses
1028 static void stroke_list_ocsp(linked_list_t
* list
, bool utc
, FILE *out
)
1031 enumerator_t
*enumerator
= list
->create_enumerator(list
);
1032 certificate_t
*cert
;
1034 while (enumerator
->enumerate(enumerator
, (void**)&cert
))
1039 fprintf(out
, "List of OCSP responses:\n");
1044 fprintf(out
, " signer: \"%Y\"\n", cert
->get_issuer(cert
));
1046 enumerator
->destroy(enumerator
);
1050 * List of registered cryptographical algorithms
1052 static void list_algs(FILE *out
)
1054 enumerator_t
*enumerator
;
1055 encryption_algorithm_t encryption
;
1056 integrity_algorithm_t integrity
;
1057 hash_algorithm_t hash
;
1058 pseudo_random_function_t prf
;
1059 diffie_hellman_group_t group
;
1062 fprintf(out
, "List of registered IKEv2 Algorithms:\n");
1063 fprintf(out
, "\n encryption: ");
1064 enumerator
= lib
->crypto
->create_crypter_enumerator(lib
->crypto
);
1065 while (enumerator
->enumerate(enumerator
, &encryption
))
1067 fprintf(out
, "%N ", encryption_algorithm_names
, encryption
);
1069 enumerator
->destroy(enumerator
);
1070 fprintf(out
, "\n integrity: ");
1071 enumerator
= lib
->crypto
->create_signer_enumerator(lib
->crypto
);
1072 while (enumerator
->enumerate(enumerator
, &integrity
))
1074 fprintf(out
, "%N ", integrity_algorithm_names
, integrity
);
1076 enumerator
->destroy(enumerator
);
1077 fprintf(out
, "\n hasher: ");
1078 enumerator
= lib
->crypto
->create_hasher_enumerator(lib
->crypto
);
1079 while (enumerator
->enumerate(enumerator
, &hash
))
1081 fprintf(out
, "%N ", hash_algorithm_names
, hash
);
1083 enumerator
->destroy(enumerator
);
1084 fprintf(out
, "\n prf: ");
1085 enumerator
= lib
->crypto
->create_prf_enumerator(lib
->crypto
);
1086 while (enumerator
->enumerate(enumerator
, &prf
))
1088 fprintf(out
, "%N ", pseudo_random_function_names
, prf
);
1090 enumerator
->destroy(enumerator
);
1091 fprintf(out
, "\n dh-group: ");
1092 enumerator
= lib
->crypto
->create_dh_enumerator(lib
->crypto
);
1093 while (enumerator
->enumerate(enumerator
, &group
))
1095 fprintf(out
, "%N ", diffie_hellman_group_names
, group
);
1097 enumerator
->destroy(enumerator
);
1102 * Implementation of stroke_list_t.list.
1104 static void list(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
)
1106 linked_list_t
*cert_list
= NULL
;
1108 if (msg
->list
.flags
& LIST_PUBKEYS
)
1110 linked_list_t
*pubkey_list
= create_unique_cert_list(CERT_TRUSTED_PUBKEY
);
1112 stroke_list_pubkeys(pubkey_list
, msg
->list
.utc
, out
);
1113 pubkey_list
->destroy_offset(pubkey_list
, offsetof(certificate_t
, destroy
));
1115 if (msg
->list
.flags
& LIST_CERTS
)
1117 linked_list_t
*pgp_list
= create_unique_cert_list(CERT_GPG
);
1119 stroke_list_pgp(pgp_list
, msg
->list
.utc
, out
);
1120 pgp_list
->destroy_offset(pgp_list
, offsetof(certificate_t
, destroy
));
1122 if (msg
->list
.flags
& (LIST_CERTS
| LIST_CACERTS
| LIST_OCSPCERTS
| LIST_AACERTS
))
1124 cert_list
= create_unique_cert_list(CERT_X509
);
1126 if (msg
->list
.flags
& LIST_CERTS
)
1128 stroke_list_certs(cert_list
, "X.509 End Entity Certificates",
1129 X509_NONE
, msg
->list
.utc
, out
);
1131 if (msg
->list
.flags
& LIST_CACERTS
)
1133 stroke_list_certs(cert_list
, "X.509 CA Certificates",
1134 X509_CA
, msg
->list
.utc
, out
);
1136 if (msg
->list
.flags
& LIST_OCSPCERTS
)
1138 stroke_list_certs(cert_list
, "X.509 OCSP Signer Certificates",
1139 X509_OCSP_SIGNER
, msg
->list
.utc
, out
);
1141 if (msg
->list
.flags
& LIST_AACERTS
)
1143 stroke_list_certs(cert_list
, "X.509 AA Certificates",
1144 X509_AA
, msg
->list
.utc
, out
);
1146 DESTROY_OFFSET_IF(cert_list
, offsetof(certificate_t
, destroy
));
1148 if (msg
->list
.flags
& LIST_ACERTS
)
1150 linked_list_t
*ac_list
= create_unique_cert_list(CERT_X509_AC
);
1152 stroke_list_acerts(ac_list
, msg
->list
.utc
, out
);
1153 ac_list
->destroy_offset(ac_list
, offsetof(certificate_t
, destroy
));
1155 if (msg
->list
.flags
& LIST_CRLS
)
1157 linked_list_t
*crl_list
= create_unique_cert_list(CERT_X509_CRL
);
1159 stroke_list_crls(crl_list
, msg
->list
.utc
, out
);
1160 crl_list
->destroy_offset(crl_list
, offsetof(certificate_t
, destroy
));
1162 if (msg
->list
.flags
& LIST_OCSP
)
1164 linked_list_t
*ocsp_list
= create_unique_cert_list(CERT_X509_OCSP_RESPONSE
);
1166 stroke_list_ocsp(ocsp_list
, msg
->list
.utc
, out
);
1168 ocsp_list
->destroy_offset(ocsp_list
, offsetof(certificate_t
, destroy
));
1170 if (msg
->list
.flags
& LIST_ALGS
)
1177 * Print leases of a single pool
1179 static void pool_leases(private_stroke_list_t
*this, FILE *out
, char *pool
,
1180 host_t
*address
, u_int size
, u_int online
, u_int offline
)
1182 enumerator_t
*enumerator
;
1183 identification_t
*id
;
1188 fprintf(out
, "Leases in pool '%s', usage: %lu/%lu, %lu online\n",
1189 pool
, online
+ offline
, size
, online
);
1190 enumerator
= this->attribute
->create_lease_enumerator(this->attribute
, pool
);
1191 while (enumerator
&& enumerator
->enumerate(enumerator
, &id
, &lease
, &on
))
1193 if (!address
|| address
->ip_equals(address
, lease
))
1195 fprintf(out
, " %15H %s '%Y'\n",
1196 lease
, on ?
"online" : "offline", id
);
1200 enumerator
->destroy(enumerator
);
1203 fprintf(out
, " no matching leases found\n");
1208 * Implementation of stroke_list_t.leases
1210 static void leases(private_stroke_list_t
*this, stroke_msg_t
*msg
, FILE *out
)
1212 enumerator_t
*enumerator
;
1213 u_int size
, offline
, online
;
1214 host_t
*address
= NULL
;
1218 if (msg
->leases
.address
)
1220 address
= host_create_from_string(msg
->leases
.address
, 0);
1223 enumerator
= this->attribute
->create_pool_enumerator(this->attribute
);
1224 while (enumerator
->enumerate(enumerator
, &pool
, &size
, &online
, &offline
))
1226 if (!msg
->leases
.pool
|| streq(msg
->leases
.pool
, pool
))
1228 pool_leases(this, out
, pool
, address
, size
, online
, offline
);
1232 enumerator
->destroy(enumerator
);
1235 if (msg
->leases
.pool
)
1237 fprintf(out
, "pool '%s' not found\n", msg
->leases
.pool
);
1241 fprintf(out
, "no pools found\n");
1244 DESTROY_IF(address
);
1248 * Implementation of stroke_list_t.destroy
1250 static void destroy(private_stroke_list_t
*this)
1258 stroke_list_t
*stroke_list_create(stroke_attribute_t
*attribute
)
1260 private_stroke_list_t
*this = malloc_thing(private_stroke_list_t
);
1262 this->public.list
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
))list
;
1263 this->public.status
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
,bool))status
;
1264 this->public.leases
= (void(*)(stroke_list_t
*, stroke_msg_t
*msg
, FILE *out
))leases
;
1265 this->public.destroy
= (void(*)(stroke_list_t
*))destroy
;
1267 this->uptime
= time_monotonic(NULL
);
1268 this->attribute
= attribute
;
1270 return &this->public;