os/security/crypto/weakcryptospi/test/tcryptospi/src/signerpositiveobjectloadstep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/signerpositiveobjectloadstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,154 @@
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 +* Example CTestStep derived implementation
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +#include "signerpositiveobjectloadstep.h"
1.28 +
1.29 +#include <cryptospi/keypair.h>
1.30 +#include <cryptospi/cryptosignatureapi.h>
1.31 +#include <cryptospi/cryptokeypairgeneratorapi.h>
1.32 +
1.33 +using namespace CryptoSpi;
1.34 +
1.35 +
1.36 +CSignerPositiveObjectLoadStep::~CSignerPositiveObjectLoadStep()
1.37 + {
1.38 + }
1.39 +
1.40 +CSignerPositiveObjectLoadStep::CSignerPositiveObjectLoadStep()
1.41 + {
1.42 + SetTestStepName(KSignerPositiveObjectLoadStep);
1.43 + }
1.44 +
1.45 +TVerdict CSignerPositiveObjectLoadStep::doTestStepPreambleL()
1.46 + {
1.47 + SetTestStepResult(EPass);
1.48 + return TestStepResult();
1.49 + }
1.50 +
1.51 +
1.52 +TVerdict CSignerPositiveObjectLoadStep::doTestStepL()
1.53 + {
1.54 + INFO_PRINTF1(_L("*** Signer - Positive Object Load ***"));
1.55 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.56 +
1.57 + if (TestStepResult()==EPass)
1.58 + {
1.59 + //Assume faliure, unless all is successful
1.60 + SetTestStepResult(EFail);
1.61 +
1.62 + TVariantPtrC testVariant;
1.63 + TVariantPtrC keyVariant;
1.64 +
1.65 + if( !GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
1.66 + {
1.67 + // Leave if there's any error.
1.68 + User::Leave(KErrNotFound);
1.69 + }
1.70 + else
1.71 + {
1.72 + //Create an new CryptoParams object to encapsulate the key type and secret key string
1.73 + CCryptoParams* keyParams = CCryptoParams::NewL();
1.74 + CleanupStack::PushL(keyParams);
1.75 +
1.76 + //Set the Key Parameters
1.77 + keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
1.78 + keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
1.79 +
1.80 + // Create a Key Pair Generator implementation
1.81 + INFO_PRINTF1(_L("Creating Key Pair Generator..."));
1.82 +
1.83 + CKeyPairGenerator * keypairImpl = NULL;
1.84 +
1.85 + TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
1.86 + KRSAKeyPairGeneratorUid,
1.87 + keyParams));
1.88 +
1.89 + CleanupStack::PushL(keypairImpl);
1.90 +
1.91 +
1.92 + // Generate a Key Pair
1.93 + INFO_PRINTF1(_L("Generating Key Pair..."));
1.94 +
1.95 + CKeyPair* keyPair = NULL;
1.96 +
1.97 + TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024,
1.98 + *keyParams,
1.99 + keyPair));
1.100 +
1.101 + CleanupStack::PushL(keyPair);
1.102 +
1.103 + // Creating Signer 1 with the necessary values from the ini file
1.104 + INFO_PRINTF1(_L("Constructing Signer 1 (No Padding)..."));
1.105 + CSigner * impl1 = NULL;
1.106 + TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl1,
1.107 + KRsaSignerUid,
1.108 + keyPair->PublicKey(),
1.109 + KPaddingModeNoneUid,
1.110 + keyParams));
1.111 +
1.112 + CleanupStack::PushL(impl1);
1.113 +
1.114 + // Creating Signer 2 with the necessary values from the ini file
1.115 + INFO_PRINTF1(_L("Constructing Signer 2 (Pkcs1_v1_5 Padding)..."));
1.116 + CSigner * impl2 = NULL;
1.117 + TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl2,
1.118 + KRsaSignerUid,
1.119 + keyPair->PublicKey(),
1.120 + KPaddingModePkcs1_v1_5_SignatureUid,
1.121 + keyParams));
1.122 +
1.123 + CleanupStack::PushL(impl2);
1.124 +
1.125 + if((impl1) && (impl2) && (err == KErrNone))
1.126 + {
1.127 + // This is a basic test for load positivity
1.128 + // from the Factory
1.129 + INFO_PRINTF1(_L("PASS: Signer - Positive Object Load"));
1.130 + SetTestStepResult(EPass);
1.131 + }
1.132 + else
1.133 + {
1.134 + ERR_PRINTF2(_L("FAIL: Signer Object Construction Failure - %d"), err);
1.135 + SetTestStepResult(EFail);
1.136 + }
1.137 +
1.138 + CleanupStack::PopAndDestroy(impl2);
1.139 + CleanupStack::PopAndDestroy(impl1);
1.140 +
1.141 + CleanupStack::PopAndDestroy(keyPair);
1.142 + CleanupStack::PopAndDestroy(keypairImpl);
1.143 + CleanupStack::PopAndDestroy(keyParams);
1.144 + }
1.145 +
1.146 + INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1.147 +
1.148 + }
1.149 + return TestStepResult();
1.150 + }
1.151 +
1.152 +
1.153 +
1.154 +TVerdict CSignerPositiveObjectLoadStep::doTestStepPostambleL()
1.155 + {
1.156 + return TestStepResult();
1.157 + }