added generic EAP_IDENTITY client implementation using peers IKEv2 ID
[strongswan.git] / src / charon / sa / authenticators / eap / eap_identity.c
1 /**
2 * @file eap_identity.c
3 *
4 * @brief Implementation of eap_identity_t.
5 *
6 */
7
8 /*
9 * Copyright (C) 2007 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #include "eap_identity.h"
24
25 #include <daemon.h>
26 #include <library.h>
27
28 typedef struct private_eap_identity_t private_eap_identity_t;
29
30 /**
31 * Private data of an eap_identity_t object.
32 */
33 struct private_eap_identity_t {
34
35 /**
36 * Public authenticator_t interface.
37 */
38 eap_identity_t public;
39
40 /**
41 * ID of the peer
42 */
43 identification_t *peer;
44 };
45
46 /**
47 * Implementation of eap_method_t.process for the peer
48 */
49 static status_t process(private_eap_identity_t *this,
50 eap_payload_t *in, eap_payload_t **out)
51 {
52 chunk_t id, hdr;
53
54 hdr = chunk_alloca(5);
55 id = this->peer->get_encoding(this->peer);
56
57 *(hdr.ptr + 0) = EAP_RESPONSE;
58 *(hdr.ptr + 1) = in->get_identifier(in);
59 *(u_int16_t*)(hdr.ptr + 2) = htons(hdr.len + id.len);
60 *(hdr.ptr + 4) = EAP_IDENTITY;
61
62 *out = eap_payload_create_data(chunk_cata("cc", hdr, id));
63 return SUCCESS;
64
65 }
66
67 /**
68 * Implementation of eap_method_t.initiate for the peer
69 */
70 static status_t initiate(private_eap_identity_t *this, eap_payload_t **out)
71 {
72 /* peer never initiates */
73 return FAILED;
74 }
75
76 /**
77 * Implementation of eap_method_t.get_type.
78 */
79 static eap_type_t get_type(private_eap_identity_t *this)
80 {
81 return EAP_IDENTITY;
82 }
83
84 /**
85 * Implementation of eap_method_t.get_msk.
86 */
87 static status_t get_msk(private_eap_identity_t *this, chunk_t *msk)
88 {
89 return FAILED;
90 }
91
92 /**
93 * Implementation of eap_method_t.is_mutual.
94 */
95 static bool is_mutual(private_eap_identity_t *this)
96 {
97 return FALSE;
98 }
99
100 /**
101 * Implementation of eap_method_t.destroy.
102 */
103 static void destroy(private_eap_identity_t *this)
104 {
105 free(this);
106 }
107
108 /*
109 * Described in header.
110 */
111 eap_identity_t *eap_create(eap_role_t role,
112 identification_t *server, identification_t *peer)
113 {
114 private_eap_identity_t *this;
115
116 if (role != EAP_PEER)
117 {
118 return NULL;
119 }
120
121 this = malloc_thing(private_eap_identity_t);
122
123 /* public functions */
124 this->public.eap_method_interface.initiate = (status_t(*)(eap_method_t*,eap_payload_t**))initiate;
125 this->public.eap_method_interface.process = (status_t(*)(eap_method_t*,eap_payload_t*,eap_payload_t**))process;
126 this->public.eap_method_interface.get_type = (eap_type_t(*)(eap_method_t*))get_type;
127 this->public.eap_method_interface.is_mutual = (bool(*)(eap_method_t*))is_mutual;
128 this->public.eap_method_interface.get_msk = (status_t(*)(eap_method_t*,chunk_t*))get_msk;
129 this->public.eap_method_interface.destroy = (void(*)(eap_method_t*))destroy;
130
131 /* private data */
132 this->peer = peer;
133
134 return &this->public;
135 }