os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsextendedstep.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/plugincharsextendedstep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,218 @@
     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 "plugincharsextendedstep.h"
    1.28 +#include "plugincharschecker.h"
    1.29 +
    1.30 +#include <cryptospi/cryptosymmetriccipherapi.h>
    1.31 +#include <cryptospi/keys.h>
    1.32 +#include <cryptospi/plugincharacteristics.h>
    1.33 +
    1.34 +using namespace CryptoSpi;
    1.35 +
    1.36 +CPluginCharsExtendedStep::~CPluginCharsExtendedStep()
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +CPluginCharsExtendedStep::CPluginCharsExtendedStep()
    1.41 +	{
    1.42 +	SetTestStepName(KPluginCharsExtendedStep);
    1.43 +	}
    1.44 +
    1.45 +TVerdict CPluginCharsExtendedStep::doTestStepPreambleL()
    1.46 +	{
    1.47 +	SetTestStepResult(EPass);
    1.48 +	return TestStepResult();
    1.49 +	}
    1.50 +				
    1.51 +TVerdict CPluginCharsExtendedStep::doTestStepL()
    1.52 +	{
    1.53 +		
    1.54 +	INFO_PRINTF1(_L("Plugin Characteristics - Extended Chracteristics"));
    1.55 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    1.56 +		
    1.57 +	if (TestStepResult()==EPass)
    1.58 +		{
    1.59 +		
    1.60 +		//Assume faliure, unless all is successful
    1.61 +		SetTestStepResult(EFail);
    1.62 +		
    1.63 +		TPtrC encryptKey;
    1.64 +		TVariantPtrC keyType;
    1.65 +		TVariantPtrC algorithmUid;
    1.66 +		TVariantPtrC cryptoMode;
    1.67 +		TVariantPtrC operationMode;
    1.68 +		TVariantPtrC paddingMode;
    1.69 +		
    1.70 +		//Each of the individual parameters required to create the Symmetric Cipher object
    1.71 +		//are read in from the specified INI configuration file	
    1.72 +		if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || 
    1.73 +			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
    1.74 +			!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
    1.75 +			!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
    1.76 +			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
    1.77 +			!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode))
    1.78 +			{
    1.79 +			ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
    1.80 +			SetTestStepResult(EFail);
    1.81 +			}
    1.82 +		else
    1.83 +			{						
    1.84 +			//Convert encryption key to an 8 Bit Descriptor
    1.85 +			HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
    1.86 +			TPtr8 keyStrPtr = keyStr->Des();
    1.87 +
    1.88 +			keyStrPtr.Copy(encryptKey);
    1.89 +			
    1.90 +			//Create an new CryptoParams object to encapsulate the key type and secret key string
    1.91 +			CCryptoParams* keyParams = CCryptoParams::NewL();
    1.92 +			CleanupStack::PushL(keyParams);
    1.93 +			keyParams->AddL(*keyStr,keyType);
    1.94 +
    1.95 +			//Create Key Object
    1.96 +			TKeyProperty keyProperty;
    1.97 +			CKey* key=CKey::NewL(keyProperty,*keyParams);
    1.98 +			CleanupStack::PushL(key);
    1.99 +			
   1.100 +			CSymmetricCipher* symmetricCipherImpl = NULL;	
   1.101 +				
   1.102 +			TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
   1.103 +																algorithmUid,
   1.104 +																*key,
   1.105 +																cryptoMode,
   1.106 +																operationMode,
   1.107 +																paddingMode,
   1.108 +																NULL)); 
   1.109 +			
   1.110 +			
   1.111 +						
   1.112 +			if(symmetricCipherImpl && (err == KErrNone))
   1.113 +				{
   1.114 +				CleanupStack::PushL(symmetricCipherImpl);
   1.115 +				
   1.116 +				INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
   1.117 +				
   1.118 +				//Retrieve all the Symmetric Cipher characteristics that are required for all test cases
   1.119 +				TInt exExtendedTestChar1;
   1.120 +				TInt exExtendedTestChar2;
   1.121 +				TPtrC exExtendedTestChar3;
   1.122 +				TVariantPtrC exExtendedConcurrency;
   1.123 +				TBool exExtendedExclusiveUse;
   1.124 +				
   1.125 +				if(!GetIntFromConfig(ConfigSection(),KConfigExExtendTestChar1,exExtendedTestChar1) ||
   1.126 +					!GetIntFromConfig(ConfigSection(),KConfigExExtendTestChar2,exExtendedTestChar2) ||
   1.127 +					!GetStringFromConfig(ConfigSection(),KConfigExExtendTestChar3,exExtendedTestChar3) ||
   1.128 +					!GetStringFromConfig(ConfigSection(),KConfigExExtendConcurrency,exExtendedConcurrency) ||
   1.129 +					!GetBoolFromConfig(ConfigSection(),KConfigExExtendExclusiveUse,exExtendedExclusiveUse))
   1.130 +					{
   1.131 +					ERR_PRINTF1(_L("** .INI Error: Expected Symmetric Cipher Extended Characteristics Not Located **"));
   1.132 +					SetTestStepResult(EFail);
   1.133 +					}
   1.134 +				else
   1.135 +					{
   1.136 +					INFO_PRINTF1(_L("** Checking Symmetric Cipher Extended Characteristics.... **"));
   1.137 +					
   1.138 +					//******************EXTENDED CHARACTERISITICS****************************
   1.139 +				
   1.140 +					//Retrieve Characteristics via CExtendedCharacteristics Object
   1.141 +					const CExtendedCharacteristics* extendedChars = NULL;
   1.142 +					
   1.143 +					TRAP_LOG(err,extendedChars = symmetricCipherImpl->GetExtendedCharacteristicsL());
   1.144 +					
   1.145 +					//Retrieve Charcteristics via the ListExtendedCharacteristics() of the CExtendedCharacteristics Object
   1.146 +					const CCryptoParams* extendedCryptoParams = NULL;
   1.147 +
   1.148 +					TRAP_LOG(err,extendedCryptoParams = extendedChars->ListExtendedCharacteristics());
   1.149 +					
   1.150 +					//***********************************************************************
   1.151 +
   1.152 +					//Convert expected string atrributes an 8 Bit Descriptor
   1.153 +					HBufC8* exTestChar3Str = HBufC8::NewLC(exExtendedTestChar3.Length());
   1.154 +					TPtr8 tmpPtr = exTestChar3Str->Des();
   1.155 +			
   1.156 +					tmpPtr.Copy(exExtendedTestChar3);
   1.157 +					
   1.158 +					//Checks BOTH the returned Extended Characteristic values from the CExtendedCharacteristics 'GET' Methods and
   1.159 +					//the CCryptoParams List returned from the ListExtendedCharacteristics() method
   1.160 +
   1.161 +					if((!(extendedChars->GetTIntCharacteristicL(KExtendCharType1Uid) == exExtendedTestChar1)) 
   1.162 +						&& (!(extendedCryptoParams->GetTIntL(KExtendCharType1Uid) == exExtendedTestChar1)))
   1.163 +						{
   1.164 +						ERR_PRINTF1(_L("** FAIL: Extended Characteristic 1 Mismatch **"));	
   1.165 +						User::Leave(KErrNotFound);
   1.166 +						}
   1.167 +						
   1.168 +					if((!(extendedChars->GetTIntCharacteristicL(KExtendCharType2Uid) == exExtendedTestChar2))
   1.169 +						&& (!(extendedCryptoParams->GetTIntL(KExtendCharType2Uid) == exExtendedTestChar2)))
   1.170 +						{
   1.171 +						ERR_PRINTF1(_L("** FAIL: Extended Characteristic 2 Mismatch **"));	
   1.172 +						User::Leave(KErrNotFound);
   1.173 +						}
   1.174 +						
   1.175 +					if((!(extendedChars->GetTDesC8CharacteristicL(KExtendCharType3Uid) == *exTestChar3Str))
   1.176 +						&& (!(extendedCryptoParams->GetTDesC8L(KExtendCharType3Uid) == *exTestChar3Str)))
   1.177 +						{
   1.178 +						ERR_PRINTF1(_L("** FAIL: Extended Characteristic 3 Mismatch **"));	
   1.179 +						User::Leave(KErrNotFound);	
   1.180 +						}
   1.181 +						
   1.182 +					if((!(extendedChars->GetTIntCharacteristicL(KConcurrencyTypeUid) == exExtendedConcurrency))
   1.183 +						&& (!(extendedCryptoParams->GetTIntL(KConcurrencyTypeUid) == exExtendedConcurrency)))
   1.184 +						{
   1.185 +						ERR_PRINTF1(_L("** FAIL: 'Concurreny' Extended Characteristic Mismatch **"));	
   1.186 +						User::Leave(KErrNotFound);
   1.187 +						}
   1.188 +						
   1.189 +					if((!(extendedChars->GetTIntCharacteristicL(KExclusiveUseTypeUid) == exExtendedExclusiveUse))
   1.190 +						&& (!(extendedCryptoParams->GetTIntL(KExclusiveUseTypeUid) == exExtendedExclusiveUse)))
   1.191 +						{
   1.192 +						ERR_PRINTF1(_L("** FAIL: 'Exclusive Use' Extended Characteristic Mismatch **"));
   1.193 +						User::Leave(KErrNotFound);
   1.194 +						}
   1.195 +						
   1.196 +					INFO_PRINTF1(_L("** PASS: Extended Characteristics Successfully Match **"));	
   1.197 +					SetTestStepResult(EPass);
   1.198 +						
   1.199 +					CleanupStack::PopAndDestroy(exTestChar3Str);
   1.200 +					}
   1.201 +					
   1.202 +				CleanupStack::PopAndDestroy(symmetricCipherImpl);
   1.203 +				}
   1.204 +			else
   1.205 +				{
   1.206 +				ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err);	
   1.207 +				}
   1.208 +				
   1.209 +			CleanupStack::PopAndDestroy(3,keyStr);
   1.210 +			}
   1.211 +		}
   1.212 +						
   1.213 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
   1.214 +	return TestStepResult();
   1.215 +
   1.216 +	}
   1.217 +
   1.218 +TVerdict CPluginCharsExtendedStep::doTestStepPostambleL()
   1.219 +	{
   1.220 +	return TestStepResult();
   1.221 +	}