sl@0: /* sl@0: * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Example CTestStep derived implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: #include "pluginloadstep.h" sl@0: #include "plugincharschecker.h" sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: sl@0: CPluginLoadStep::~CPluginLoadStep() sl@0: { sl@0: } sl@0: sl@0: sl@0: CPluginLoadStep::CPluginLoadStep() sl@0: { sl@0: SetTestStepName(KPluginLoadStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CPluginLoadStep::doTestStepPreambleL() sl@0: { sl@0: SetTestStepResult(EPass); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CPluginLoadStep::doTestStepL() sl@0: { sl@0: sl@0: INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); sl@0: sl@0: if (TestStepResult()==EPass) sl@0: { sl@0: //Assume faliure, unless all is successful sl@0: SetTestStepResult(EFail); sl@0: sl@0: TPtrC encryptKey; sl@0: TVariantPtrC keyType; sl@0: TVariantPtrC algorithm; sl@0: TVariantPtrC operationMode; sl@0: TVariantPtrC paddingMode; sl@0: TBool ruleSelectorToggle = EFalse; sl@0: sl@0: sl@0: if( !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || sl@0: !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) || sl@0: !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) || sl@0: !GetStringFromConfig(ConfigSection(),KConfigOperationMode, operationMode) || sl@0: !GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ) || sl@0: !GetBoolFromConfig(ConfigSection(),KConfigRuleSelectorToggle, ruleSelectorToggle )) sl@0: { sl@0: ERR_PRINTF1(_L("** Error: Failed to Load DoStep() Configuration Parameters **")); sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: else sl@0: { sl@0: //Convert encryption key to an 8 Bit Descriptor sl@0: HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length()); sl@0: TPtr8 keyStrPtr = keyStr->Des(); sl@0: sl@0: keyStrPtr.Copy(encryptKey); sl@0: sl@0: //Create an new CryptoParams object to encapsulate the key type and secret key string sl@0: CCryptoParams* keyParams = CCryptoParams::NewL(); sl@0: CleanupStack::PushL(keyParams); sl@0: keyParams->AddL(*keyStr,keyType); sl@0: sl@0: //Create Key Object sl@0: TKeyProperty keyProperty; sl@0: CKey* key=CKey::NewL(keyProperty,*keyParams); sl@0: CleanupStack::PushL(key); sl@0: sl@0: //***** Determine whether to set the Rule Selector ***** sl@0: sl@0: CRuleSelector* ruleSelector = NULL; sl@0: sl@0: if(ruleSelectorToggle) sl@0: { sl@0: //Create Rule Selection Rules Object sl@0: CSelectionRules* rules = CSelectionRules::NewL(); sl@0: CleanupStack::PushL(rules); sl@0: sl@0: //Create Rule Selector Object sl@0: ruleSelector = CRuleSelector::NewL(rules); sl@0: CleanupStack::Pop(rules); sl@0: CleanupStack::PushL(ruleSelector); sl@0: sl@0: //Set the Selector Passing in a pointer to the Default Selector and SPI State sl@0: CCryptoSpiStateApi::SetSelector(ruleSelector); sl@0: } sl@0: sl@0: //****************************************************** sl@0: sl@0: // Create a Symmetric Cipher with the values from the ini file sl@0: CryptoSpi::CSymmetricCipher * impl = NULL; sl@0: sl@0: TRAPD(err,CSymmetricCipherFactory::CreateSymmetricCipherL(impl, sl@0: algorithm, sl@0: *key, sl@0: KCryptoModeEncryptUid, sl@0: operationMode, sl@0: paddingMode, sl@0: NULL)); sl@0: sl@0: if(impl && (err==KErrNone)) sl@0: { sl@0: INFO_PRINTF1(_L("Successful Implementation Object Load...")); sl@0: sl@0: CleanupStack::PushL(impl); sl@0: sl@0: //Define a pointer of type TCharacteristics in order to store the appropriate sl@0: //encryption object's characterisctics sl@0: const TCharacteristics* characteristics(NULL); sl@0: sl@0: //Retrieve the characteristics for the symmetric cipher implementation object sl@0: TRAP_LOG(err, impl->GetCharacteristicsL(characteristics)); sl@0: sl@0: TVariantPtrC exAlgorithmUid; sl@0: TVariantPtrC exImplementationUid; sl@0: sl@0: if(!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) || sl@0: !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid)) sl@0: { sl@0: ERR_PRINTF1(_L("** .INI Error: Expected Algorithm Arguments Not Located **")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Checking Plug-in Selection...")); sl@0: sl@0: CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC(); sl@0: sl@0: TPtrC errorMessage; sl@0: sl@0: //Perform plug-in Check sl@0: if(pluginCheck->checkSelectedPlugin(characteristics, sl@0: exAlgorithmUid, sl@0: exImplementationUid, sl@0: errorMessage)) sl@0: { sl@0: INFO_PRINTF1(_L("** PASS: Expected Plugin Loaded Successfully **")); sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("** FAIL: Unexpected Plugin Implementation Loaded - %S **"),&errorMessage); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(pluginCheck); sl@0: sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(impl); sl@0: sl@0: sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF2(_L("*** FAIL: Implementation Object Load Failure ***"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: if(ruleSelectorToggle) sl@0: { sl@0: //Set the Selector Passing in a pointer to the Default Selector and SPI State sl@0: CCryptoSpiStateApi::UnsetSelector(); sl@0: sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3,keyStr); sl@0: } sl@0: sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF1(_L("*** FAIL: Test Case Initialistion Failure ***")); sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CPluginLoadStep::doTestStepPostambleL() sl@0: { sl@0: return TestStepResult(); sl@0: }