networksecurity/ipsec/te_ipsec_selector_confilict/src/te_loadpolicy_bbd.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 ** @File :- te_loadpolicy_bbd.cpp Implements loading the policy 
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  * @file ts_ipsec_polapi.cpp Implements main test code for IPsec
       
    22  */
       
    23 
       
    24 #include "te_loadpolicy_bbd.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.183 255.255.255.255 protocol 17 = { trans_1(10.225.208.183) }\r\n\
       
    50 inbound local 10.225.208.102 255.255.255.255 protocol 17  = { trans_1(10.225.208.183) }\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_LoadPolicyBBD::CT_LoadPolicyBBD()
       
    87 	{
       
    88 	}
       
    89 
       
    90 /**
       
    91 Purpose: Destructor of CT_LoadPolicyBBD class
       
    92 @internalComponent
       
    93 */
       
    94 CT_LoadPolicyBBD::~CT_LoadPolicyBBD()
       
    95 	{
       
    96 	delete iObject;
       
    97 	iObject = NULL;
       
    98 	}
       
    99 
       
   100 /**
       
   101 Purpose: Command fuction of CT_LoadPolicyBBD class
       
   102 @internalComponent
       
   103 */
       
   104 CT_LoadPolicyBBD* CT_LoadPolicyBBD::NewL()
       
   105 	{
       
   106 	CT_LoadPolicyBBD*	ret = new (ELeave) CT_LoadPolicyBBD();
       
   107 	CleanupStack::PushL(ret);
       
   108 	ret->ConstructL();
       
   109 	CleanupStack::Pop(ret);
       
   110 	return ret;
       
   111 	}
       
   112 	
       
   113 	
       
   114 /**
       
   115 Purpose: Command fuction for a wrapper class
       
   116 @internalComponent
       
   117 */
       
   118 void CT_LoadPolicyBBD::ConstructL()
       
   119 	{
       
   120     TInt errfound;
       
   121     
       
   122 	iObject = new (ELeave) TInt;
       
   123 	errfound = iDrpPolicyServer.Connect();
       
   124 	if( errfound != KErrNone )
       
   125 	    {
       
   126 	    ERR_PRINTF2(_L("failed to connect RIpsecPolicyServ with error: %d"), errfound);
       
   127 	    SetBlockResult(EFail);
       
   128 	    return;
       
   129 	    }
       
   130 	errfound=iBypsPolicyServer.Connect();
       
   131 	if( errfound != KErrNone )
       
   132 	    {
       
   133 	    ERR_PRINTF2(_L("failed to connect RIpsecPolicyServ with error: %d"), errfound);
       
   134 	    SetBlockResult(EFail); 
       
   135 	    return;
       
   136 	    }
       
   137 
       
   138 	iMyZoneInfoSet.iSelectorZone.iScope = KScopeNetwork;
       
   139 	iMyZoneInfoSet.iSelectorZone.iId = 8;
       
   140 	iMyZoneInfoSet.iEndPointZone.iScope = KScopeNetwork;
       
   141 	iMyZoneInfoSet.iEndPointZone.iId = 7;
       
   142 	        
       
   143 	}
       
   144 
       
   145 
       
   146 /**
       
   147 Purpose: Command fuction for a wrapper class
       
   148 @internalComponent
       
   149 */
       
   150 TBool CT_LoadPolicyBBD::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(KTestLoadBypassPolicy() == aCommand)
       
   164 		{
       
   165 	    DoLoadBypassModePolicy(aSection);
       
   166 		}
       
   167 	else if (KTestLoadDropModePolicy() == aCommand)
       
   168 	    {
       
   169         DoLoadDropModePolicy(aSection);
       
   170 	    }
       
   171 	else if (KLoadNewBypassPolicy() == aCommand)
       
   172         {
       
   173         DoLoadNewBypassModePolicy(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 (KUnloadNewBypassPolicy() == aCommand)
       
   184 	    {
       
   185 	    DoUnloadNewBypassPolicy(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_LoadPolicyBBD::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  * Bypass policy loading for ONB scripts
       
   235  */
       
   236 void CT_LoadPolicyBBD::DoLoadBypassModePolicy(const TDesC& /*aSection*/) 
       
   237     {
       
   238     RSocketServ pSocketServ;
       
   239     /** Handle to SADB socket */
       
   240     RSADB pSADB;     
       
   241     TInt err;
       
   242         
       
   243     err = pSocketServ.Connect();
       
   244     if ( err != KErrNone)
       
   245          {
       
   246          ERR_PRINTF2(_L("DoLoadBypassModePolicy():- Failed to connect  RSocketServ with error: %d"), err);
       
   247          SetBlockResult(EFail);   
       
   248          }   
       
   249     err = pSADB.Open(pSocketServ);
       
   250     if ( err != KErrNone)
       
   251          {
       
   252          ERR_PRINTF2(_L("DoLoadBypassModePolicy():- Failed to open RSADB with error: %d"), err);
       
   253          SetBlockResult(EFail);  
       
   254          }                                   
       
   255         
       
   256     
       
   257     HBufC8 *policyData = HBufC8::NewLC( KMyPolicy().Length() + 256); // Allow size for IP spec.
       
   258     TPtr8 policyDataPtr(policyData->Des());
       
   259     policyDataPtr.Append(KMyPolicy);
       
   260     
       
   261     TRequestStatus status;
       
   262     iBypsPolicyServer.LoadPolicy( *policyData, iBypsPolicyHandle, status, iMyZoneInfoSet);
       
   263     User::WaitForRequest(status);
       
   264     
       
   265     err = status.Int();
       
   266     if( err == KErrNone)
       
   267         {
       
   268         iBypsPolicyServer.ActivatePolicy( iBypsPolicyHandle(), status );
       
   269         User::WaitForRequest(status);
       
   270         User::LeaveIfError(status.Int());   
       
   271         SetBlockResult(EPass);
       
   272         }
       
   273     else
       
   274         {
       
   275         SetError(status.Int());
       
   276         ERR_PRINTF2(_L("DoLoadNewBypassPolicy():- LoadPolicy failed with error: %d"), err);
       
   277         SetBlockResult(EFail);
       
   278         }
       
   279     CleanupStack::PopAndDestroy(policyData);
       
   280     pSADB.Close();
       
   281     pSocketServ.Close();    
       
   282     }
       
   283 
       
   284 /*
       
   285 *Execute the test for closing the connection.
       
   286 */
       
   287 void CT_LoadPolicyBBD::DoLoadDropModePolicy(const TDesC& /*aSection*/)
       
   288     {       
       
   289     RSocketServ pSocketServ;
       
   290     /** Handle to SADB socket */
       
   291     RSADB pSADB;
       
   292     TInt err;
       
   293             
       
   294     err = pSocketServ.Connect();
       
   295     if ( err != KErrNone)
       
   296          {
       
   297          ERR_PRINTF2(_L("DoLoadDropModePolicy():- Failed to connect  RSocketServ with error: %d"), err);
       
   298          SetBlockResult(EFail);   
       
   299          }   
       
   300     err = pSADB.Open(pSocketServ);
       
   301     if ( err != KErrNone)
       
   302          {
       
   303          ERR_PRINTF2(_L("DoLoadDropModePolicy():- Failed to open RSADB with error: %d"), err);
       
   304          SetBlockResult(EFail);  
       
   305          }                                   
       
   306                
       
   307     HBufC8 *policyData = HBufC8::NewLC( KMyPolicy1().Length() + 256); // Allow size for IP spec.
       
   308     TPtr8 policyDataPtr(policyData->Des());
       
   309     policyDataPtr.Append(KMyPolicy1);
       
   310     /***
       
   311      * this code is to check the UMA setopt function
       
   312      * 
       
   313      */
       
   314     TInt sur = 0x2002E241;
       
   315     _LIT8(KFormatStr,"%D");
       
   316     TBuf8<50> sidbuf;
       
   317     sidbuf.Format(KFormatStr,sur);
       
   318     TLex8 lex(sidbuf);    
       
   319     TInt intval;
       
   320     err = lex.Val(intval);
       
   321     
       
   322     //storing the SID information to the policy server which
       
   323     //is used to identify the UMA policy in ipsec policy manager handler.
       
   324     TInt error=0 ;
       
   325     //pPolicyServer.SetOpt(KOptionNameSid, KOptionLevelDefault, sidbuf);
       
   326     //ERR_PRINTF2(_L("DoLoadDropModePolicy->LoadPolicy ERROR  in setOpt to the policy server %s"), sidBuffer);
       
   327     RDebug::Printf("\n see the value \n");
       
   328     if ( KErrNone != error )
       
   329     {
       
   330     ERR_PRINTF2(_L("DoLoadDropModePolicy->LoadPolicy ERROR  in setOpt to the policy server %d"), error);
       
   331     }
       
   332     
       
   333     TRequestStatus status;
       
   334     iDrpPolicyServer.LoadPolicy( *policyData, iDrpPolicyHandle, status, iMyZoneInfoSet);
       
   335     User::WaitForRequest(status);
       
   336     TInt err1 = status.Int();
       
   337     if(err1 == KErrNone)
       
   338         {
       
   339         iDrpPolicyServer.ActivatePolicy(iDrpPolicyHandle(), status );
       
   340         User::WaitForRequest(status);
       
   341         User::LeaveIfError(status.Int());   
       
   342         SetBlockResult(EPass);
       
   343         }
       
   344     else
       
   345         {
       
   346         SetError(status.Int());
       
   347         ERR_PRINTF2(_L("DoLoadDropModePolicy->LoadPolicy failed with error: %d"),err1);
       
   348         SetBlockResult(EFail);
       
   349         }
       
   350     CleanupStack::PopAndDestroy(policyData);    
       
   351     pSADB.Close();
       
   352     pSocketServ.Close();     
       
   353     }
       
   354 
       
   355 
       
   356 void CT_LoadPolicyBBD::DoLoadNewBypassModePolicy(const TDesC& /*aSection*/)
       
   357     {       
       
   358     RSocketServ pSocketServ;
       
   359     /** Handle to SADB socket */
       
   360     RSADB pSADB;
       
   361     TInt err;
       
   362             
       
   363     err = pSocketServ.Connect();
       
   364     if ( err != KErrNone)
       
   365          {
       
   366          ERR_PRINTF2(_L("DoLoadNewBypassModePolicy():- Failed to connect  RSocketServ with error: %d"), err);
       
   367          SetBlockResult(EFail);  
       
   368          }   
       
   369     err = pSADB.Open(pSocketServ);
       
   370     if ( err != KErrNone)
       
   371          {
       
   372          ERR_PRINTF2(_L("DoLoadNewBypassModePolicy():- Failed to open RSADB with error: %d"), err);
       
   373          SetBlockResult(EFail);   
       
   374          }                                   
       
   375                     
       
   376     HBufC8 *policyData = HBufC8::NewLC( KMyPolicy2().Length() + 256); // Allow size for IP spec.
       
   377     TPtr8 policyDataPtr(policyData->Des());
       
   378     policyDataPtr.Append(KMyPolicy2);
       
   379     
       
   380 
       
   381     TRequestStatus status;
       
   382     iBypsPolicyServer.LoadPolicy( *policyData, iNewBypsPolicyHandle, status, iMyZoneInfoSet);
       
   383     User::WaitForRequest(status);
       
   384     
       
   385     err = status.Int();
       
   386     if( err == KErrNone)
       
   387         {
       
   388         iBypsPolicyServer.ActivatePolicy( iNewBypsPolicyHandle(), status );
       
   389         User::WaitForRequest(status);
       
   390         User::LeaveIfError(status.Int());   
       
   391         SetBlockResult(EPass);
       
   392         }
       
   393     else
       
   394         {
       
   395         SetError(status.Int());
       
   396         ERR_PRINTF2(_L("DoLoadNewBypassPolicy():- LoadPolicy failed with error: %d"), err);
       
   397         SetBlockResult(EFail);
       
   398         }
       
   399     CleanupStack::PopAndDestroy(policyData);
       
   400     pSADB.Close();
       
   401     pSocketServ.Close();     
       
   402     }
       
   403 
       
   404 
       
   405 /*
       
   406 *Execute the test to unload the policy.
       
   407 */
       
   408 void CT_LoadPolicyBBD::DoUnloadDropPolicy(const TDesC& /*aSection*/)
       
   409     {      
       
   410     TRequestStatus status;
       
   411     iDrpPolicyServer.UnloadPolicy(iDrpPolicyHandle(),status);
       
   412     User::WaitForRequest(status);
       
   413     TInt err = status.Int();
       
   414     if( err != KErrNone)
       
   415         {
       
   416         SetError(err);
       
   417         ERR_PRINTF2(_L("DoUnloadDropPolicy():- UnloadPolicy failed with error: %d"), err);
       
   418         SetBlockResult(EFail);
       
   419         }
       
   420     }
       
   421 
       
   422 /*
       
   423 *Execute the test to unload the policy.
       
   424 */
       
   425 void CT_LoadPolicyBBD::DoUnloadNewBypassPolicy(const TDesC& /*aSection*/)
       
   426     {      
       
   427     TRequestStatus status;    
       
   428     iBypsPolicyServer.UnloadPolicy(iNewBypsPolicyHandle(),status);
       
   429     User::WaitForRequest(status);
       
   430     TInt err = status.Int();
       
   431     if( err != KErrNone)
       
   432         {
       
   433         SetError(err);
       
   434         ERR_PRINTF2(_L("DoUnloadNewBypassPolicy():- UnloadPolicy failed with error: %d"), err);
       
   435         SetBlockResult(EFail);
       
   436         }
       
   437     }
       
   438 
       
   439 /*
       
   440 *Execute the test to unload the policy.
       
   441 */
       
   442 void CT_LoadPolicyBBD::DoUnloadBypassPolicy(const TDesC& /*aSection*/)
       
   443     {      
       
   444     TRequestStatus status;    
       
   445     iBypsPolicyServer.UnloadPolicy(iBypsPolicyHandle(),status);
       
   446     User::WaitForRequest(status);
       
   447     TInt err = status.Int();
       
   448     if( err != KErrNone)
       
   449         {
       
   450         SetError(err);
       
   451         ERR_PRINTF2(_L("DoUnloadBypassPolicy():- UnloadPolicy failed with error: %d"), err);
       
   452         SetBlockResult(EFail);
       
   453         }
       
   454     }
       
   455 
       
   456 
       
   457 /*
       
   458 *Execute the test for closing the connection.
       
   459 */
       
   460 void CT_LoadPolicyBBD::DoCmdClose(const TDesC& /*aSection*/)
       
   461     {      
       
   462     SetBlockResult(EPass);
       
   463     }
       
   464     
       
   465 
       
   466