aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins/eap_ttls/eap_ttls_peer.c
blob: 0e4d70fa8c313db8cd0f80b31a9e8c51d167acd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2010 Andreas Steffen
 * Copyright (C) 2010 HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "eap_ttls_peer.h"

#include <debug.h>

#define AVP_EAP_MESSAGE		79

typedef struct private_eap_ttls_peer_t private_eap_ttls_peer_t;

/**
 * Private data of an eap_ttls_peer_t object.
 */
struct private_eap_ttls_peer_t {

	/**
	 * Public eap_ttls_peer_t interface.
	 */
	eap_ttls_peer_t public;

	/**
	 * Peer identity
	 */
	identification_t *peer;

	/**
	 * EAP-TTLS state information
	 */
	bool start_phase2;
};


METHOD(tls_application_t, process, status_t,
	private_eap_ttls_peer_t *this, tls_reader_t *reader)
{
	return NEED_MORE;
}

METHOD(tls_application_t, build, status_t,
	private_eap_ttls_peer_t *this, tls_writer_t *writer)
{
	if (this->start_phase2)
	{
		chunk_t data = chunk_from_chars(
			0x02, 0x00, 0x00, 10, 0x01, 'c', 'a', 'r', 'o', 'l', 0x00, 0x00);
		u_int8_t avp_flags = 0x40;
		u_int32_t avp_len;

		avp_len = 8 + data.len - 2;
		writer->write_uint32(writer, AVP_EAP_MESSAGE);
		writer->write_uint8(writer, avp_flags);
		writer->write_uint24(writer, avp_len);
		writer->write_data(writer, data);
		this->start_phase2 = FALSE;
	}
	return INVALID_STATE;
}

METHOD(tls_application_t, destroy, void,
	private_eap_ttls_peer_t *this)
{
	free(this);
}

/**
 * See header
 */
eap_ttls_peer_t *eap_ttls_peer_create(identification_t *peer)
{
	private_eap_ttls_peer_t *this;

	INIT(this,
		.public.application = {
			.process = _process,
			.build = _build,
			.destroy = _destroy,
		},
		.peer = peer,
		.start_phase2 = TRUE,
	);

	return &this->public;
}