diff options
Diffstat (limited to 'Source/charon/encoding')
-rw-r--r-- | Source/charon/encoding/generator.c | 5 | ||||
-rw-r--r-- | Source/charon/encoding/parser.c | 11 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/Makefile.payloads | 3 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/eap_payload.c | 232 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/eap_payload.h | 101 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/encodings.c | 2 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/encodings.h | 10 | ||||
-rw-r--r-- | Source/charon/encoding/payloads/payload.c | 3 |
8 files changed, 366 insertions, 1 deletions
diff --git a/Source/charon/encoding/generator.c b/Source/charon/encoding/generator.c index 9a2bfa3a0..65244a725 100644 --- a/Source/charon/encoding/generator.c +++ b/Source/charon/encoding/generator.c @@ -49,6 +49,7 @@ #include <encoding/payloads/vendor_id_payload.h> #include <encoding/payloads/cp_payload.h> #include <encoding/payloads/configuration_attribute.h> +#include <encoding/payloads/eap_payload.h> typedef struct private_generator_t private_generator_t; @@ -750,6 +751,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload) case SPIS: case CONFIGURATION_ATTRIBUTE_VALUE: case VID_DATA: + case EAP_MESSAGE: { u_int32_t payload_length_position_offset; u_int16_t length_of_payload; @@ -788,6 +790,9 @@ static void generate_payload (private_generator_t *this,payload_t *payload) case CONFIGURATION_ATTRIBUTE_VALUE: header_length = CONFIGURATION_ATTRIBUTE_HEADER_LENGTH; break; + case EAP_MESSAGE: + header_length = EAP_PAYLOAD_HEADER_LENGTH; + break; default: break; } diff --git a/Source/charon/encoding/parser.c b/Source/charon/encoding/parser.c index b1308cf87..e3d7fa8c5 100644 --- a/Source/charon/encoding/parser.c +++ b/Source/charon/encoding/parser.c @@ -50,6 +50,7 @@ #include <encoding/payloads/vendor_id_payload.h> #include <encoding/payloads/cp_payload.h> #include <encoding/payloads/configuration_attribute.h> +#include <encoding/payloads/eap_payload.h> typedef struct private_parser_t private_parser_t; @@ -873,6 +874,16 @@ static status_t parse_payload(private_parser_t *this, payload_type_t payload_typ } break; } + case EAP_MESSAGE: + { + size_t data_length = payload_length - EAP_PAYLOAD_HEADER_LENGTH; + if (this->parse_chunk(this, rule_number, output + rule->offset, data_length) != SUCCESS) + { + pld->destroy(pld); + return PARSE_ERROR; + } + break; + } case SPIS: { size_t data_length = payload_length - DELETE_PAYLOAD_HEADER_LENGTH; diff --git a/Source/charon/encoding/payloads/Makefile.payloads b/Source/charon/encoding/payloads/Makefile.payloads index 40d55d32a..b03da7a92 100644 --- a/Source/charon/encoding/payloads/Makefile.payloads +++ b/Source/charon/encoding/payloads/Makefile.payloads @@ -66,6 +66,9 @@ OBJS+= $(BUILD_DIR)configuration_attribute.o $(BUILD_DIR)configuration_attribute.o : $(PAYLOADS_DIR)configuration_attribute.c $(PAYLOADS_DIR)configuration_attribute.h $(CC) $(CFLAGS) -c -o $@ $< +OBJS+= $(BUILD_DIR)eap_payload.o +$(BUILD_DIR)eap_payload.o : $(PAYLOADS_DIR)eap_payload.c $(PAYLOADS_DIR)eap_payload.h + $(CC) $(CFLAGS) -c -o $@ $< OBJS+= $(BUILD_DIR)ts_payload.o $(BUILD_DIR)ts_payload.o : $(PAYLOADS_DIR)ts_payload.c $(PAYLOADS_DIR)ts_payload.h diff --git a/Source/charon/encoding/payloads/eap_payload.c b/Source/charon/encoding/payloads/eap_payload.c new file mode 100644 index 000000000..f6f8426e0 --- /dev/null +++ b/Source/charon/encoding/payloads/eap_payload.c @@ -0,0 +1,232 @@ +/** + * @file eap_payload.c + * + * @brief Implementation of eap_payload_t. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * 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_payload.h" + +#include <utils/allocator.h> + + +typedef struct private_eap_payload_t private_eap_payload_t; + +/** + * Private data of an eap_payload_t object. + * + */ +struct private_eap_payload_t { + /** + * Public eap_payload_t interface. + */ + eap_payload_t public; + + /** + * Next payload type. + */ + u_int8_t next_payload; + + /** + * Critical flag. + */ + bool critical; + + /** + * Length of this payload. + */ + u_int16_t payload_length; + + /** + * The contained message. + */ + chunk_t message; +}; + +/** + * Encoding rules to parse or generate a EAP payload. + * + * The defined offsets are the positions in a object of type + * private_eap_payload_t. + * + */ +encoding_rule_t eap_payload_encodings[] = { + /* 1 Byte next payload type, stored in the field next_payload */ + { U_INT_8, offsetof(private_eap_payload_t, next_payload) }, + /* the critical bit */ + { FLAG, offsetof(private_eap_payload_t, critical) }, + /* 7 Bit reserved bits, nowhere stored */ + { RESERVED_BIT, 0 }, + { RESERVED_BIT, 0 }, + { RESERVED_BIT, 0 }, + { RESERVED_BIT, 0 }, + { RESERVED_BIT, 0 }, + { RESERVED_BIT, 0 }, + { RESERVED_BIT, 0 }, + /* Length of the whole payload*/ + { PAYLOAD_LENGTH, offsetof(private_eap_payload_t, payload_length)}, + /* some eap data bytes, length is defined in PAYLOAD_LENGTH */ + { EAP_MESSAGE, offsetof(private_eap_payload_t, message) } +}; + +/* + 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! Next Payload !C! RESERVED ! Payload Length ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ! ! + ~ EAP Message ~ + ! ! + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +*/ + +/** + * Implementation of payload_t.verify. + */ +static status_t verify(private_eap_payload_t *this) +{ + if (this->critical) + { + /* critical bit is set! */ + return FAILED; + } + return SUCCESS; +} + +/** + * Implementation of eap_payload_t.get_encoding_rules. + */ +static void get_encoding_rules(private_eap_payload_t *this, encoding_rule_t **rules, size_t *rule_count) +{ + *rules = eap_payload_encodings; + *rule_count = sizeof(eap_payload_encodings) / sizeof(encoding_rule_t); +} + +/** + * Implementation of payload_t.get_type. + */ +static payload_type_t get_payload_type(private_eap_payload_t *this) +{ + return EXTENSIBLE_AUTHENTICATION; +} + +/** + * Implementation of payload_t.get_next_type. + */ +static payload_type_t get_next_type(private_eap_payload_t *this) +{ + return (this->next_payload); +} + +/** + * Implementation of payload_t.set_next_type. + */ +static void set_next_type(private_eap_payload_t *this,payload_type_t type) +{ + this->next_payload = type; +} + +/** + * Implementation of payload_t.get_length. + */ +static size_t get_length(private_eap_payload_t *this) +{ + return this->payload_length; +} + +/** + * Implementation of eap_payload_t.set_message. + */ +static void set_message (private_eap_payload_t *this, chunk_t message) +{ + if (this->message.ptr != NULL) + { + allocator_free_chunk(&(this->message)); + } + this->message.ptr = allocator_clone_bytes(message.ptr,message.len); + this->message.len = message.len; + this->payload_length = EAP_PAYLOAD_HEADER_LENGTH + this->message.len; +} + +/** + * Implementation of eap_payload_t.get_message. + */ +static chunk_t get_message (private_eap_payload_t *this) +{ + return (this->message); +} + +/** + * Implementation of eap_payload_t.get_data_clone. + */ +static chunk_t get_message_clone (private_eap_payload_t *this) +{ + chunk_t cloned_message; + if (this->message.ptr == NULL) + { + return (this->message); + } + cloned_message.ptr = allocator_clone_bytes(this->message.ptr,this->message.len); + cloned_message.len = this->message.len; + return cloned_message; +} + +/** + * Implementation of payload_t.destroy and eap_payload_t.destroy. + */ +static void destroy(private_eap_payload_t *this) +{ + if (this->message.ptr != NULL) + { + allocator_free_chunk(&(this->message)); + } + + allocator_free(this); +} + +/* + * Described in header + */ +eap_payload_t *eap_payload_create() +{ + private_eap_payload_t *this = allocator_alloc_thing(private_eap_payload_t); + + /* interface functions */ + this->public.payload_interface.verify = (status_t (*) (payload_t *))verify; + this->public.payload_interface.get_encoding_rules = (void (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules; + this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length; + this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type; + this->public.payload_interface.set_next_type = (void (*) (payload_t *,payload_type_t)) set_next_type; + this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_payload_type; + this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; + + /* public functions */ + this->public.destroy = (void (*) (eap_payload_t *)) destroy; + this->public.set_message = (void (*) (eap_payload_t *,chunk_t)) set_message; + this->public.get_message_clone = (chunk_t (*) (eap_payload_t *)) get_message_clone; + this->public.get_message = (chunk_t (*) (eap_payload_t *)) get_message; + + /* private variables */ + this->critical = FALSE; + this->next_payload = NO_PAYLOAD; + this->payload_length = EAP_PAYLOAD_HEADER_LENGTH; + this->message = CHUNK_INITIALIZER; + + return (&(this->public)); +} diff --git a/Source/charon/encoding/payloads/eap_payload.h b/Source/charon/encoding/payloads/eap_payload.h new file mode 100644 index 000000000..b7b466769 --- /dev/null +++ b/Source/charon/encoding/payloads/eap_payload.h @@ -0,0 +1,101 @@ +/** + * @file eap_payload.h + * + * @brief Interface of eap_payload_t. + * + */ + +/* + * Copyright (C) 2005 Jan Hutter, Martin Willi + * 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. + */ + +#ifndef _EAP_PAYLOAD_H_ +#define _EAP_PAYLOAD_H_ + +#include <types.h> +#include <encoding/payloads/payload.h> + +/** + * Length of a EAP payload without the EAP Message in bytes. + * + * @ingroup payloads + */ +#define EAP_PAYLOAD_HEADER_LENGTH 4 + + +typedef struct eap_payload_t eap_payload_t; + +/** + * Object representing an IKEv2 EAP payload. + * + * The EAP payload format is described in draft section 3.16. + * + * @ingroup payloads + * + */ +struct eap_payload_t { + /** + * The payload_t interface. + */ + payload_t payload_interface; + + /** + * @brief Set the EAP Message. + * + * Data are getting cloned. + * + * @param this calling eap_payload_t object + * @param message EAP message as chunk_t + */ + void (*set_message) (eap_payload_t *this, chunk_t message); + + /** + * @brief Get the EAP message. + * + * Returned data are a copy of the internal one. + * + * @param this calling eap_payload_t object + * @return EAP message as chunk_t + */ + chunk_t (*get_message_clone) (eap_payload_t *this); + + /** + * @brief Get the EAP message. + * + * Returned data are NOT copied. + * + * @param this calling eap_payload_t object + * @return EAP message as chunk_t + */ + chunk_t (*get_message) (eap_payload_t *this); + + /** + * @brief Destroys an eap_payload_t object. + * + * @param this eap_payload_t object to destroy + */ + void (*destroy) (eap_payload_t *this); +}; + +/** + * @brief Creates an empty eap_payload_t object. + * + * @return created eap_payload_t object + * + * @ingroup payloads + */ +eap_payload_t *eap_payload_create(); + + +#endif //_EAP_PAYLOAD_H_ diff --git a/Source/charon/encoding/payloads/encodings.c b/Source/charon/encoding/payloads/encodings.c index 035d71ada..44ae826b1 100644 --- a/Source/charon/encoding/payloads/encodings.c +++ b/Source/charon/encoding/payloads/encodings.c @@ -62,6 +62,6 @@ mapping_t encoding_type_m[] = { {CONFIGURATION_ATTRIBUTES, "CONFIGURATION_ATTRIBUTES"}, {CONFIGURATION_ATTRIBUTE_LENGTH, "CONFIGURATION_ATTRIBUTE_LENGTH"}, {CONFIGURATION_ATTRIBUTE_VALUE, "CONFIGURATION_ATTRIBUTE_VALUE"}, - + {EAP_MESSAGE, "EAP_MESSAGE"}, {MAPPING_END, NULL} }; diff --git a/Source/charon/encoding/payloads/encodings.h b/Source/charon/encoding/payloads/encodings.h index 1262a0cbe..a53dc3e63 100644 --- a/Source/charon/encoding/payloads/encodings.h +++ b/Source/charon/encoding/payloads/encodings.h @@ -426,6 +426,16 @@ enum encoding_type_t{ CERTREQ_DATA, /** + * Representating an EAP message field. + * + * When generating the content of the chunkt pointing to + * is written. + * + * When parsing (Payload Length - 4) bytes are read and written into the chunk pointing to. + */ + EAP_MESSAGE, + + /** * Representating the SPIS field in a DELETE payload. * * When generating the content of the chunkt pointing to diff --git a/Source/charon/encoding/payloads/payload.c b/Source/charon/encoding/payloads/payload.c index 2ee8ee642..d311365eb 100644 --- a/Source/charon/encoding/payloads/payload.c +++ b/Source/charon/encoding/payloads/payload.c @@ -39,6 +39,7 @@ #include <encoding/payloads/vendor_id_payload.h> #include <encoding/payloads/cp_payload.h> #include <encoding/payloads/configuration_attribute.h> +#include <encoding/payloads/eap_payload.h> /* * build the mappings for payload_type_t @@ -117,6 +118,8 @@ payload_t *payload_create(payload_type_t type) return (payload_t*)cp_payload_create(); case CONFIGURATION_ATTRIBUTE: return (payload_t*)configuration_attribute_create(); + case EXTENSIBLE_AUTHENTICATION: + return (payload_t*)eap_payload_create(); case ENCRYPTED: return (payload_t*)encryption_payload_create(); default: |