os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsasymmetriccipherstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @internalTechnology
sl@0
    22
*/
sl@0
    23
 
sl@0
    24
#include "plugincharsasymmetriccipherstep.h"
sl@0
    25
#include "plugincharschecker.h"
sl@0
    26
sl@0
    27
#include <cryptospi/cryptoasymmetriccipherapi.h>
sl@0
    28
#include <cryptospi/cryptokeypairgeneratorapi.h>
sl@0
    29
#include <cryptospi/keypair.h>
sl@0
    30
sl@0
    31
using namespace CryptoSpi;
sl@0
    32
sl@0
    33
CPluginCharsAsymmetricCipherStep::~CPluginCharsAsymmetricCipherStep()
sl@0
    34
	{
sl@0
    35
	}
sl@0
    36
sl@0
    37
CPluginCharsAsymmetricCipherStep::CPluginCharsAsymmetricCipherStep()
sl@0
    38
	{
sl@0
    39
	SetTestStepName(KPluginCharsAsymmetricCipherStep);
sl@0
    40
	}
sl@0
    41
sl@0
    42
TVerdict CPluginCharsAsymmetricCipherStep::doTestStepPreambleL()
sl@0
    43
	{
sl@0
    44
	SetTestStepResult(EPass);
sl@0
    45
	return TestStepResult();
sl@0
    46
	}
sl@0
    47
				
sl@0
    48
TVerdict CPluginCharsAsymmetricCipherStep::doTestStepL()
sl@0
    49
	{
sl@0
    50
	
sl@0
    51
	INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Cipher Chracteristics"));
sl@0
    52
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
sl@0
    53
		
sl@0
    54
	if (TestStepResult()==EPass)
sl@0
    55
		{
sl@0
    56
		
sl@0
    57
		//Assume faliure, unless all is successful
sl@0
    58
		SetTestStepResult(EFail);
sl@0
    59
		
sl@0
    60
		TVariantPtrC algorithmUid;
sl@0
    61
		TVariantPtrC cryptoMode;
sl@0
    62
		TVariantPtrC paddingMode;
sl@0
    63
		TVariantPtrC invalidPaddingMode;
sl@0
    64
		
sl@0
    65
		//Each of the individual parameters required to create the Asymmetric Cipher object
sl@0
    66
		//are read in from the specified INI configuration file					
sl@0
    67
		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
sl@0
    68
			!GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
sl@0
    69
			!GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
sl@0
    70
			!GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode))
sl@0
    71
			{
sl@0
    72
			ERR_PRINTF1(_L("** .INI Error: Asymmetric Cipher Arguments Not Located **"));
sl@0
    73
			SetTestStepResult(EFail);
sl@0
    74
			}
sl@0
    75
		else
sl@0
    76
			{
sl@0
    77
			CCryptoParams* keyParams = CCryptoParams::NewLC(); 
sl@0
    78
			
sl@0
    79
			//****************************************************
sl@0
    80
			//Create Key Pair and Key Pair Generator Objects
sl@0
    81
   			CKeyPair* keyPair = NULL;
sl@0
    82
			CKeyPairGenerator * keypairImpl = NULL;
sl@0
    83
			
sl@0
    84
			INFO_PRINTF1(_L("Generating RSA keys"));
sl@0
    85
			
sl@0
    86
			// create an RSA key pair
sl@0
    87
			keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
sl@0
    88
			keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
sl@0
    89
sl@0
    90
			// create a key pair generator implementation interface
sl@0
    91
			TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
sl@0
    92
																			KRSAKeyPairGeneratorUid, 
sl@0
    93
																			keyParams));
sl@0
    94
											
sl@0
    95
			CleanupStack::PushL(keypairImpl);
sl@0
    96
sl@0
    97
			// Create a Key Pair	
sl@0
    98
			TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
sl@0
    99
			
sl@0
   100
			CleanupStack::PushL(keyPair);
sl@0
   101
			
sl@0
   102
			//*****************************************************
sl@0
   103
			
sl@0
   104
			CAsymmetricCipher* asymmetricCipherImpl = NULL;	
sl@0
   105
				
sl@0
   106
			TRAP(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL(asymmetricCipherImpl,
sl@0
   107
																	algorithmUid,
sl@0
   108
																	keyPair->PrivateKey(),
sl@0
   109
																	cryptoMode,
sl@0
   110
																	paddingMode,
sl@0
   111
																	NULL));
sl@0
   112
			
sl@0
   113
			if(asymmetricCipherImpl && (err == KErrNone))
