|
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_HEADER_H_) |
|
22 #define _TLS_RECORD_HEADER_H_ |
|
23 |
|
24 #include "eap_tools.h" |
|
25 #include "eap_header.h" |
|
26 #include "eap_general_header_base.h" |
|
27 |
|
28 /** @file */ |
|
29 |
|
30 |
|
31 /** |
|
32 * This is enumeration of TLS-versions. |
|
33 */ |
|
34 enum tls_version_e |
|
35 { |
|
36 tls_version_illegal = 0x0000, |
|
37 tls_version_3_1 = 0x0301, |
|
38 tls_version_last = 0x0301, ///< keep this same as the last acceptable version. |
|
39 }; |
|
40 |
|
41 |
|
42 /** |
|
43 * This is enumeration of TLS-record protocols. |
|
44 */ |
|
45 enum tls_record_protocol_e |
|
46 { |
|
47 tls_record_protocol_change_cipher_spec = (20), ///< This is change cipher spec. |
|
48 tls_record_protocol_alert = (21), ///< This is alert. |
|
49 tls_record_protocol_handshake = (22), ///< This is handshake. |
|
50 tls_record_protocol_application_data = (23), ///< This is application data. |
|
51 tls_record_protocol_none = (255), ///< This is initialization value. Meaning is no protocol selected. |
|
52 }; |
|
53 |
|
54 |
|
55 //---------------------------------------------------------------------------- |
|
56 |
|
57 |
|
58 /// This class defines header of TLS record. |
|
59 /** |
|
60 * Here is a figure of header of TLS record. |
|
61 * TLS-record data follows tls_record_header_c. |
|
62 * @code |
|
63 * TLS record-header: |
|
64 * 0 1 2 3 |
|
65 * 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 |
|
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
67 * | Protocol: aa | Version: 3 | Version: 1 | Length: m | |
|
68 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
69 * | Length: n | |
|
70 * +-+-+-+-+-+-+-+-+ |
|
71 * @endcode |
|
72 * |
|
73 * @code |
|
74 * The fields of this header are: |
|
75 * 8-bits m_protocol; This is a TLS-protocol field. |
|
76 * 16-bits m_version; This is a TLS-version. |
|
77 * 16-bits m_length; This is a length field. The length (in bytes) of |
|
78 * the following TLSPlaintext.fragment (TLS-record data). |
|
79 * The length should not exceed 2^14. |
|
80 * @endcode |
|
81 * |
|
82 */ |
|
83 class EAP_EXPORT tls_record_header_c |
|
84 : public eap_general_header_base_c |
|
85 { |
|
86 private: |
|
87 //-------------------------------------------------- |
|
88 |
|
89 /// This is pointer to the tools class. |
|
90 abs_eap_am_tools_c * const m_am_tools; |
|
91 |
|
92 //-------------------------------------------------- |
|
93 protected: |
|
94 //-------------------------------------------------- |
|
95 |
|
96 enum offsets |
|
97 { |
|
98 m_protocol_offset = 0ul, ///< This is offset of the protocol 8-bit field. |
|
99 m_version_offset = m_protocol_offset+sizeof(u8_t), ///< This is offset of the version 16-bit field. |
|
100 m_length_offset = m_version_offset+sizeof(u16_t), ///< This is offset of the length 16-bit field. |
|
101 m_data_offset = m_length_offset+sizeof(u16_t), ///< This is offset of the data of TLS-record. |
|
102 }; |
|
103 |
|
104 //-------------------------------------------------- |
|
105 public: |
|
106 //-------------------------------------------------- |
|
107 |
|
108 /// Destructor does nothing. |
|
109 virtual ~tls_record_header_c(); |
|
110 |
|
111 /// Constructor initializes the class. |
|
112 tls_record_header_c( |
|
113 abs_eap_am_tools_c * const tools, |
|
114 void * const header_buffer, |
|
115 const u32_t header_buffer_length); |
|
116 |
|
117 /// This function returns protocol of the TLS-record. |
|
118 tls_record_protocol_e get_protocol() const; |
|
119 |
|
120 /// This function returns version of the TLS-record. |
|
121 tls_version_e get_version() const; |
|
122 |
|
123 /// This function returns data length of the TLS-record. |
|
124 /// The length (in bytes) of the following TLSPlaintext.fragment (TLS-record data). The length should not exceed 2^14. |
|
125 u16_t get_data_length() const; |
|
126 |
|
127 /// This function returns header length of the TLS-record. This includes only protocol, version and length fiels. |
|
128 static u32_t get_header_length(); |
|
129 |
|
130 /// This function returns pointer to offset of the TLS-record data. |
|
131 /// @param offset is the offset of queried data in bytes. |
|
132 /// @param contignuous_bytes is the length of queried data in bytes. |
|
133 u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const; |
|
134 |
|
135 |
|
136 /// This function returns pointer to begin of the TLS-record data. |
|
137 /// @param contignuous_bytes is the length of queried data in bytes. |
|
138 u8_t * get_data(const u32_t contignuous_bytes) const; |
|
139 |
|
140 |
|
141 static eap_const_string get_tls_protocol_string(const tls_record_protocol_e protocol); |
|
142 |
|
143 /// This function returns debug strings of the TLS-protocol values. |
|
144 eap_const_string get_tls_protocol_string() const; |
|
145 |
|
146 /// This function sets the protocol of TLS-record. |
|
147 void set_protocol(tls_record_protocol_e protocol); |
|
148 |
|
149 /// This function sets the version of the TLS-record. |
|
150 void set_version(tls_version_e version); |
|
151 |
|
152 /// This function sets the data length of the TLS-record. |
|
153 void set_data_length(const u16_t p_length); |
|
154 |
|
155 /// This function resets the TLS-record header. |
|
156 void reset_header( |
|
157 const u16_t buffer_length, |
|
158 const tls_version_e version); |
|
159 |
|
160 /// This function checks the header is valid. |
|
161 eap_status_e check_header() const; |
|
162 |
|
163 // |
|
164 //-------------------------------------------------- |
|
165 }; // class tls_record_header_c |
|
166 |
|
167 |
|
168 //-------------------------------------------------- |
|
169 |
|
170 #endif //#if !defined(_TLS_RECORD_HEADER_H_) |
|
171 |
|
172 |
|
173 |
|
174 // End. |