Added eap-dynamic plugin which can proxy any other EAP method
[strongswan.git] / src / libcharon / plugins / eap_dynamic / eap_dynamic.c
1 /*
2 * Copyright (C) 2012 Tobias Brunner
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
16 #include "eap_dynamic.h"
17
18 #include <daemon.h>
19 #include <library.h>
20
21 typedef struct private_eap_dynamic_t private_eap_dynamic_t;
22
23 /**
24 * Private data of an eap_dynamic_t object.
25 */
26 struct private_eap_dynamic_t {
27
28 /**
29 * Public authenticator_t interface.
30 */
31 eap_dynamic_t public;
32
33 /**
34 * ID of the server
35 */
36 identification_t *server;
37
38 /**
39 * ID of the peer
40 */
41 identification_t *peer;
42
43 /**
44 * The proxied EAP method
45 */
46 eap_method_t *method;
47 };
48
49 METHOD(eap_method_t, initiate, status_t,
50 private_eap_dynamic_t *this, eap_payload_t **out)
51 {
52 return FAILED;
53 }
54
55 METHOD(eap_method_t, process, status_t,
56 private_eap_dynamic_t *this, eap_payload_t *in, eap_payload_t **out)
57 {
58 return FAILED;
59 }
60
61 METHOD(eap_method_t, get_type, eap_type_t,
62 private_eap_dynamic_t *this, u_int32_t *vendor)
63 {
64 if (this->method)
65 {
66 return this->method->get_type(this->method, vendor);
67 }
68 *vendor = 0;
69 return EAP_DYNAMIC;
70 }
71
72 METHOD(eap_method_t, get_msk, status_t,
73 private_eap_dynamic_t *this, chunk_t *msk)
74 {
75 if (this->method)
76 {
77 return this->method->get_msk(this->method, msk);
78 }
79 return FAILED;
80 }
81
82 METHOD(eap_method_t, get_identifier, u_int8_t,
83 private_eap_dynamic_t *this)
84 {
85 if (this->method)
86 {
87 return this->method->get_identifier(this->method);
88 }
89 return 0;
90 }
91
92 METHOD(eap_method_t, set_identifier, void,
93 private_eap_dynamic_t *this, u_int8_t identifier)
94 {
95 if (this->method)
96 {
97 this->method->set_identifier(this->method, identifier);
98 }
99 }
100
101 METHOD(eap_method_t, is_mutual, bool,
102 private_eap_dynamic_t *this)
103 {
104 if (this->method)
105 {
106 return this->method->is_mutual(this->method);
107 }
108 return FALSE;
109 }
110
111 METHOD(eap_method_t, destroy, void,
112 private_eap_dynamic_t *this)
113 {
114 DESTROY_IF(this->method);
115 this->server->destroy(this->server);
116 this->peer->destroy(this->peer);
117 free(this);
118 }
119
120 /*
121 * Defined in header
122 */
123 eap_dynamic_t *eap_dynamic_create(identification_t *server,
124 identification_t *peer)
125 {
126 private_eap_dynamic_t *this;
127
128 INIT(this,
129 .public = {
130 .interface = {
131 .initiate = _initiate,
132 .process = _process,
133 .get_type = _get_type,
134 .is_mutual = _is_mutual,
135 .get_msk = _get_msk,
136 .get_identifier = _get_identifier,
137 .set_identifier = _set_identifier,
138 .destroy = _destroy,
139 },
140 },
141 .peer = peer->clone(peer),
142 .server = server->clone(server),
143 );
144
145 return &this->public;
146 }