eapol/eapol_framework/eapol_common/type/mschapv2/include/eap_type_mschapv2_header.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 #ifndef _MSCHAPV2_HEADER_H_
       
    21 #define _MSCHAPV2_HEADER_H_
       
    22 
       
    23 #include "eap_am_tools.h"
       
    24 
       
    25 #include "eap_tools.h"
       
    26 #include "eap_general_header_base.h"
       
    27 
       
    28 enum eap_mschapv2_version
       
    29 {
       
    30 	MSCHAPV2_ILLEGAL_VERSION = 0x0000,
       
    31 	MSCHAPV2_VERSION_1       = 0x0001,
       
    32 	MSCHAPV2_LAST_VERSION    = 0x0001  ///< Keep this same as the last acceptable version.
       
    33 };
       
    34 
       
    35 enum mschapv2_opcode_e
       
    36 {
       
    37 	mschapv2_opcode_challenge         =  1,
       
    38 	mschapv2_opcode_response          =  2,
       
    39 	mschapv2_opcode_success           =  3,
       
    40 	mschapv2_opcode_failure           =  4,
       
    41 	mschapv2_opcode_change_password   =  7,
       
    42 	mschapv2_opcode_unknown           =  255 // Internal error
       
    43 };
       
    44 
       
    45 /// This class defines header of MS-CHAP-v2 EAP-type.
       
    46 /**
       
    47  * Here is a figure of header of MS-CHAP-v2 EAP-type.
       
    48  * Data is m_eap_length - sizeof(mschapv2_header_c) data octets that follows mschapv2_header_c.
       
    49  * @code
       
    50  *
       
    51  *   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
       
    52  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    53  *  |     Code      |   Identifier  |            Length             |
       
    54  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    55  *  |     Type=29   |   OpCode      |  MS-CHAPv2-ID |  MS-Length...
       
    56  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    57  *  |   MS-Length   |     Data...
       
    58  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    59  * @endcode
       
    60  */
       
    61 class EAP_EXPORT mschapv2_header_c
       
    62 : public eap_general_header_base_c
       
    63 {
       
    64 private:
       
    65 
       
    66 	abs_eap_am_tools_c * const m_am_tools;
       
    67 
       
    68 	u32_t m_length;
       
    69 
       
    70 protected:
       
    71 
       
    72 	enum offsets
       
    73 	{
       
    74 		m_opcode_offset = 0ul,
       
    75 		m_mschapv2_id_offset = m_opcode_offset + sizeof(u8_t),
       
    76 		m_ms_length_offset = m_mschapv2_id_offset + sizeof(u8_t),
       
    77 		m_data_offset = m_ms_length_offset + sizeof(u16_t)
       
    78 	};
       
    79 
       
    80 public:
       
    81 
       
    82 	EAP_FUNC_IMPORT virtual ~mschapv2_header_c();
       
    83 
       
    84 	EAP_FUNC_IMPORT mschapv2_header_c(
       
    85 		abs_eap_am_tools_c * const tools,
       
    86 		void * const header_buffer,
       
    87 		const u32_t header_buffer_length);
       
    88 
       
    89 	EAP_FUNC_IMPORT mschapv2_opcode_e get_opcode() const;
       
    90 
       
    91 	EAP_FUNC_IMPORT void set_opcode(const mschapv2_opcode_e p_opcode);
       
    92 
       
    93 	EAP_FUNC_IMPORT u8_t get_mschapv2_id() const;
       
    94 
       
    95 	EAP_FUNC_IMPORT void set_mschapv2_id(u8_t p_id);
       
    96 
       
    97 	EAP_FUNC_IMPORT u16_t get_ms_length() const;
       
    98 
       
    99 	EAP_FUNC_IMPORT void set_ms_length(u16_t p_length);
       
   100 
       
   101 	EAP_FUNC_IMPORT u8_t * get_data() const;
       
   102 
       
   103 	EAP_FUNC_IMPORT u32_t get_data_length() const;
       
   104 
       
   105 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   106 
       
   107 }; // class mschapv2_header_c
       
   108 
       
   109 //--------------------------------------------------
       
   110 
       
   111 /// This class defines Challenge payload of MS-CHAP-v2.
       
   112 /**
       
   113  * Here is a figure of Challenge payload of MS-CHAP-v2.
       
   114  * @code
       
   115  *
       
   116  *   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
       
   117  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   118  *  |  Value Size   |   Challenge 16 octets                         |
       
   119  *  +-+-+-+-+-+-+-+-+-+-+-+-                                 -+-+-+-+
       
   120  *  |                                                               |
       
   121  *  +-+-+-+-                                                 -+-+-+-+
       
   122  *  |                                                               |
       
   123  *  +-+-+-+-                                                 -+-+-+-+
       
   124  *  |                                                               |
       
   125  *  +-+-         -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   126  *  |               |     Name ...
       
   127  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   128  * @endcode
       
   129  */
       
   130 class EAP_EXPORT mschapv2_challenge_c
       
   131 : public eap_general_header_base_c
       
   132 {
       
   133 private:
       
   134 
       
   135 	abs_eap_am_tools_c * const m_am_tools;
       
   136 
       
   137 	u32_t m_length;
       
   138 
       
   139 protected:
       
   140 
       
   141 	enum offsets
       
   142 	{
       
   143 		m_value_size_offset = 0ul,
       
   144 		m_challenge_offset = m_value_size_offset + sizeof(u8_t),
       
   145 		m_name_offset = m_challenge_offset + 16 * sizeof(u8_t),
       
   146 	};
       
   147 
       
   148 public:
       
   149 
       
   150 	EAP_FUNC_IMPORT virtual ~mschapv2_challenge_c();
       
   151 
       
   152 	EAP_FUNC_IMPORT mschapv2_challenge_c(
       
   153 		abs_eap_am_tools_c * const tools,
       
   154 		void * const header_buffer,
       
   155 		const u32_t header_buffer_length);
       
   156 
       
   157 	EAP_FUNC_IMPORT static u32_t get_header_minimum_size();
       
   158 
       
   159 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   160 
       
   161 	EAP_FUNC_IMPORT void set_value_size();
       
   162 
       
   163 	EAP_FUNC_IMPORT const u8_t * get_challenge() const;
       
   164 
       
   165 	EAP_FUNC_IMPORT void set_challenge(const u8_t * const p_challenge);
       
   166 
       
   167 	EAP_FUNC_IMPORT const u8_t * get_name() const;
       
   168 
       
   169 	EAP_FUNC_IMPORT u32_t get_name_length() const;
       
   170 
       
   171 	EAP_FUNC_IMPORT void set_name(const u8_t * const p_name);
       
   172 }; // class mschapv2_challenge_c
       
   173 
       
   174 //--------------------------------------------------
       
   175 
       
   176 /// This class defines Change Password payload of MS-CHAP-v2.
       
   177 /**
       
   178  * Here is a figure of Change Password payload of MS-CHAP-v2.
       
   179  * @code
       
   180  *
       
   181  *   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
       
   182  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   183  *  |  Encrypted Block 516 octets                                   |
       
   184  *  +-+-+-+-                                                 -+-+-+-+
       
   185  *  |                                                               |
       
   186  *  +-+-+-+-                                                 -+-+-+-+
       
   187  *  .                                                               .
       
   188  *  .                                                               .
       
   189  *  .                                                               .
       
   190  *  +-+-+-+-                                                 -+-+-+-+
       
   191  *  |                                                               |
       
   192  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   193  *  |   Encrypted Hash 16 octets                                    |
       
   194  *  +-+-+-+-                                                 -+-+-+-+
       
   195  *  |                                                               |
       
   196  *  +-+-+-+-                                                 -+-+-+-+
       
   197  *  |                                                               |
       
   198  *  +-+-+-+-                                                 -+-+-+-+
       
   199  *  |                                                               |
       
   200  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   201  *  |   Peer Challenge 16 octets                                    |
       
   202  *  +-+-+-+-                                                 -+-+-+-+
       
   203  *  |                                                               |
       
   204  *  +-+-+-+-                                                 -+-+-+-+
       
   205  *  |                                                               |
       
   206  *  +-+-+-+-                                                 -+-+-+-+
       
   207  *  |                                                               |
       
   208  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   209  *  |    Reserved 8 octets                                          |
       
   210  *  +-+-+-+-                                                 -+-+-+-+
       
   211  *  |                                                               |
       
   212  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   213  *  |    NT Response 24 octets                                      |
       
   214  *  +-+-+-+-                                                 -+-+-+-+
       
   215  *  |                                                               |
       
   216  *  +-+-+-+-                                                 -+-+-+-+
       
   217  *  |                                                               |
       
   218  *  +-+-+-+-                                                 -+-+-+-+
       
   219  *  |                                                               |
       
   220  *  +-+-+-+-                                                 -+-+-+-+
       
   221  *  |                                                               |
       
   222  *  +-+-+-+-                                                 -+-+-+-+
       
   223  *  |                                                               |
       
   224  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   225  *  |    Flags      |
       
   226  *  +-+-+-+-+-+-+-+-+
       
   227  * @endcode
       
   228  */
       
   229 class EAP_EXPORT mschapv2_change_password_c
       
   230 : public eap_general_header_base_c
       
   231 {
       
   232 private:
       
   233 
       
   234 	abs_eap_am_tools_c * const m_am_tools;
       
   235 
       
   236 	u32_t m_length;
       
   237 
       
   238 protected:
       
   239 
       
   240 	enum offsets
       
   241 	{
       
   242 		m_encrypted_pw_block_offset = 0ul,
       
   243 		m_encrypted_hash_offset = m_encrypted_pw_block_offset + 516 * sizeof(u8_t),
       
   244 		m_peer_challenge_offset = m_encrypted_hash_offset + 16 * sizeof(u8_t),
       
   245 		m_reserved_offset = m_peer_challenge_offset + 16 * sizeof(u8_t),
       
   246 		m_nt_response_offset = m_reserved_offset + 8 * sizeof(u8_t),
       
   247 		m_flags_offset = m_nt_response_offset + 24 * sizeof(u8_t),
       
   248 	};
       
   249 
       
   250 public:
       
   251 
       
   252 	EAP_FUNC_IMPORT virtual ~mschapv2_change_password_c();
       
   253 
       
   254 	EAP_FUNC_IMPORT mschapv2_change_password_c(
       
   255 		abs_eap_am_tools_c * const tools,
       
   256 		void * const header_buffer,
       
   257 		const u32_t header_buffer_length);
       
   258 
       
   259 	EAP_FUNC_IMPORT static u32_t get_header_minimum_size();
       
   260 
       
   261 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   262 
       
   263 	EAP_FUNC_IMPORT const u8_t * get_encrypted_pw_block() const;
       
   264 
       
   265 	EAP_FUNC_IMPORT void set_encrypted_pw_block(const u8_t * const p_encrypted_pw_block);
       
   266 
       
   267 	EAP_FUNC_IMPORT const u8_t * get_encrypted_hash() const;
       
   268 
       
   269 	EAP_FUNC_IMPORT void set_encrypted_hash(const u8_t * const p_encrypted_hash);
       
   270 
       
   271 	EAP_FUNC_IMPORT const u8_t * get_peer_challenge() const;
       
   272 
       
   273 	EAP_FUNC_IMPORT void set_peer_challenge(const u8_t * const p_peer_challenge);
       
   274 
       
   275 	EAP_FUNC_IMPORT const u8_t * get_nt_response() const;
       
   276 
       
   277 	EAP_FUNC_IMPORT void set_nt_response(const u8_t * const p_nt_response);
       
   278 
       
   279 	EAP_FUNC_IMPORT eap_status_e set_constants();
       
   280 }; // class mschapv2_change_password_c
       
   281 
       
   282 //--------------------------------------------------
       
   283 
       
   284 /// This class defines Response payload of MS-CHAP-v2.
       
   285 /**
       
   286  * Here is a figure of Response payload of MS-CHAP-v2.
       
   287  * @code
       
   288  *
       
   289  *   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
       
   290  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   291  *  |  Value Size   |   Peer Challenge 16 octets                    |
       
   292  *  +-+-+-+-+-+-+-+-+-+-+-+-                                 -+-+-+-+
       
   293  *  |                                                               |
       
   294  *  +-+-+-+-                                                 -+-+-+-+
       
   295  *  |                                                               |
       
   296  *  +-+-+-+-                                                 -+-+-+-+
       
   297  *  |                                                               |
       
   298  *  +-+-         -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   299  *  |               |     Reserved 8 octets                         |
       
   300  *  +-+-+-+-+-+-+-+-+-+-+-                                   -+-+-+-+
       
   301  *  |                                                               |
       
   302  *  +-+-         -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   303  *  |               |     NT Response 24 octets                     |
       
   304  *  +-+-+-+-+-+-+-+-+-+-+-                                   -+-+-+-+
       
   305  *  |                                                               |
       
   306  *  +-+-+-+-                                                 -+-+-+-+
       
   307  *  |                                                               |
       
   308  *  +-+-+-+-                                                 -+-+-+-+
       
   309  *  |                                                               |
       
   310  *  +-+-+-+-                                                 -+-+-+-+
       
   311  *  |                                                               |
       
   312  *  +-+-+-+-                                                 -+-+-+-+
       
   313  *  |                                                               |
       
   314  *  +-+-         -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   315  *  |               |    Flags      |   Name ...                   
       
   316  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
       
   317  * @endcode
       
   318  */
       
   319 class EAP_EXPORT mschapv2_response_c
       
   320 : public eap_general_header_base_c
       
   321 {
       
   322 private:
       
   323 
       
   324 	abs_eap_am_tools_c * const m_am_tools;
       
   325 
       
   326 	u32_t m_length;
       
   327 
       
   328 protected:
       
   329 
       
   330 	enum offsets
       
   331 	{
       
   332 		m_value_size_offset = 0ul,
       
   333 		m_peer_challenge_offset = m_value_size_offset + sizeof(u8_t),
       
   334 		m_reserved_offset = m_peer_challenge_offset + 16 * sizeof(u8_t),
       
   335 		m_nt_response_offset = m_reserved_offset + 8 * sizeof(u8_t),
       
   336 		m_flags_offset = m_nt_response_offset + 24 * sizeof(u8_t),
       
   337 		m_name_offset = m_flags_offset + sizeof(u8_t)
       
   338 	};
       
   339 
       
   340 public:
       
   341 
       
   342 	EAP_FUNC_IMPORT virtual ~mschapv2_response_c();
       
   343 
       
   344 	EAP_FUNC_IMPORT mschapv2_response_c(
       
   345 		abs_eap_am_tools_c * const tools,
       
   346 		void * const header_buffer,
       
   347 		const u32_t header_buffer_length);
       
   348 
       
   349 	EAP_FUNC_IMPORT static u32_t get_header_minimum_size();
       
   350 
       
   351 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   352 
       
   353 	EAP_FUNC_IMPORT const u8_t * get_peer_challenge() const;
       
   354 
       
   355 	EAP_FUNC_IMPORT void set_peer_challenge(const u8_t * const p_challenge);
       
   356 
       
   357 	EAP_FUNC_IMPORT const u8_t * get_nt_response() const;
       
   358 
       
   359 	EAP_FUNC_IMPORT void set_nt_response(const u8_t * const p_challenge);
       
   360 
       
   361 	EAP_FUNC_IMPORT const u8_t * get_name() const;
       
   362 
       
   363 	EAP_FUNC_IMPORT u32_t get_name_length() const;
       
   364 
       
   365 	EAP_FUNC_IMPORT void set_name(const u8_t * const p_name);
       
   366 
       
   367 	EAP_FUNC_IMPORT eap_status_e set_constants();
       
   368 }; // class mschapv2_response_c
       
   369 
       
   370 //--------------------------------------------------
       
   371 
       
   372 #endif //_MSCHAPV2_HEADER_H_
       
   373 
       
   374 // End of File