sl@0
   114
				{
sl@0
   115
				
sl@0
   116
				CleanupStack::PushL(asymmetricCipherImpl);
sl@0
   117
				
sl@0
   118
				INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Cipher Object **"));
sl@0
   119
				
sl@0
   120
				//Define a pointer of type TCharacteristics in order to store the asymmetric cipher
sl@0
   121
				//encryption object's characterisctics	
sl@0
   122
				const TCharacteristics* chars(NULL);
sl@0
   123
							
sl@0
   124
				//Retrieve the characteristics for the asymmetric cipher implementation object
sl@0
   125
				TRAP_LOG(err, asymmetricCipherImpl->GetCharacteristicsL(chars));
sl@0
   126
					
sl@0
   127
				//Static cast the characteristics to type TAsymmetricCipherCharacteristics
sl@0
   128
				const TAsymmetricCipherCharacteristics* asymmetricChars = static_cast<const TAsymmetricCipherCharacteristics*>(chars);
sl@0
   129
				
sl@0
   130
				//Retrieve all the Common characteristics that are required for all test cases
sl@0
   131
				TVariantPtrC exInterfaceUid;
sl@0
   132
				TVariantPtrC exAlgorithmUid;
sl@0
   133
				TVariantPtrC exImplementationUid;
sl@0
   134
				TVariantPtrC exCreatorName;
sl@0
   135
				TBool exFIPSApproved;
sl@0
   136
				TBool exHardwareSupported;
sl@0
   137
				TInt exMaxConcurrencySupported;
sl@0
   138
				TVariantPtrC exAlgorithmName;
sl@0
   139
				TInt exLatency;
sl@0
   140
				TInt exThroughput;
sl@0
   141
				
sl@0
   142
				//Retrieve all the Asymmetric characteristics that are required for all test cases
sl@0
   143
				TInt exAsymmetricMaxKeyLength;
sl@0
   144
				TVariantPtrC exAsymmetricPaddingModes;
sl@0
   145
				TInt exAsymmetricPaddingModeNum;
sl@0
   146
				TInt exAsymmetricKeySupportMode;
sl@0
   147
				
sl@0
   148
				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
sl@0
   149
					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
sl@0
   150
					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
sl@0
   151
					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
sl@0
   152
					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
sl@0
   153
					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
sl@0
   154
					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
sl@0
   155
					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
sl@0
   156
					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
sl@0
   157
					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
sl@0
   158
					!GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymmetricMaxKeyLength) ||
sl@0
   159
					!GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exAsymmetricPaddingModes) ||
sl@0
   160
					!GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exAsymmetricPaddingModeNum) ||
sl@0
   161
					!GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exAsymmetricKeySupportMode))
sl@0
   162
					{
sl@0
   163
					ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Cipher/Common Chracteristic Arguments Not Located **"));
sl@0
   164
					SetTestStepResult(EFail);
sl@0
   165
					}
sl@0
   166
				else
sl@0
   167
					{
sl@0
   168
					INFO_PRINTF1(_L("** Checking Asymmetric Cipher/Common Characteristics.... **"));
sl@0
   169
					
sl@0
   170
					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
sl@0
   171
					
sl@0
   172
					//Retrieve the Common Characteristics from TAsymmetricCipherCharacteristics 
sl@0
   173
					const TCommonCharacteristics* asymCommonChars = &asymmetricChars->cmn;
sl@0
   174
					
sl@0
   175
					TPtrC errorMessage;
sl@0
   176
					
sl@0
   177
					//Perform Asymmetric Cipher/Common Characteristic Checks
sl@0
   178
					if(pluginCheck->checkCommonCharacteristics(asymCommonChars,
sl@0
   179
																exInterfaceUid,
sl@0
   180
																exAlgorithmUid,
sl@0
   181
																exImplementationUid,
sl@0
   182
																exCreatorName,
sl@0
   183
																exFIPSApproved,
sl@0
   184
																exHardwareSupported,
sl@0
   185
																exMaxConcurrencySupported,
sl@0
   186
																exAlgorithmName,
sl@0
   187
																exLatency,
sl@0
   188
																exThroughput,
sl@0
   189
																errorMessage) &&
sl@0
   190
						pluginCheck->checkAsymmetricCharacteristics(asymmetricChars,
sl@0
   191
																exAsymmetricMaxKeyLength,
sl@0
   192
																exAsymmetricPaddingModes,
sl@0
   193
																exAsymmetricPaddingModeNum,
sl@0
   194
																exAsymmetricKeySupportMode,
sl@0
   195
																errorMessage))
sl@0
   196
						{
sl@0
   197
						INFO_PRINTF1(_L("Asymmetric Cipher/Common characteristics successfully match expected values..."));
sl@0
   198
						
sl@0
   199
						if(asymmetricChars->IsPaddingModeSupported(paddingMode) && !asymmetricChars->IsPaddingModeSupported(invalidPaddingMode))
sl@0
   200
							{
sl@0
   201
							INFO_PRINTF1(_L("Successful Padding Mode Supported Tests...."));
sl@0
   202
							
sl@0
   203
							INFO_PRINTF1(_L("** PASS: Asymmetric Cipher/Common Characteristics Tests Successful **"));
sl@0
   204
sl@0
   205
							SetTestStepResult(EPass);
sl@0
   206
							}
sl@0
   207
						else
sl@0
   208
							{
sl@0
   209
							ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results"));	
sl@0
   210
							}	
sl@0
   211
						}
sl@0
   212
					else
sl@0
   213
						{
sl@0
   214
						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);		
sl@0
   215
						}
sl@0
   216
						
sl@0
   217
					CleanupStack::PopAndDestroy(pluginCheck);
sl@0
   218
					}
sl@0
   219
					
sl@0
   220
				CleanupStack::PopAndDestroy(asymmetricCipherImpl);
sl@0
   221
				}				
sl@0
   222
			else
sl@0
   223
				{
sl@0
   224
				ERR_PRINTF1(_L("** Error: Loading Asymmetric Cipher Object **"));
sl@0
   225
				}
sl@0
   226
				
sl@0
   227
			CleanupStack::PopAndDestroy(3,keyParams);
sl@0
   228
			}
sl@0
   229
			
sl@0
   230
		}
sl@0
   231
		
sl@0
   232
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
sl@0
   233
	return TestStepResult();
sl@0
   234
	}
sl@0
   235
sl@0
   236
TVerdict CPluginCharsAsymmetricCipherStep::doTestStepPostambleL()
sl@0
   237
	{
sl@0
   238
	return TestStepResult();
sl@0
   239
	}