2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 revosec AG
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 "certexpire_listener.h"
20 typedef struct private_certexpire_listener_t private_certexpire_listener_t
;
23 * Private data of an certexpire_listener_t object.
25 struct private_certexpire_listener_t
{
28 * Public certexpire_listener_t interface.
30 certexpire_listener_t
public;
33 METHOD(listener_t
, authorize
, bool,
34 private_certexpire_listener_t
*this, ike_sa_t
*ike_sa
,
35 bool final
, bool *success
)
37 enumerator_t
*rounds
, *enumerator
;
38 certificate_t
*cert
, *ca
= NULL
;
39 linked_list_t
*trustchain
;
43 /* Check all rounds in final hook, as local authentication data are
44 * not completely available after round-invocation. */
50 /* collect local certificates */
51 trustchain
= linked_list_create();
52 rounds
= ike_sa
->create_auth_cfg_enumerator(ike_sa
, TRUE
);
53 while (rounds
->enumerate(rounds
, &auth
))
55 cert
= auth
->get(auth
, AUTH_RULE_SUBJECT_CERT
);
58 trustchain
->insert_last(trustchain
, cert
);
60 enumerator
= auth
->create_enumerator(auth
);
61 while (enumerator
->enumerate(enumerator
, &rule
, &cert
))
63 if (rule
== AUTH_RULE_IM_CERT
)
65 trustchain
->insert_last(trustchain
, cert
);
67 if (rule
== AUTH_RULE_CA_CERT
)
69 /* the last CA cert is the one used in the trustchain.
70 * Previous CA certificates have been received as cert
75 enumerator
->destroy(enumerator
);
78 trustchain
->insert_last(trustchain
, ca
);
82 rounds
->destroy(rounds
);
83 /* TODO: handle trustchain expiry information */
84 trustchain
->destroy(trustchain
);
86 /* collect remote certificates */
87 trustchain
= linked_list_create();
88 rounds
= ike_sa
->create_auth_cfg_enumerator(ike_sa
, FALSE
);
89 while (rounds
->enumerate(rounds
, &auth
))
91 cert
= auth
->get(auth
, AUTH_RULE_SUBJECT_CERT
);
94 trustchain
->insert_last(trustchain
, cert
);
96 enumerator
= auth
->create_enumerator(auth
);
97 while (enumerator
->enumerate(enumerator
, &rule
, &cert
))
99 if (rule
== AUTH_RULE_IM_CERT
)
101 trustchain
->insert_last(trustchain
, cert
);
104 enumerator
->destroy(enumerator
);
106 cert
= auth
->get(auth
, AUTH_RULE_CA_CERT
);
109 trustchain
->insert_last(trustchain
, cert
);
113 rounds
->destroy(rounds
);
114 /* TODO: handle trustchain expiry information */
115 trustchain
->destroy(trustchain
);
119 METHOD(certexpire_listener_t
, destroy
, void,
120 private_certexpire_listener_t
*this)
128 certexpire_listener_t
*certexpire_listener_create()
130 private_certexpire_listener_t
*this;
135 .authorize
= _authorize
,
141 return &this->public;