os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsasymkeypairstep.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 "plugincharsasymkeypairstep.h"
    25 #include "plugincharschecker.h"
    26 
    27 #include <cryptospi/keypair.h>
    28 #include <cryptospi/cryptokeypairgeneratorapi.h>
    29 
    30 using namespace CryptoSpi;
    31 
    32 CPluginCharsAsymKeyPairStep::~CPluginCharsAsymKeyPairStep()
    33 	{
    34 	}
    35 
    36 CPluginCharsAsymKeyPairStep::CPluginCharsAsymKeyPairStep()
    37 	{
    38 	SetTestStepName(KPluginCharsAsymKeyPairStep);
    39 	}
    40 
    41 TVerdict CPluginCharsAsymKeyPairStep::doTestStepPreambleL()
    42 	{
    43 	SetTestStepResult(EPass);
    44 	return TestStepResult();
    45 	}
    46 				
    47 TVerdict CPluginCharsAsymKeyPairStep::doTestStepL()
    48 	{
    49 	
    50 	INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Key Pair Generator Chracteristics"));
    51 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    52 		
    53 	if (TestStepResult()==EPass)
    54 		{
    55 		
    56 		//Assume faliure, unless all is successful
    57 		SetTestStepResult(EFail);
    58 		
    59 		TVariantPtrC algorithmUid;
    60 		
    61 		//Each of the individual parameters required to create the Asymmetric Key Pair Generator object
    62 		//are read in from the specified INI configuration file					
    63 		if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid))
    64 			{
    65 			ERR_PRINTF1(_L("** .INI Error: Asymmetric Key Pair Generator Cipher Arguments Not Located **"));
    66 			SetTestStepResult(EFail);
    67 			}
    68 		else
    69 			{
    70 			CCryptoParams* keyParams = CCryptoParams::NewLC(); 	
    71 			
    72 			//Create Key Pair Generator Object
    73 			CKeyPairGenerator* keyPairGenImpl = NULL;
    74 			
    75 			//Create a Asymmetric Key Pair Generator Implementation
    76 			TRAPD(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keyPairGenImpl, 
    77 																		algorithmUid, 
    78 																		keyParams));
    79 																			
    80 			if(keyPairGenImpl && (err == KErrNone))
    81 				{
    82 				
    83 				CleanupStack::PushL(keyPairGenImpl);
    84 				
    85 				INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Key Pair Generator Object **"));
    86 				
    87 				//Define a pointer of type TCharacteristics in order to store the asymmetric key pair generator
    88 				//object's characterisctics	
    89 				const TCharacteristics* chars(NULL);
    90 							
    91 				//Retrieve the characteristics for the asymmetric key pair generator implementation object
    92 				keyPairGenImpl->GetCharacteristicsL(chars);
    93 				
    94 				//Static cast the characteristics to type TKeyAgreementCharacteristics
    95 				const TAsymmetricKeypairGeneratorCharacteristics* asymkeypairgenChars = static_cast<const TAsymmetricKeypairGeneratorCharacteristics*>(chars);
    96 				
    97 				//Retrieve all the Common characteristics that are required for the test
    98 				TVariantPtrC exInterfaceUid;
    99 				TVariantPtrC exAlgorithmUid;
   100 				TVariantPtrC exImplementationUid;
   101 				TVariantPtrC exCreatorName;
   102 				TBool exFIPSApproved;
   103 				TBool exHardwareSupported;
   104 				TInt exMaxConcurrencySupported;
   105 				TVariantPtrC exAlgorithmName;
   106 				TInt exLatency;
   107 				TInt exThroughput;
   108 				
   109 				//Retrieve all the Asymmetric Key Pair Generator characteristics that are required for the test
   110 				TInt exAsymKeyPairMaxKeyLength;
   111 					
   112 				if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
   113 					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
   114 					!GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
   115 					!GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
   116 					!GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
   117 					!GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
   118 					!GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
   119 					!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
   120 					!GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
   121 					!GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
   122 					!GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymKeyPairMaxKeyLength))
   123 					{
   124 					ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Key Pair Generator/Common Characteristics Not Located **"));
   125 					SetTestStepResult(EFail);
   126 					}
   127 				else
   128 					{
   129 			
   130 					INFO_PRINTF1(_L("** Checking Asymmetric Key Pair Generator/Common Characteristics.... **"));
   131 					
   132 					CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
   133 					
   134 					//Retrieve the Common Characteristics from TAsymmetricKeypairGeneratorCharacteristics 
   135 					const TCommonCharacteristics* asymkeypairgenCommonChars = &asymkeypairgenChars->cmn;
   136 					
   137 					TPtrC errorMessage;
   138 					
   139 					//Perform Key Agreement/Common Characteristic Checks
   140 					if(pluginCheck->checkCommonCharacteristics(asymkeypairgenCommonChars,
   141 																exInterfaceUid,
   142 																exAlgorithmUid,
   143 																exImplementationUid,
   144 																exCreatorName,
   145 																exFIPSApproved,
   146 																exHardwareSupported,
   147 																exMaxConcurrencySupported,
   148 																exAlgorithmName,
   149 																exLatency,
   150 																exThroughput,
   151 																errorMessage) &&
   152 					pluginCheck->checkAsymKeypairGenCharacteristics(asymkeypairgenChars,
   153 																exAsymKeyPairMaxKeyLength,
   154 																errorMessage))
   155 						{
   156 						INFO_PRINTF1(_L("** PASS : Asymmetric Key Pair Generator/Common characteristics successfully match expected values **"));
   157 						SetTestStepResult(EPass);	
   158 						}
   159 					else
   160 						{
   161 						ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);	
   162 						}
   163 					
   164 					CleanupStack::PopAndDestroy(pluginCheck);
   165 					}
   166 				
   167 				CleanupStack::PopAndDestroy(keyPairGenImpl);
   168 				}
   169 			else
   170 				{
   171 				ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Key Pair Generator Object - %d ***"), err);
   172 				}
   173 				
   174 			CleanupStack::PopAndDestroy(keyParams);			
   175 			}
   176 		
   177 		}
   178 		
   179 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());	
   180 	return TestStepResult();
   181 	}
   182 
   183 TVerdict CPluginCharsAsymKeyPairStep::doTestStepPostambleL()
   184 	{
   185 	return TestStepResult();
   186 	}