|
1 /* |
|
2 * Copyright (c) 2009 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 "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: Class to represent IKEv2 payloads and to construct IKEv2 datagrams |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef IKEV2MESSAGE_H_ |
|
19 #define IKEV2MESSAGE_H_ |
|
20 |
|
21 #include <e32base.h> |
|
22 |
|
23 class CIkeCaList; |
|
24 class CDesC8Array; |
|
25 class TIkeV2TrafficSelector; |
|
26 class CIkeV2Identity; |
|
27 |
|
28 NONSHARABLE_CLASS(CIkeV2Payload) : public CBase |
|
29 { |
|
30 public: |
|
31 ~CIkeV2Payload(); |
|
32 |
|
33 TUint8 NextPayload() const; |
|
34 void SetNextPayload(TUint8 aNextPayload); |
|
35 |
|
36 TUint16 PayloadLength() const; |
|
37 void SetPayloadLength(TUint16 aLength); |
|
38 |
|
39 TPtrC8 PayloadData() const; |
|
40 TUint8 PayloadType() const; |
|
41 |
|
42 protected: |
|
43 CIkeV2Payload(TUint8 aPayloadType); |
|
44 |
|
45 HBufC8* iPayloadData; |
|
46 |
|
47 private: |
|
48 TUint8 iPayloadType; |
|
49 }; |
|
50 |
|
51 |
|
52 NONSHARABLE_CLASS(CIkevV2CertReqPayload) : public CIkeV2Payload |
|
53 { |
|
54 public: |
|
55 static CIkevV2CertReqPayload* NewL(const CIkeCaList& aCaList); |
|
56 |
|
57 private: |
|
58 CIkevV2CertReqPayload(); |
|
59 void ConstructL(const CIkeCaList& aCaList); |
|
60 }; |
|
61 |
|
62 NONSHARABLE_CLASS(CIkevV2CertPayload) : public CIkeV2Payload |
|
63 { |
|
64 public: |
|
65 static CIkevV2CertPayload* NewL(const TDesC8& aCertData); |
|
66 |
|
67 private: |
|
68 CIkevV2CertPayload(); |
|
69 void ConstructL(const TDesC8& aCertData); |
|
70 }; |
|
71 |
|
72 |
|
73 |
|
74 NONSHARABLE_CLASS(CIkevV2SaPayload) : public CIkeV2Payload |
|
75 { |
|
76 public: |
|
77 static CIkevV2SaPayload* NewL(const TDesC8& aSaData); |
|
78 |
|
79 private: |
|
80 CIkevV2SaPayload(); |
|
81 void ConstructL(const TDesC8& aSaData); |
|
82 |
|
83 }; |
|
84 |
|
85 |
|
86 NONSHARABLE_CLASS(CIkevV2KePayload) : public CIkeV2Payload |
|
87 { |
|
88 public: |
|
89 static CIkevV2KePayload* NewL(TUint16 aDHGroup, const TDesC8& aKeData); |
|
90 |
|
91 private: |
|
92 CIkevV2KePayload(); |
|
93 void ConstructL(TUint16 aDHGroup, const TDesC8& aKeData); |
|
94 }; |
|
95 |
|
96 |
|
97 NONSHARABLE_CLASS(CIkevV2NoncePayload) : public CIkeV2Payload |
|
98 { |
|
99 public: |
|
100 static CIkevV2NoncePayload* NewL(const TDesC8& aNonceData); |
|
101 |
|
102 private: |
|
103 CIkevV2NoncePayload(); |
|
104 void ConstructL(const TDesC8& aNonceData); |
|
105 }; |
|
106 |
|
107 |
|
108 NONSHARABLE_CLASS(CIkevV2IdPayload) : public CIkeV2Payload |
|
109 { |
|
110 protected: |
|
111 CIkevV2IdPayload(TUint8 aPayloadType); |
|
112 void ConstructL(const CIkeV2Identity& aIdentity); |
|
113 }; |
|
114 |
|
115 NONSHARABLE_CLASS(CIkevV2IdiPayload) : public CIkevV2IdPayload |
|
116 { |
|
117 public: |
|
118 static CIkevV2IdiPayload* NewL(const CIkeV2Identity& aIdentity); |
|
119 |
|
120 private: |
|
121 CIkevV2IdiPayload(); |
|
122 }; |
|
123 |
|
124 |
|
125 NONSHARABLE_CLASS(CIkevV2IdrPayload) : public CIkevV2IdPayload |
|
126 { |
|
127 public: |
|
128 static CIkevV2IdrPayload* NewL(const CIkeV2Identity& aIdentity); |
|
129 |
|
130 private: |
|
131 CIkevV2IdrPayload(); |
|
132 }; |
|
133 |
|
134 |
|
135 NONSHARABLE_CLASS(CIkeV2AuthPayload) : public CIkeV2Payload |
|
136 { |
|
137 public: |
|
138 static CIkeV2AuthPayload* NewL(TUint8 aAuthMethod, const TDesC8& aAuthData); |
|
139 |
|
140 private: |
|
141 CIkeV2AuthPayload(); |
|
142 void ConstructL(TUint8 aAuthMethod, const TDesC8& aAuthData); |
|
143 }; |
|
144 |
|
145 |
|
146 NONSHARABLE_CLASS(CIkeV2NotifyPayload) : public CIkeV2Payload |
|
147 { |
|
148 public: |
|
149 static CIkeV2NotifyPayload* NewL(TUint8 aProtocolId, |
|
150 const TDesC8& aSpi, |
|
151 TUint16 aNotifyType, |
|
152 const TDesC8& aNotifyData); |
|
153 |
|
154 private: |
|
155 CIkeV2NotifyPayload(); |
|
156 void ConstructL(TUint8 aProtocolId, |
|
157 const TDesC8& aSpi, |
|
158 TUint16 aNotifyType, |
|
159 const TDesC8& aNotifyData); |
|
160 }; |
|
161 |
|
162 |
|
163 NONSHARABLE_CLASS(CIkeV2ConfigurationPayload) : public CIkeV2Payload |
|
164 { |
|
165 public: |
|
166 static CIkeV2ConfigurationPayload* NewL(TUint8 aCfgType, |
|
167 const TDesC8& aConfigurationData); |
|
168 |
|
169 private: |
|
170 CIkeV2ConfigurationPayload(); |
|
171 void ConstructL(TUint8 aCfgType, |
|
172 const TDesC8& aConfigurationData); |
|
173 }; |
|
174 |
|
175 |
|
176 NONSHARABLE_CLASS(CIkeV2VendorIdPayload) : public CIkeV2Payload |
|
177 { |
|
178 public: |
|
179 static CIkeV2VendorIdPayload* NewL(const TDesC8& aVendorIdData); |
|
180 |
|
181 private: |
|
182 CIkeV2VendorIdPayload(); |
|
183 void ConstructL(const TDesC8& aVendorIdData); |
|
184 }; |
|
185 |
|
186 |
|
187 NONSHARABLE_CLASS(CIkeV2DeletePayload) : public CIkeV2Payload |
|
188 { |
|
189 public: |
|
190 static CIkeV2DeletePayload* NewL(TUint8 aProtocolId, const CDesC8Array& aSpiList); |
|
191 |
|
192 private: |
|
193 CIkeV2DeletePayload(); |
|
194 void ConstructL(TUint8 aProtocolId, const CDesC8Array& aSpiList); |
|
195 }; |
|
196 |
|
197 |
|
198 NONSHARABLE_CLASS(CIkeV2EapPayload) : public CIkeV2Payload |
|
199 { |
|
200 public: |
|
201 static CIkeV2EapPayload* NewL(const TDesC8& aEapData); |
|
202 |
|
203 private: |
|
204 CIkeV2EapPayload(); |
|
205 void ConstructL(const TDesC8& aEapData); |
|
206 }; |
|
207 |
|
208 |
|
209 NONSHARABLE_CLASS(CIkeV2TsPayload) : public CIkeV2Payload |
|
210 { |
|
211 protected: |
|
212 CIkeV2TsPayload(TUint aPayloadType); |
|
213 void ConstructL(const CArrayFix<TIkeV2TrafficSelector>& aTsList); |
|
214 }; |
|
215 |
|
216 class CIkeV2TsiPayload : public CIkeV2TsPayload |
|
217 { |
|
218 public: |
|
219 static CIkeV2TsiPayload* NewL(const CArrayFix<TIkeV2TrafficSelector>& aTsList); |
|
220 |
|
221 private: |
|
222 CIkeV2TsiPayload(); |
|
223 }; |
|
224 |
|
225 NONSHARABLE_CLASS(CIkeV2TsrPayload) : public CIkeV2TsPayload |
|
226 { |
|
227 public: |
|
228 static CIkeV2TsrPayload* NewL(const CArrayFix<TIkeV2TrafficSelector>& aTsList); |
|
229 |
|
230 private: |
|
231 CIkeV2TsrPayload(); |
|
232 }; |
|
233 |
|
234 |
|
235 NONSHARABLE_CLASS(CIkeV2EncryptedPayload) : public CIkeV2TsPayload |
|
236 { |
|
237 public: |
|
238 static CIkeV2EncryptedPayload* NewL(TUint aBlockSize); |
|
239 |
|
240 TUint BlockSize() const; |
|
241 TPtrC8 InitializationVector() const; |
|
242 |
|
243 void SetContentLength(TUint16 aLength); |
|
244 private: |
|
245 CIkeV2EncryptedPayload(); |
|
246 void ConstructL(TUint aBlockSize); |
|
247 |
|
248 TUint iBlockSize; |
|
249 }; |
|
250 |
|
251 class MIkeDebug; |
|
252 class TInetAddr; |
|
253 |
|
254 NONSHARABLE_CLASS(CIkeV2Message) : public CBase |
|
255 { |
|
256 public: |
|
257 |
|
258 /** |
|
259 * Constructs new IKE message. |
|
260 * |
|
261 * @param aInitiatorSpi Initiator SPI |
|
262 * @param aResponderSpi Responder SPI |
|
263 * @param aExchangeType Type of the exchange. Possible values are: |
|
264 * IKE_SA_INIT, IKE_AUTH, CREATE_CHILD_SA and INFORMATIONAL. |
|
265 * @param aFlags Message flags. Possible flags are: |
|
266 * IKEV2_INITIATOR and IKEV2_RESPONSE_MSG. |
|
267 */ |
|
268 static CIkeV2Message* NewL(const TDesC8& aInitiatorSpi, |
|
269 const TDesC8& aResponderSpi, |
|
270 TUint8 aExchangeType, |
|
271 TBool aIntiator, |
|
272 TBool aResponse, |
|
273 TUint32 aMessageId, |
|
274 MIkeDebug& aDebug); |
|
275 ~CIkeV2Message(); |
|
276 |
|
277 TPtrC8 InitiatorSpi()const; |
|
278 TPtrC8 ResponderSpi() const; |
|
279 |
|
280 TUint8 NextPayload() const; |
|
281 |
|
282 TUint8 MajorVersion() const; |
|
283 TUint8 MinorVersion() const; |
|
284 |
|
285 TUint8 ExchangeType() const; |
|
286 |
|
287 TUint8 Flags() const; |
|
288 |
|
289 TUint32 MessageId() const; |
|
290 |
|
291 TUint32 Length() const; |
|
292 |
|
293 void AppendCertReqPayloadL(const CIkeCaList& aCaList); |
|
294 void AppendCertPayloadL(const TDesC8& aCertificateData); |
|
295 void AppendSaPayloadL(const TDesC8& aSaData); |
|
296 void AppendKePayloadL(TUint16 aDHGroup, const TDesC8& aKeData); |
|
297 void AppendNoncePayloadL(const TDesC8& aNonceData); |
|
298 void AppendIdiPayloadL(const CIkeV2Identity& aIdentity); |
|
299 void AppendIdrPayloadL(const CIkeV2Identity& aIdentity); |
|
300 void AppendAuthPayloadL(TUint8 aAuthMethod, const TDesC8& aAuthData); |
|
301 void AppendNotifyPayloadL(TUint8 aProtocolId, |
|
302 const TDesC8& aSpi, |
|
303 TUint16 aNotifyType, |
|
304 const TDesC8& aNotifyData); |
|
305 |
|
306 /** |
|
307 * A special method for adding a cookie notify in the |
|
308 * beginning of an existing ike message. |
|
309 */ |
|
310 void PrependCookieNotifyPayloadL(const TDesC8& aCookieData); |
|
311 |
|
312 void AppendConfigurationPayloadL(TUint8 aCfgType, |
|
313 const TDesC8& aConfigurationData); |
|
314 void AppendVendorIdPayloadL(const TDesC8& aVendorIdData); |
|
315 void AppendDeletePayloadL(TUint8 aProtocolId, const CDesC8Array& aSpiList); |
|
316 void AppendEapPayloadL(const TDesC8& aEapData); |
|
317 void AppendTsiPayloadL(const CArrayFix<TIkeV2TrafficSelector>& aTsList); |
|
318 void AppendTsrPayloadL(const CArrayFix<TIkeV2TrafficSelector>& aTsList); |
|
319 |
|
320 /** |
|
321 * Adds the encrypted payload to the message. |
|
322 * The added encrypted payload has to be the first added payload. |
|
323 */ |
|
324 void AppendEncryptedPayloadL(TUint aBlockSize); |
|
325 |
|
326 |
|
327 /** |
|
328 * Gets the ike message datagram, which is ready to be |
|
329 * send to the receiver. |
|
330 * |
|
331 * @param aEncryptionAlgorith Encryption algorithm to be used to encrypt the datagram. |
|
332 * If the message does not contain an encryption payload, this |
|
333 * parameter is ignored. |
|
334 * @param aEncryptionKey Encryption key used to used to encrypt the datagram. |
|
335 * If the message does not contain an encryption payload, this |
|
336 * parameter is ignored. |
|
337 * @param aIntegrityAlgorithm Algorithm used to calculate the integrity checks sum. |
|
338 * If the message does not contain an encryption payload, this |
|
339 * parameter is ignored. |
|
340 * @param aSourceAddress Source address of the datagram. Needed for message tracing in |
|
341 * debug builds. |
|
342 * @param aDestinationAddress Destination address of the datagram. Needed for message tracing in |
|
343 * debug builds. |
|
344 */ |
|
345 void PrepareIkeMessageDatagramL(TUint16 aEncryptionAlgorithm, |
|
346 const TDesC8& aEncryptionKey, |
|
347 TUint16 aIntegrityAlgorithm, |
|
348 const TDesC8& aIntegrityKey, |
|
349 const TInetAddr& aSourceAddress, |
|
350 const TInetAddr& aDestinationAddress); |
|
351 |
|
352 TPtrC8 IkeMessageDatagram() const; |
|
353 private: |
|
354 CIkeV2Message(MIkeDebug& aDebug); |
|
355 void ConstructL(const TDesC8& aInitiatorSpi, |
|
356 const TDesC8& aResponderSpi, |
|
357 TUint8 aExchangeType, |
|
358 TBool aIntiator, |
|
359 TBool aResponse, |
|
360 TUint32 aMessageId); |
|
361 |
|
362 void AppendPayloadL(CIkeV2Payload* aPayload); |
|
363 |
|
364 void SetFlags(TUint8 aFlags); |
|
365 void SetLength(TUint32 aDatagramLength); |
|
366 void SetNextPayload(TUint8 aNextPayload); |
|
367 |
|
368 |
|
369 MIkeDebug& iDebug; |
|
370 HBufC8* iIkeV2MessageHeader; |
|
371 RPointerArray<CIkeV2Payload> iPayloads; |
|
372 |
|
373 TBool iModified; |
|
374 HBufC8* iIkeV2Datagram; |
|
375 }; |
|
376 |
|
377 #endif /* IKEV2MESSAGE_H_ */ |