eapol/eapol_framework/eapol_common/type/tls_peap/tls/include/tls_record_message.h
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(_TLS_RECORD_MESSAGE_H_)
       
    22 #define _TLS_RECORD_MESSAGE_H_
       
    23 
       
    24 #include "eap_tools.h"
       
    25 #include "eap_array.h"
       
    26 #include "tls_record_header.h"
       
    27 #include "tls_handshake_message.h"
       
    28 #include "tls_change_cipher_spec_message.h"
       
    29 #include "tls_alert_message.h"
       
    30 #include "tls_application_data_message.h"
       
    31 #include "abs_tls_message_hash.h"
       
    32 
       
    33 
       
    34 /** @file */
       
    35 
       
    36 //----------------------------------------------------------------------------
       
    37 
       
    38 /**
       
    39  * This class defines one TLS record message.
       
    40  * Note the protocols are exclusive. Only one protocol is allowed in one record message.
       
    41  * The m_protocol attribute of m_tls_record_header attribute tells the used protocol.
       
    42  * Parse and analyse of TLS-records is asyncronous.
       
    43  * m_analyse_index tells the index of message where asyncronous
       
    44  * analyse of TLS-record must continue.
       
    45  * Analysed records are skipped during the asyncronous
       
    46  * analyse of records. Asyncronous analyse is needed
       
    47  * because of the PKI functions are asyncronous in
       
    48  * Symbian.
       
    49  */
       
    50 class EAP_EXPORT tls_record_message_c
       
    51 {
       
    52 private:
       
    53 	//--------------------------------------------------
       
    54 
       
    55 	/// This is pointer to the tools class. @see abs_eap_am_tools_c.
       
    56 	abs_eap_am_tools_c * const m_am_tools;
       
    57 
       
    58 	/// This is pointer to interface of message HASH creation. See abs_tls_message_hash_c.
       
    59 	abs_tls_message_hash_c * const m_message_hash;
       
    60 
       
    61 	/// This is the protocol of the TLS-record. See tls_record_protocol_e.
       
    62 	tls_record_protocol_e m_protocol;
       
    63 
       
    64 	/// This is the version of the TLS-record.
       
    65 	tls_version_e m_version;
       
    66 
       
    67 	/// This is the length of the data of the TLS-record, not including the header.
       
    68 	/// The length (in bytes) of the following TLSPlaintext.fragment (TLS-record data). The length should not exceed 2^14.
       
    69 	u32_t m_length;
       
    70 
       
    71 	/// This flag tells the TLS-record header is included to m_record_message_data.
       
    72 	bool m_tls_record_header_is_included;
       
    73 
       
    74 	/// This buffer is used both sent and received TLS-records.
       
    75 	/// This buffer includes reference to the record included in the whole received TLS-message (header+data) in tls_message_c.
       
    76 	/// This buffer includes whole data of TLS-record of sent TLS-message.
       
    77 	eap_variable_data_c m_record_message_data;
       
    78 
       
    79 	/// This is the index of message where asyncronous analyse of TLS-message must continue.
       
    80 	u32_t m_analyse_index;
       
    81 
       
    82 	/// This flag tells this record is parsed.
       
    83 	bool m_parsed_record;
       
    84 
       
    85 	/// This flag tells whether the cipher suite is applied to this record (true) or not (false).
       
    86 	bool m_cipher_suite_applied;
       
    87 
       
    88 	/// This array includes Handshake messages. There could be many handshake messages.
       
    89 	eap_array_c<tls_handshake_message_c> m_handshake_messages;
       
    90 	/// This array includes ChangeCipherSpec messages. Normally there should be only one message.
       
    91 	eap_array_c<tls_change_cipher_spec_message_c> m_change_cipher_spec_messages;
       
    92 	/// This array includes Alert messages. Normally there should be only one message.
       
    93 	eap_array_c<tls_alert_message_c> m_alert_messages;
       
    94 	/// This array includes Application data messages.
       
    95 	eap_array_c<tls_application_data_message_c> m_application_data_messages;
       
    96 
       
    97 	/// This indicates whether this object is client (true) or server (false). This is mostly for traces.
       
    98 	const bool m_is_client;
       
    99 
       
   100 	/// This indicates whether this object was generated successfully.
       
   101 	bool m_is_valid;
       
   102 
       
   103 	//--------------------------------------------------
       
   104 
       
   105 	/**
       
   106 	 * The set_is_valid() function sets the state of the object valid.
       
   107 	 * The creator of this object calls this function after it is initialized. 
       
   108 	 */
       
   109 	EAP_FUNC_IMPORT void set_is_valid();
       
   110 
       
   111 	//--------------------------------------------------
       
   112 protected:
       
   113 	//--------------------------------------------------
       
   114 
       
   115 	//--------------------------------------------------
       
   116 public:
       
   117 	//--------------------------------------------------
       
   118 
       
   119 	/**
       
   120 	 * The destructor of the tls_record_message_c class does nothing special.
       
   121 	 */
       
   122 	EAP_FUNC_IMPORT virtual ~tls_record_message_c();
       
   123 
       
   124 	/**
       
   125 	 * The constructor of the tls_record_c class simply initializes the attributes.
       
   126 	 */
       
   127 	EAP_FUNC_IMPORT tls_record_message_c(
       
   128 		abs_eap_am_tools_c * const tools,
       
   129 		abs_tls_message_hash_c * const message_hash,
       
   130 		const bool is_client);
       
   131 
       
   132 	/**
       
   133 	 * Object must indicate it's validity.
       
   134 	 * If object initialization fails this function must return false.
       
   135 	 * @return This function returns the validity of this object.
       
   136 	 */
       
   137 	EAP_FUNC_IMPORT bool get_is_valid();
       
   138 
       
   139 
       
   140 	/**
       
   141 	 * This function returns the index of message where analyse must continue.
       
   142 	 */
       
   143 	EAP_FUNC_IMPORT u32_t get_analyse_index() const;
       
   144 
       
   145 	/**
       
   146 	 * This function saves the index of message where analyse must continue.
       
   147 	 */
       
   148 	EAP_FUNC_IMPORT void save_analyse_index(const u32_t analyse_index);
       
   149 
       
   150 
       
   151 	/**
       
   152 	 * This function returns the flag that tells whether this record is parsed (true) or not (flase).
       
   153 	 */
       
   154 	EAP_FUNC_IMPORT bool get_parsed_record() const;
       
   155 
       
   156 	/**
       
   157 	 * This function sets the flag that tells this record is parsed.
       
   158 	 */
       
   159 	EAP_FUNC_IMPORT void set_parsed_record();
       
   160 
       
   161 
       
   162 	/**
       
   163 	 * This function returns the flag that tells whether the TLS-record header is included to m_record_message_data (true) or not (flase).
       
   164 	 */
       
   165 	EAP_FUNC_IMPORT bool get_tls_record_header_is_included() const;
       
   166 
       
   167 	/**
       
   168 	 * This function sets the flag that tells whether the TLS-record header is included to m_record_message_data (true) or not (flase).
       
   169 	 */
       
   170 	EAP_FUNC_IMPORT void set_tls_record_header_is_included(const bool when_true_tls_record_header_is_included);
       
   171 
       
   172 
       
   173 	/**
       
   174 	 * This function returns the flag that tells whether the cipher suite is applied to this record (true) or not (flase).
       
   175 	 */
       
   176 	EAP_FUNC_IMPORT bool get_cipher_suite_applied() const;
       
   177 
       
   178 	/**
       
   179 	 * This function sets the flag that tells the cipher suite is applied to this record.
       
   180 	 */
       
   181 	EAP_FUNC_IMPORT void set_cipher_suite_applied();
       
   182 
       
   183 
       
   184 	/**
       
   185 	 * This function sets the protocol of this record.
       
   186 	 */
       
   187 	EAP_FUNC_IMPORT eap_status_e set_protocol(
       
   188 		tls_record_protocol_e protocol);
       
   189 
       
   190 	/**
       
   191 	 * This function sets the version of TLS.
       
   192 	 */
       
   193 	EAP_FUNC_IMPORT eap_status_e set_version(
       
   194 		tls_version_e version);
       
   195 
       
   196 	/**
       
   197 	 * This function copies the appropriate fields of this record.
       
   198 	 */
       
   199 	EAP_FUNC_IMPORT eap_status_e set_record_header_copy(
       
   200 		const tls_record_header_c * const tls_record_header);
       
   201 
       
   202 	/**
       
   203 	 * This function sets the reference of TLS-record data.
       
   204 	 * NOTE this does not copy the message.
       
   205 	 */
       
   206 	EAP_FUNC_IMPORT eap_status_e set_record_message_data(
       
   207 			void * const data,
       
   208 			const u32_t data_length);
       
   209 
       
   210 	/**
       
   211 	 * This function returns the reference of TLS-record data.
       
   212 	 * NOTE this is not a copy of the message.
       
   213 	 */
       
   214 	EAP_FUNC_IMPORT eap_variable_data_c * get_record_message_data();
       
   215 
       
   216 	/**
       
   217 	 * This function returns the protocol of TLS-record.
       
   218 	 */
       
   219 	EAP_FUNC_IMPORT tls_record_protocol_e get_protocol() const;
       
   220 
       
   221 	/**
       
   222 	 * This function returns the version of TLS-record.
       
   223 	 */
       
   224 	EAP_FUNC_IMPORT tls_version_e get_version() const;
       
   225 
       
   226 	/**
       
   227 	 * This function returns the data length of TLS-record.
       
   228 	 */
       
   229 	EAP_FUNC_IMPORT u32_t get_data_length() const;
       
   230 
       
   231 	/**
       
   232 	 * This function adds the data length of TLS-record.
       
   233 	 */
       
   234 	EAP_FUNC_IMPORT eap_status_e add_data_length(const u32_t data_length);
       
   235 
       
   236 	/**
       
   237 	 * This function adds TLS-handshake message to this TLS-record.
       
   238 	 */
       
   239 	EAP_FUNC_IMPORT eap_status_e add_handshake_message(
       
   240 		tls_handshake_message_c * const handshake_message,
       
   241 		const bool free_handshake_message);
       
   242 
       
   243 	/**
       
   244 	 * This function adds TLS-change cipher spec message to this TLS-record.
       
   245 	 */
       
   246 	EAP_FUNC_IMPORT eap_status_e add_change_cipher_spec_message(
       
   247 		tls_change_cipher_spec_message_c * const change_cipher_spec_message,
       
   248 		const bool free_change_cipher_spec_message);
       
   249 
       
   250 	/**
       
   251 	 * This function adds TLS-alert message to this TLS-record.
       
   252 	 */
       
   253 	EAP_FUNC_IMPORT eap_status_e add_alert_message(
       
   254 		tls_alert_message_c * const alert_message,
       
   255 		const bool free_alert_message);
       
   256 
       
   257 	/**
       
   258 	 * This function adds TLS-application data message to this TLS-record.
       
   259 	 */
       
   260 	EAP_FUNC_IMPORT eap_status_e add_application_data_message(
       
   261 		tls_application_data_message_c * const alert_message,
       
   262 		const bool free_alert_message);
       
   263 
       
   264 	/**
       
   265 	 * This function adds data of every TLS-protocol message to internal message buffer (m_record_message_data).
       
   266 	 */
       
   267 	EAP_FUNC_IMPORT eap_status_e add_message_data();
       
   268 
       
   269 	/**
       
   270 	 * This function returns count of the TLS-handshake messages.
       
   271 	 */
       
   272 	EAP_FUNC_IMPORT u32_t get_handshake_count() const;
       
   273 
       
   274 	/**
       
   275 	 * This function returns count of the TLS-change cipher spec messages.
       
   276 	 */
       
   277 	EAP_FUNC_IMPORT u32_t get_change_cipher_spec_count() const;
       
   278 
       
   279 	/**
       
   280 	 * This function returns count of the TLS-alert messages.
       
   281 	 */
       
   282 	EAP_FUNC_IMPORT u32_t get_alert_count() const;
       
   283 
       
   284 	/**
       
   285 	 * This function returns count of the TLS-application data messages.
       
   286 	 */
       
   287 	EAP_FUNC_IMPORT u32_t get_application_data_count() const;
       
   288 
       
   289 	/**
       
   290 	 * This function returns the TLS-handshake message selected by index.
       
   291 	 */
       
   292 	EAP_FUNC_IMPORT tls_handshake_message_c * get_handshake(
       
   293 		const u32_t index) EAP_TEMPLATE_CONST;
       
   294 
       
   295 	/**
       
   296 	 * This function returns the TLS-change cipher spec message selected by index.
       
   297 	 */
       
   298 	EAP_FUNC_IMPORT const tls_change_cipher_spec_message_c * get_change_cipher_spec(
       
   299 		const u32_t index) const;
       
   300 
       
   301 	/**
       
   302 	 * This function returns the TLS-alert message selected by index.
       
   303 	 */
       
   304 	EAP_FUNC_IMPORT const tls_alert_message_c * get_alert(
       
   305 		const u32_t index) const;
       
   306 
       
   307 	/**
       
   308 	 * This function returns the TLS-application data message selected by index.
       
   309 	 */
       
   310 	EAP_FUNC_IMPORT tls_application_data_message_c * get_application_data(
       
   311 		const u32_t index) const;
       
   312 
       
   313 	// 
       
   314 	//--------------------------------------------------
       
   315 }; // class tls_record_message_c
       
   316 
       
   317 
       
   318 //--------------------------------------------------
       
   319 
       
   320 #endif //#if !defined(_TLS_RECORD_MESSAGE_H_)
       
   321 
       
   322 
       
   323 
       
   324 // End.