os/security/crypto/weakcryptospi/test/tcryptospi/src/dummyeccsignerloadstep.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/dummyeccsignerloadstep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,151 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009-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 "dummyeccsignerloadstep.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 +CDummyEccSignerLoadStep::~CDummyEccSignerLoadStep()
    1.37 +	{
    1.38 +	}
    1.39 +
    1.40 +CDummyEccSignerLoadStep::CDummyEccSignerLoadStep()
    1.41 +	{
    1.42 +	SetTestStepName(KDummyEccSignerLoadStep);
    1.43 +	}
    1.44 +
    1.45 +TVerdict CDummyEccSignerLoadStep::doTestStepPreambleL()
    1.46 +	{
    1.47 +	SetTestStepResult(EPass);
    1.48 +	return TestStepResult();
    1.49 +	}
    1.50 +
    1.51 +
    1.52 +TVerdict CDummyEccSignerLoadStep::doTestStepL()
    1.53 +	{
    1.54 +	INFO_PRINTF1(_L("*** Dummy Ecc Signer - Load ***"));
    1.55 +	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    1.56 +	
    1.57 +    //Assume failure, unless all is successful
    1.58 +    SetTestStepResult(EFail);
    1.59 +    
    1.60 +    TVariantPtrC testVariant;
    1.61 +    TVariantPtrC keyVariant;
    1.62 +
    1.63 +    if(	!GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
    1.64 +        {
    1.65 +        // Leave if there's any error.
    1.66 +        ERR_PRINTF1(_L("*** FAIL: Problem in configuration file ***"));
    1.67 +        User::Leave(KErrNotFound);
    1.68 +        }
    1.69 +    //Create an new CryptoParams object to encapsulate the key type and secret key string
    1.70 +    CCryptoParams* keyParams = CCryptoParams::NewLC();
    1.71 +
    1.72 +    /**
    1.73 +     * Note that we are actually generating RSA keys in place 
    1.74 +     * of ECC keys here. The reason for that is we do not have 
    1.75 +     * a working ECC implementation. This test case just tests 
    1.76 +     * if dummyecc signer is getting loaded. This is getting  
    1.77 +     * tested since KEccSignerUid is being passed as input to  
    1.78 +     * CreateSignerL. Keys have no significance in this test 
    1.79 +     * case.
    1.80 +     */
    1.81 +    //Set the Key Parameters
    1.82 +    keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
    1.83 +    keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
    1.84 +    
    1.85 +    // Create a Key Pair Generator implementation
    1.86 +    INFO_PRINTF1(_L("Creating Key Pair Generator...")); 
    1.87 +    
    1.88 +    CKeyPairGenerator * keypairImpl = NULL;
    1.89 +    TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
    1.90 +                                                        KRSAKeyPairGeneratorUid, 
    1.91 +                                                        keyParams));
    1.92 +    if(err != KErrNone)
    1.93 +        {
    1.94 +        ERR_PRINTF1(_L("*** FAIL: Failed to Create generator impl interface ***"));
    1.95 +        CleanupStack::PopAndDestroy(keyParams);
    1.96 +        return EFail;
    1.97 +        }                             
    1.98 +    CleanupStack::PushL(keypairImpl);
    1.99 +                    
   1.100 +    // Generate a Key Pair 
   1.101 +    INFO_PRINTF1(_L("Generating Key Pair..."));
   1.102 +    
   1.103 +    CKeyPair* keyPair = NULL;
   1.104 +    
   1.105 +    TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, 
   1.106 +                                        *keyParams, 
   1.107 +                                        keyPair));
   1.108 +    if(err != KErrNone)
   1.109 +        {
   1.110 +        ERR_PRINTF1(_L("*** FAIL: Failed to Create key pair ***"));
   1.111 +        CleanupStack::PopAndDestroy(keypairImpl);
   1.112 +        CleanupStack::PopAndDestroy(keyParams);
   1.113 +        return EFail;
   1.114 +        }                                    
   1.115 +    CleanupStack::PushL(keyPair);
   1.116 +
   1.117 +    // Creating Signer 1 with the necessary values from the ini	file
   1.118 +    INFO_PRINTF1(_L("Constructing Signer 1 (No Padding)..."));
   1.119 +    CSigner * impl = NULL;	
   1.120 +    TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl,
   1.121 +                                           KEccSignerUid,
   1.122 +                                           keyPair->PublicKey(),
   1.123 +                                           KPaddingModeNoneUid,
   1.124 +                                           keyParams));
   1.125 +    
   1.126 +    CleanupStack::PushL(impl);
   1.127 +    
   1.128 +    if(err == KErrNone)
   1.129 +        {
   1.130 +        // This is a basic test for load positivity
   1.131 +        // from the Factory
   1.132 +        INFO_PRINTF1(_L("PASS: Dummy ECC Signer - Positive Object Load"));
   1.133 +        SetTestStepResult(EPass);
   1.134 +        }
   1.135 +    else
   1.136 +        {
   1.137 +        ERR_PRINTF2(_L("FAIL: Signer Object Construction Failure - %d"), err);
   1.138 +        }
   1.139 +    
   1.140 +    CleanupStack::PopAndDestroy(impl);
   1.141 +    CleanupStack::PopAndDestroy(keyPair);
   1.142 +    CleanupStack::PopAndDestroy(keypairImpl);
   1.143 +    CleanupStack::PopAndDestroy(keyParams);
   1.144 +
   1.145 +    INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   1.146 +    return TestStepResult();
   1.147 +	}
   1.148 +
   1.149 +
   1.150 +
   1.151 +TVerdict CDummyEccSignerLoadStep::doTestStepPostambleL()
   1.152 +	{
   1.153 +	return TestStepResult();
   1.154 +	}