From: Sansar Choinyambuu Date: Fri, 3 Dec 2010 09:22:51 +0000 (+0100) Subject: PB-TNC messages implemented X-Git-Tag: 4.5.1~464 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1ee0e20f73f6bc2c1ab313d2654c71749bda8e1;p=thirdparty%2Fstrongswan.git PB-TNC messages implemented --- diff --git a/src/libcharon/plugins/tnccs_20/Makefile.am b/src/libcharon/plugins/tnccs_20/Makefile.am index 1afa787592..73c18ce41a 100644 --- a/src/libcharon/plugins/tnccs_20/Makefile.am +++ b/src/libcharon/plugins/tnccs_20/Makefile.am @@ -15,7 +15,11 @@ libstrongswan_tnccs_20_la_SOURCES = \ tnccs_20_plugin.h tnccs_20_plugin.c tnccs_20.h tnccs_20.c \ tnccs_20_types.h tnccs_20_types.c \ messages/pb_tnc_message.h messages/pb_tnc_message.c \ - messages/pb_pa_message.h messages/pb_pa_message.c + messages/pb_pa_message.h messages/pb_pa_message.c \ + messages/pb_assessment_result_message.h messages/pb_assessment_result_message.c \ + messages/pb_access_recommendation_message.h messages/pb_access_recommendation_message.c \ + messages/pb_error_message.h messages/pb_error_message.c \ + messages/pb_language_preference_message.h messages/pb_language_preference_message.c \ + messages/pb_reason_string_message.h messages/pb_reason_string_message.c libstrongswan_tnccs_20_la_LDFLAGS = -module -avoid-version - diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_access_recommendation_message.c b/src/libcharon/plugins/tnccs_20/messages/pb_access_recommendation_message.c new file mode 100644 index 0000000000..dc43e29e35 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_access_recommendation_message.c @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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 "pb_access_recommendation_message.h" + +#include +#include +#include + +typedef struct private_pb_access_recommendation_message_t private_pb_access_recommendation_message_t; + +/** + * PB-Access-Recommendation message (see section 4.7 of RFC 5793) + * + * 0 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Reserved | Access Recommendation Code | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define ACCESS_RECOMMENDATION_RESERVED 0x0000 +#define ACCESS_RECOMMENDATION_MESSAGE_SIZE 4 + +/** + * Private data of a private_pb_access_recommendation_message_t object. + * + */ +struct private_pb_access_recommendation_message_t { + /** + * Public pb_access_recommendation_message_t interface. + */ + pb_access_recommendation_message_t public; + + /** + * PB-TNC message type + */ + pb_tnc_msg_type_t type; + + /** + * Access recommendation code + */ + u_int16_t recommendation; + + /** + * Encoded message + */ + chunk_t encoding; +}; + +METHOD(pb_tnc_message_t, get_type, pb_tnc_msg_type_t, + private_pb_access_recommendation_message_t *this) +{ + return this->type; +} + +METHOD(pb_tnc_message_t, get_encoding, chunk_t, + private_pb_access_recommendation_message_t *this) +{ + return this->encoding; +} + +METHOD(pb_tnc_message_t, build, void, + private_pb_access_recommendation_message_t *this) +{ + tls_writer_t *writer; + + /* build message */ + writer = tls_writer_create(ACCESS_RECOMMENDATION_MESSAGE_SIZE); + writer->write_uint16(writer, ACCESS_RECOMMENDATION_RESERVED); + writer->write_uint16(writer, this->recommendation); + free(this->encoding.ptr); + this->encoding = writer->get_buf(writer); + this->encoding = chunk_clone(this->encoding); + writer->destroy(writer); +} + +METHOD(pb_tnc_message_t, process, status_t, + private_pb_access_recommendation_message_t *this) +{ + tls_reader_t *reader; + u_int16_t reserved; + + if (this->encoding.len < ACCESS_RECOMMENDATION_MESSAGE_SIZE) + { + DBG1(DBG_TNC,"%N message is shorter than message size of %u bytes", + pb_tnc_msg_type_names, PB_MSG_ACCESS_RECOMMENDATION, + ACCESS_RECOMMENDATION_MESSAGE_SIZE); + return FAILED; + } + + /* process message */ + reader = tls_reader_create(this->encoding); + reader->read_uint16(reader, &reserved); + reader->read_uint16(reader, &this->recommendation); + + reader->destroy(reader); + return SUCCESS; +} + +METHOD(pb_tnc_message_t, destroy, void, + private_pb_access_recommendation_message_t *this) +{ + free(this->encoding.ptr); + free(this); +} + +METHOD(pb_access_recommendation_message_t, get_access_recommendation, u_int16_t, + private_pb_access_recommendation_message_t *this) +{ + return this->recommendation; +} + +/** + * See header + */ +pb_tnc_message_t *pb_access_recommendation_message_create_from_data(chunk_t data) +{ + private_pb_access_recommendation_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_access_recommendation = _get_access_recommendation, + }, + .type = PB_MSG_ACCESS_RECOMMENDATION, + .encoding = chunk_clone(data), + ); + + return &this->public.pb_interface; +} + +/** + * See header + */ +pb_tnc_message_t *pb_access_recommendation_message_create(u_int16_t recommendation) +{ + private_pb_access_recommendation_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_access_recommendation = _get_access_recommendation, + }, + .type = PB_MSG_ACCESS_RECOMMENDATION, + .recommendation = recommendation, + ); + + return &this->public.pb_interface; +} diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_access_recommendation_message.h b/src/libcharon/plugins/tnccs_20/messages/pb_access_recommendation_message.h new file mode 100644 index 0000000000..0b3c849e9b --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_access_recommendation_message.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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. + */ + +/** + * @defgroup pb_access_recommendation_message pb_access_recommendation_message + * @{ @ingroup tnccs_20 + */ + +#ifndef PB_ACCESS_RECOMMENDATION_MESSAGE_H_ +#define PB_ACCESS_RECOMMENDATION_MESSAGE_H_ + +#include "pb_tnc_message.h" + +typedef struct pb_access_recommendation_message_t pb_access_recommendation_message_t; + +/** + * Classs representing the PB-Access-Recommendation message type. + */ +struct pb_access_recommendation_message_t { + + /** + * PB-TNC Message interface + */ + pb_tnc_message_t pb_interface; + + /** + * Get PB Access Recommendation + * + * @return PB Access Recommendation + */ + u_int16_t (*get_access_recommendation)(pb_access_recommendation_message_t *this); +}; + +/** + * Create a PB-Access-Recommendation message from parameters + * + * @param access_recommendation Access Recommendation code + */ +pb_tnc_message_t* pb_access_recommendation_message_create(u_int16_t recommendation); + +/** + * Create an unprocessed PB-Access-Recommendation message from raw data + * + * @param data PB-Access-Recommendation message data + */ +pb_tnc_message_t* pb_access_recommendation_message_create_from_data(chunk_t data); + +#endif /** PB_PA_MESSAGE_H_ @}*/ diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_assessment_result_message.c b/src/libcharon/plugins/tnccs_20/messages/pb_assessment_result_message.c new file mode 100644 index 0000000000..41e2e67fb4 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_assessment_result_message.c @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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 "pb_assessment_result_message.h" + +#include +#include +#include + +typedef struct private_pb_assessment_result_message_t private_pb_assessment_result_message_t; + +/** + * PB-Assessment-Result message (see section 4.6 of RFC 5793) + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Assessment Result | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define ASSESSMENT_RESULT_MESSAGE_SIZE 4 + +/** + * Private data of a pb_assessment_result_message_t object. + * + */ +struct private_pb_assessment_result_message_t { + /** + * Public pb_assessment_result_message_t interface. + */ + pb_assessment_result_message_t public; + + /** + * PB-TNC message type + */ + pb_tnc_msg_type_t type; + + /** + * Assessment result code + */ + u_int32_t assessment_result; + + /** + * Encoded message + */ + chunk_t encoding; +}; + +METHOD(pb_tnc_message_t, get_type, pb_tnc_msg_type_t, + private_pb_assessment_result_message_t *this) +{ + return this->type; +} + +METHOD(pb_tnc_message_t, get_encoding, chunk_t, + private_pb_assessment_result_message_t *this) +{ + return this->encoding; +} + +METHOD(pb_tnc_message_t, build, void, + private_pb_assessment_result_message_t *this) +{ + tls_writer_t *writer; + + /* build message */ + writer = tls_writer_create(ASSESSMENT_RESULT_MESSAGE_SIZE); + writer->write_uint32(writer, this->assessment_result); + free(this->encoding.ptr); + this->encoding = writer->get_buf(writer); + this->encoding = chunk_clone(this->encoding); + writer->destroy(writer); +} + +METHOD(pb_tnc_message_t, process, status_t, + private_pb_assessment_result_message_t *this) +{ + tls_reader_t *reader; + + if (this->encoding.len < ASSESSMENT_RESULT_MESSAGE_SIZE) + { + DBG1(DBG_TNC,"%N message is shorter than message size of %u bytes", + pb_tnc_msg_type_names, PB_MSG_ASSESSMENT_RESULT, + ASSESSMENT_RESULT_MESSAGE_SIZE); + return FAILED; + } + + /* process message */ + reader = tls_reader_create(this->encoding); + reader->read_uint32(reader, &this->assessment_result); + + reader->destroy(reader); + return SUCCESS; +} + +METHOD(pb_tnc_message_t, destroy, void, + private_pb_assessment_result_message_t *this) +{ + free(this->encoding.ptr); + free(this); +} + +METHOD(pb_assessment_result_message_t, get_assessment_result, u_int32_t, + private_pb_assessment_result_message_t *this) +{ + return this->assessment_result; +} + +/** + * See header + */ +pb_tnc_message_t *pb_assessment_result_message_create_from_data(chunk_t data) +{ + private_pb_assessment_result_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_assessment_result = _get_assessment_result, + }, + .type = PB_MSG_ASSESSMENT_RESULT, + .encoding = chunk_clone(data), + ); + + return &this->public.pb_interface; +} + +/** + * See header + */ +pb_tnc_message_t *pb_assessment_result_message_create(u_int32_t assessment_result) +{ + private_pb_assessment_result_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_assessment_result = _get_assessment_result, + }, + .type = PB_MSG_ASSESSMENT_RESULT, + .assessment_result = assessment_result, + ); + + return &this->public.pb_interface; +} diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_assessment_result_message.h b/src/libcharon/plugins/tnccs_20/messages/pb_assessment_result_message.h new file mode 100644 index 0000000000..cec7a292e1 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_assessment_result_message.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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. + */ + +/** + * @defgroup pb_assessment_result_message pb_assessment_result_message + * @{ @ingroup tnccs_20 + */ + +#ifndef PB_ASSESSMENT_RESULT_MESSAGE_H_ +#define PB_ASSESSMENT_RESULT_MESSAGE_H_ + +#include "pb_tnc_message.h" + +typedef struct pb_assessment_result_message_t pb_assessment_result_message_t; + +/** + * Classs representing the PB-Assessment-Result message type. + */ +struct pb_assessment_result_message_t { + + /** + * PB-TNC Message interface + */ + pb_tnc_message_t pb_interface; + + /** + * Get PB Assessment result + * + * @return PB Assessment result + */ + u_int32_t (*get_assessment_result)(pb_assessment_result_message_t *this); +}; + +/** + * Create a PB-Assessment-Result message from parameters + * + * @param assessment_result Assessment result code + */ +pb_tnc_message_t* pb_assessment_result_message_create(u_int32_t assessment_result); + +/** + * Create an unprocessed PB-Assessment-Result message from raw data + * + * @param data PB-Assessment-Result message data + */ +pb_tnc_message_t* pb_assessment_result_message_create_from_data(chunk_t data); + +#endif /** PB_PA_MESSAGE_H_ @}*/ diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_error_message.c b/src/libcharon/plugins/tnccs_20/messages/pb_error_message.c new file mode 100644 index 0000000000..48c9fad8c8 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_error_message.c @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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 "pb_error_message.h" +#include "../tnccs_20_types.h" + +#include +#include +#include + +typedef struct private_pb_error_message_t private_pb_error_message_t; + +/** + * PB-Error message (see section 4.9 of RFC 5793) + * + * 0 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Flags | Error Code Vendor ID | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Error Code | Reserved | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Error Parameters (Variable Length) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define ERROR_FLAG_NONE 0x00 +#define ERROR_FLAG_FATAL (1<<7) +#define ERROR_RESERVED 0x00 +#define ERROR_HEADER_SIZE 8 + +/** + * Private data of a pb_error_message_t object. + * + */ +struct private_pb_error_message_t { + /** + * Public pb_error_message_t interface. + */ + pb_error_message_t public; + + /** + * PB-TNC message type + */ + pb_tnc_msg_type_t type; + + /** + * Fatal flag + */ + bool fatal; + + /** + * PB Error Code Vendor ID + */ + u_int32_t vendor_id; + + /** + * PB Error Code + */ + u_int16_t error_code; + + /** + * PB Error Parameters + */ + u_int32_t error_parameters; + + /** + * Encoded message + */ + chunk_t encoding; +}; + +METHOD(pb_tnc_message_t, get_type, pb_tnc_msg_type_t, + private_pb_error_message_t *this) +{ + return this->type; +} + +METHOD(pb_tnc_message_t, get_encoding, chunk_t, + private_pb_error_message_t *this) +{ + return this->encoding; +} + +METHOD(pb_tnc_message_t, build, void, + private_pb_error_message_t *this) +{ + tls_writer_t *writer; + + /* build message header */ + writer = tls_writer_create(ERROR_HEADER_SIZE); + writer->write_uint8 (writer, this->fatal ? + ERROR_FLAG_FATAL : ERROR_FLAG_NONE); + writer->write_uint24(writer, this->vendor_id); + writer->write_uint16(writer, this->error_code); + writer->write_uint16(writer, ERROR_RESERVED); + + /* create encoding by concatenating message header and message body */ + free(this->encoding.ptr); + + if(this->error_parameters) + { + if(this->error_code == PB_ERROR_VERSION_NOT_SUPPORTED) + { + /* Bad version */ + writer->write_uint8(writer, this->error_parameters); + writer->write_uint8(writer, 2); /* Max version */ + writer->write_uint8(writer, 2); /* Min version */ + writer->write_uint8(writer, 0); /* Reserved */ + } + else + { + /* Error parameters */ + writer->write_uint32(writer, this->error_parameters); + } + } + this->encoding = writer->get_buf(writer); + this->encoding = chunk_clone(this->encoding); + writer->destroy(writer); +} + +METHOD(pb_tnc_message_t, process, status_t, + private_pb_error_message_t *this) +{ + u_int8_t flags; + u_int16_t reserved; + size_t error_parameters_len; + tls_reader_t *reader; + + if (this->encoding.len < ERROR_HEADER_SIZE) + { + DBG1(DBG_TNC,"%N message is shorter than header size of %u bytes", + pb_tnc_msg_type_names, PB_MSG_ERROR, ERROR_HEADER_SIZE); + return FAILED; + } + + /* process message header */ + reader = tls_reader_create(this->encoding); + reader->read_uint8 (reader, &flags); + reader->read_uint24(reader, &this->vendor_id); + reader->read_uint16(reader, &this->error_code); + reader->read_uint16(reader, &reserved); + + /* process error parameters */ + error_parameters_len = reader->remaining(reader); + if (error_parameters_len) + { + reader->read_uint32(reader, &this->error_parameters); + } + reader->destroy(reader); + return SUCCESS; +} + +METHOD(pb_tnc_message_t, destroy, void, + private_pb_error_message_t *this) +{ + free(this->encoding.ptr); + free(this); +} + +METHOD(pb_error_message_t, get_vendor_id, u_int32_t, + private_pb_error_message_t *this) +{ + return this->vendor_id; +} + +METHOD(pb_error_message_t, get_error_code, u_int16_t, + private_pb_error_message_t *this) +{ + return this->error_code; +} + +METHOD(pb_error_message_t, get_parameters, u_int32_t, + private_pb_error_message_t *this) +{ + return this->error_parameters; +} + +METHOD(pb_error_message_t, get_fatal_flag, bool, + private_pb_error_message_t *this) +{ + return this->fatal; +} + +METHOD(pb_error_message_t, set_fatal_flag, void, + private_pb_error_message_t *this, bool fatal) +{ + this->fatal = fatal; +} + +/** + * See header + */ +pb_tnc_message_t *pb_error_message_create_from_data(chunk_t data) +{ + private_pb_error_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_vendor_id = _get_vendor_id, + .get_error_code = _get_error_code, + .get_parameters = _get_parameters, + .get_fatal_flag = _get_fatal_flag, + .set_fatal_flag = _set_fatal_flag, + }, + .type = PB_MSG_ERROR, + .encoding = chunk_clone(data), + ); + + return &this->public.pb_interface; +} + +/** + * See header + */ +pb_tnc_message_t *pb_error_message_create(u_int32_t vendor_id, + pb_tnc_error_code_t error_code) +{ + private_pb_error_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_vendor_id = _get_vendor_id, + .get_error_code = _get_error_code, + .get_parameters = _get_parameters, + .get_fatal_flag = _get_fatal_flag, + .set_fatal_flag = _set_fatal_flag, + }, + .type = PB_MSG_ERROR, + .vendor_id = vendor_id, + .error_code = error_code, + ); + + return &this->public.pb_interface; +} + +/** + * See header + */ +pb_tnc_message_t *pb_error_message_create_with_parameter(u_int32_t vendor_id, + pb_tnc_error_code_t error_code, + u_int32_t error_parameters) +{ + private_pb_error_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_vendor_id = _get_vendor_id, + .get_error_code = _get_error_code, + .get_parameters = _get_parameters, + .get_fatal_flag = _get_fatal_flag, + .set_fatal_flag = _set_fatal_flag, + }, + .type = PB_MSG_ERROR, + .vendor_id = vendor_id, + .error_code = error_code, + .error_parameters = error_parameters, + ); + + return &this->public.pb_interface; +} diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_error_message.h b/src/libcharon/plugins/tnccs_20/messages/pb_error_message.h new file mode 100644 index 0000000000..987758b89e --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_error_message.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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. + */ + +/** + * @defgroup pb_error_message pb_error_message + * @{ @ingroup tnccs_20 + */ + +#ifndef PB_ERROR_MESSAGE_H_ +#define PB_ERROR_MESSAGE_H_ + +#include "pb_tnc_message.h" + +typedef struct pb_error_message_t pb_error_message_t; + +/** + * Classs representing the PB-Error message type. + */ +struct pb_error_message_t { + + /** + * PB-TNC Message interface + */ + pb_tnc_message_t pb_interface; + + /** + * Get PB Error code Vendor ID + * + * @return PB Error code Vendor ID + */ + u_int32_t (*get_vendor_id)(pb_error_message_t *this); + + /** + * Get PB Error Code + * + * @return PB Error Code + */ + u_int16_t (*get_error_code)(pb_error_message_t *this); + + /** + * Get the PB Error Parameters + * + * @return PB Error Parameter + */ + u_int32_t (*get_parameters)(pb_error_message_t *this); + + /** + * Get the fatal flag + * + * @return fatal flag + */ + bool (*get_fatal_flag)(pb_error_message_t *this); + + /** + * Set the fatal flag + * + * @param excl fatal flag + */ + void (*set_fatal_flag)(pb_error_message_t *this, bool is_fatal); +}; + +/** + * Create a PB-Error message from parameters + * + * @param vendor_id Error Code Vendor ID + * @param error_code Error Code + */ +pb_tnc_message_t* pb_error_message_create(u_int32_t vendor_id, + pb_tnc_error_code_t error_code); +/** + * Create a PB-Error message from parameters + * + * @param vendor_id Error Code Vendor ID + * @param error_code Error Code + * @param error_parameters Error parameters + */ +pb_tnc_message_t* pb_error_message_create_with_parameter(u_int32_t vendor_id, + pb_tnc_error_code_t error_code, + u_int32_t error_parameters); +/** + * Create an unprocessed PB-Error message from raw data + * + * @param data PB-Error message data + */ +pb_tnc_message_t* pb_error_message_create_from_data(chunk_t data); + +#endif /** PB_PA_MESSAGE_H_ @}*/ diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_language_preference_message.c b/src/libcharon/plugins/tnccs_20/messages/pb_language_preference_message.c new file mode 100644 index 0000000000..da211f184c --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_language_preference_message.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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 "pb_language_preference_message.h" + +#include +#include +#include + +typedef struct private_pb_language_preference_message_t private_pb_language_preference_message_t; + +/** + * PB-Language-Preference message (see section 4.10 of RFC 5793) + * + * 0 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Language Preference (Variable Length) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +/** + * Private data of a private_pb_language_preference_message_t object. + * + */ +struct private_pb_language_preference_message_t { + /** + * Public pb_access_recommendation_message_t interface. + */ + pb_language_preference_message_t public; + + /** + * PB-TNC message type + */ + pb_tnc_msg_type_t type; + + /** + * Language preference + */ + chunk_t language_preference; + + /** + * Encoded message + */ + chunk_t encoding; +}; + +METHOD(pb_tnc_message_t, get_type, pb_tnc_msg_type_t, + private_pb_language_preference_message_t *this) +{ + return this->type; +} + +METHOD(pb_tnc_message_t, get_encoding, chunk_t, + private_pb_language_preference_message_t *this) +{ + return this->encoding; +} + +METHOD(pb_tnc_message_t, build, void, + private_pb_language_preference_message_t *this) +{ + tls_writer_t *writer; + + /* build message */ + writer = tls_writer_create(0); + writer->write_data(writer, this->language_preference); + + free(this->encoding.ptr); + this->encoding = writer->get_buf(writer); + this->encoding = chunk_clone(this->encoding); + writer->destroy(writer); +} + +METHOD(pb_tnc_message_t, process, status_t, + private_pb_language_preference_message_t *this) +{ + tls_reader_t *reader; + + if (this->encoding.len) + { + /* process message */ + reader = tls_reader_create(this->encoding); + reader->read_data(reader, this->encoding.len, + &this->language_preference); + this->language_preference = chunk_clone(this->language_preference); + reader->destroy(reader); + } + + return SUCCESS; +} + +METHOD(pb_tnc_message_t, destroy, void, + private_pb_language_preference_message_t *this) +{ + free(this->encoding.ptr); + free(this->language_preference.ptr); + free(this); +} + +METHOD(pb_language_preference_message_t, get_language_preference, chunk_t, + private_pb_language_preference_message_t *this) +{ + return this->language_preference; +} + +/** + * See header + */ +pb_tnc_message_t *pb_language_preference_message_create_from_data(chunk_t data) +{ + private_pb_language_preference_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_language_preference = _get_language_preference, + }, + .type = PB_MSG_LANGUAGE_PREFERENCE, + .encoding = chunk_clone(data), + ); + + return &this->public.pb_interface; +} + +/** + * See header + */ +pb_tnc_message_t *pb_language_preference_message_create(chunk_t language_preference) +{ + private_pb_language_preference_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_language_preference = _get_language_preference, + }, + .type = PB_MSG_LANGUAGE_PREFERENCE, + .language_preference = language_preference, + ); + + return &this->public.pb_interface; +} diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_language_preference_message.h b/src/libcharon/plugins/tnccs_20/messages/pb_language_preference_message.h new file mode 100644 index 0000000000..25d8a578c4 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_language_preference_message.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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. + */ + +/** + * @defgroup pb_language_preference_message pb_language_preference_message + * @{ @ingroup tnccs_20 + */ + +#ifndef PB_LANGUAGE_PREFERENCE_MESSAGE_H_ +#define PB_LANGUAGE_PREFERENCE_MESSAGE_H_ + +#include "pb_tnc_message.h" + +typedef struct pb_language_preference_message_t pb_language_preference_message_t; + +/** + * Classs representing the PB-Language-Preference message type. + */ +struct pb_language_preference_message_t { + + /** + * PB-TNC Message interface + */ + pb_tnc_message_t pb_interface; + + /** + * Get PB Language Preference + * + * @return Language preference + */ + chunk_t (*get_language_preference)(pb_language_preference_message_t *this); +}; + +/** + * Create a PB-Language-Preference message from parameters + * + * @param language_preference Preferred language(s) + */ +pb_tnc_message_t* pb_language_preference_message_create(chunk_t language_preference); + +/** + * Create an unprocessed PB-Language-Preference message from raw data + * + * @param data PB-Language-Preference message data + */ +pb_tnc_message_t* pb_language_preference_message_create_from_data(chunk_t data); + +#endif /** PB_PA_MESSAGE_H_ @}*/ diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_reason_string_message.c b/src/libcharon/plugins/tnccs_20/messages/pb_reason_string_message.c new file mode 100644 index 0000000000..5dcab033f5 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_reason_string_message.c @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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 "pb_reason_string_message.h" + +#include +#include +#include + +typedef struct private_pb_reason_string_message_t private_pb_reason_string_message_t; + +/** + * PB-Language-Preference message (see section 4.11 of RFC 5793) + * + * 0 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Reason String Length | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Reason String (Variable Length) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Lang Code Len | Reason String Language Code (Variable Length) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ + +#define REASON_STRING_HEADER_SIZE 5 + +/** + * Private data of a private_pb_reason_string_message_t object. + * + */ +struct private_pb_reason_string_message_t { + /** + * Public pb_reason_string_message_t interface. + */ + pb_reason_string_message_t public; + + /** + * PB-TNC message type + */ + pb_tnc_msg_type_t type; + + /** + * Reason string length + */ + u_int32_t reason_string_length; + + /** + * Reason string + */ + chunk_t reason_string; + + /** + * Language code length + */ + u_int8_t language_code_length; + + /** + * Language code + */ + chunk_t language_code; + + /** + * Encoded message + */ + chunk_t encoding; +}; + +METHOD(pb_tnc_message_t, get_type, pb_tnc_msg_type_t, + private_pb_reason_string_message_t *this) +{ + return this->type; +} + +METHOD(pb_tnc_message_t, get_encoding, chunk_t, + private_pb_reason_string_message_t *this) +{ + return this->encoding; +} + +METHOD(pb_tnc_message_t, build, void, + private_pb_reason_string_message_t *this) +{ + tls_writer_t *writer; + + /* build message */ + writer = tls_writer_create(REASON_STRING_HEADER_SIZE); + writer->write_uint32(writer, this->reason_string_length); + writer->write_data(writer, this->reason_string); + + writer->write_uint8(writer, this->language_code_length); + writer->write_data(writer, this->language_code); + + free(this->encoding.ptr); + this->encoding = writer->get_buf(writer); + this->encoding = chunk_clone(this->encoding); + writer->destroy(writer); +} + +METHOD(pb_tnc_message_t, process, status_t, + private_pb_reason_string_message_t *this) +{ + tls_reader_t *reader; + + if (this->encoding.len < REASON_STRING_HEADER_SIZE) + { + DBG1(DBG_TNC,"%N message is shorter than header size of %u bytes", + pb_tnc_msg_type_names, PB_MSG_REASON_STRING, + REASON_STRING_HEADER_SIZE); + return FAILED; + } + + /* process message */ + reader = tls_reader_create(this->encoding); + reader->read_uint32(reader, &this->reason_string_length); + reader->read_data(reader, this->reason_string_length, &this->reason_string); + + reader->read_uint8(reader, &this->language_code_length); + reader->read_data(reader, this->language_code_length, &this->language_code); + + reader->destroy(reader); + return SUCCESS; +} + +METHOD(pb_tnc_message_t, destroy, void, + private_pb_reason_string_message_t *this) +{ + free(this->encoding.ptr); + free(this->reason_string.ptr); + free(this->language_code.ptr); + free(this); +} + +METHOD(pb_reason_string_message_t, get_reason_string_length, u_int32_t, + private_pb_reason_string_message_t *this) +{ + return this->reason_string_length; +} + +METHOD(pb_reason_string_message_t, get_reason_string, chunk_t, + private_pb_reason_string_message_t *this) +{ + return this->reason_string; +} + +METHOD(pb_reason_string_message_t, get_language_code_length, u_int8_t, + private_pb_reason_string_message_t *this) +{ + return this->language_code_length; +} + +METHOD(pb_reason_string_message_t, get_language_code, chunk_t, + private_pb_reason_string_message_t *this) +{ + return this->language_code; +} + +/** + * See header + */ +pb_tnc_message_t *pb_reason_string_message_create_from_data(chunk_t data) +{ + private_pb_reason_string_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_reason_string_length = _get_reason_string_length, + .get_reason_string = _get_reason_string, + .get_language_code_length = _get_language_code_length, + .get_language_code = _get_language_code, + }, + .type = PB_MSG_REASON_STRING, + .encoding = chunk_clone(data), + ); + + return &this->public.pb_interface; +} + +/** + * See header + */ +pb_tnc_message_t *pb_reason_string_message_create(chunk_t reason_string, + chunk_t language_code) +{ + private_pb_reason_string_message_t *this; + + INIT(this, + .public = { + .pb_interface = { + .get_type = _get_type, + .get_encoding = _get_encoding, + .build = _build, + .process = _process, + .destroy = _destroy, + }, + .get_reason_string_length = _get_reason_string_length, + .get_reason_string = _get_reason_string, + .get_language_code_length = _get_language_code_length, + .get_language_code = _get_language_code, + }, + .type = PB_MSG_REASON_STRING, + .reason_string_length = reason_string.len, + .reason_string = reason_string, + .language_code_length = language_code.len, + .language_code = language_code, + ); + + return &this->public.pb_interface; +} diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_reason_string_message.h b/src/libcharon/plugins/tnccs_20/messages/pb_reason_string_message.h new file mode 100644 index 0000000000..c7c9a311a6 --- /dev/null +++ b/src/libcharon/plugins/tnccs_20/messages/pb_reason_string_message.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2010 Sansar Choinyambuu + * 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 . + * + * 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. + */ + +/** + * @defgroup pb_reason_string_message pb_reason_string_message + * @{ @ingroup tnccs_20 + */ + +#ifndef PB_REASON_STRING_MESSAGE_H_ +#define PB_REASON_STRING_MESSAGE_H_ + +#include "pb_tnc_message.h" + +typedef struct pb_reason_string_message_t pb_reason_string_message_t; + +/** + * Classs representing the PB-Reason-String message type. + */ +struct pb_reason_string_message_t { + + /** + * PB-TNC Message interface + */ + pb_tnc_message_t pb_interface; + + /** + * Get Reason String Length + * + * @return Length of reason string + */ + chunk_t (*get_reason_string_length)(pb_reason_string_message_t *this); + + /** + * Get Reason String + * + * @return Reason string + */ + chunk_t (*get_reason_string)(pb_reason_string_message_t *this); + + /** + * Get Reason String Language Code Length + * + * @return Length of language code + */ + chunk_t (*get_language_code_length)(pb_reason_string_message_t *this); + + /** + * Get Reason String Language Code + * + * @return Language code + */ + chunk_t (*get_language_code)(pb_reason_string_message_t *this); +}; + +/** + * Create a PB-Reason-String message from parameters + * + * @param reason_string Reason string + * @param language_code Language code + */ +pb_tnc_message_t* pb_reason_string_message_create(chunk_t reason_string, + chunk_t language_code); + +/** + * Create an unprocessed PB-Reason-String message from raw data + * + * @param data PB-Reason-String message data + */ +pb_tnc_message_t* pb_reason_string_message_create_from_data(chunk_t data); + +#endif /** PB_PA_MESSAGE_H_ @}*/ diff --git a/src/libcharon/plugins/tnccs_20/messages/pb_tnc_message.c b/src/libcharon/plugins/tnccs_20/messages/pb_tnc_message.c index 30cd32deab..de0e118ad1 100644 --- a/src/libcharon/plugins/tnccs_20/messages/pb_tnc_message.c +++ b/src/libcharon/plugins/tnccs_20/messages/pb_tnc_message.c @@ -15,6 +15,11 @@ #include "pb_tnc_message.h" #include "pb_pa_message.h" +#include "pb_error_message.h" +#include "pb_language_preference_message.h" +#include "pb_assessment_result_message.h" +#include "pb_access_recommendation_message.h" +#include "pb_reason_string_message.h" #include @@ -28,20 +33,19 @@ pb_tnc_message_t* pb_tnc_message_create(pb_tnc_msg_type_t type, chunk_t value) case PB_MSG_PA: return pb_pa_message_create_from_data(value); case PB_MSG_ERROR: - return NULL; /* TODO */ + return pb_error_message_create_from_data(value); case PB_MSG_EXPERIMENTAL: - return NULL; /* TODO */ + return NULL; case PB_MSG_LANGUAGE_PREFERENCE: - return NULL; /* TODO */ + return pb_language_preference_message_create_from_data(value); case PB_MSG_ASSESSMENT_RESULT: - return NULL; /* TODO */ + return pb_assessment_result_message_create_from_data(value); case PB_MSG_ACCESS_RECOMMENDATION: - return NULL; /* TODO */ + return pb_access_recommendation_message_create_from_data(value); case PB_MSG_REMEDIATION_PARAMETERS: - return NULL; /* TODO */ + return NULL; case PB_MSG_REASON_STRING: - return NULL; /* TODO */ + return pb_reason_string_message_create_from_data(value); } return NULL; } -