os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsmacstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalTechnology
    22 */
    23  
    24 #include "plugincharsmacstep.h"
    25 #include "plugincharschecker.h"
    26 
    27 #include <cryptospi/cryptomacapi.h>
    28 #include <cryptospi/keys.h>
    29 
    30 using namespace CryptoSpi;
    31 
    32 CPluginCharsMacStep::~CPluginCharsMacStep()
    33 	{
    34 	}
    35 
    36 CPluginCharsMacStep::CPluginCharsMacStep()
    37 	{
    38 	SetTestStepName(KPluginCharsMacStep);
    39 	}
    40 
    41 TVerdict CPluginCharsMacStep::doTestStepPreambleL()
    42 	{
    43 	SetTestStepResult(EPass);
    44 	return TestStepResult();
    45 	}
    46 				
    47 TVerdict CPluginCharsMacStep::doTestStepL()
    48 	{
    49 	
    50 	INFO_PRINTF1(_L("Plugin Characteristics - Mac Chracteristics"));
    51 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    52 		
    53 	if (TestStepResult()==EPass)
    54 		{
    55 		//Assume failure, unless all is successful
    56 		SetTestStepResult(EFail);
    57 		
    58 		TVariantPtrC algorithmUid;
    59 		TPtrC encryptKey;
    60 		TVariantPtrC keyType;
    61 
    62 		//Each of the individual parameters required to create the Mac object
    63 		//are read in from the specified INI configuration file	
    64 		if (!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
    65 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
    66 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
    67 			{
    68 			ERR_PRINTF1(_L("** .INI Error: Mac Arguments Not Located **"));
    69 			SetTestStepResult(EFail);
    70 			}
    71 		else
    72 			{
    73 			CMac* macImpl = NULL;
    74 			
    75 			//Convert encryption key to an 8 Bit Descriptor
    76 			HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
    77 			TPtr8 keyStrPtr = keyStr->Des();
    78 			
    79 			keyStrPtr.Copy(encryptKey);
    80 							
    81 			//Create an new CryptoParams object to encapsulate the key type and secret key string
    82 			CCryptoParams* keyParams = CCryptoParams::NewL();
    83 			CleanupStack::PushL(keyParams);
    84 			keyParams->AddL(*keyStr,keyType);
    85 			
    86 			//Create Key Object
    87 			TKeyProperty keyProperty;
    88 			CKey* key=CKey::NewL(keyProperty,*keyParams);
    89 			CleanupStack::PushL(key);
    90 
    91 			TRAPD_LOG(err,CMacFactory::CreateMacL(macImpl,
    92 													algorithmUid,
    93 													*key,
    94 													NULL));
    95 			
    96 			if (err != KErrNone)
    97 				{
    98 				delete macImpl;
    99 				ERR_PRINTF2(_L("*** FAIL: Failed to Create Mac Object - %d ***"), err);
   100 				User::Leave(err);
   101 				}
   102 			
   103 			CleanupStack::PushL(macImpl);
   104 			
   105 			INFO_PRINTF1(_L("** Successfully Loaded Mac Object **"));
   106 
   107 			//Define a pointer of type TCharacteristics in order to store the hash
   108 			//cryptographic object's characterisctics	
   109 			const TCharacteristics* chars(NULL);
   110 			
   111 			//Retrieve the characteristics for the hash implementation object
   112 			TRAP_LOG(err, macImpl->GetCharacteristicsL(chars));
   113 						
   114 			//Static cast the characteristics to type TMacCharacteristics
   115 			const TMacCharacteristics* macChars = static_cast<const TMacCharacteristics*>(chars);
   116 			
   117 			//Retrieve all the Common characteristics that are required for all test cases
   118 			TVariantPtrC exInterfaceUid;
   119 			TVariantPtrC exAlgorithmUid;
   120 			TVariantPtrC exImplementationUid;
   121 			TVariantPtrC exCreatorName;
   122 			TBool exFIPSApproved;
   123 			TBool exHardwareSupported;
   124 			TInt exMaxConcurrencySupported;
   125 			TVariantPtrC exAlgorithmName;
   126 			TInt exLatency;
   127 			TInt exThroughput;
   128 			
   129 			//Retrieve all the Mac characteristics that are required for all test cases
   130 			TVariantPtrC exMacMode;
   131 			
   132 			if (!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
   133 				!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
   134 				!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
   135 				!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
   136 				!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
   137 				!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
   138 				!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
   139 				!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
   140 				!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
   141 				!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
   142 				!GetStringFromConfig(ConfigSection(),KConfigExMacMode,exMacMode))
   143 				{
   144 				ERR_PRINTF1(_L("** .INI Error: Expected Mac/Common Characteristic Arguments Not Located **"));
   145 				SetTestStepResult(EFail);
   146 				}
   147 			else
   148 				{
   149 				INFO_PRINTF1(_L("** Checking Mac/Common Characteristics.... **"));
   150 				
   151 				CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
   152 
   153 				//Retrieve the Common Characteristics from TMacCharacteristics 
   154 				const TCommonCharacteristics* macCommonChars = &macChars->iMacChar;
   155 				
   156 				TPtrC errorMessage;
   157 
   158 				//Perform Mac/Common Characteristic Checks
   159 				if(pluginCheck->checkCommonCharacteristics(macCommonChars,
   160 											exInterfaceUid,
   161 											exAlgorithmUid,
   162 											exImplementationUid,
   163 											exCreatorName,
   164 											exFIPSApproved,
   165 											exHardwareSupported,
   166 											exMaxConcurrencySupported,
   167 											exAlgorithmName,
   168 											exLatency,
   169 											exThroughput,
   170 											errorMessage) &&
   171 					pluginCheck->checkMacCharacteristics(macChars, exMacMode, errorMessage))
   172 					{
   173 					INFO_PRINTF1(_L("Mac/Common characteristics successfully match expected values..."));
   174 					SetTestStepResult(EPass);
   175 					}
   176 				else
   177 					{
   178 					ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
   179 					}
   180 
   181 				CleanupStack::PopAndDestroy(pluginCheck);
   182 				}
   183 
   184 			CleanupStack::PopAndDestroy(macImpl);
   185 			CleanupStack::PopAndDestroy(key);
   186 			CleanupStack::PopAndDestroy(keyParams);
   187 			CleanupStack::PopAndDestroy(keyStr);
   188 			}
   189 		}
   190 		
   191 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   192 	return TestStepResult();
   193 	}
   194 
   195 TVerdict CPluginCharsMacStep::doTestStepPostambleL()
   196 	{
   197 	return TestStepResult();
   198 	}