os/security/crypto/weakcryptospi/test/tcryptospi/src/signerpositiveobjectloadstep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 "signerpositiveobjectloadstep.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 CSignerPositiveObjectLoadStep::~CSignerPositiveObjectLoadStep()
    34 	{
    35 	}
    36 
    37 CSignerPositiveObjectLoadStep::CSignerPositiveObjectLoadStep()
    38 	{
    39 	SetTestStepName(KSignerPositiveObjectLoadStep);
    40 	}
    41 
    42 TVerdict CSignerPositiveObjectLoadStep::doTestStepPreambleL()
    43 	{
    44 	SetTestStepResult(EPass);
    45 	return TestStepResult();
    46 	}
    47 
    48 
    49 TVerdict CSignerPositiveObjectLoadStep::doTestStepL()
    50 	{
    51 	INFO_PRINTF1(_L("*** Signer - Positive Object Load ***"));
    52 	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
    53 	
    54   	if (TestStepResult()==EPass)
    55 		{
    56 		//Assume faliure, unless all is successful
    57 		SetTestStepResult(EFail);
    58 		
    59 		TVariantPtrC testVariant;
    60 		TVariantPtrC keyVariant;
    61 
    62 		if(	!GetStringFromConfig(ConfigSection(),KConfigExchangeKey, keyVariant))
    63 			{
    64 			// Leave if there's any error.
    65 			User::Leave(KErrNotFound);
    66 			}
    67 		else
    68 			{
    69 			//Create an new CryptoParams object to encapsulate the key type and secret key string
    70 			CCryptoParams* keyParams = CCryptoParams::NewL();
    71 			CleanupStack::PushL(keyParams);
    72 
    73 			//Set the Key Parameters
    74 			keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
    75 			keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
    76 			
    77 			// Create a Key Pair Generator implementation
    78 			INFO_PRINTF1(_L("Creating Key Pair Generator...")); 
    79 			
    80 			CKeyPairGenerator * keypairImpl = NULL;
    81 
    82 			TRAPD_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl, 
    83 																KRSAKeyPairGeneratorUid, 
    84 																keyParams));
    85 																
    86 			CleanupStack::PushL(keypairImpl);
    87 							
    88 							
    89 			// Generate a Key Pair 
    90 			INFO_PRINTF1(_L("Generating Key Pair..."));
    91 			
    92 			CKeyPair* keyPair = NULL;
    93 			
    94 			TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, 
    95 												*keyParams, 
    96 												keyPair));
    97 												
    98 			CleanupStack::PushL(keyPair);
    99 
   100 			// Creating Signer 1 with the necessary values from the ini	file
   101 			INFO_PRINTF1(_L("Constructing Signer 1 (No Padding)..."));
   102 			CSigner * impl1 = NULL;	
   103 		    TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl1,
   104 												   KRsaSignerUid,
   105 												   keyPair->PublicKey(),
   106 												   KPaddingModeNoneUid,
   107 												   keyParams));
   108 			
   109 			CleanupStack::PushL(impl1);
   110 			
   111 			// Creating Signer 2 with the necessary values from the ini	file
   112 			INFO_PRINTF1(_L("Constructing Signer 2 (Pkcs1_v1_5 Padding)..."));
   113 			CSigner * impl2 = NULL;	
   114 		    TRAP_LOG(err,CSignatureFactory::CreateSignerL(impl2,
   115 												   KRsaSignerUid,
   116 												   keyPair->PublicKey(),
   117 												   KPaddingModePkcs1_v1_5_SignatureUid,
   118 												   keyParams));
   119 			
   120 			CleanupStack::PushL(impl2);
   121 
   122 			if((impl1) && (impl2) && (err == KErrNone))
   123 				{
   124 				// This is a basic test for load positivity
   125 				// from the Factory
   126 				INFO_PRINTF1(_L("PASS: Signer - Positive Object Load"));
   127 				SetTestStepResult(EPass);
   128 				}
   129 			else
   130 				{
   131 				ERR_PRINTF2(_L("FAIL: Signer Object Construction Failure - %d"), err);
   132 				SetTestStepResult(EFail);
   133 				}
   134 
   135 			CleanupStack::PopAndDestroy(impl2);	
   136 			CleanupStack::PopAndDestroy(impl1);
   137 			
   138 			CleanupStack::PopAndDestroy(keyPair);
   139 			CleanupStack::PopAndDestroy(keypairImpl);
   140 			CleanupStack::PopAndDestroy(keyParams);
   141 			}
   142 
   143 		INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
   144 		
   145 		}
   146 	  return TestStepResult();
   147 	}
   148 
   149 
   150 
   151 TVerdict CSignerPositiveObjectLoadStep::doTestStepPostambleL()
   152 	{
   153 	return TestStepResult();
   154 	}