fixed copy-and-paste errors
[strongswan.git] / src / libcharon / plugins / eap_tnc / eap_tnc.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
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_tnc.h"
17
18 #include <daemon.h>
19 #include <library.h>
20
21 typedef struct private_eap_tnc_t private_eap_tnc_t;
22
23 /**
24 * Private data of an eap_tnc_t object.
25 */
26 struct private_eap_tnc_t {
27
28 /**
29 * Public authenticator_t interface.
30 */
31 eap_tnc_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 /**
45 * Flags of an EAP-TNC message
46 */
47 typedef enum {
48 EAP_TNC_LENGTH = (1<<7),
49 EAP_TNC_MORE_FRAGS = (1<<6),
50 EAP_TNC_START = (1<<5),
51 EAP_TNC_DH = (1<<4),
52 EAP_TNC_VERSION = 0x07
53 } eap_tnc_flags_t;
54
55 /**
56 * EAP-TNC packet format
57 */
58 typedef struct __attribute__((packed)) {
59 u_int8_t code;
60 u_int8_t identifier;
61 u_int16_t length;
62 u_int8_t type;
63 u_int8_t flags;
64 } eap_tnc_packet_t;
65
66 METHOD(eap_method_t, initiate_peer, status_t,
67 private_eap_tnc_t *this, eap_payload_t **out)
68 {
69 /* peer never initiates */
70 return FAILED;
71 }
72
73 METHOD(eap_method_t, initiate_server, status_t,
74 private_eap_tnc_t *this, eap_payload_t **out)
75 {
76 return NEED_MORE;
77 }
78
79 METHOD(eap_method_t, process_peer, status_t,
80 private_eap_tnc_t *this, eap_payload_t *in, eap_payload_t **out)
81 {
82 eap_tnc_packet_t *pkt;
83 chunk_t data;
84
85 data = in->get_data(in);
86
87 pkt = (eap_tnc_packet_t*)data.ptr;
88 if (data.len < sizeof(eap_tnc_packet_t) ||
89 untoh16(&pkt->length) != data.len)
90 {
91 DBG1(DBG_IKE, "invalid EAP-TNC packet length");
92 return FAILED;
93 }
94 if (pkt->flags & EAP_TNC_START)
95 {
96 DBG1(DBG_IKE, "EAP-TNC version is v%u", pkt->flags & EAP_TNC_VERSION);
97 }
98 *out = eap_payload_create_nak(in->get_identifier(in));
99
100 return NEED_MORE;
101 }
102
103 METHOD(eap_method_t, process_server, status_t,
104 private_eap_tnc_t *this, eap_payload_t *in, eap_payload_t **out)
105 {
106 chunk_t data;
107
108 data = in->get_data(in);
109 DBG2(DBG_IKE, "received EAP-TNC data: %B", &data);
110
111 return SUCCESS;
112 }
113
114 METHOD(eap_method_t, get_type, eap_type_t,
115 private_eap_tnc_t *this, u_int32_t *vendor)
116 {
117 *vendor = 0;
118 return EAP_TNC;
119 }
120
121 METHOD(eap_method_t, get_msk, status_t,
122 private_eap_tnc_t *this, chunk_t *msk)
123 {
124 return FAILED;
125 }
126
127 METHOD(eap_method_t, is_mutual, bool,
128 private_eap_tnc_t *this)
129 {
130 return FALSE;
131 }
132
133 METHOD(eap_method_t, destroy, void,
134 private_eap_tnc_t *this)
135 {
136 this->peer->destroy(this->peer);
137 this->server->destroy(this->server);
138 free(this);
139 }
140
141 /*
142 * See header
143 */
144 eap_tnc_t *eap_tnc_create_server(identification_t *server, identification_t *peer)
145 {
146 private_eap_tnc_t *this;
147
148 INIT(this,
149 .public = {
150 .eap_method = {
151 .initiate = _initiate_server,
152 .process = _process_server,
153 .get_type = _get_type,
154 .is_mutual = _is_mutual,
155 .get_msk = _get_msk,
156 .destroy = _destroy,
157 },
158 },
159 .peer = peer->clone(peer),
160 .server = server->clone(server),
161 );
162
163 return &this->public;
164 }
165
166 /*
167 * See header
168 */
169 eap_tnc_t *eap_tnc_create_peer(identification_t *server, identification_t *peer)
170 {
171 private_eap_tnc_t *this;
172
173 INIT(this,
174 .public = {
175 .eap_method = {
176 .initiate = _initiate_peer,
177 .process = _process_peer,
178 .get_type = _get_type,
179 .is_mutual = _is_mutual,
180 .get_msk = _get_msk,
181 .destroy = _destroy,
182 },
183 },
184 .peer = peer->clone(peer),
185 .server = server->clone(server),
186 );
187
188 return &this->public;
189 }
190