1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/pluginloadstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,223 @@
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 +* Example CTestStep derived implementation
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +#include "pluginloadstep.h"
1.28 +#include "plugincharschecker.h"
1.29 +
1.30 +#include <cryptospi/cryptosymmetriccipherapi.h>
1.31 +#include <cryptospi/keys.h>
1.32 +
1.33 +#include <cryptospi/cryptospistateapi.h>
1.34 +#include <cryptospi/cryptohashapi.h>
1.35 +#include <cryptospi/cryptorandomapi.h>
1.36 +#include <cryptospi/cryptosymmetriccipherapi.h>
1.37 +#include <cryptospi/cryptoasymmetriccipherapi.h>
1.38 +#include <cryptospi/cryptosignatureapi.h>
1.39 +#include <cryptospi/cryptokeypairgeneratorapi.h>
1.40 +#include <cryptospi/cryptokeyagreementapi.h>
1.41 +#include <cryptospi/ruleselector.h>
1.42 +
1.43 +using namespace CryptoSpi;
1.44 +
1.45 +
1.46 +CPluginLoadStep::~CPluginLoadStep()
1.47 + {
1.48 + }
1.49 +
1.50 +
1.51 +CPluginLoadStep::CPluginLoadStep()
1.52 + {
1.53 + SetTestStepName(KPluginLoadStep);
1.54 + }
1.55 +
1.56 +
1.57 +TVerdict CPluginLoadStep::doTestStepPreambleL()
1.58 + {
1.59 + SetTestStepResult(EPass);
1.60 + return TestStepResult();
1.61 + }
1.62 +
1.63 +
1.64 +TVerdict CPluginLoadStep::doTestStepL()
1.65 + {
1.66 +
1.67 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.68 +
1.69 + if (TestStepResult()==EPass)
1.70 + {
1.71 + //Assume faliure, unless all is successful
1.72 + SetTestStepResult(EFail);
1.73 +
1.74 + TPtrC encryptKey;
1.75 + TVariantPtrC keyType;
1.76 + TVariantPtrC algorithm;
1.77 + TVariantPtrC operationMode;
1.78 + TVariantPtrC paddingMode;
1.79 + TBool ruleSelectorToggle = EFalse;
1.80 +
1.81 +
1.82 + if( !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
1.83 + !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
1.84 + !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) ||
1.85 + !GetStringFromConfig(ConfigSection(),KConfigOperationMode, operationMode) ||
1.86 + !GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ) ||
1.87 + !GetBoolFromConfig(ConfigSection(),KConfigRuleSelectorToggle, ruleSelectorToggle ))
1.88 + {
1.89 + ERR_PRINTF1(_L("** Error: Failed to Load DoStep() Configuration Parameters **"));
1.90 + User::Leave(KErrNotFound);
1.91 + }
1.92 + else
1.93 + {
1.94 + //Convert encryption key to an 8 Bit Descriptor
1.95 + HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
1.96 + TPtr8 keyStrPtr = keyStr->Des();
1.97 +
1.98 + keyStrPtr.Copy(encryptKey);
1.99 +
1.100 + //Create an new CryptoParams object to encapsulate the key type and secret key string
1.101 + CCryptoParams* keyParams = CCryptoParams::NewL();
1.102 + CleanupStack::PushL(keyParams);
1.103 + keyParams->AddL(*keyStr,keyType);
1.104 +
1.105 + //Create Key Object
1.106 + TKeyProperty keyProperty;
1.107 + CKey* key=CKey::NewL(keyProperty,*keyParams);
1.108 + CleanupStack::PushL(key);
1.109 +
1.110 + //***** Determine whether to set the Rule Selector *****
1.111 +
1.112 + CRuleSelector* ruleSelector = NULL;
1.113 +
1.114 + if(ruleSelectorToggle)
1.115 + {
1.116 + //Create Rule Selection Rules Object
1.117 + CSelectionRules* rules = CSelectionRules::NewL();
1.118 + CleanupStack::PushL(rules);
1.119 +
1.120 + //Create Rule Selector Object
1.121 + ruleSelector = CRuleSelector::NewL(rules);
1.122 + CleanupStack::Pop(rules);
1.123 + CleanupStack::PushL(ruleSelector);
1.124 +
1.125 + //Set the Selector Passing in a pointer to the Default Selector and SPI State
1.126 + CCryptoSpiStateApi::SetSelector(ruleSelector);
1.127 + }
1.128 +
1.129 + //******************************************************
1.130 +
1.131 + // Create a Symmetric Cipher with the values from the ini file
1.132 + CryptoSpi::CSymmetricCipher * impl = NULL;
1.133 +
1.134 + TRAPD(err,CSymmetricCipherFactory::CreateSymmetricCipherL(impl,
1.135 + algorithm,
1.136 + *key,
1.137 + KCryptoModeEncryptUid,
1.138 + operationMode,
1.139 + paddingMode,
1.140 + NULL));
1.141 +
1.142 + if(impl && (err==KErrNone))
1.143 + {
1.144 + INFO_PRINTF1(_L("Successful Implementation Object Load..."));
1.145 +
1.146 + CleanupStack::PushL(impl);
1.147 +
1.148 + //Define a pointer of type TCharacteristics in order to store the appropriate
1.149 + //encryption object's characterisctics
1.150 + const TCharacteristics* characteristics(NULL);
1.151 +
1.152 + //Retrieve the characteristics for the symmetric cipher implementation object
1.153 + TRAP_LOG(err, impl->GetCharacteristicsL(characteristics));
1.154 +
1.155 + TVariantPtrC exAlgorithmUid;
1.156 + TVariantPtrC exImplementationUid;
1.157 +
1.158 + if(!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
1.159 + !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid))
1.160 + {
1.161 + ERR_PRINTF1(_L("** .INI Error: Expected Algorithm Arguments Not Located **"));
1.162 + SetTestStepResult(EFail);
1.163 + }
1.164 + else
1.165 + {
1.166 + INFO_PRINTF1(_L("Checking Plug-in Selection..."));
1.167 +
1.168 + CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
1.169 +
1.170 + TPtrC errorMessage;
1.171 +
1.172 + //Perform plug-in Check
1.173 + if(pluginCheck->checkSelectedPlugin(characteristics,
1.174 + exAlgorithmUid,
1.175 + exImplementationUid,
1.176 + errorMessage))
1.177 + {
1.178 + INFO_PRINTF1(_L("** PASS: Expected Plugin Loaded Successfully **"));
1.179 + SetTestStepResult(EPass);
1.180 + }
1.181 + else
1.182 + {
1.183 + ERR_PRINTF2(_L("** FAIL: Unexpected Plugin Implementation Loaded - %S **"),&errorMessage);
1.184 + }
1.185 +
1.186 + CleanupStack::PopAndDestroy(pluginCheck);
1.187 +
1.188 + }
1.189 +
1.190 + CleanupStack::PopAndDestroy(impl);
1.191 +
1.192 +
1.193 + }
1.194 + else
1.195 + {
1.196 + ERR_PRINTF2(_L("*** FAIL: Implementation Object Load Failure ***"), err);
1.197 + SetTestStepResult(EFail);
1.198 + }
1.199 +
1.200 + if(ruleSelectorToggle)
1.201 + {
1.202 + //Set the Selector Passing in a pointer to the Default Selector and SPI State
1.203 + CCryptoSpiStateApi::UnsetSelector();
1.204 +
1.205 + CleanupStack::PopAndDestroy();
1.206 + }
1.207 +
1.208 + CleanupStack::PopAndDestroy(3,keyStr);
1.209 + }
1.210 +
1.211 + }
1.212 + else
1.213 + {
1.214 + ERR_PRINTF1(_L("*** FAIL: Test Case Initialistion Failure ***"));
1.215 + }
1.216 +
1.217 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.218 +
1.219 + return TestStepResult();
1.220 + }
1.221 +
1.222 +
1.223 +TVerdict CPluginLoadStep::doTestStepPostambleL()
1.224 + {
1.225 + return TestStepResult();
1.226 + }