|
1 /* |
|
2 * Copyright (c) 2003 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 "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * @File :- te_loadpolicy_uma.cpp Implements loading the policy |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 * @file ts_ipsec_polapi.cpp Implements main test code for IPsec |
|
22 */ |
|
23 |
|
24 #include "te_loadpolicy_uma.h" |
|
25 #include "te_ipsecconst.h" |
|
26 #include "te_selectorconflict.h" |
|
27 #include <ES_SOCK.H> |
|
28 #include "lib_pfkey.h" |
|
29 #include "pfkey_ext.h" |
|
30 #include "pfkey_send.h" |
|
31 #include <commdbconnpref.h> |
|
32 |
|
33 |
|
34 #if defined(SYMBIAN_CRYPTO) |
|
35 #include <cryptostrength.h> |
|
36 #else |
|
37 #include <cryptalg.h> |
|
38 #endif |
|
39 |
|
40 _LIT8( KMyPolicy, |
|
41 "SECURITY_FILE_VERSION: 3\r\n[INFO]\r\n\ |
|
42 IpSec Policy LOADING\r\n\ |
|
43 [POLICY]\r\n\ |
|
44 sa trans_1 = {\r\n\ |
|
45 esp\r\n\ |
|
46 encrypt_alg 12\r\n\ |
|
47 src_specific\r\n\ |
|
48 }\r\n\ |
|
49 outbound remote 10.225.208.86 255.255.255.255 protocol 17 = { trans_1(10.225.208.86) }\r\n\ |
|
50 inbound local 10.225.208.102 255.255.255.255 protocol 17 = { trans_1(10.225.208.86) }\r\n\ |
|
51 inbound = {}\r\n\ |
|
52 outbound = {}\r\n" ); |
|
53 |
|
54 |
|
55 _LIT8( KMyPolicy1, |
|
56 "SECURITY_FILE_VERSION: 3\r\n[INFO]\r\n\ |
|
57 IpSec Policy LOADING\r\n\ |
|
58 [POLICY]\r\n\ |
|
59 sa trans_2 = {\r\n\ |
|
60 esp\r\n\ |
|
61 encrypt_alg 12\r\n\ |
|
62 src_specific\r\n\ |
|
63 }\r\n\ |
|
64 outbound remote 10.225.208.49 255.255.255.255 protocol 17 = { trans_2(10.225.208.49) }\r\n\ |
|
65 inbound local 10.225.208.155 255.255.255.255 protocol 17 = { trans_2(10.225.208.49) }\r\n" ); |
|
66 |
|
67 _LIT8( KMyPolicy2, |
|
68 "SECURITY_FILE_VERSION: 3\r\n[INFO]\r\n\ |
|
69 IpSec Policy LOADING\r\n\ |
|
70 [POLICY]\r\n\ |
|
71 sa trans_3 = {\r\n\ |
|
72 esp\r\n\ |
|
73 encrypt_alg 12\r\n\ |
|
74 src_specific\r\n\ |
|
75 }\r\n\ |
|
76 outbound remote 192.168.1.1 255.255.255.255 protocol 17 = { trans_3() }\r\n\ |
|
77 inbound local 192.168.1.2 255.255.255.255 protocol 17 = { trans_3() }\r\n\ |
|
78 inbound = {}\r\n\ |
|
79 outbound = {}\r\n" ); |
|
80 |
|
81 |
|
82 /** |
|
83 Purpose: Constructor of CT_IPSecIKEV2TestWrapper class |
|
84 @internalComponent |
|
85 */ |
|
86 CT_LoadPolicyUMA::CT_LoadPolicyUMA() |
|
87 { |
|
88 } |
|
89 /** |
|
90 Purpose: Destructor of CT_LoadPolicyUMA class |
|
91 @internalComponent |
|
92 */ |
|
93 CT_LoadPolicyUMA::~CT_LoadPolicyUMA() |
|
94 { |
|
95 delete iObject; |
|
96 iObject = NULL; |
|
97 } |
|
98 |
|
99 /** |
|
100 Purpose: Command fuction of CT_LoadPolicyUMA class |
|
101 @internalComponent |
|
102 */ |
|
103 CT_LoadPolicyUMA* CT_LoadPolicyUMA::NewL() |
|
104 { |
|
105 CT_LoadPolicyUMA* ret = new (ELeave) CT_LoadPolicyUMA(); |
|
106 CleanupStack::PushL(ret); |
|
107 ret->ConstructL(); |
|
108 CleanupStack::Pop(ret); |
|
109 return ret; |
|
110 } |
|
111 |
|
112 /** |
|
113 Purpose: Command fuction for a wrapper class |
|
114 @internalComponent |
|
115 */ |
|
116 void CT_LoadPolicyUMA::ConstructL() |
|
117 { |
|
118 TInt errfound; |
|
119 iObject = new (ELeave) TInt; |
|
120 |
|
121 errfound = iDrpPolicyServer.Connect(); |
|
122 if( errfound != KErrNone ) |
|
123 { |
|
124 ERR_PRINTF2(_L("failed to connect RIpsecPolicyServ with error: %d"), errfound); |
|
125 SetBlockResult(EFail); |
|
126 return; |
|
127 } |
|
128 errfound=iBypsPolicyServer.Connect(); |
|
129 if( errfound != KErrNone ) |
|
130 { |
|
131 ERR_PRINTF2(_L("failed to connect RIpsecPolicyServ with error: %d"), errfound); |
|
132 SetBlockResult(EFail); |
|
133 return; |
|
134 } |
|
135 |
|
136 iMyZoneInfoSet.iSelectorZone.iScope = KScopeNetwork; |
|
137 iMyZoneInfoSet.iSelectorZone.iId = 8; |
|
138 iMyZoneInfoSet.iEndPointZone.iScope = KScopeNetwork; |
|
139 iMyZoneInfoSet.iEndPointZone.iId = 7; |
|
140 } |
|
141 |
|
142 /** |
|
143 Purpose: Command fuction for a wrapper class |
|
144 @internalComponent |
|
145 */ |
|
146 TBool CT_LoadPolicyUMA::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
147 { |
|
148 TBool ret = ETrue; |
|
149 |
|
150 // Print out the parameters for debugging |
|
151 INFO_PRINTF2( _L("<font size=2 color=990000><b>aCommand = %S</b></font>"), &aCommand ); |
|
152 INFO_PRINTF2( _L("aSection = %S"), &aSection ); |
|
153 INFO_PRINTF2( _L("aAsyncErrorIndex = %D"), aAsyncErrorIndex ); |
|
154 |
|
155 if(KNewCMD() == aCommand) |
|
156 { |
|
157 DoCmdNewL(aSection); |
|
158 } |
|
159 else if(KLOadUMAPolicy() == aCommand) |
|
160 { |
|
161 DoLoadUMAPolicy(aSection); |
|
162 } |
|
163 else if (KTestLoadDropModePolicy() == aCommand) |
|
164 { |
|
165 DoLoadDropModePolicy(aSection); |
|
166 } |
|
167 else if (KLoadUMAByPassPolicy() == aCommand) |
|
168 { |
|
169 DoLoadBypassModePolicy(aSection); |
|
170 } |
|
171 else if (KUnloadDropPolicy() == aCommand) |
|
172 { |
|
173 DoUnloadDropPolicy(aSection); |
|
174 } |
|
175 else if (KUnloadBypassPolicy() == aCommand) |
|
176 { |
|
177 DoUnloadBypassPolicy(aSection); |
|
178 } |
|
179 else if (KUnloadUMAPolicy() == aCommand) |
|
180 { |
|
181 DoUnloadUMAPolicy(aSection); |
|
182 } |
|
183 else if (KCloseConnection() == aCommand) |
|
184 { |
|
185 DoCmdClose(aSection); |
|
186 } |
|
187 else |
|
188 { |
|
189 ret = EFalse; |
|
190 } |
|
191 |
|
192 return ret; |
|
193 } |
|
194 |
|
195 |
|
196 /** |
|
197 Purpose: To create a new object of the CTEFTest type through the API. |
|
198 |
|
199 Ini file options: |
|
200 iniData - The data from the ini file at the section provided. |
|
201 |
|
202 @internalComponent |
|
203 @param aSection Current ini file command section |
|
204 */ |
|
205 void CT_LoadPolicyUMA::DoCmdNewL(const TDesC& aSection) |
|
206 { |
|
207 TInt objectValue = 0; |
|
208 TInt iapid =0; |
|
209 if (!GetIntFromConfig(aSection, KObjectValue(), objectValue)) |
|
210 { |
|
211 ERR_PRINTF2(_L("<font color=FF0000>No parameter %S</font>"), &KObjectValue()); |
|
212 SetBlockResult(EFail); |
|
213 } |
|
214 else |
|
215 { |
|
216 *iObject = objectValue; |
|
217 |
|
218 if(!GetIntFromConfig(aSection, KIapid(), iapid)) |
|
219 { |
|
220 ERR_PRINTF2(_L("<font color=FF0000>No parameter %S</font>"), &KObjectValue()); |
|
221 |
|
222 SetBlockResult(EFail); |
|
223 } |
|
224 else |
|
225 { |
|
226 } |
|
227 } |
|
228 } |
|
229 |
|
230 /** |
|
231 * UMA policy loading for ONB scripts |
|
232 */ |
|
233 void CT_LoadPolicyUMA::DoLoadUMAPolicy(const TDesC& /*aSection*/) |
|
234 { |
|
235 RSocketServ pSocketServ; |
|
236 /** Handle to SADB socket */ |
|
237 RSADB pSADB; |
|
238 TInt err; |
|
239 |
|
240 err = pSocketServ.Connect(); |
|
241 if ( err != KErrNone) |
|
242 { |
|
243 ERR_PRINTF2(_L("DoLoadUMAPolicy():- Failed to connect RSocketServ with error: %d"), err); |
|
244 SetBlockResult(EFail); |
|
245 } |
|
246 err = pSADB.Open(pSocketServ); |
|
247 if ( err != KErrNone) |
|
248 { |
|
249 ERR_PRINTF2(_L("DoLoadUMAPolicy():- Failed to open RSADB with error: %d"), err); |
|
250 SetBlockResult(EFail); |
|
251 } |
|
252 |
|
253 /*** |
|
254 * this code is to check the UMA setopt function |
|
255 * if we call with 0 then it is considered as UMA policy |
|
256 */ |
|
257 TInt sur = 0; |
|
258 _LIT8(KFormatStr,"%D"); |
|
259 TBuf8<50> sidbuf; |
|
260 sidbuf.Format(KFormatStr,sur); |
|
261 TLex8 lex(sidbuf); |
|
262 TInt intval; |
|
263 err = lex.Val(intval); |
|
264 |
|
265 //storing the SID information to the policy server which |
|
266 //is used to identify the UMA policy in ipsec policy manager handler. |
|
267 TInt error = iBypsPolicyServer.SetOpt(KOptionNameSid, KOptionLevelDefault, sidbuf); |
|
268 if ( KErrNone != error ) |
|
269 { |
|
270 ERR_PRINTF2(_L("DoLoadUMAPolicy->LoadPolicy ERROR in setOpt to the policy server %d"), error); |
|
271 SetError(error); |
|
272 SetBlockResult(EFail); |
|
273 return ; |
|
274 } |
|
275 |
|
276 HBufC8 *policyData = HBufC8::NewLC( KMyPolicy().Length() + 256); // Allow size for IP spec. |
|
277 TPtr8 policyDataPtr(policyData->Des()); |
|
278 policyDataPtr.Append(KMyPolicy); |
|
279 TRequestStatus status; |
|
280 iBypsPolicyServer.LoadPolicy( *policyData, iUMAPolicyHandle, status, iMyZoneInfoSet); |
|
281 User::WaitForRequest(status); |
|
282 err = status.Int(); |
|
283 if( err == KErrNone) |
|
284 { |
|
285 iBypsPolicyServer.ActivatePolicy( iUMAPolicyHandle(), status ); |
|
286 User::WaitForRequest(status); |
|
287 User::LeaveIfError(status.Int()); |
|
288 SetBlockResult(EPass); |
|
289 } |
|
290 else |
|
291 { |
|
292 SetError(status.Int()); |
|
293 ERR_PRINTF2(_L("DoLoadUMAPolicy():- LoadPolicy failed with error: %d"), err); |
|
294 SetBlockResult(EFail); |
|
295 } |
|
296 CleanupStack::PopAndDestroy(policyData); |
|
297 pSADB.Close(); |
|
298 pSocketServ.Close(); |
|
299 } |
|
300 |
|
301 /* |
|
302 *Execute the test for loading the drop mode policy. |
|
303 */ |
|
304 void CT_LoadPolicyUMA::DoLoadDropModePolicy(const TDesC& /*aSection*/) |
|
305 { |
|
306 RSocketServ pSocketServ; |
|
307 /** Handle to SADB socket */ |
|
308 RSADB pSADB; |
|
309 TInt err; |
|
310 |
|
311 err = pSocketServ.Connect(); |
|
312 if ( err != KErrNone) |
|
313 { |
|
314 ERR_PRINTF2(_L("DoLoadDropModePolicy():- Failed to connect RSocketServ with error: %d"), err); |
|
315 SetBlockResult(EFail); |
|
316 } |
|
317 err = pSADB.Open(pSocketServ); |
|
318 if ( err != KErrNone) |
|
319 { |
|
320 ERR_PRINTF2(_L("DoLoadDropModePolicy():- Failed to open RSADB with error: %d"), err); |
|
321 SetBlockResult(EFail); |
|
322 } |
|
323 |
|
324 |
|
325 /*** |
|
326 * this code is to check the UMA setopt function |
|
327 * if we call with 0 then it is considered as UMA policy |
|
328 * in this case we are passing some other value |
|
329 */ |
|
330 TInt sur = 0x100; |
|
331 _LIT8(KFormatStr,"%D"); |
|
332 TBuf8<50> sidbuf; |
|
333 sidbuf.Format(KFormatStr,sur); |
|
334 /* if you want to check the value un comment this part of the code |
|
335 TLex8 lex(sidbuf); |
|
336 TInt intval; |
|
337 TInt err = lex.Val(intval); |
|
338 */ |
|
339 |
|
340 //storing the SID information to the policy server which |
|
341 //is used to identify the UMA policy in ipsec policy manager handler. |
|
342 TInt error = iBypsPolicyServer.SetOpt(KOptionNameSid, KOptionLevelDefault, sidbuf); |
|
343 if ( KErrNone != error ) |
|
344 { |
|
345 ERR_PRINTF2(_L("DoLoadDropModePolicy->LoadPolicy ERROR in setOpt to the policy server %d"), error); |
|
346 SetError(error); |
|
347 SetBlockResult(EFail); |
|
348 return ; |
|
349 } |
|
350 HBufC8 *policyData = HBufC8::NewLC( KMyPolicy1().Length() + 256); // Allow size for IP spec. |
|
351 TPtr8 policyDataPtr(policyData->Des()); |
|
352 policyDataPtr.Append(KMyPolicy1); |
|
353 |
|
354 TRequestStatus status; |
|
355 iDrpPolicyServer.LoadPolicy( *policyData, iDrpPolicyHandle, status, iMyZoneInfoSet); |
|
356 User::WaitForRequest(status); |
|
357 TInt err1 = status.Int(); |
|
358 if(err1 == KErrNone) |
|
359 { |
|
360 iDrpPolicyServer.ActivatePolicy(iDrpPolicyHandle(), status ); |
|
361 User::WaitForRequest(status); |
|
362 User::LeaveIfError(status.Int()); |
|
363 SetBlockResult(EPass); |
|
364 } |
|
365 else |
|
366 { |
|
367 SetError(status.Int()); |
|
368 ERR_PRINTF2(_L("DoLoadDropModePolicy->LoadPolicy failed with error: %d"),err1); |
|
369 SetBlockResult(EFail); |
|
370 } |
|
371 CleanupStack::PopAndDestroy(policyData); |
|
372 |
|
373 pSADB.Close(); |
|
374 pSocketServ.Close(); |
|
375 } |
|
376 |
|
377 |
|
378 void CT_LoadPolicyUMA::DoLoadBypassModePolicy(const TDesC& /*aSection*/) |
|
379 { |
|
380 RSocketServ pSocketServ; |
|
381 /** Handle to SADB socket */ |
|
382 RSADB pSADB; |
|
383 TInt err; |
|
384 |
|
385 err = pSocketServ.Connect(); |
|
386 if ( err != KErrNone) |
|
387 { |
|
388 ERR_PRINTF2(_L("DoLoadBypassModePolicy():- Failed to connect RSocketServ with error: %d"), err); |
|
389 SetBlockResult(EFail); |
|
390 } |
|
391 err = pSADB.Open(pSocketServ); |
|
392 if ( err != KErrNone) |
|
393 { |
|
394 ERR_PRINTF2(_L("DoLoadBypassModePolicy():- Failed to open RSADB with error: %d"), err); |
|
395 SetBlockResult(EFail); |
|
396 } |
|
397 |
|
398 /*** |
|
399 * this code is to check the UMA setopt function |
|
400 * if we call with 0 then it is considered as UMA policy |
|
401 * in this case we are passing some other value |
|
402 * |
|
403 * this is done becoze we don't have any value present in comms database or it could be a big bug |
|
404 */ |
|
405 TInt sur = 0x100; |
|
406 _LIT8(KFormatStr,"%D"); |
|
407 TBuf8<50> sidbuf; |
|
408 sidbuf.Format(KFormatStr,sur); |
|
409 TLex8 lex(sidbuf); |
|
410 TInt intval; |
|
411 err = lex.Val(intval); |
|
412 |
|
413 //storing the SID information to the policy server which |
|
414 //is used to identify the UMA policy in ipsec policy manager handler. |
|
415 TInt error = iBypsPolicyServer.SetOpt(KOptionNameSid, KOptionLevelDefault, sidbuf); |
|
416 if ( KErrNone != error ) |
|
417 { |
|
418 ERR_PRINTF2(_L("DoLoadBypassModePolicy->LoadPolicy ERROR in setOpt to the policy server %d"), error); |
|
419 SetError(error); |
|
420 SetBlockResult(EFail); |
|
421 return ; |
|
422 } |
|
423 HBufC8 *policyData = HBufC8::NewLC( KMyPolicy2().Length() + 256); // Allow size for IP spec. |
|
424 TPtr8 policyDataPtr(policyData->Des()); |
|
425 policyDataPtr.Append(KMyPolicy2); |
|
426 TRequestStatus status; |
|
427 iBypsPolicyServer.LoadPolicy( *policyData, iBypsPolicyHandle, status, iMyZoneInfoSet); |
|
428 User::WaitForRequest(status); |
|
429 err = status.Int(); |
|
430 if( err == KErrNone) |
|
431 { |
|
432 iBypsPolicyServer.ActivatePolicy( iBypsPolicyHandle(), status ); |
|
433 User::WaitForRequest(status); |
|
434 User::LeaveIfError(status.Int()); |
|
435 SetBlockResult(EPass); |
|
436 } |
|
437 else |
|
438 { |
|
439 SetError(status.Int()); |
|
440 ERR_PRINTF2(_L("DoLoadBypassModePolicy():- LoadPolicy failed with error: %d"), err); |
|
441 SetBlockResult(EFail); |
|
442 } |
|
443 CleanupStack::PopAndDestroy(policyData); |
|
444 pSADB.Close(); |
|
445 pSocketServ.Close(); |
|
446 } |
|
447 |
|
448 /* |
|
449 *Execute the test to unload the policy. |
|
450 */ |
|
451 void CT_LoadPolicyUMA::DoUnloadDropPolicy(const TDesC& /*aSection*/) |
|
452 { |
|
453 TRequestStatus status; |
|
454 iDrpPolicyServer.UnloadPolicy(iDrpPolicyHandle(),status); |
|
455 User::WaitForRequest(status); |
|
456 TInt err = status.Int(); |
|
457 if( err != KErrNone) |
|
458 { |
|
459 SetError(err); |
|
460 ERR_PRINTF2(_L("DoUnloadDropPolicy():- UnloadPolicy failed with error: %d"), err); |
|
461 SetBlockResult(EFail); |
|
462 } |
|
463 } |
|
464 |
|
465 /* |
|
466 *Execute the test to unload the policy. |
|
467 */ |
|
468 void CT_LoadPolicyUMA::DoUnloadUMAPolicy(const TDesC& /*aSection*/) |
|
469 { |
|
470 TRequestStatus status; |
|
471 iBypsPolicyServer.UnloadPolicy(iUMAPolicyHandle(),status); |
|
472 User::WaitForRequest(status); |
|
473 TInt err = status.Int(); |
|
474 if( err != KErrNone) |
|
475 { |
|
476 SetError(err); |
|
477 ERR_PRINTF2(_L("DoUnloadUMAPolicy():- UnloadPolicy failed with error: %d"), err); |
|
478 SetBlockResult(EFail); |
|
479 } |
|
480 } |
|
481 /* |
|
482 *Execute the test for unload the policy. |
|
483 */ |
|
484 void CT_LoadPolicyUMA::DoUnloadBypassPolicy(const TDesC& /*aSection*/) |
|
485 { |
|
486 TRequestStatus status; |
|
487 iBypsPolicyServer.UnloadPolicy(iBypsPolicyHandle(),status); |
|
488 User::WaitForRequest(status); |
|
489 TInt err = status.Int(); |
|
490 if( err != KErrNone) |
|
491 { |
|
492 SetError(err); |
|
493 ERR_PRINTF2(_L("DoUnloadBypassPolicy():- UnloadPolicy failed with error: %d"), err); |
|
494 SetBlockResult(EFail); |
|
495 } |
|
496 } |
|
497 |
|
498 /* |
|
499 *Execute the test for closing the connection. |
|
500 */ |
|
501 void CT_LoadPolicyUMA::DoCmdClose(const TDesC& /*aSection*/) |
|
502 { |
|
503 SetBlockResult(EPass); |
|
504 } |
|
505 |
|
506 |
|
507 |