os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsasymkeypairstep.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/plugincharsasymkeypairstep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,186 @@
     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 "plugincharsasymkeypairstep.h"
    1.28 +#include "plugincharschecker.h"
    1.29 +
    1.30 +#include <cryptospi/keypair.h>
    1.31 +#include <cryptospi/cryptokeypairgeneratorapi.h>
    1.32 +
    1.33 +using namespace CryptoSpi;
    1.34 +
    1.35 +CPluginCharsAsymKeyPairStep::~CPluginCharsAsymKeyPairStep()
    1.36 +	{
    1.37 +	}
    1.38 +
    1.39 +CPluginCharsAsymKeyPairStep::CPluginCharsAsymKeyPairStep()
    1.40 +	{
    1.41 +	SetTestStepName(KPluginCharsAsymKeyPairStep);
    1.42 +	}
    1.43 +
    1.44 +TVerdict CPluginCharsAsymKeyPairStep::doTestStepPreambleL()
    1.45 +	{
    1.46 +	SetTestStepResult(EPass);
    1.47 +	return TestStepResult();
    1.48 +	}
    1.49 +				
    1.50 +TVerdict CPluginCharsAsymKeyPairStep::doTestStepL()
    1.51 +	{
    1.52 +	
    1.53 +	INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Key Pair Generator 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 +		TVariantPtrC algorithmUid;
    1.63 +		
    1.64 +		//Each of the individual parameters required to create the Asymmetric Key Pair Generator object
    1.65 +		//are read in from the specified INI configuration file					
    1.66 +		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
    1.67 +			{
    1.68 +			ERR_PRINTF1(_L("** .INI Error: Asymmetric Key Pair Generator Cipher Arguments Not Located **"));
    1.69 +			SetTestStepResult(EFail);
    1.70 +			}
    1.71 +		else
    1.72 +			{
    1.73 +			CCryptoParams* keyParams = CCryptoParams::NewLC(); 	
    1.74 +			
    1.75 +			//Create Key Pair Generator Object
    1.76 +			CKeyPairGenerator* keyPairGenImpl = NULL;
    1.77 +			
    1.78 +			//Create a Asymmetric Key Pair Generator Implementation
    1.79 +			TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keyPairGenImpl, 
    1.80 +																		algorithmUid, 
    1.81 +																		keyParams));
    1.82 +																			
    1.83 +			if(keyPairGenImpl && (err == KErrNone))
    1.84 +				{
    1.85 +				
    1.86 +				CleanupStack::PushL(keyPairGenImpl);
    1.87 +				
    1.88 +				INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Key Pair Generator Object **"));
    1.89 +				
    1.90 +				//Define a pointer of type TCharacteristics in order to store the asymmetric key pair generator
    1.91 +				//object's characterisctics	
    1.92 +				const TCharacteristics* chars(NULL);
    1.93 +							
    1.94 +				//Retrieve the characteristics for the asymmetric key pair generator implementation object
    1.95 +				keyPairGenImpl->GetCharacteristicsL(chars);
    1.96 +				
    1.97 +				//Static cast the characteristics to type TKeyAgreementCharacteristics
    1.98 +				const TAsymmetricKeypairGeneratorCharacteristics* asymkeypairgenChars = static_cast<const TAsymmetricKeypairGeneratorCharacteristics*>(chars);
    1.99 +				
   1.100 +				//Retrieve all the Common characteristics that are required for the test
   1.101 +				TVariantPtrC exInterfaceUid;
   1.102 +				TVariantPtrC exAlgorithmUid;
   1.103 +				TVariantPtrC exImplementationUid;
   1.104 +				TVariantPtrC exCreatorName;
   1.105 +				TBool exFIPSApproved;
   1.106 +				TBool exHardwareSupported;
   1.107 +				TInt exMaxConcurrencySupported;
   1.108 +				TVariantPtrC exAlgorithmName;
   1.109 +				TInt exLatency;
   1.110 +				TInt exThroughput;
   1.111 +				
   1.112 +				//Retrieve all the Asymmetric Key Pair Generator characteristics that are required for the test
   1.113 +				TInt exAsymKeyPairMaxKeyLength;
   1.114 +					
   1.115 +				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
   1.116 +					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
   1.117 +					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
   1.118 +					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
   1.119 +					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
   1.120 +					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
   1.121 +					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
   1.122 +					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
   1.123 +					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
   1.124 +					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
   1.125 +					!GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymKeyPairMaxKeyLength))
   1.126 +					{
   1.127 +					ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Key Pair Generator/Common Characteristics Not Located **"));
   1.128 +					SetTestStepResult(EFail);
   1.129 +					}
   1.130 +				else
   1.131 +					{
   1.132 +			
   1.133 +					INFO_PRINTF1(_L("** Checking Asymmetric Key Pair Generator/Common Characteristics.... **"));
   1.134 +					
   1.135 +					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
   1.136 +					
   1.137 +					//Retrieve the Common Characteristics from TAsymmetricKeypairGeneratorCharacteristics 
   1.138 +					const TCommonCharacteristics* asymkeypairgenCommonChars = &asymkeypairgenChars->cmn;
   1.139 +					
   1.140 +					TPtrC errorMessage;
   1.141 +					
   1.142 +					//Perform Key Agreement/Common Characteristic Checks
   1.143 +					if(pluginCheck->checkCommonCharacteristics(asymkeypairgenCommonChars,
   1.144 +																exInterfaceUid,
   1.145 +																exAlgorithmUid,
   1.146 +																exImplementationUid,
   1.147 +																exCreatorName,
   1.148 +																exFIPSApproved,
   1.149 +																exHardwareSupported,
   1.150 +																exMaxConcurrencySupported,
   1.151 +																exAlgorithmName,
   1.152 +																exLatency,
   1.153 +																exThroughput,
   1.154 +																errorMessage) &&
   1.155 +					pluginCheck->checkAsymKeypairGenCharacteristics(asymkeypairgenChars,
   1.156 +																exAsymKeyPairMaxKeyLength,
   1.157 +																errorMessage))
   1.158 +						{
   1.159 +						INFO_PRINTF1(_L("** PASS : Asymmetric Key Pair Generator/Common characteristics successfully match expected values **"));
   1.160 +						SetTestStepResult(EPass);	
   1.161 +						}
   1.162 +					else
   1.163 +						{
   1.164 +						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
   1.165 +						}
   1.166 +					
   1.167 +					CleanupStack::PopAndDestroy(pluginCheck);
   1.168 +					}
   1.169 +				
   1.170 +				CleanupStack::PopAndDestroy(keyPairGenImpl);
   1.171 +				}
   1.172 +			else
   1.173 +				{
   1.174 +				ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Key Pair Generator Object - %d ***"), err);
   1.175 +				}
   1.176 +				
   1.177 +			CleanupStack::PopAndDestroy(keyParams);			
   1.178 +			}
   1.179 +		
   1.180 +		}
   1.181 +		
   1.182 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
   1.183 +	return TestStepResult();
   1.184 +	}
   1.185 +
   1.186 +TVerdict CPluginCharsAsymKeyPairStep::doTestStepPostambleL()
   1.187 +	{
   1.188 +	return TestStepResult();
   1.189 +	}