os/security/crypto/weakcryptospi/test/tcryptospi/src/dummyeccsignerloadstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009-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 * Example CTestStep derived implementation
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22  @internalTechnology
    23 */
    24 #include "dummyeccsignerloadstep.h"
    25 
    26 #include <cryptospi/keypair.h>
    27 #include <cryptospi/cryptosignatureapi.h>
    28 #include <cryptospi/cryptokeypairgeneratorapi.h>
    29 
    30 using namespace CryptoSpi;
    31 
    32 
    33 CDummyEccSignerLoadStep::~CDummyEccSignerLoadStep()
    34 	{
    35 	}
    36 
    37 CDummyEccSignerLoadStep::CDummyEccSignerLoadStep()
    38 	{
    39 	SetTestStepName(KDummyEccSignerLoadStep);
    40 	}
    41 
    42 TVerdict CDummyEccSignerLoadStep::doTestStepPreambleL()
    43 	{
    44 	SetTestStepResult(EPass);
    45 	return TestStepResult();
    46 	}
    47 
    48 
    49 TVerdict CDummyEccSignerLoadStep::doTestStepL()
    50 	{
    51 	INFO_PRINTF1(_L("*** Dummy Ecc Signer - Load ***"));
    52 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    53 	
    54     //Assume failure, unless all is successful
    55     SetTestStepResult(EFail);
    56     
    57     TVariantPtrC testVariant;
    58     TVariantPtrC keyVariant;
    59 
    60     if(	!GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
    61         {
    62         // Leave if there's any error.
    63         ERR_PRINTF1(_L("*** FAIL: Problem in configuration file ***"));
    64         User::Leave(KErrNotFound);
    65         }
    66     //Create an new CryptoParams object to encapsulate the key type and secret key string
    67     CCryptoParams* keyParams = CCryptoParams::NewLC();
    68 
    69     /**
    70      * Note that we are actually generating RSA keys in place 
    71      * of ECC keys here. The reason for that is we do not have 
    72      * a working ECC implementation. This test case just tests 
    73      * if dummyecc signer is getting loaded. This is getting  
    74      * tested since KEccSignerUid is being passed as input to  
    75      * CreateSignerL. Keys have no significance in this test 
    76      * case.
    77      */
    78     //Set the Key Parameters
    79     keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
    80     keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
    81     
    82     // Create a Key Pair Generator implementation
    83     INFO_PRINTF1(_L("Creating Key Pair Generator...")); 
    84     
    85     CKeyPairGenerator * keypairImpl = NULL;
    86     TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
    87                                                         KRSAKeyPairGeneratorUid, 
    88                                                         keyParams));
    89     if(err != KErrNone)
    90         {
    91         ERR_PRINTF1(_L("*** FAIL: Failed to Create generator impl interface ***"));
    92         CleanupStack::PopAndDestroy(keyParams);
    93         return EFail;
    94         }                             
    95     CleanupStack::PushL(keypairImpl);
    96                     
    97     // Generate a Key Pair 
    98     INFO_PRINTF1(_L("Generating Key Pair..."));
    99     
   100     CKeyPair* keyPair = NULL;
   101     
   102     TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, 
   103                                         *keyParams, 
   104                                         keyPair));
   105     if(err != KErrNone)
   106         {
   107         ERR_PRINTF1(_L("*** FAIL: Failed to Create key pair ***"));
   108         CleanupStack::PopAndDestroy(keypairImpl);
   109         CleanupStack::PopAndDestroy(keyParams);
   110         return EFail;
   111         }                                    
   112     CleanupStack::PushL(keyPair);
   113 
   114     // Creating Signer 1 with the necessary values from the ini	file
   115     INFO_PRINTF1(_L("Constructing Signer 1 (No Padding)..."));
   116     CSigner * impl = NULL;	
   117     TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl,
   118                                            KEccSignerUid,
   119                                            keyPair->PublicKey(),
   120                                            KPaddingModeNoneUid,
   121                                            keyParams));
   122     
   123     CleanupStack::PushL(impl);
   124     
   125     if(err == KErrNone)
   126         {
   127         // This is a basic test for load positivity
   128         // from the Factory
   129         INFO_PRINTF1(_L("PASS: Dummy ECC Signer - Positive Object Load"));
   130         SetTestStepResult(EPass);
   131         }
   132     else
   133         {
   134         ERR_PRINTF2(_L("FAIL: Signer Object Construction Failure - %d"), err);
   135         }
   136     
   137     CleanupStack::PopAndDestroy(impl);
   138     CleanupStack::PopAndDestroy(keyPair);
   139     CleanupStack::PopAndDestroy(keypairImpl);
   140     CleanupStack::PopAndDestroy(keyParams);
   141 
   142     INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   143     return TestStepResult();
   144 	}
   145 
   146 
   147 
   148 TVerdict CDummyEccSignerLoadStep::doTestStepPostambleL()
   149 	{
   150 	return TestStepResult();
   151 	}