Update contrib.
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include "plugincharsasymsignstep.h"
25 #include "plugincharschecker.h"
27 #include <cryptospi/keypair.h>
28 #include <cryptospi/cryptokeypairgeneratorapi.h>
29 #include <cryptospi/cryptosignatureapi.h>
31 using namespace CryptoSpi;
33 CPluginCharsAsymSignStep::~CPluginCharsAsymSignStep()
37 CPluginCharsAsymSignStep::CPluginCharsAsymSignStep()
39 SetTestStepName(KPluginCharsAsymSignStep);
42 TVerdict CPluginCharsAsymSignStep::doTestStepPreambleL()
44 SetTestStepResult(EPass);
45 return TestStepResult();
48 TVerdict CPluginCharsAsymSignStep::doTestStepL()
51 INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Signer Chracteristics"));
52 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
54 if (TestStepResult()==EPass)
57 //Assume faliure, unless all is successful
58 SetTestStepResult(EFail);
60 TVariantPtrC algorithmUid;
61 TVariantPtrC paddingMode;
62 TVariantPtrC invalidPaddingMode;
64 //Each of the individual parameters required to create the Asymmetric Singer object
65 //are read in from the specified INI configuration file
66 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
67 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
68 !GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode))
70 ERR_PRINTF1(_L("** .INI Error: Asymmetric Signer Arguments Not Located **"));
71 SetTestStepResult(EFail);
75 CCryptoParams* keyParams = CCryptoParams::NewLC();
77 //****************************************************
78 //Create Key Pair and Key Pair Generator Objects
79 CKeyPair* keyPair = NULL;
80 CKeyPairGenerator * keypairImpl = NULL;
82 INFO_PRINTF1(_L("Generating RSA keys"));
84 // create an RSA key pair
85 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
86 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
88 // create a key pair generator implementation interface
89 TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
90 KRSAKeyPairGeneratorUid,
93 CleanupStack::PushL(keypairImpl);
96 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
98 CleanupStack::PushL(keyPair);
100 //*****************************************************
102 CSigner* asymmetricSignerImpl = NULL;
104 TRAP(err,CSignatureFactory::CreateSignerL(asymmetricSignerImpl,
106 keyPair->PublicKey(),
110 if(asymmetricSignerImpl && (err == KErrNone))
113 CleanupStack::PushL(asymmetricSignerImpl);
115 INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Signer Object **"));
117 //Define a pointer of type TCharacteristics in order to store the asymmetric signer
118 //object's characterisctics
119 const TCharacteristics* chars(NULL);
121 //Retrieve the characteristics for the asymmetric signer implementation object
122 TRAP_LOG(err, asymmetricSignerImpl->GetCharacteristicsL(chars));
124 //Static cast the characteristics to type TAsymmetricSignatureCharacteristics
125 const TAsymmetricSignatureCharacteristics* asymsignChars = static_cast<const TAsymmetricSignatureCharacteristics*>(chars);
127 //Retrieve all the Common characteristics that are required for the test
128 TVariantPtrC exInterfaceUid;
129 TVariantPtrC exAlgorithmUid;
130 TVariantPtrC exImplementationUid;
131 TVariantPtrC exCreatorName;
132 TBool exFIPSApproved;
133 TBool exHardwareSupported;
134 TInt exMaxConcurrencySupported;
135 TVariantPtrC exAlgorithmName;
139 //Retrieve all the Asymmetric Signer characteristics that are required for the test
140 TInt exAsymSignMaxKeyLength;
141 TInt exAsymSignKeySupportMode;
142 TVariantPtrC exAsymSignPaddingModes;
143 TInt exAsymSignPaddingModeNum;
145 if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
146 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
147 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
148 !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
149 !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
150 !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
151 !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
152 !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
153 !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
154 !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
155 !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymSignMaxKeyLength) ||
156 !GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exAsymSignPaddingModes) ||
157 !GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exAsymSignPaddingModeNum) ||
158 !GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exAsymSignKeySupportMode))
160 ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Signer/Common Characteristics Not Located **"));
161 SetTestStepResult(EFail);
166 INFO_PRINTF1(_L("** Checking Asymmetric Signer/Common Characteristics.... **"));
168 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
170 //Retrieve the Common Characteristics from TAsymmetricSignatureCharacteristics
171 const TCommonCharacteristics* asymsignCommonChars = &asymsignChars->cmn;
175 //Perform Asymmetric Signer/Common Characteristic Checks
176 if(pluginCheck->checkCommonCharacteristics(asymsignCommonChars,
183 exMaxConcurrencySupported,
188 pluginCheck->checkAsymSignatureCharacteristics(asymsignChars,
189 exAsymSignMaxKeyLength,
190 exAsymSignPaddingModes,
191 exAsymSignPaddingModeNum,
192 exAsymSignKeySupportMode,
195 INFO_PRINTF1(_L("Asymmetric Signer/Common characteristics successfully match expected values..."));
197 if(asymsignChars->IsPaddingModeSupported(paddingMode) && !asymsignChars->IsPaddingModeSupported(invalidPaddingMode))
199 INFO_PRINTF1(_L("Successful Padding Mode Supported Tests...."));
201 INFO_PRINTF1(_L("** PASS: Asymmetric Signer/Common Characteristics Tests Successful **"));
203 SetTestStepResult(EPass);
207 ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results"));
212 ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
215 CleanupStack::PopAndDestroy(pluginCheck);
218 CleanupStack::PopAndDestroy(asymmetricSignerImpl);
222 ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Signer Object - %d ***"), err);
225 CleanupStack::PopAndDestroy(3,keyParams);
230 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
231 return TestStepResult();
235 TVerdict CPluginCharsAsymSignStep::doTestStepPostambleL()
237 return TestStepResult();