1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/plugincharsasymsignstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,238 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalTechnology
1.25 +*/
1.26 +
1.27 +#include "plugincharsasymsignstep.h"
1.28 +#include "plugincharschecker.h"
1.29 +
1.30 +#include <cryptospi/keypair.h>
1.31 +#include <cryptospi/cryptokeypairgeneratorapi.h>
1.32 +#include <cryptospi/cryptosignatureapi.h>
1.33 +
1.34 +using namespace CryptoSpi;
1.35 +
1.36 +CPluginCharsAsymSignStep::~CPluginCharsAsymSignStep()
1.37 + {
1.38 + }
1.39 +
1.40 +CPluginCharsAsymSignStep::CPluginCharsAsymSignStep()
1.41 + {
1.42 + SetTestStepName(KPluginCharsAsymSignStep);
1.43 + }
1.44 +
1.45 +TVerdict CPluginCharsAsymSignStep::doTestStepPreambleL()
1.46 + {
1.47 + SetTestStepResult(EPass);
1.48 + return TestStepResult();
1.49 + }
1.50 +
1.51 +TVerdict CPluginCharsAsymSignStep::doTestStepL()
1.52 + {
1.53 +
1.54 + INFO_PRINTF1(_L("Plugin Characteristics - Asymmetric Signer Chracteristics"));
1.55 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.56 +
1.57 + if (TestStepResult()==EPass)
1.58 + {
1.59 +
1.60 + //Assume faliure, unless all is successful
1.61 + SetTestStepResult(EFail);
1.62 +
1.63 + TVariantPtrC algorithmUid;
1.64 + TVariantPtrC paddingMode;
1.65 + TVariantPtrC invalidPaddingMode;
1.66 +
1.67 + //Each of the individual parameters required to create the Asymmetric Singer object
1.68 + //are read in from the specified INI configuration file
1.69 + if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
1.70 + !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
1.71 + !GetStringFromConfig(ConfigSection(),KConfigInvalidPaddingMode,invalidPaddingMode))
1.72 + {
1.73 + ERR_PRINTF1(_L("** .INI Error: Asymmetric Signer Arguments Not Located **"));
1.74 + SetTestStepResult(EFail);
1.75 + }
1.76 + else
1.77 + {
1.78 + CCryptoParams* keyParams = CCryptoParams::NewLC();
1.79 +
1.80 + //****************************************************
1.81 + //Create Key Pair and Key Pair Generator Objects
1.82 + CKeyPair* keyPair = NULL;
1.83 + CKeyPairGenerator * keypairImpl = NULL;
1.84 +
1.85 + INFO_PRINTF1(_L("Generating RSA keys"));
1.86 +
1.87 + // create an RSA key pair
1.88 + keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
1.89 + keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
1.90 +
1.91 + // create a key pair generator implementation interface
1.92 + TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
1.93 + KRSAKeyPairGeneratorUid,
1.94 + keyParams));
1.95 +
1.96 + CleanupStack::PushL(keypairImpl);
1.97 +
1.98 + // Create a Key Pair
1.99 + TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
1.100 +
1.101 + CleanupStack::PushL(keyPair);
1.102 +
1.103 + //*****************************************************
1.104 +
1.105 + CSigner* asymmetricSignerImpl = NULL;
1.106 +
1.107 + TRAP(err,CSignatureFactory::CreateSignerL(asymmetricSignerImpl,
1.108 + algorithmUid,
1.109 + keyPair->PublicKey(),
1.110 + paddingMode,
1.111 + NULL));
1.112 +
1.113 + if(asymmetricSignerImpl && (err == KErrNone))
1.114 + {
1.115 +
1.116 + CleanupStack::PushL(asymmetricSignerImpl);
1.117 +
1.118 + INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Signer Object **"));
1.119 +
1.120 + //Define a pointer of type TCharacteristics in order to store the asymmetric signer
1.121 + //object's characterisctics
1.122 + const TCharacteristics* chars(NULL);
1.123 +
1.124 + //Retrieve the characteristics for the asymmetric signer implementation object
1.125 + TRAP_LOG(err, asymmetricSignerImpl->GetCharacteristicsL(chars));
1.126 +
1.127 + //Static cast the characteristics to type TAsymmetricSignatureCharacteristics
1.128 + const TAsymmetricSignatureCharacteristics* asymsignChars = static_cast<const TAsymmetricSignatureCharacteristics*>(chars);
1.129 +
1.130 + //Retrieve all the Common characteristics that are required for the test
1.131 + TVariantPtrC exInterfaceUid;
1.132 + TVariantPtrC exAlgorithmUid;
1.133 + TVariantPtrC exImplementationUid;
1.134 + TVariantPtrC exCreatorName;
1.135 + TBool exFIPSApproved;
1.136 + TBool exHardwareSupported;
1.137 + TInt exMaxConcurrencySupported;
1.138 + TVariantPtrC exAlgorithmName;
1.139 + TInt exLatency;
1.140 + TInt exThroughput;
1.141 +
1.142 + //Retrieve all the Asymmetric Signer characteristics that are required for the test
1.143 + TInt exAsymSignMaxKeyLength;
1.144 + TInt exAsymSignKeySupportMode;
1.145 + TVariantPtrC exAsymSignPaddingModes;
1.146 + TInt exAsymSignPaddingModeNum;
1.147 +
1.148 + if(!GetStringFromConfig(ConfigSection(),KConfigExInterfaceUid,exInterfaceUid) ||
1.149 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
1.150 + !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid) ||
1.151 + !GetStringFromConfig(ConfigSection(),KConfigExCreatorName,exCreatorName) ||
1.152 + !GetBoolFromConfig(ConfigSection(),KConfigExFIPSApproved,exFIPSApproved) ||
1.153 + !GetBoolFromConfig(ConfigSection(),KConfigExHardwareSupport,exHardwareSupported) ||
1.154 + !GetIntFromConfig(ConfigSection(),KConfigExMaxConcurrency,exMaxConcurrencySupported) ||
1.155 + !GetStringFromConfig(ConfigSection(),KConfigExAlgorithmName,exAlgorithmName) ||
1.156 + !GetIntFromConfig(ConfigSection(),KConfigExLatency,exLatency) ||
1.157 + !GetIntFromConfig(ConfigSection(),KConfigExThroughput,exThroughput) ||
1.158 + !GetIntFromConfig(ConfigSection(),KConfigExMaxKeyLength,exAsymSignMaxKeyLength) ||
1.159 + !GetStringFromConfig(ConfigSection(),KConfigExPaddingModes,exAsymSignPaddingModes) ||
1.160 + !GetIntFromConfig(ConfigSection(),KConfigExPaddingModeNum,exAsymSignPaddingModeNum) ||
1.161 + !GetIntFromConfig(ConfigSection(),KConfigExKeySupportMode,exAsymSignKeySupportMode))
1.162 + {
1.163 + ERR_PRINTF1(_L("** .INI Error: Expected Asymmetric Signer/Common Characteristics Not Located **"));
1.164 + SetTestStepResult(EFail);
1.165 + }
1.166 + else
1.167 + {
1.168 +
1.169 + INFO_PRINTF1(_L("** Checking Asymmetric Signer/Common Characteristics.... **"));
1.170 +
1.171 + CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
1.172 +
1.173 + //Retrieve the Common Characteristics from TAsymmetricSignatureCharacteristics
1.174 + const TCommonCharacteristics* asymsignCommonChars = &asymsignChars->cmn;
1.175 +
1.176 + TPtrC errorMessage;
1.177 +
1.178 + //Perform Asymmetric Signer/Common Characteristic Checks
1.179 + if(pluginCheck->checkCommonCharacteristics(asymsignCommonChars,
1.180 + exInterfaceUid,
1.181 + exAlgorithmUid,
1.182 + exImplementationUid,
1.183 + exCreatorName,
1.184 + exFIPSApproved,
1.185 + exHardwareSupported,
1.186 + exMaxConcurrencySupported,
1.187 + exAlgorithmName,
1.188 + exLatency,
1.189 + exThroughput,
1.190 + errorMessage) &&
1.191 + pluginCheck->checkAsymSignatureCharacteristics(asymsignChars,
1.192 + exAsymSignMaxKeyLength,
1.193 + exAsymSignPaddingModes,
1.194 + exAsymSignPaddingModeNum,
1.195 + exAsymSignKeySupportMode,
1.196 + errorMessage))
1.197 + {
1.198 + INFO_PRINTF1(_L("Asymmetric Signer/Common characteristics successfully match expected values..."));
1.199 +
1.200 + if(asymsignChars->IsPaddingModeSupported(paddingMode) && !asymsignChars->IsPaddingModeSupported(invalidPaddingMode))
1.201 + {
1.202 + INFO_PRINTF1(_L("Successful Padding Mode Supported Tests...."));
1.203 +
1.204 + INFO_PRINTF1(_L("** PASS: Asymmetric Signer/Common Characteristics Tests Successful **"));
1.205 +
1.206 + SetTestStepResult(EPass);
1.207 + }
1.208 + else
1.209 + {
1.210 + ERR_PRINTF1(_L("** FAIL: Unexpected 'Padding' Mode Supported Results"));
1.211 + }
1.212 + }
1.213 + else
1.214 + {
1.215 + ERR_PRINTF2(_L("** FAIL: Characteristic Mismatch - %S **"),&errorMessage);
1.216 + }
1.217 +
1.218 + CleanupStack::PopAndDestroy(pluginCheck);
1.219 + }
1.220 +
1.221 + CleanupStack::PopAndDestroy(asymmetricSignerImpl);
1.222 + }
1.223 + else
1.224 + {
1.225 + ERR_PRINTF2(_L("*** FAIL: Failed to Create Asymmetric Signer Object - %d ***"), err);
1.226 + }
1.227 +
1.228 + CleanupStack::PopAndDestroy(3,keyParams);
1.229 + }
1.230 +
1.231 + }
1.232 +
1.233 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.234 + return TestStepResult();
1.235 +
1.236 + }
1.237 +
1.238 +TVerdict CPluginCharsAsymSignStep::doTestStepPostambleL()
1.239 + {
1.240 + return TestStepResult();
1.241 + }