os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharscommonstep.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharscommonstep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,206 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 + @internalTechnology
    1.25 +*/
    1.26 + 
    1.27 +#include "plugincharscommonstep.h"
    1.28 +#include "plugincharschecker.h"
    1.29 +
    1.30 +#include <cryptospi/cryptosymmetriccipherapi.h>
    1.31 +#include <cryptospi/keys.h>
    1.32 +
    1.33 +using namespace CryptoSpi;
    1.34 +
    1.35 +CPluginCharsCommonStep::~CPluginCharsCommonStep()
    1.36 +	{
    1.37 +	}
    1.38 +
    1.39 +CPluginCharsCommonStep::CPluginCharsCommonStep()
    1.40 +	{
    1.41 +	SetTestStepName(KPluginCharsCommonStep);
    1.42 +	}
    1.43 +
    1.44 +TVerdict CPluginCharsCommonStep::doTestStepPreambleL()
    1.45 +	{
    1.46 +	SetTestStepResult(EPass);
    1.47 +	return TestStepResult();
    1.48 +	}
    1.49 +				
    1.50 +TVerdict CPluginCharsCommonStep::doTestStepL()
    1.51 +	{
    1.52 +	
    1.53 +	INFO_PRINTF1(_L("Plugin Characteristics - Common Chracteristics"));
    1.54 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    1.55 +		
    1.56 +	if (TestStepResult()==EPass)
    1.57 +		{
    1.58 +		
    1.59 +		//Assume faliure, unless all is successful
    1.60 +		SetTestStepResult(EFail);
    1.61 +		
    1.62 +		TPtrC encryptKey;
    1.63 +		TVariantPtrC keyType;
    1.64 +		TVariantPtrC algorithmUid;
    1.65 +		TVariantPtrC cryptoMode;
    1.66 +		TVariantPtrC operationMode;
    1.67 +		TVariantPtrC paddingMode;
    1.68 +		
    1.69 +		//Each of the individual parameters required to create the Symmetric Cipher object
    1.70 +		//are read in from the specified INI configuration file	
    1.71 +		if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || 
    1.72 +			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
    1.73 +			!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
    1.74 +			!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
    1.75 +			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
    1.76 +			!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode))
    1.77 +			{
    1.78 +			ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
    1.79 +			SetTestStepResult(EFail);
    1.80 +			}
    1.81 +		else
    1.82 +			{						
    1.83 +			//Convert encryption key to an 8 Bit Descriptor
    1.84 +			HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
    1.85 +			TPtr8 keyStrPtr = keyStr->Des();
    1.86 +
    1.87 +			keyStrPtr.Copy(encryptKey);
    1.88 +			
    1.89 +			//Create an new CryptoParams object to encapsulate the key type and secret key string
    1.90 +			CCryptoParams* keyParams = CCryptoParams::NewL();
    1.91 +			CleanupStack::PushL(keyParams);
    1.92 +			keyParams->AddL(*keyStr,keyType);
    1.93 +
    1.94 +			//Create Key Object
    1.95 +			TKeyProperty keyProperty;
    1.96 +			CKey* key=CKey::NewL(keyProperty,*keyParams);
    1.97 +			CleanupStack::PushL(key);
    1.98 +			
    1.99 +			CSymmetricCipher* symmetricCipherImpl = NULL;	
   1.100 +				
   1.101 +			TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
   1.102 +																algorithmUid,
   1.103 +																*key,
   1.104 +																cryptoMode,
   1.105 +																operationMode,
   1.106 +																paddingMode,
   1.107 +																NULL)); 
   1.108 +			
   1.109 +			
   1.110 +						
   1.111 +			if(symmetricCipherImpl && (err == KErrNone))
   1.112 +				{
   1.113 +				
   1.114 +				CleanupStack::PushL(symmetricCipherImpl);
   1.115 +				
   1.116 +				INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
   1.117 +				
   1.118 +				//Define a pointer of type TCharacteristics in order to store the symmetric cipher
   1.119 +				//encryption object's characterisctics	
   1.120 +				const TCharacteristics* chars(NULL);
   1.121 +							
   1.122 +				//Retrieve the characteristics for the symmetric cipher implementation object
   1.123 +				TRAP_LOG(err, symmetricCipherImpl->GetCharacteristicsL(chars));
   1.124 +				
   1.125 +				//Static cast the characteristics to type TCommonCharacteristics
   1.126 +				const TCommonCharacteristics* commonChars = static_cast<const TCommonCharacteristics*>(chars);
   1.127 +
   1.128 +				//Retrieve all the Common characteristics that are required for all test cases
   1.129 +				TVariantPtrC exInterfaceUid;
   1.130 +				TVariantPtrC exAlgorithmUid;
   1.131 +				TVariantPtrC exImplementationUid;
   1.132 +				TVariantPtrC exCreatorName;
   1.133 +				TBool exFIPSApproved;
   1.134 +				TBool exHardwareSupported;
   1.135 +				TInt exMaxConcurrencySupported;
   1.136 +				TVariantPtrC exAlgorithmName;
   1.137 +				TInt exLatency;
   1.138 +				TInt exThroughput;
   1.139 +				
   1.140 +				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
   1.141 +					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
   1.142 +					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
   1.143 +					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
   1.144 +					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
   1.145 +					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
   1.146 +					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
   1.147 +					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
   1.148 +					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
   1.149 +					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput))
   1.150 +					{
   1.151 +					ERR_PRINTF1(_L("** .INI Error: Expected Common Characteristic Arguments Not Located **"));
   1.152 +					SetTestStepResult(EFail);
   1.153 +					}
   1.154 +				else
   1.155 +					{
   1.156 +			
   1.157 +					INFO_PRINTF1(_L("** Checking common Characteristics.... **"));
   1.158 +					
   1.159 +					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
   1.160 +					
   1.161 +					TPtrC errorMessage;
   1.162 +					
   1.163 +					//******************************************************************
   1.164 +					//Perform Characteristic Checks
   1.165 +					//******************************************************************
   1.166 +					if(pluginCheck->checkCommonCharacteristics(commonChars,
   1.167 +																exInterfaceUid,
   1.168 +																exAlgorithmUid,
   1.169 +																exImplementationUid,
   1.170 +																exCreatorName,
   1.171 +																exFIPSApproved,
   1.172 +																exHardwareSupported,
   1.173 +																exMaxConcurrencySupported,
   1.174 +																exAlgorithmName,
   1.175 +																exLatency,
   1.176 +																exThroughput,
   1.177 +																errorMessage))
   1.178 +						{
   1.179 +						INFO_PRINTF1(_L("** PASS : Common characteristics successfully match expected values **"));
   1.180 +						SetTestStepResult(EPass);	
   1.181 +						}
   1.182 +					else
   1.183 +						{
   1.184 +						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
   1.185 +						}
   1.186 +						
   1.187 +					CleanupStack::PopAndDestroy(pluginCheck);
   1.188 +					}
   1.189 +				
   1.190 +				CleanupStack::PopAndDestroy(symmetricCipherImpl);
   1.191 +				}
   1.192 +			else
   1.193 +				{
   1.194 +				ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err);	
   1.195 +				}
   1.196 +				
   1.197 +			CleanupStack::PopAndDestroy(3,keyStr);
   1.198 +			}
   1.199 +		}
   1.200 +						
   1.201 +		
   1.202 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
   1.203 +	return TestStepResult();
   1.204 +	}
   1.205 +
   1.206 +TVerdict CPluginCharsCommonStep::doTestStepPostambleL()
   1.207 +	{
   1.208 +	return TestStepResult();
   1.209 +	}