added generic TLS application data handler and specific EAP-TTLS instantiation
[strongswan.git] / src / libcharon / plugins / eap_ttls / eap_ttls_peer.c
1 /*
2 * Copyright (C) 2010 Andreas Steffen
3 * Copyright (C) 2010 HSR 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_ttls_peer.h"
17
18 #include <debug.h>
19
20 #define AVP_EAP_MESSAGE 79
21
22 typedef struct private_eap_ttls_peer_t private_eap_ttls_peer_t;
23
24 /**
25 * Private data of an eap_ttls_peer_t object.
26 */
27 struct private_eap_ttls_peer_t {
28
29 /**
30 * Public eap_ttls_peer_t interface.
31 */
32 eap_ttls_peer_t public;
33
34 /**
35 * Peer identity
36 */
37 identification_t *peer;
38
39 /**
40 * EAP-TTLS state information
41 */
42 bool start_phase2;
43 };
44
45
46 METHOD(tls_application_t, process, status_t,
47 private_eap_ttls_peer_t *this, tls_reader_t *reader)
48 {
49 return NEED_MORE;
50 }
51
52 METHOD(tls_application_t, build, status_t,
53 private_eap_ttls_peer_t *this, tls_writer_t *writer)
54 {
55 if (this->start_phase2)
56 {
57 chunk_t data = chunk_from_chars(
58 0x02, 0x00, 0x00, 10, 0x01, 'c', 'a', 'r', 'o', 'l', 0x00, 0x00);
59 u_int8_t avp_flags = 0x40;
60 u_int32_t avp_len;
61
62 avp_len = 8 + data.len - 2;
63 writer->write_uint32(writer, AVP_EAP_MESSAGE);
64 writer->write_uint8(writer, avp_flags);
65 writer->write_uint24(writer, avp_len);
66 writer->write_data(writer, data);
67 this->start_phase2 = FALSE;
68 }
69 return INVALID_STATE;
70 }
71
72 METHOD(tls_application_t, destroy, void,
73 private_eap_ttls_peer_t *this)
74 {
75 free(this);
76 }
77
78 /**
79 * See header
80 */
81 eap_ttls_peer_t *eap_ttls_peer_create(identification_t *peer)
82 {
83 private_eap_ttls_peer_t *this;
84
85 INIT(this,
86 .public.application = {
87 .process = _process,
88 .build = _build,
89 .destroy = _destroy,
90 },
91 .peer = peer,
92 .start_phase2 = TRUE,
93 );
94
95 return &this->public;
96 }