networksecurity/ipsec/te_ipsec_selector_confilict/src/te_loadpolicy_bdd.cpp
branchRCL_3
changeset 58 8d540f55e491
parent 53 7e41d162e158
equal deleted inserted replaced
57:abbed5a4b42a 58:8d540f55e491
       
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  * @file ts_ipsec_polapi.cpp Implements main test code for IPsec
       
    21  */
       
    22 
       
    23 #include "te_loadpolicy_bdd.h"
       
    24 #include "te_ipsecconst.h"
       
    25 #include "te_selectorconflict.h"
       
    26 #include "te_ipsecconst.h"
       
    27 #include <ES_SOCK.H> 
       
    28 #include "lib_pfkey.h"
       
    29 #include "pfkey_ext.h"
       
    30 #include "pfkey_send.h"
       
    31 #include "ipsecpolapi.h"
       
    32 #include <commdbconnpref.h>
       
    33 
       
    34 
       
    35 #if defined(SYMBIAN_CRYPTO)
       
    36 #include <cryptostrength.h>
       
    37 #else
       
    38 #include <cryptalg.h>
       
    39 #endif
       
    40 
       
    41 
       
    42 _LIT8( KMyPolicy,  
       
    43 "SECURITY_FILE_VERSION: 3\r\n[INFO]\r\n\
       
    44 IpSec Policy LOADING\r\n\
       
    45 [POLICY]\r\n\
       
    46 sa trans_1 = {\r\n\
       
    47 esp\r\n\
       
    48 encrypt_alg 12\r\n\
       
    49 src_specific\r\n\
       
    50 }\r\n\
       
    51 remote 10.225.208.183 255.255.255.255 = { trans_1(10.225.208.183) }\r\n" );
       
    52 
       
    53 
       
    54 _LIT8( KMyPolicy1,  
       
    55 "SECURITY_FILE_VERSION: 3\r\n[INFO]\r\n\
       
    56 IpSec Policy LOADING\r\n\
       
    57 [POLICY]\r\n\
       
    58 sa trans_2 = {\r\n\
       
    59 esp\r\n\
       
    60 encrypt_alg 12\r\n\
       
    61 src_specific\r\n\
       
    62 }\r\n\
       
    63 outbound remote 10.225.208.99 255.255.255.0 protocol 17 = { trans_2(10.225.208.99) }\r\n\
       
    64 inbound local 10.225.208.155 255.255.255.0 protocol 17  = { trans_2(10.225.208.99) }\r\n\
       
    65 inbound = {}\r\n\
       
    66 outbound = {}\r\n" );
       
    67 
       
    68 _LIT8( KMyPolicy2,  
       
    69 "SECURITY_FILE_VERSION: 3\r\n[INFO]\r\n\
       
    70 IpSec Policy LOADING\r\n\
       
    71 [POLICY]\r\n\
       
    72 sa trans_1 = {\r\n\
       
    73 esp\r\n\
       
    74 encrypt_alg 12\r\n\
       
    75 src_specific\r\n\
       
    76 }\r\n\
       
    77 remote 10.225.208.1 255.255.255.255 = { trans_1(10.225.208.1) }\r\n" );
       
    78 
       
    79 
       
    80 
       
    81 /**
       
    82 Purpose: Constructor of CT_IPSecIKEV2TestWrapper class
       
    83 @internalComponent
       
    84 */
       
    85 CT_LoadPolicyBDD::CT_LoadPolicyBDD()
       
    86 	{
       
    87 	}
       
    88 
       
    89 
       
    90 /**
       
    91 Purpose: Destructor of CT_LoadPolicyBDD class
       
    92 @internalComponent
       
    93 */
       
    94 CT_LoadPolicyBDD::~CT_LoadPolicyBDD()
       
    95 	{
       
    96 	delete iObject;
       
    97 	iObject = NULL;
       
    98 	}
       
    99 
       
   100 
       
   101 /**
       
   102 Purpose: Command fuction of CT_LoadPolicyBDD class
       
   103 @internalComponent
       
   104 */
       
   105 CT_LoadPolicyBDD* CT_LoadPolicyBDD::NewL()
       
   106 	{
       
   107 	CT_LoadPolicyBDD*	ret = new (ELeave) CT_LoadPolicyBDD();
       
   108 	CleanupStack::PushL(ret);
       
   109 	ret->ConstructL();
       
   110 	CleanupStack::Pop(ret);
       
   111 	return ret;
       
   112 	}
       
   113 	
       
   114 	
       
   115 /**
       
   116 Purpose: Command fuction for a wrapper class
       
   117 @internalComponent
       
   118 */
       
   119 void CT_LoadPolicyBDD::ConstructL()
       
   120 	{
       
   121     TInt errfound;
       
   122     
       
   123 	iObject = new (ELeave) TInt;	
       
   124 	errfound = iDrpPolicyServer.Connect();
       
   125 	if( errfound != KErrNone )
       
   126 	    {
       
   127 	    ERR_PRINTF2(_L("failed to connect RIpsecPolicyServ with error: %d"), errfound);
       
   128 	    SetBlockResult(EFail);
       
   129 	    return;
       
   130 	    }
       
   131 	errfound=iBypsPolicyServer.Connect();
       
   132 	if( errfound != KErrNone )
       
   133 	    {
       
   134 	    ERR_PRINTF2(_L("failed to connect RIpsecPolicyServ with error: %d"), errfound);
       
   135 	    SetBlockResult(EFail);
       
   136 	    return;
       
   137 	    }
       
   138 	
       
   139 	iMyZoneInfoSet.iSelectorZone.iScope = KScopeNetwork;
       
   140 	iMyZoneInfoSet.iSelectorZone.iId = 8;
       
   141 	iMyZoneInfoSet.iEndPointZone.iScope = KScopeNetwork;
       
   142 	iMyZoneInfoSet.iEndPointZone.iId = 7;
       
   143 	}
       
   144 
       
   145 
       
   146 /**
       
   147 Purpose: Command fuction for a wrapper class
       
   148 @internalComponent
       
   149 */
       
   150 TBool CT_LoadPolicyBDD::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   151 	{
       
   152 	TBool ret = ETrue;
       
   153 
       
   154 	// Print out the parameters for debugging
       
   155 	INFO_PRINTF2( _L("<font size=2 color=990000><b>aCommand = %S</b></font>"), &aCommand );
       
   156 	INFO_PRINTF2( _L("aSection = %S"), &aSection );
       
   157 	INFO_PRINTF2( _L("aAsyncErrorIndex = %D"), aAsyncErrorIndex );
       
   158 
       
   159 	if(KNewCMD() == aCommand)
       
   160 		{
       
   161 		DoCmdNewL(aSection);
       
   162 		}
       
   163 	else if(KTestLoadDropPolicy() == aCommand)
       
   164 		 {
       
   165 	     DoLoadDropModePolicy(aSection);
       
   166 		 }
       
   167 	else if (KLoadBypasspolicy()== aCommand)
       
   168 	     {
       
   169 	     DoLoadBypassModePolicy(aSection);
       
   170 	     }
       
   171 	else if (KLoadNewDroppolicy()== aCommand)
       
   172 	     {
       
   173 	     DoLoadNewDropModePolicy(aSection);
       
   174 	     }
       
   175 	else if (KUnloadDropPolicy() == aCommand)
       
   176 	     {
       
   177 	     DoUnloadDropPolicy(aSection);
       
   178 	     }
       
   179 	else if (KUnloadBypassPolicy() == aCommand)
       
   180 	     {
       
   181 	     DoUnloadBypassPolicy(aSection);
       
   182 	     }
       
   183 	else if (KUnloadNewDropPolicy() == aCommand)
       
   184 	     {
       
   185 	     DoUnloadNewDropModePolicy(aSection);
       
   186 	     }
       
   187 	else if (KCloseConnection() == aCommand)
       
   188 	    {
       
   189 	    DoCmdClose(aSection);
       
   190 	    }
       
   191 	else
       
   192 		{
       
   193 		ret = EFalse;
       
   194 		}
       
   195 
       
   196 	return ret;
       
   197 	}
       
   198 
       
   199 
       
   200 /**
       
   201 Purpose: To create a new object of the CTEFTest type through the API.
       
   202 
       
   203 Ini file options:
       
   204 	iniData - The data from the ini file at the section provided.
       
   205 
       
   206 @internalComponent
       
   207 @param  aSection Current ini file command section
       
   208 */
       
   209 void CT_LoadPolicyBDD::DoCmdNewL(const TDesC& aSection)
       
   210 	{
       
   211 	TInt objectValue = 0;
       
   212 	TInt iapid =0;
       
   213 	if (!GetIntFromConfig(aSection, KObjectValue(), objectValue))
       
   214 		{
       
   215 		ERR_PRINTF2(_L("<font color=FF0000>No parameter %S</font>"), &KObjectValue());
       
   216 		SetBlockResult(EFail);
       
   217 		}
       
   218 	else
       
   219 	    {
       
   220 	    *iObject = objectValue;	    
       
   221 	    
       
   222         if(!GetIntFromConfig(aSection, KIapid(), iapid))
       
   223             {
       
   224             ERR_PRINTF2(_L("<font color=FF0000>No parameter %S</font>"), &KObjectValue());
       
   225             SetBlockResult(EFail);
       
   226             }
       
   227         else
       
   228             {
       
   229        
       
   230             }
       
   231 	    }
       
   232 	}
       
   233 
       
   234 
       
   235 void CT_LoadPolicyBDD::DoLoadDropModePolicy(const TDesC& /*aSection*/)//this will load a drop mode policy
       
   236     {
       
   237         RSocketServ pSocketServ;
       
   238         /** Handle to SADB socket */
       
   239         RSADB pSADB; 
       
   240         TInt err;
       
   241         
       
   242         err = pSocketServ.Connect();
       
   243         if ( err != KErrNone)
       
   244             {
       
   245             ERR_PRINTF2(_L("DoLoadDropModePolicy():- Failed to connect  RSocketServ with error: %d"), err);
       
   246             SetBlockResult(EFail);   
       
   247             }   
       
   248         err = pSADB.Open(pSocketServ);
       
   249         if ( err != KErrNone)
       
   250             {
       
   251             ERR_PRINTF2(_L("DoLoadDropModePolicy():- Failed to open RSADB with error: %d"), err);
       
   252             SetBlockResult(EFail);   
       
   253             }                  
       
   254         HBufC8 *policyData = HBufC8::NewLC( KMyPolicy().Length() + 256); // Allow size for IP spec.
       
   255         TPtr8 policyDataPtr(policyData->Des());
       
   256         policyDataPtr.Append(KMyPolicy);
       
   257         
       
   258         TRequestStatus status;
       
   259         iDrpPolicyServer.LoadPolicy( *policyData, iDrpPolicyHandle, status, iMyZoneInfoSet);
       
   260         User::WaitForRequest(status);
       
   261         
       
   262         err = status.Int();
       
   263         if( err == KErrNone)
       
   264             {
       
   265             iDrpPolicyServer.ActivatePolicy( iDrpPolicyHandle(), status );
       
   266             User::WaitForRequest(status);
       
   267             User::LeaveIfError(status.Int());   
       
   268             SetBlockResult(EPass);
       
   269             }
       
   270         else
       
   271             {
       
   272             SetError(status.Int());
       
   273             ERR_PRINTF2(_L("DoLoadDropModePolicy():- LoadPolicy failed with error: %d"), err);
       
   274             SetBlockResult(EFail);
       
   275             }
       
   276         CleanupStack::PopAndDestroy(policyData);
       
   277         pSADB.Close();
       
   278         pSocketServ.Close();    
       
   279 
       
   280     }
       
   281 
       
   282 void CT_LoadPolicyBDD::DoLoadBypassModePolicy(const TDesC& /*aSection*/)
       
   283     {       
       
   284     RSocketServ pSocketServ;
       
   285     /** Handle to SADB socket */
       
   286     RSADB pSADB;
       
   287     TInt err;
       
   288     
       
   289     err = pSocketServ.Connect();
       
   290     if ( err != KErrNone)
       
   291          {
       
   292          ERR_PRINTF2(_L("DoLoadBypassModePolicy():- Failed to connect  RSocketServ with error: %d"), err);
       
   293          SetBlockResult(EFail);   
       
   294          }   
       
   295     err = pSADB.Open(pSocketServ);
       
   296     if ( err != KErrNone)
       
   297          {
       
   298          ERR_PRINTF2(_L("DoLoadBypassModePolicy():- Failed to open RSADB with error: %d"), err);
       
   299          SetBlockResult(EFail);  
       
   300          }                                   
       
   301     
       
   302     HBufC8 *policyData = HBufC8::NewLC( KMyPolicy1().Length() + 256); // Allow size for IP spec.
       
   303     TPtr8 policyDataPtr(policyData->Des());
       
   304     policyDataPtr.Append(KMyPolicy1);
       
   305     
       
   306     TRequestStatus status;
       
   307     iBypsPolicyServer.LoadPolicy( *policyData,iBypsPolicyHandle, status, iMyZoneInfoSet);
       
   308     User::WaitForRequest(status);
       
   309     
       
   310     if(status.Int() == KErrNone)
       
   311         {
       
   312         iBypsPolicyServer.ActivatePolicy( iBypsPolicyHandle(), status );
       
   313         User::WaitForRequest(status);
       
   314         User::LeaveIfError(status.Int());   
       
   315         SetBlockResult(EPass);
       
   316         }
       
   317     else
       
   318         {
       
   319         SetError(status.Int());
       
   320         ERR_PRINTF2(_L("DoLoadBypassModePolicy():- LoadPolicy failed with error: %d"), status.Int());
       
   321         SetBlockResult(EFail);
       
   322         }
       
   323     CleanupStack::PopAndDestroy(policyData);    
       
   324     pSADB.Close();
       
   325     pSocketServ.Close();     
       
   326     }
       
   327 
       
   328 
       
   329 
       
   330 
       
   331 void CT_LoadPolicyBDD::DoLoadNewDropModePolicy(const TDesC& /*aSection*/)
       
   332     {       
       
   333     RSocketServ pSocketServ;
       
   334     /** Handle to SADB socket */ 
       
   335     RSADB pSADB;         
       
   336     TInt err;
       
   337         
       
   338     err = pSocketServ.Connect();
       
   339     if ( err != KErrNone)
       
   340          {
       
   341          ERR_PRINTF2(_L("DoLoadNewDropModePolicy():- Failed to connect  RSocketServ with error: %d"), err);
       
   342          SetBlockResult(EFail);   
       
   343          }   
       
   344     err = pSADB.Open(pSocketServ);
       
   345     if ( err != KErrNone)
       
   346          {
       
   347          ERR_PRINTF2(_L("DoLoadNewDropModePolicy():- Failed to open RSADB with error: %d"), err);
       
   348          SetBlockResult(EFail);   
       
   349          }                                   
       
   350             
       
   351     HBufC8 *policyData = HBufC8::NewLC( KMyPolicy2().Length() + 256); // Allow size for IP spec.
       
   352     TPtr8 policyDataPtr(policyData->Des());
       
   353     policyDataPtr.Append(KMyPolicy2);
       
   354     
       
   355 
       
   356     TRequestStatus status;   
       
   357     iDrpPolicyServer.LoadPolicy( *policyData, iNewDrpPolicyHandle, status, iMyZoneInfoSet);
       
   358     User::WaitForRequest(status);
       
   359     
       
   360     if(status.Int() == KErrNone)
       
   361         {
       
   362         iDrpPolicyServer.ActivatePolicy( iNewDrpPolicyHandle(), status );
       
   363         User::WaitForRequest(status);
       
   364         User::LeaveIfError(status.Int());   
       
   365         SetBlockResult(EPass);
       
   366         }
       
   367     else
       
   368         {
       
   369         SetError(status.Int());
       
   370         ERR_PRINTF2(_L("DoLoadNewDropModePolicy():- LoadPolicy failed with error: %d"), status.Int());
       
   371         SetBlockResult(EFail);
       
   372         }
       
   373     CleanupStack::PopAndDestroy(policyData);    
       
   374     pSADB.Close();
       
   375     pSocketServ.Close();     
       
   376     }
       
   377 
       
   378 
       
   379 /*
       
   380 *Execute the test to unload the policy.
       
   381 */
       
   382 void CT_LoadPolicyBDD::DoUnloadDropPolicy(const TDesC& /*aSection*/)
       
   383     {      
       
   384     TRequestStatus status;
       
   385     iDrpPolicyServer.UnloadPolicy(iDrpPolicyHandle(),status);
       
   386     User::WaitForRequest(status);
       
   387     TInt err = status.Int();
       
   388     if( err != KErrNone)
       
   389         {
       
   390         SetError(err);
       
   391         ERR_PRINTF2(_L("DoUnloadDropPolicy():- UnloadPolicy failed with error: %d"), err);
       
   392         SetBlockResult(EFail);
       
   393         }
       
   394     }
       
   395 
       
   396 /*
       
   397 *Execute the test to unload the policy.
       
   398 */
       
   399 void CT_LoadPolicyBDD::DoUnloadBypassPolicy(const TDesC& /*aSection*/)
       
   400     {      
       
   401     TRequestStatus status;    
       
   402     iBypsPolicyServer.UnloadPolicy(iBypsPolicyHandle(),status);
       
   403     User::WaitForRequest(status);
       
   404     TInt err = status.Int();
       
   405     if( err != KErrNone)
       
   406         {
       
   407         SetError(err);
       
   408         ERR_PRINTF2(_L("DoUnloadBypassPolicy():- UnloadPolicy failed with error: %d"), err);
       
   409         SetBlockResult(EFail);
       
   410         }
       
   411     }
       
   412 
       
   413 /*
       
   414 *Execute the test to unload the policy.
       
   415 */
       
   416 void CT_LoadPolicyBDD::DoUnloadNewDropModePolicy(const TDesC& /*aSection*/)
       
   417     {  
       
   418 
       
   419     TRequestStatus status;
       
   420     iDrpPolicyServer.UnloadPolicy(iNewDrpPolicyHandle(),status);
       
   421     User::WaitForRequest(status);
       
   422     TInt err = status.Int();
       
   423     if( err != KErrNone)
       
   424         {
       
   425         SetError(err);
       
   426         ERR_PRINTF2(_L("DoUnloadNewDropPolicy():- UnloadPolicy failed with error: %d"), err);
       
   427         SetBlockResult(EFail);
       
   428         }
       
   429    
       
   430     }
       
   431 
       
   432 
       
   433 /*
       
   434 *Execute the test for closing the connection.
       
   435 */
       
   436 void CT_LoadPolicyBDD::DoCmdClose(const TDesC& /*aSection*/)
       
   437     {       
       
   438     SetBlockResult(EPass);
       
   439     }
       
   440     
       
   441 
       
   442