crypto/weakcryptospi/test/tcryptospi/src/ruleselectcommonstep.cpp
changeset 8 35751d3474b7
child 49 2f10d260163b
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2007-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 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23 #include "ruleselectcommonstep.h"
       
    24 #include "plugincharschecker.h"
       
    25 #include "cryptosymmetriccipherapi.h"
       
    26 #include "cryptoasymmetriccipherapi.h"
       
    27 #include <cryptospi/cryptohashapi.h>
       
    28 #include <cryptospi/cryptorandomapi.h>
       
    29 #include "cryptosignatureapi.h"
       
    30 #include "cryptokeyagreementapi.h"
       
    31 #include "cryptokeypairgeneratorapi.h"
       
    32 #include "keypair.h"
       
    33 #include "keys.h"
       
    34 
       
    35 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
       
    36 #include <cryptospi/cryptomacapi.h>
       
    37 #endif
       
    38 
       
    39 #include <cryptospi/cryptospistateapi.h>
       
    40 #include <cryptospi/ruleselector.h>
       
    41 
       
    42 using namespace CryptoSpi;
       
    43 
       
    44 CRuleSelectCommonStep::~CRuleSelectCommonStep()
       
    45 	{
       
    46 	}
       
    47 
       
    48 CRuleSelectCommonStep::CRuleSelectCommonStep()
       
    49 	{
       
    50 	SetTestStepName(KRuleSelectCommonStep);
       
    51 	}
       
    52 
       
    53 TVerdict CRuleSelectCommonStep::doTestStepPreambleL()
       
    54 	{
       
    55 	SetTestStepResult(EPass);
       
    56 	return TestStepResult();
       
    57 	}
       
    58 
       
    59 TVerdict CRuleSelectCommonStep::doTestStepL()
       
    60 	{
       
    61 	
       
    62 	INFO_PRINTF1(_L("Rule Selection - Common Characteristics Selection"));
       
    63 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
    64 	
       
    65 	if (TestStepResult()==EPass)
       
    66 		{
       
    67 		
       
    68 		TInt err = 0;
       
    69 
       
    70 		//Create Default Selection Rules Object
       
    71 		CSelectionRules* rules = CSelectionRules::NewL();
       
    72 		CleanupStack::PushL(rules);
       
    73 		
       
    74 		//*************SELECTION RULE CREATION AND ADDITION**************
       
    75 
       
    76 		//Boolean to determine whether there are more rules to apply
       
    77 		TBool moreRules;
       
    78 		moreRules = ETrue;
       
    79 		
       
    80 		//Itterator representing the current rule. Appended to the end of each selection
       
    81 		//rule INI parameter 
       
    82 		TInt currentRule;
       
    83 		currentRule = 1;
       
    84 		
       
    85 		//Total number of selection rules added to the CSelectionRules object
       
    86 		TInt totalRules;
       
    87 		totalRules = 0;
       
    88 			
       
    89 		TVariantPtrC interfaceScope;
       
    90 		TVariantPtrC algorithmScope;
       
    91 		TVariantPtrC charUid;
       
    92 		TVariantPtrC compareOperator;
       
    93 		TVariantPtrC charValue;
       
    94 		TVariantPtrC charValueType;		
       
    95 		TBool isOptional;
       
    96 		
       
    97 		
       
    98 		//Whilst there are selection rules present in the INI file that have yet to be
       
    99 		//added to the CSelectionRules object	
       
   100 		while(moreRules)
       
   101 			{
       
   102 			INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
   103 			
       
   104 			//Constructs each of the parameter names required to extract the necessary 
       
   105 			//selection rule data from the specified INI configuration file
       
   106 			TBuf<KMaxConfigParamStringSize> interfaceScopeStr(KConfigInterfaceScopeBase);
       
   107 			interfaceScopeStr.AppendNum(currentRule);
       
   108 			INFO_PRINTF2(_L("interfaceScopeStr = %S"), &interfaceScopeStr);
       
   109 			
       
   110 			TBuf<KMaxConfigParamStringSize> algorithmScopeStr(KConfigAlgorithmScopeBase);
       
   111 			algorithmScopeStr.AppendNum(currentRule);
       
   112 			INFO_PRINTF2(_L("algorithmScopeStr = %S"), &algorithmScopeStr);
       
   113 			
       
   114 			TBuf<KMaxConfigParamStringSize> charUidStr(KConfigCharUidBase);
       
   115 			charUidStr.AppendNum(currentRule);
       
   116 			INFO_PRINTF2(_L("charUidStr = %S"), &charUidStr);
       
   117 			
       
   118 			TBuf<KMaxConfigParamStringSize> compareOperatorStr(KConfigCompareOperatorBase);
       
   119 			compareOperatorStr.AppendNum(currentRule);
       
   120 			INFO_PRINTF2(_L("compareOperatorStr = %S"), &compareOperatorStr);
       
   121 			
       
   122 			TBuf<KMaxConfigParamStringSize> charValueStr(KConfigCharValueBase);
       
   123 			charValueStr.AppendNum(currentRule);
       
   124 			INFO_PRINTF2(_L("charValueStr = %S"), &charValueStr);
       
   125 			
       
   126 			TBuf<KMaxConfigParamStringSize> charValueTypeStr(KConfigCharValueTypeBase);
       
   127 			charValueTypeStr.AppendNum(currentRule);
       
   128 			INFO_PRINTF2(_L("charValueTypeStr = %S"), &charValueTypeStr);
       
   129 			
       
   130 			TBuf<KMaxConfigParamStringSize> isOptionalStr(KConfigIsOptionalBase);
       
   131 			isOptionalStr.AppendNum(currentRule);
       
   132 			INFO_PRINTF2(_L("isOptionalStr = %S"), &isOptionalStr);
       
   133 			
       
   134 			
       
   135 			//Extracts the parameter data for a single rule from the specified INI file 
       
   136 			if(!GetStringFromConfig(ConfigSection(),interfaceScopeStr,interfaceScope) ||
       
   137 				!GetStringFromConfig(ConfigSection(),algorithmScopeStr,algorithmScope) ||
       
   138 				!GetStringFromConfig(ConfigSection(),charUidStr,charUid) ||
       
   139 				!GetStringFromConfig(ConfigSection(),compareOperatorStr,compareOperator) ||
       
   140 				!GetStringFromConfig(ConfigSection(),charValueTypeStr,charValueType) ||
       
   141 				!GetBoolFromConfig(ConfigSection(),isOptionalStr,isOptional))
       
   142 				{
       
   143 				moreRules = EFalse;
       
   144 				}
       
   145 			else
       
   146 				{
       
   147 				
       
   148 				//Creates a pointer to store the address of the newly created selection rule		
       
   149 				CSelectionRuleContent* rule = NULL;
       
   150 				
       
   151 				//Creates a pointer to store the contents of the rule value parameter, so that
       
   152 				//it can be passed in at construction of the selection rule.
       
   153 				CCryptoParam* ruleValueParam = NULL;
       
   154 				
       
   155 				//Depending on the 'RuleValueType' parameter read in from the INI file, the 'RuleValue'
       
   156 				//parameter will either be read in as an Integer,String or a Boolean.
       
   157 				switch(charValueType)
       
   158 					{
       
   159 					case ERuleValueInteger:
       
   160 						{
       
   161 						TInt charValue;
       
   162 						
       
   163 						if(!GetIntFromConfig(ConfigSection(),charValueStr,charValue))
       
   164 							{
       
   165 							//Should the integer value be represented by a constant..
       
   166 							TVariantPtrC strCharValue;
       
   167 							
       
   168 							if(!GetStringFromConfig(ConfigSection(),charValueStr,strCharValue))
       
   169 								{
       
   170 								ERR_PRINTF1(_L("** .INI Error: INTEGER Rule Value Not Initialised Correctly **"));
       
   171 								SetTestStepResult(EFail);	
       
   172 								}
       
   173 							else
       
   174 								{
       
   175 								ruleValueParam = CCryptoIntParam::NewL(TInt(strCharValue),TUid(charUid));	
       
   176 								}
       
   177 							}
       
   178 						else
       
   179 							{		
       
   180 							//The Integer Rule Value is encapsulated as a CCryptoIntParam object so that it can be passed in as 
       
   181 							//a parameter when constructing the selection rule				
       
   182 							ruleValueParam = CCryptoIntParam::NewL(charValue,charUid);											
       
   183 							}
       
   184 							
       
   185 						break;	
       
   186 						}
       
   187 						
       
   188 					case ERuleValueDes8:
       
   189 						{		
       
   190 						TPtrC charValue;
       
   191 						
       
   192 						if(!GetStringFromConfig(ConfigSection(),charValueStr,charValue))
       
   193 							{
       
   194 							ERR_PRINTF1(_L("** .INI Error: STRING Rule Value Not Initialised Correctly **"));
       
   195 							SetTestStepResult(EFail);	
       
   196 							}
       
   197 						else
       
   198 							{
       
   199 							//Convert encryption key to an 8 Bit Descriptor
       
   200 							HBufC8* charStr = HBufC8::NewLC(charValue.Length());
       
   201 							TPtr8 charStrPtr = charStr->Des();
       
   202 			
       
   203 							charStrPtr.Copy(charValue);
       
   204 							
       
   205 							//The String Rule Value is encapsulated as a CCryptoDesC8Param object so that it can be passed in as 
       
   206 							//a parameter when constructing the selection rule
       
   207 							ruleValueParam = CCryptoDesC8Param::NewL(charStrPtr,charUid);
       
   208 							
       
   209 							CleanupStack::PopAndDestroy(charStr);
       
   210 							}
       
   211 							
       
   212 						break;	
       
   213 						}
       
   214 						
       
   215 					case ERuleValueDes16:
       
   216 						{		
       
   217 						TPtrC charValue;
       
   218 						
       
   219 						if(!GetStringFromConfig(ConfigSection(),charValueStr,charValue))
       
   220 							{
       
   221 							ERR_PRINTF1(_L("** .INI Error: STRING Rule Value Not Initialised Correctly **"));
       
   222 							SetTestStepResult(EFail);	
       
   223 							}
       
   224 						else
       
   225 							{						
       
   226 							//The String Rule Value is encapsulated as a CCryptoDesC8Param object so that it can be passed in as 
       
   227 							//a parameter when constructing the selection rule
       
   228 							ruleValueParam = CCryptoDesC16Param::NewL(charValue,charUid);
       
   229 							}
       
   230 							
       
   231 						break;	
       
   232 						}
       
   233 						
       
   234 					case ERuleValueBoolean:
       
   235 						{
       
   236 						TBool charValue;
       
   237 						
       
   238 						if(!GetBoolFromConfig(ConfigSection(),charValueStr,charValue))
       
   239 							{
       
   240 							ERR_PRINTF1(_L("** .INI Error: BOOLEAN Rule Value Not Initialised Correctly **"));
       
   241 							SetTestStepResult(EFail);	
       
   242 							}
       
   243 						else
       
   244 							{
       
   245 							//The Boolean Rule Value is encapsulated as a CCryptoInt8Param object so that it can be passed in as 
       
   246 							//a parameter when constructing the selection rule
       
   247 							ruleValueParam = CCryptoIntParam::NewL(charValue,charUid);
       
   248 							}
       
   249 							
       
   250 						break;	
       
   251 						}
       
   252 						
       
   253 					default:
       
   254 						{
       
   255 						ERR_PRINTF1(_L("** .INI Error: Rule Value Type Unknown **"));
       
   256 						SetTestStepResult(EFail);
       
   257 						break;	
       
   258 						}	
       
   259 					}
       
   260 						
       
   261 				
       
   262 				if(TestStepResult() == EPass)
       
   263 					{
       
   264 					
       
   265 					//Creates the CSelectionRuleContent object, passing in all the parameters read in
       
   266 					//from the specified INI configuration file
       
   267 							
       
   268 					TRAP_LOG(err, rule = CSelectionRuleContent::NewL(interfaceScope,
       
   269 																	algorithmScope,
       
   270 																	ruleValueParam,
       
   271 																	TRuleOperator((TInt)compareOperator),
       
   272 																	isOptional));	
       
   273 					if(err == KErrNone)
       
   274 						{
       
   275 						//Add the newly created selection rule to the CSelectionRules collection by
       
   276 						//calling the 'AddSelectionRule' method and passing in the address of the rule
       
   277 						TRAP_LOG(err,rules->AddSelectionRuleL(rule));
       
   278 						
       
   279 						if(err == KErrNone)
       
   280 							{
       
   281 							INFO_PRINTF2(_L("Rule %d Created, Added and Destoryed"), currentRule);
       
   282 							
       
   283 							currentRule++;
       
   284 							totalRules++;						
       
   285 							}
       
   286 						else
       
   287 							{
       
   288 							ERR_PRINTF2(_L("RULE FAILURE: Failed to Add Selection Rule %d "), currentRule);
       
   289 							moreRules = EFalse;
       
   290 							SetTestStepResult(EFail);
       
   291 							}
       
   292 						}	
       
   293 					else
       
   294 						{
       
   295 						ERR_PRINTF2(_L("RULE FAILURE: Failed to Create Selection Rule %d "), currentRule);
       
   296 						moreRules = EFalse;	
       
   297 						SetTestStepResult(EFail);
       
   298 						}
       
   299 					
       
   300 						
       
   301 					}
       
   302 				else
       
   303 					{
       
   304 					moreRules = EFalse;	
       
   305 					}
       
   306 				}	
       
   307 			}
       
   308 			
       
   309 		//If 1 or more selection rule objects were added successfully without error, the test step
       
   310 		//can proceed to the next phase   
       
   311 		if((TestStepResult() == EPass) && (totalRules > 0))
       
   312 			{
       
   313 			INFO_PRINTF2(_L("Successfully Added Selection Rules: %d"), totalRules);
       
   314 			}
       
   315 		else if((TestStepResult() == EFail) && (totalRules > 0))
       
   316 			{
       
   317 			ERR_PRINTF1(_L("** .INI Error: Errornous Selection Rule Data **"));
       
   318 			SetTestStepResult(EFail);
       
   319 			}
       
   320 		else
       
   321 			{
       
   322 			ERR_PRINTF1(_L("** NO VALID SELECTION RULE DATA FOUND **"));	
       
   323 			}
       
   324 
       
   325 		//**************************************************************		
       
   326 		
       
   327 		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
       
   328 		
       
   329 		if(TestStepResult()==EPass)
       
   330 			{	
       
   331 			
       
   332 			//Assume faliure, unless all is successful
       
   333 			SetTestStepResult(EFail);
       
   334 				
       
   335 			//Create Rule Selector Object	
       
   336 			CRuleSelector* ruleSelector = CRuleSelector::NewL(rules);
       
   337 			CleanupStack::Pop(rules);
       
   338 			CleanupStack::PushL(ruleSelector);
       
   339 
       
   340 			//Set the Selector Passing in a pointer to the Rule Selector and SPI State	
       
   341 			CCryptoSpiStateApi::SetSelector(ruleSelector);
       
   342 
       
   343 			//Define a pointer of type CCryptoBase to store the address ofthe instantiated encryption object
       
   344 			CCryptoBase* plugin = NULL;
       
   345 
       
   346 			TVariantPtrC interfaceType;
       
   347 			
       
   348 			//Extract the Encryption Type parameter from the specified INI file
       
   349 			if(!GetStringFromConfig(ConfigSection(),KConfigInterfaceType,interfaceType))
       
   350 				{
       
   351 				ERR_PRINTF1(_L("** .INI Error: Encryption Type Data Not Located **"));
       
   352 				SetTestStepResult(EFail);
       
   353 				}
       
   354 			else
       
   355 				{
       
   356 				//Depending on the Interface Type retrieved, the appropriate factory object
       
   357 				//is created and assigned to the previously CCryptoBase plugin pointer
       
   358 				switch(interfaceType) 
       
   359 					{			
       
   360 					case KAsymmetricCipherInterface:
       
   361 						{
       
   362 		
       
   363 						TPtrC16 encryptKey;
       
   364 						TVariantPtrC keyType;
       
   365 						TVariantPtrC algorithmUid;
       
   366 						TVariantPtrC cryptoMode;
       
   367 						TVariantPtrC paddingMode;
       
   368 						TVariantPtrC algorithmParams;
       
   369 						
       
   370 						//Each of the individual parameters required to create the Asymmetric Cipher object
       
   371 						//are read in from the specified INI configuration file	
       
   372 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   373 							!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
       
   374 							!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
       
   375 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   376 							{
       
   377 							ERR_PRINTF1(_L("** .INI Error: Asymmetric Cipher Arguments Not Located **"));
       
   378 							SetTestStepResult(EFail);
       
   379 							}
       
   380 						else
       
   381 							{
       
   382 								
       
   383 							//********** Rule Selector Unselcted to Create Key Pair ************
       
   384 							CCryptoSpiStateApi::UnsetSelector();
       
   385 							
       
   386 							CCryptoParams* keyParams = CCryptoParams::NewLC(); 
       
   387 							
       
   388 							//Create Key Pair and Key Pair Generator Objects
       
   389 				   			CKeyPair* keyPair = NULL;
       
   390 							CKeyPairGenerator * keypairImpl = NULL;
       
   391 							
       
   392 							INFO_PRINTF1(_L("Generating RSA keys"));
       
   393 							
       
   394 							// create an RSA key pair
       
   395 							keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
       
   396 							keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
       
   397 
       
   398 							// create a key pair generator implementation interface
       
   399 							TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
       
   400 															keypairImpl, 
       
   401 															KRSAKeyPairGeneratorUid, 
       
   402 															keyParams));
       
   403 															
       
   404 							CleanupStack::PushL(keypairImpl);
       
   405 
       
   406 							// Create a Key Pair	
       
   407 							TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
       
   408 							
       
   409 							CleanupStack::PushL(keyPair);
       
   410 							
       
   411 							CCryptoSpiStateApi::SetSelector(ruleSelector);
       
   412 							//******************************************************************
       
   413 							
       
   414 							CAsymmetricCipher* asymmetricCipherImpl;	
       
   415 								
       
   416 							TRAP_LOG(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL(asymmetricCipherImpl,
       
   417 																							algorithmUid,
       
   418 																							keyPair->PublicKey(),
       
   419 																							cryptoMode,
       
   420 																							paddingMode,
       
   421 																							NULL));
       
   422 							
       
   423 							if(asymmetricCipherImpl && (err == KErrNone))
       
   424 								{
       
   425 								plugin = static_cast<CCryptoBase*>(asymmetricCipherImpl);
       
   426 								
       
   427 								INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Cipher Object **"));
       
   428 								SetTestStepResult(EPass);	
       
   429 								}
       
   430 							else
       
   431 								{
       
   432 								ERR_PRINTF2(_L("** Error: Loading Asymmetric Cipher Object - %d **"), err);
       
   433 								SetTestStepResult(EFail);
       
   434 								}
       
   435 								
       
   436 							CleanupStack::PopAndDestroy(3,keyParams);	
       
   437 							} 
       
   438 							
       
   439 						break;
       
   440 						}
       
   441 							
       
   442 					case KSymmetricCipherInterface:
       
   443 						{
       
   444 						
       
   445 						TPtrC16 encryptKey;
       
   446 						TVariantPtrC keyType;
       
   447 						TVariantPtrC algorithmUid;
       
   448 						TVariantPtrC cryptoMode;
       
   449 						TVariantPtrC operationMode;
       
   450 						TVariantPtrC paddingMode;
       
   451 						TVariantPtrC algorithmParams;
       
   452 						
       
   453 						//Each of the individual parameters required to create the Symmetric Cipher object
       
   454 						//are read in from the specified INI configuration file
       
   455 						if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || 
       
   456 							!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
       
   457 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   458 							!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
       
   459 							!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
       
   460 							!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
       
   461 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   462 							{
       
   463 							ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
       
   464 							SetTestStepResult(EFail);
       
   465 							}
       
   466 						else
       
   467 							{
       
   468 							//Convert encryption key to an 8 Bit Descriptor
       
   469 							HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
       
   470 							TPtr8 keyStrPtr = keyStr->Des();
       
   471 			
       
   472 							keyStrPtr.Copy(encryptKey);
       
   473 							
       
   474 							//Create an new CryptoParams object to encapsulate the key type and secret key string
       
   475 							CCryptoParams* keyParams = CCryptoParams::NewL();
       
   476 							CleanupStack::PushL(keyParams);
       
   477 							keyParams->AddL(*keyStr,keyType);
       
   478 			
       
   479 							//Create Key Object
       
   480 							TKeyProperty keyProperty;
       
   481 							CKey* key=CKey::NewL(keyProperty,*keyParams);
       
   482 							CleanupStack::PushL(key);
       
   483 							
       
   484 							CSymmetricCipher* symmetricCipherImpl = NULL;	
       
   485 								
       
   486 							TRAP_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
       
   487 																						algorithmUid,
       
   488 																						*key,
       
   489 																						cryptoMode,
       
   490 																						operationMode,
       
   491 																						paddingMode,
       
   492 																						NULL));
       
   493 							
       
   494 							
       
   495 							if(symmetricCipherImpl && (err == KErrNone))
       
   496 								{
       
   497 								
       
   498 								plugin = static_cast<CCryptoBase*>(symmetricCipherImpl);
       
   499 								
       
   500 								INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
       
   501 								SetTestStepResult(EPass);	
       
   502 								}
       
   503 							else
       
   504 								{
       
   505 								ERR_PRINTF2(_L("** Error: Loading Symmetric Cipher Object - %d **"), err);
       
   506 								SetTestStepResult(EFail);
       
   507 								} 
       
   508 									
       
   509 							CleanupStack::PopAndDestroy(3,keyStr);
       
   510 							} 
       
   511 							
       
   512 						break;
       
   513 						}
       
   514 						
       
   515 					case KHashInterface:
       
   516 						{
       
   517 						TVariantPtrC algorithmUid;
       
   518 						TVariantPtrC operationMode;
       
   519 						TVariantPtrC algorithmParams;
       
   520 						
       
   521 						//Each of the individual parameters required to create the Hash object
       
   522 						//are read in from the specified INI configuration file	
       
   523 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   524 #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT							
       
   525 							!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
       
   526 #endif							
       
   527 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   528 							{
       
   529 							ERR_PRINTF1(_L("** .INI Error: Hash Arguments Not Located **"));
       
   530 							SetTestStepResult(EFail);
       
   531 							}
       
   532 						else
       
   533 							{
       
   534 							CHash* hashImpl = NULL;
       
   535 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT							
       
   536 							if (GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode))
       
   537 								{
       
   538 								TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
       
   539 																	algorithmUid,
       
   540 																	operationMode,
       
   541 																	NULL,
       
   542 																	NULL));
       
   543 								}
       
   544 							else
       
   545 								{
       
   546 								TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
       
   547 																	algorithmUid,
       
   548 																	NULL));								
       
   549 								}
       
   550 #else
       
   551 							TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
       
   552 																	algorithmUid,
       
   553 																	operationMode,
       
   554 																	NULL,
       
   555 																	NULL));
       
   556 #endif							
       
   557 
       
   558 							if(hashImpl && (err == KErrNone))
       
   559 								{
       
   560 								plugin = static_cast<CCryptoBase*>(hashImpl);
       
   561 								
       
   562 								INFO_PRINTF1(_L("** Successfully Loaded Hash Object **"));
       
   563 								SetTestStepResult(EPass);	
       
   564 								}
       
   565 							else
       
   566 								{
       
   567 								ERR_PRINTF2(_L("** Error: Loading Hash Object - %d **"), err);
       
   568 								SetTestStepResult(EFail);
       
   569 								}	
       
   570 							}
       
   571 							
       
   572 						break;
       
   573 						}
       
   574 
       
   575 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT							
       
   576 					case KMacInterface:
       
   577 						{
       
   578 						TVariantPtrC algorithmUid;
       
   579 						TPtrC encryptKey;
       
   580 						TVariantPtrC keyType;
       
   581 						
       
   582 						//Each of the individual parameters required to create the Mac object
       
   583 						//are read in from the specified INI configuration file	
       
   584 						if (!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   585 							!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
       
   586 							!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
       
   587 							{
       
   588 							ERR_PRINTF1(_L("** .INI Error: Mac Arguments Not Located **"));
       
   589 							SetTestStepResult(EFail);
       
   590 							}
       
   591 						else
       
   592 							{
       
   593 							CMac* macImpl = NULL;
       
   594 							
       
   595 							//Convert encryption key to an 8 Bit Descriptor
       
   596 							HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
       
   597 							TPtr8 keyStrPtr = keyStr->Des();
       
   598 							
       
   599 							keyStrPtr.Copy(encryptKey);
       
   600 											
       
   601 							//Create an new CryptoParams object to encapsulate the key type and secret key string
       
   602 							CCryptoParams* keyParams = CCryptoParams::NewL();
       
   603 							CleanupStack::PushL(keyParams);
       
   604 							keyParams->AddL(*keyStr,keyType);
       
   605 							
       
   606 							//Create Key Object
       
   607 							TKeyProperty keyProperty;
       
   608 							CKey* key=CKey::NewL(keyProperty,*keyParams);
       
   609 							CleanupStack::PushL(key);
       
   610 									
       
   611 							TRAP_LOG(err,CMacFactory::CreateMacL(macImpl,
       
   612 																algorithmUid,
       
   613 																*key,
       
   614 																NULL));
       
   615 							
       
   616 							if(macImpl && (err == KErrNone))
       
   617 								{
       
   618 								plugin = static_cast<CCryptoBase*>(macImpl);
       
   619 								
       
   620 								INFO_PRINTF1(_L("** Successfully Loaded Mac Object **"));
       
   621 								SetTestStepResult(EPass);	
       
   622 								}
       
   623 							else
       
   624 								{
       
   625 								delete macImpl;
       
   626 								ERR_PRINTF2(_L("** Error: Loading Mac Object - %d **"), err);
       
   627 								SetTestStepResult(EFail);
       
   628 								}
       
   629 							
       
   630 							CleanupStack::PopAndDestroy(3,keyStr);
       
   631 							}
       
   632 						
       
   633 						break;
       
   634 						}
       
   635 #endif							
       
   636 						
       
   637 					case KRandomInterface:
       
   638 						{
       
   639 						
       
   640 						TVariantPtrC algorithmUid;
       
   641 						TVariantPtrC algorithmParams;
       
   642 						
       
   643 						//Each of the individual parameters required to create the Random object
       
   644 						//are read in from the specified INI configuration file
       
   645 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   646 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   647 							{
       
   648 							ERR_PRINTF1(_L("** .INI Error: Random Arguments Not Located **"));
       
   649 							SetTestStepResult(EFail);
       
   650 							}
       
   651 						else
       
   652 							{
       
   653 							CryptoSpi::CRandom* randomImpl = NULL;
       
   654 							
       
   655 							TRAP_LOG(err,CRandomFactory::CreateRandomL(randomImpl,
       
   656 																		algorithmUid,
       
   657 																		NULL));
       
   658 
       
   659 							if(randomImpl && (err == KErrNone))
       
   660 								{
       
   661 								plugin = static_cast<CCryptoBase*>(randomImpl);
       
   662 								
       
   663 								INFO_PRINTF1(_L("** Successfully Loaded Random Object **"));
       
   664 								SetTestStepResult(EPass);	
       
   665 								}
       
   666 							else
       
   667 								{
       
   668 								ERR_PRINTF2(_L("** Error: Loading Random Object - %d **"), err);
       
   669 								SetTestStepResult(EFail);
       
   670 								}
       
   671 								
       
   672 							} 
       
   673 							
       
   674 						break;	
       
   675 						}
       
   676 						
       
   677 					case KSignerInterface:
       
   678 						{
       
   679 						TVariantPtrC algorithmUid;
       
   680 						TVariantPtrC paddingMode;
       
   681 						TVariantPtrC algorithmParams;
       
   682 						
       
   683 						//Each of the individual parameters required to create the Signer object
       
   684 						//are read in from the specified INI configuration file
       
   685 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   686 							!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
       
   687 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   688 							{
       
   689 							ERR_PRINTF1(_L("** .INI Error: Signer Arguments Not Located **"));
       
   690 							SetTestStepResult(EFail);
       
   691 							}
       
   692 						else
       
   693 							{
       
   694 							
       
   695 							//********** Rule Selector Unselected to Create Key Pair ************
       
   696 							CCryptoSpiStateApi::UnsetSelector();
       
   697 							
       
   698 							CCryptoParams* keyParams = CCryptoParams::NewLC(); 
       
   699 							
       
   700 							//Create Key Pair and Key Pair Generator Objects
       
   701 				   			CKeyPair* keyPair = NULL;
       
   702 							CKeyPairGenerator * keypairImpl = NULL;
       
   703 							
       
   704 							INFO_PRINTF1(_L("Generating RSA keys"));
       
   705 							
       
   706 							// create an RSA key pair
       
   707 							keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
       
   708 							keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
       
   709 
       
   710 							// create a key pair generator implementation interface
       
   711 							TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
       
   712 																							KRSAKeyPairGeneratorUid, 
       
   713 																							keyParams));
       
   714 															
       
   715 							CleanupStack::PushL(keypairImpl);
       
   716 
       
   717 							// Create a Key Pair	
       
   718 							TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
       
   719 							
       
   720 							CleanupStack::PushL(keyPair);
       
   721 							
       
   722 							CCryptoSpiStateApi::SetSelector(ruleSelector);
       
   723 							//******************************************************************
       
   724 							
       
   725 							CSigner* signerImpl = NULL;	
       
   726 							
       
   727 						    TRAP_LOG(err,CSignatureFactory::CreateSignerL(signerImpl,
       
   728 																	   		algorithmUid,
       
   729 																	   		keyPair->PrivateKey(),
       
   730 																	   		paddingMode,
       
   731 																	   		NULL));
       
   732 																	   
       
   733 							if(signerImpl && (err == KErrNone))
       
   734 								{
       
   735 								plugin = static_cast<CCryptoBase*>(signerImpl);
       
   736 								
       
   737 								INFO_PRINTF1(_L("** Successfully Loaded Signer Object **"));
       
   738 								SetTestStepResult(EPass);	
       
   739 								}
       
   740 							else
       
   741 								{
       
   742 								ERR_PRINTF2(_L("** Error: Loading Signer Object - %d **"), err);
       
   743 								SetTestStepResult(EFail);
       
   744 								}
       
   745 							
       
   746 							CleanupStack::PopAndDestroy(3,keyParams);	
       
   747 							}
       
   748 							
       
   749 						break;
       
   750 						}
       
   751 						
       
   752 					case KVerifierInterface:
       
   753 						{
       
   754 						TVariantPtrC algorithmUid;
       
   755 						TVariantPtrC paddingMode;
       
   756 						TVariantPtrC algorithmParams;
       
   757 						
       
   758 						//Each of the individual parameters required to create the Verifier object
       
   759 						//are read in from the specified INI configuration file
       
   760 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   761 							!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
       
   762 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   763 							{
       
   764 							ERR_PRINTF1(_L("** .INI Error: Verifier Arguments Not Located **"));
       
   765 							SetTestStepResult(EFail);
       
   766 							}
       
   767 						else
       
   768 							{
       
   769 							
       
   770 							//********** Rule Selector Unselected to Create Key Pair ************
       
   771 							CCryptoSpiStateApi::UnsetSelector();
       
   772 							
       
   773 							CCryptoParams* keyParams = CCryptoParams::NewLC(); 
       
   774 							
       
   775 							//Create Key Pair and Key Pair Generator Objects
       
   776 				   			CKeyPair* keyPair = NULL;
       
   777 							CKeyPairGenerator * keypairImpl = NULL;
       
   778 							
       
   779 							INFO_PRINTF1(_L("Generating RSA keys"));
       
   780 							
       
   781 							// create an RSA key pair
       
   782 							keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
       
   783 							keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
       
   784 
       
   785 							// create a key pair generator implementation interface
       
   786 							TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
       
   787 																							KRSAKeyPairGeneratorUid, 
       
   788 																							keyParams));
       
   789 															
       
   790 							CleanupStack::PushL(keypairImpl);
       
   791 
       
   792 							// Create a Key Pair	
       
   793 							TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
       
   794 							
       
   795 							CleanupStack::PushL(keyPair);
       
   796 							
       
   797 							CCryptoSpiStateApi::SetSelector(ruleSelector);
       
   798 							//******************************************************************
       
   799 							
       
   800 							CVerifier* verifierImpl = NULL;	
       
   801 							
       
   802 						    TRAP_LOG(err,CSignatureFactory::CreateVerifierL(verifierImpl,
       
   803 																	   		algorithmUid,
       
   804 																	   		keyPair->PublicKey(),
       
   805 																	   		paddingMode,
       
   806 																	   		NULL));
       
   807 																	   
       
   808 							if(verifierImpl && (err == KErrNone))
       
   809 								{
       
   810 								plugin = static_cast<CCryptoBase*>(verifierImpl);
       
   811 								
       
   812 								INFO_PRINTF1(_L("** Successfully Loaded Verifier Object **"));
       
   813 								SetTestStepResult(EPass);	
       
   814 								}
       
   815 							else
       
   816 								{
       
   817 								ERR_PRINTF2(_L("** Error: Loading Verifier Object - %d **"), err);
       
   818 								SetTestStepResult(EFail);
       
   819 								}
       
   820 							
       
   821 							CleanupStack::PopAndDestroy(3,keyParams);
       
   822 							}
       
   823 							
       
   824 						break;
       
   825 						}
       
   826 						
       
   827 					case KKeypairGeneratorInterface:
       
   828 						{
       
   829 						TVariantPtrC algorithmUid;
       
   830 						TVariantPtrC algorithmParams;
       
   831 						
       
   832 						//Each of the individual parameters required to create the Key Pair Generator object
       
   833 						//are read in from the specified INI configuration file
       
   834 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   835 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   836 							{
       
   837 							ERR_PRINTF1(_L("** .INI Error: Key Pair Generator Arguments Not Located **"));
       
   838 							SetTestStepResult(EFail);
       
   839 							}
       
   840 						else
       
   841 							{
       
   842 						
       
   843 							CCryptoParams* keyParams = CCryptoParams::NewLC(); 
       
   844 								
       
   845 							//Create Key Pair and Key Pair Generator Objects
       
   846 							CKeyPairGenerator * keypairImpl = NULL;
       
   847 							
       
   848 							INFO_PRINTF1(_L("Generating RSA keys"));
       
   849 							
       
   850 							// create an RSA key pair
       
   851 							keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
       
   852 							keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
       
   853 
       
   854 							// create a key pair generator implementation interface
       
   855 							TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
       
   856 																							algorithmUid, 
       
   857 																							keyParams));
       
   858 																							
       
   859 							if(keypairImpl && (err == KErrNone))
       
   860 								{
       
   861 								plugin = static_cast<CCryptoBase*>(keypairImpl);
       
   862 								
       
   863 								INFO_PRINTF1(_L("** Successfully Loaded Key Pair Generator Object **"));
       
   864 								SetTestStepResult(EPass);	
       
   865 								}
       
   866 							else
       
   867 								{
       
   868 								ERR_PRINTF2(_L("** Error: Loading Key Pair Generator Object - %d **"), err);
       
   869 								SetTestStepResult(EFail);
       
   870 								}
       
   871 								
       
   872 							CleanupStack::PopAndDestroy(keyParams);
       
   873 							}
       
   874 						
       
   875 						break;
       
   876 						}
       
   877 						
       
   878 					case KKeyAgreementInterface:
       
   879 						{
       
   880 						TVariantPtrC algorithmUid;
       
   881 						TVariantPtrC algorithmParams;
       
   882 						
       
   883 						//Each of the individual parameters required to create the Key Agreement object
       
   884 						//are read in from the specified INI configuration file
       
   885 						if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
       
   886 							!GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
       
   887 							{
       
   888 							ERR_PRINTF1(_L("** .INI Error: Key Agreement Arguments Not Located **"));
       
   889 							SetTestStepResult(EFail);
       
   890 							}
       
   891 						else
       
   892 							{
       
   893 							//********** Rule Selector Unselected to Create Key Pair ************
       
   894 							CCryptoSpiStateApi::UnsetSelector();
       
   895 	 		 
       
   896 							RInteger DH_N = RInteger::NewPrimeL(64);
       
   897 							CleanupClosePushL(DH_N);
       
   898 							
       
   899 							RInteger DH_N_MinusOne = RInteger::NewL(DH_N);
       
   900 							CleanupClosePushL(DH_N_MinusOne);
       
   901 							DH_N_MinusOne-=1;
       
   902 							
       
   903 							RInteger DH_G = RInteger::NewRandomL(TInteger::Two(), DH_N_MinusOne);	
       
   904 							CleanupClosePushL(DH_G);
       
   905 							
       
   906 							CCryptoParams* keyParams = CCryptoParams::NewLC(); 
       
   907 										
       
   908 							TRAP_LOG(err,keyParams->AddL(DH_N, KDhKeyParameterNUid));
       
   909 							TRAP_LOG(err,keyParams->AddL(DH_G, KDhKeyParameterGUid));
       
   910 							
       
   911 							//Create Key Pair and Key Pair Generator Objects
       
   912 				   			CKeyPair* keyPair = NULL;
       
   913 							CKeyPairGenerator * keypairImpl = NULL;
       
   914 							
       
   915 							INFO_PRINTF1(_L("Generating Key Pair..."));
       
   916 							
       
   917 							// create a key pair generator implementation interface
       
   918 							TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
       
   919 																							KDHKeyPairGeneratorUid, 
       
   920 																							keyParams));								
       
   921 							CleanupStack::PushL(keypairImpl);
       
   922 
       
   923 							// Create a Key Pair	
       
   924 							TRAP_LOG(err,keypairImpl->GenerateKeyPairL(NULL, *keyParams, keyPair));
       
   925 							
       
   926 							CleanupStack::PushL(keyPair);
       
   927 							
       
   928 							CCryptoSpiStateApi::SetSelector(ruleSelector);
       
   929 							//******************************************************************
       
   930 							
       
   931 							CKeyAgreement* keyAgreementImpl = NULL;	
       
   932 								
       
   933 							TRAP_LOG(err,CKeyAgreementFactory::CreateKeyAgreementL(keyAgreementImpl,
       
   934 																				algorithmUid,
       
   935 																				keyPair->PrivateKey(),
       
   936 																				keyParams));
       
   937 																				
       
   938 							if(keyAgreementImpl && (err == KErrNone))
       
   939 								{
       
   940 								plugin = static_cast<CCryptoBase*>(keyAgreementImpl);
       
   941 								
       
   942 								INFO_PRINTF1(_L("** Successfully Loaded Key Agreement Object **"));
       
   943 								SetTestStepResult(EPass);	
       
   944 								}
       
   945 							else
       
   946 								{
       
   947 								ERR_PRINTF2(_L("** Error: Loading Key Agreement Object - %d **"), err);
       
   948 								SetTestStepResult(EFail);
       
   949 								}
       
   950 								
       
   951 							CleanupStack::PopAndDestroy(6,&DH_N);
       
   952 							}
       
   953 							
       
   954 						break;
       
   955 						}
       
   956 						
       
   957 					default:
       
   958 						{
       
   959 						ERR_PRINTF1(_L("** .INI Error: Interface Type Unknown **"));
       
   960 						SetTestStepResult(EFail);
       
   961 						break;	
       
   962 						}
       
   963 						
       
   964 					}
       
   965 				}		
       
   966 				
       
   967 			if(TestStepResult()==EPass)
       
   968 				{
       
   969 				//Push the selected implementation onto the Cleanup Stack
       
   970 				CleanupStack::PushL(plugin);	
       
   971 				
       
   972 				//Assume faliure, unless all is successful
       
   973 				SetTestStepResult(EFail);
       
   974 				
       
   975 				//Define a pointer of type TCharacteristics in order to store the appropriate
       
   976 				//encryption object's characterisctics
       
   977 				const TCharacteristics* characteristics(NULL);
       
   978 					
       
   979 				//Retrieve the characteristics for the symmetric cipher implementation object
       
   980 				TRAP_LOG(err, plugin->GetCharacteristicsL(characteristics));
       
   981 				
       
   982 				TVariantPtrC exAlgorithmUid;
       
   983 				TVariantPtrC exImplementationUid;
       
   984 						
       
   985 				if(!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
       
   986 					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid))
       
   987 					{
       
   988 					ERR_PRINTF1(_L("** .INI Error: Expected Algorithm Arguments Not Located **"));
       
   989 					SetTestStepResult(EFail);
       
   990 					}
       
   991 				else
       
   992 					{
       
   993 					INFO_PRINTF1(_L("Checking Plug-in Selection..."));
       
   994 					
       
   995 					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
       
   996 					
       
   997 					TPtrC errorMessage;
       
   998 					
       
   999 					//Perform plug-in Check
       
  1000 					if(pluginCheck->checkSelectedPlugin(characteristics,
       
  1001 													exAlgorithmUid,
       
  1002 													exImplementationUid,
       
  1003 													errorMessage))
       
  1004 						{
       
  1005 						INFO_PRINTF1(_L("** PASS: Correct Plugin Implementation Selected **"));
       
  1006 						SetTestStepResult(EPass);	
       
  1007 						}
       
  1008 					else
       
  1009 						{
       
  1010 						ERR_PRINTF2(_L("** FAIL: Wrong Plugin Implementation Selected - %S **"),&errorMessage);	
       
  1011 						}
       
  1012 					
       
  1013 					CleanupStack::PopAndDestroy(pluginCheck);
       
  1014 					}
       
  1015 					
       
  1016 				CleanupStack::PopAndDestroy(plugin);
       
  1017 				}
       
  1018 			
       
  1019 			//Unselect Rule Selector	
       
  1020 			CCryptoSpiStateApi::UnsetSelector();
       
  1021 			
       
  1022 			//Pop and Destroy Rule Selector from the Cleanup Stack	
       
  1023 			CleanupStack::PopAndDestroy(ruleSelector);	
       
  1024 			}	
       
  1025 		}
       
  1026 		
       
  1027 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());		
       
  1028 	return TestStepResult();
       
  1029 	}
       
  1030 
       
  1031 
       
  1032 TVerdict CRuleSelectCommonStep::doTestStepPostambleL()
       
  1033 	{
       
  1034 	return TestStepResult();
       
  1035 	}
       
  1036