os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsextendedstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 "plugincharsextendedstep.h"
    25 #include "plugincharschecker.h"
    26 
    27 #include <cryptospi/cryptosymmetriccipherapi.h>
    28 #include <cryptospi/keys.h>
    29 #include <cryptospi/plugincharacteristics.h>
    30 
    31 using namespace CryptoSpi;
    32 
    33 CPluginCharsExtendedStep::~CPluginCharsExtendedStep()
    34 	{
    35 	}
    36 
    37 CPluginCharsExtendedStep::CPluginCharsExtendedStep()
    38 	{
    39 	SetTestStepName(KPluginCharsExtendedStep);
    40 	}
    41 
    42 TVerdict CPluginCharsExtendedStep::doTestStepPreambleL()
    43 	{
    44 	SetTestStepResult(EPass);
    45 	return TestStepResult();
    46 	}
    47 				
    48 TVerdict CPluginCharsExtendedStep::doTestStepL()
    49 	{
    50 		
    51 	INFO_PRINTF1(_L("Plugin Characteristics - Extended Chracteristics"));
    52 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    53 		
    54 	if (TestStepResult()==EPass)
    55 		{
    56 		
    57 		//Assume faliure, unless all is successful
    58 		SetTestStepResult(EFail);
    59 		
    60 		TPtrC encryptKey;
    61 		TVariantPtrC keyType;
    62 		TVariantPtrC algorithmUid;
    63 		TVariantPtrC cryptoMode;
    64 		TVariantPtrC operationMode;
    65 		TVariantPtrC paddingMode;
    66 		
    67 		//Each of the individual parameters required to create the Symmetric Cipher object
    68 		//are read in from the specified INI configuration file	
    69 		if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) || 
    70 			!GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
    71 			!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
    72 			!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
    73 			!GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
    74 			!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode))
    75 			{
    76 			ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
    77 			SetTestStepResult(EFail);
    78 			}
    79 		else
    80 			{						
    81 			//Convert encryption key to an 8 Bit Descriptor
    82 			HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
    83 			TPtr8 keyStrPtr = keyStr->Des();
    84 
    85 			keyStrPtr.Copy(encryptKey);
    86 			
    87 			//Create an new CryptoParams object to encapsulate the key type and secret key string
    88 			CCryptoParams* keyParams = CCryptoParams::NewL();
    89 			CleanupStack::PushL(keyParams);
    90 			keyParams->AddL(*keyStr,keyType);
    91 
    92 			//Create Key Object
    93 			TKeyProperty keyProperty;
    94 			CKey* key=CKey::NewL(keyProperty,*keyParams);
    95 			CleanupStack::PushL(key);
    96 			
    97 			CSymmetricCipher* symmetricCipherImpl = NULL;	
    98 				
    99 			TRAPD_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
   100 																algorithmUid,
   101 																*key,
   102 																cryptoMode,
   103 																operationMode,
   104 																paddingMode,
   105 																NULL)); 
   106 			
   107 			
   108 						
   109 			if(symmetricCipherImpl && (err == KErrNone))
   110 				{
   111 				CleanupStack::PushL(symmetricCipherImpl);
   112 				
   113 				INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
   114 				
   115 				//Retrieve all the Symmetric Cipher characteristics that are required for all test cases
   116 				TInt exExtendedTestChar1;
   117 				TInt exExtendedTestChar2;
   118 				TPtrC exExtendedTestChar3;
   119 				TVariantPtrC exExtendedConcurrency;
   120 				TBool exExtendedExclusiveUse;
   121 				
   122 				if(!GetIntFromConfig(ConfigSection(),KConfigExExtendTestChar1,exExtendedTestChar1) ||
   123 					!GetIntFromConfig(ConfigSection(),KConfigExExtendTestChar2,exExtendedTestChar2) ||
   124 					!GetStringFromConfig(ConfigSection(),KConfigExExtendTestChar3,exExtendedTestChar3) ||
   125 					!GetStringFromConfig(ConfigSection(),KConfigExExtendConcurrency,exExtendedConcurrency) ||
   126 					!GetBoolFromConfig(ConfigSection(),KConfigExExtendExclusiveUse,exExtendedExclusiveUse))
   127 					{
   128 					ERR_PRINTF1(_L("** .INI Error: Expected Symmetric Cipher Extended Characteristics Not Located **"));
   129 					SetTestStepResult(EFail);
   130 					}
   131 				else
   132 					{
   133 					INFO_PRINTF1(_L("** Checking Symmetric Cipher Extended Characteristics.... **"));
   134 					
   135 					//******************EXTENDED CHARACTERISITICS****************************
   136 				
   137 					//Retrieve Characteristics via CExtendedCharacteristics Object
   138 					const CExtendedCharacteristics* extendedChars = NULL;
   139 					
   140 					TRAP_LOG(err,extendedChars = symmetricCipherImpl->GetExtendedCharacteristicsL());
   141 					
   142 					//Retrieve Charcteristics via the ListExtendedCharacteristics() of the CExtendedCharacteristics Object
   143 					const CCryptoParams* extendedCryptoParams = NULL;
   144 
   145 					TRAP_LOG(err,extendedCryptoParams = extendedChars->ListExtendedCharacteristics());
   146 					
   147 					//***********************************************************************
   148 
   149 					//Convert expected string atrributes an 8 Bit Descriptor
   150 					HBufC8* exTestChar3Str = HBufC8::NewLC(exExtendedTestChar3.Length());
   151 					TPtr8 tmpPtr = exTestChar3Str->Des();
   152 			
   153 					tmpPtr.Copy(exExtendedTestChar3);
   154 					
   155 					//Checks BOTH the returned Extended Characteristic values from the CExtendedCharacteristics 'GET' Methods and
   156 					//the CCryptoParams List returned from the ListExtendedCharacteristics() method
   157 
   158 					if((!(extendedChars->GetTIntCharacteristicL(KExtendCharType1Uid) == exExtendedTestChar1)) 
   159 						&& (!(extendedCryptoParams->GetTIntL(KExtendCharType1Uid) == exExtendedTestChar1)))
   160 						{
   161 						ERR_PRINTF1(_L("** FAIL: Extended Characteristic 1 Mismatch **"));	
   162 						User::Leave(KErrNotFound);
   163 						}
   164 						
   165 					if((!(extendedChars->GetTIntCharacteristicL(KExtendCharType2Uid) == exExtendedTestChar2))
   166 						&& (!(extendedCryptoParams->GetTIntL(KExtendCharType2Uid) == exExtendedTestChar2)))
   167 						{
   168 						ERR_PRINTF1(_L("** FAIL: Extended Characteristic 2 Mismatch **"));	
   169 						User::Leave(KErrNotFound);
   170 						}
   171 						
   172 					if((!(extendedChars->GetTDesC8CharacteristicL(KExtendCharType3Uid) == *exTestChar3Str))
   173 						&& (!(extendedCryptoParams->GetTDesC8L(KExtendCharType3Uid) == *exTestChar3Str)))
   174 						{
   175 						ERR_PRINTF1(_L("** FAIL: Extended Characteristic 3 Mismatch **"));	
   176 						User::Leave(KErrNotFound);	
   177 						}
   178 						
   179 					if((!(extendedChars->GetTIntCharacteristicL(KConcurrencyTypeUid) == exExtendedConcurrency))
   180 						&& (!(extendedCryptoParams->GetTIntL(KConcurrencyTypeUid) == exExtendedConcurrency)))
   181 						{
   182 						ERR_PRINTF1(_L("** FAIL: 'Concurreny' Extended Characteristic Mismatch **"));	
   183 						User::Leave(KErrNotFound);
   184 						}
   185 						
   186 					if((!(extendedChars->GetTIntCharacteristicL(KExclusiveUseTypeUid) == exExtendedExclusiveUse))
   187 						&& (!(extendedCryptoParams->GetTIntL(KExclusiveUseTypeUid) == exExtendedExclusiveUse)))
   188 						{
   189 						ERR_PRINTF1(_L("** FAIL: 'Exclusive Use' Extended Characteristic Mismatch **"));
   190 						User::Leave(KErrNotFound);
   191 						}
   192 						
   193 					INFO_PRINTF1(_L("** PASS: Extended Characteristics Successfully Match **"));	
   194 					SetTestStepResult(EPass);
   195 						
   196 					CleanupStack::PopAndDestroy(exTestChar3Str);
   197 					}
   198 					
   199 				CleanupStack::PopAndDestroy(symmetricCipherImpl);
   200 				}
   201 			else
   202 				{
   203 				ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Cipher Object - %d ***"), err);	
   204 				}
   205 				
   206 			CleanupStack::PopAndDestroy(3,keyStr);
   207 			}
   208 		}
   209 						
   210 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
   211 	return TestStepResult();
   212 
   213 	}
   214 
   215 TVerdict CPluginCharsExtendedStep::doTestStepPostambleL()
   216 	{
   217 	return TestStepResult();
   218 	}