os/security/crypto/weakcryptospi/test/tcryptospi/src/te_cryptospiserver.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* Example file/test code to demonstrate how to develop a TestExecute Server
sl@0
    16
* Developers should take this project as a template and substitute their own
sl@0
    17
* for (WINS && !EKA2) versions will be xxxServer.Dll and require a thread to be started
sl@0
    18
* in the process of the client. The client initialises the server by calling the
sl@0
    19
* one and only ordinal.
sl@0
    20
*
sl@0
    21
*/
sl@0
    22
sl@0
    23
sl@0
    24
/**
sl@0
    25
 @file
sl@0
    26
 @internalTechnology
sl@0
    27
*/
sl@0
    28
sl@0
    29
#include "te_cryptospiserver.h"
sl@0
    30
sl@0
    31
#include "symmetriccipherpositiveobjectloadstep.h"
sl@0
    32
#include "symmetriccipherencrypteddatacheckstep.h"
sl@0
    33
#include "symmetriccipherencryptdecryptstep.h"
sl@0
    34
#include "symmetriccipherincrementalencryptdecryptstep.h"
sl@0
    35
#include "symmetriccipherobjectreusestep.h"
sl@0
    36
#include "symmetriccipherprocessbeforeivsetstep.h"
sl@0
    37
#include "symmetriccipherbadivlengthstep.h"
sl@0
    38
#include "symmetriccipherctrmodeoutoforderstep.h"
sl@0
    39
sl@0
    40
#include "asymmetriccipherpositiveobjectloadstep.h"
sl@0
    41
#include "asymmetriccipherencrypteddatacheckstep.h"
sl@0
    42
#include "asymmetriccipherencryptdecryptstep.h"
sl@0
    43
sl@0
    44
#include "hashpositiveobjectloadstep.h"
sl@0
    45
#include "hashbasichashofdatastep.h"
sl@0
    46
#include "hashincrementalhashstep.h"
sl@0
    47
#include "hashincrementalhashwithresetstep.h"
sl@0
    48
#include "hashincrementalhashwithcopystep.h"
sl@0
    49
#include "hashincrementalhashwithreplicatestep.h"
sl@0
    50
sl@0
    51
#include "hmacpositiveobjectloadstep.h"
sl@0
    52
#include "hmacbasichashofdatastep.h"
sl@0
    53
#include "hmacincrementalhmacstep.h"
sl@0
    54
#include "hmacincrementalhmacwithresetstep.h"
sl@0
    55
#include "hmacincrementalhmacwithcopystep.h"
sl@0
    56
#include "hmacincrementalhmacwithreplicatestep.h"
sl@0
    57
#include "hmacsetkeycheckingstep.h"
sl@0
    58
#include "hmacsetoperationmodecheckingstep.h"
sl@0
    59
sl@0
    60
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
sl@0
    61
#include "hash_basic_data_step.h"
sl@0
    62
#include "hash_incremental_step.h"
sl@0
    63
#include "hash_incremental_with_copy_step.h"
sl@0
    64
#include "hash_incremental_with_replicate_step.h"
sl@0
    65
#include "hash_incremental_with_reset_step.h"
sl@0
    66
#include "hash_positive_object_load_step.h"
sl@0
    67
sl@0
    68
#include "mac_basic_data_step.h"
sl@0
    69
#include "mac_incremental_with_copy_step.h"
sl@0
    70
#include "mac_incremental_with_replicate_step.h"
sl@0
    71
#include "mac_incremental_reset_step.h"
sl@0
    72
#include "mac_incremental_step.h"
sl@0
    73
#include "mac_positive_object_load_step.h"
sl@0
    74
#include "symmetric_mac_basic_data_step.h" 
sl@0
    75
#include "symmetric_mac_incremental_with_replicate_step.h"
sl@0
    76
#include "symmetric_mac_incremental_with_copy_step.h"
sl@0
    77
#include "symmetric_mac_incremental_reset_step.h"
sl@0
    78
#include "symmetric_mac_incremental_re_init_step.h"
sl@0
    79
#include "symmetric_mac_incremental_step.h"
sl@0
    80
sl@0
    81
#include "plugincharsmacstep.h"
sl@0
    82
sl@0
    83
#include "plugin_chars_new_hash_step.h"
sl@0
    84
#endif
sl@0
    85
sl@0
    86
#include "randomnumbergeneratorgeneralusagestep.h"
sl@0
    87
sl@0
    88
#include "keyexchangesyncstep.h"
sl@0
    89
#include "keypairgeneratorpositiveobjectloadstep.h"
sl@0
    90
#include "signerpositiveobjectloadstep.h"
sl@0
    91
#include "verifierpositiveobjectloadstep.h"
sl@0
    92
#include "signerverifierstep.h"
sl@0
    93
sl@0
    94
#include "pluginloadstep.h"
sl@0
    95
sl@0
    96
#include "plugincharscommonstep.h"
sl@0
    97
#include "plugincharssymmetriccipherstep.h"
sl@0
    98
#include "plugincharsasymmetriccipherstep.h"
sl@0
    99
#include "plugincharshashstep.h"
sl@0
   100
#include "plugincharsrandomstep.h"
sl@0
   101
#include "plugincharsasymsignstep.h"
sl@0
   102
#include "plugincharskeyagreestep.h"
sl@0
   103
#include "plugincharsasymkeypairstep.h"
sl@0
   104
#include "plugincharsextendedstep.h"
sl@0
   105
sl@0
   106
#include "ruleselectcommonstep.h"
sl@0
   107
sl@0
   108
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
sl@0
   109
#include "dummyecccipherloadstep.h"
sl@0
   110
#include "dummyeccsignerloadstep.h"
sl@0
   111
#endif
sl@0
   112
//#include "pluginruleselectstep.h"
sl@0
   113
sl@0
   114
_LIT(KServerName,"Te_CryptoSpi");
sl@0
   115
CTe_CryptoSpi* CTe_CryptoSpi::NewL()
sl@0
   116
/**
sl@0
   117
 * @return - Instance of the test server
sl@0
   118
 * Same code for Secure and non-secure variants
sl@0
   119
 * Called inside the MainL() function to create and start the
sl@0
   120
 * CTestServer derived server.
sl@0
   121
 */
sl@0
   122
	{
sl@0
   123
	CTe_CryptoSpi * server = new (ELeave) CTe_CryptoSpi();
sl@0
   124
	CleanupStack::PushL(server);
sl@0
   125
sl@0
   126
	server->ConstructL(KServerName);
sl@0
   127
	CleanupStack::Pop(server);
sl@0
   128
	return server;
sl@0
   129
	}
sl@0
   130
sl@0
   131
sl@0
   132
// Secure variants much simpler
sl@0
   133
// For EKA2, just an E32Main and a MainL()
sl@0
   134
LOCAL_C void MainL()
sl@0
   135
/**
sl@0
   136
 * Secure variant
sl@0
   137
 * Much simpler, uses the new Rendezvous() call to sync with the client
sl@0
   138
 */
sl@0
   139
	{
sl@0
   140
	// Leave the hooks in for platform security
sl@0
   141
#if (defined __DATA_CAGING__)
sl@0
   142
	RProcess().DataCaging(RProcess::EDataCagingOn);
sl@0
   143
	RProcess().DataCaging(RProcess::ESecureApiOn);
sl@0
   144
#endif
sl@0
   145
	CActiveScheduler* sched=NULL;
sl@0
   146
	sched=new(ELeave) CActiveScheduler;
sl@0
   147
	CActiveScheduler::Install(sched);
sl@0
   148
	CTe_CryptoSpi* server = NULL;
sl@0
   149
	// Create the CTestServer derived server
sl@0
   150
	TRAPD(err,server = CTe_CryptoSpi::NewL());
sl@0
   151
	if(!err)
sl@0
   152
		{
sl@0
   153
		// Sync with the client and enter the active scheduler
sl@0
   154
		RProcess::Rendezvous(KErrNone);
sl@0
   155
		sched->Start();
sl@0
   156
		}
sl@0
   157
	delete server;
sl@0
   158
	delete sched;
sl@0
   159
	}
sl@0
   160
sl@0
   161
sl@0
   162
sl@0
   163
GLDEF_C TInt E32Main()
sl@0
   164
/**
sl@0
   165
 * @return - Standard Epoc error code on process exit
sl@0
   166
 * Secure variant only
sl@0
   167
 * Process entry point. Called by client using RProcess API
sl@0
   168
 */
sl@0
   169
	{
sl@0
   170
	__UHEAP_MARK;
sl@0
   171
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   172
	if(cleanup == NULL)
sl@0
   173
		{
sl@0
   174
		return KErrNoMemory;
sl@0
   175
		}
sl@0
   176
	TRAPD(err,MainL());
sl@0
   177
	delete cleanup;
sl@0
   178
	__UHEAP_MARKEND;
sl@0
   179
	return err;
sl@0
   180
    }
sl@0
   181
sl@0
   182
sl@0
   183
CTestStep* CTe_CryptoSpi::CreateTestStep(const TDesC& aStepName)
sl@0
   184
/**
sl@0
   185
 * @return - A CTestStep derived instance
sl@0
   186
 * Secure and non-secure variants
sl@0
   187
 * Implementation of CTestServer pure virtual
sl@0
   188
 */
sl@0
   189
	{
sl@0
   190
	CTestStep* testStep = NULL;
sl@0
   191
	
sl@0
   192
	if(aStepName == KSymmetricCipherPositiveObjectLoadStep)
sl@0
   193
		testStep = new CSymmetricCipherPositiveObjectLoadStep();
sl@0
   194
	else if(aStepName == KSymmetricCipherEncryptDecryptStep)
sl@0
   195
		testStep = new CSymmetricCipherEncryptDecryptStep();
sl@0
   196
	else if(aStepName == KSymmetricCipherEncryptedDataCheckStep)
sl@0
   197
		testStep = new CSymmetricCipherEncryptedDataCheckStep();
sl@0
   198
	else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptStep)
sl@0
   199
		testStep = new CSymmetricCipherIncrementalEncryptDecryptStep();
sl@0
   200
	else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptMinus1ByteStep)
sl@0
   201
        testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(-1);
sl@0
   202
	else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptMinus3BytesStep)
sl@0
   203
        testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(-3);
sl@0
   204
	else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptPlus1ByteStep)
sl@0
   205
        testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(1);
sl@0
   206
	else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptPlus3BytesStep)
sl@0
   207
        testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(3);
sl@0
   208
	else if(aStepName == KSymmetricCipherObjectReuseStep)
sl@0
   209
        testStep = new CSymmetricCipherObjectReuseStep();
sl@0
   210
	else if(aStepName == KSymmetricCipherProcessBeforeIvSetStep)
sl@0
   211
		testStep = new CSymmetricCipherProcessBeforeIvSetStep();
sl@0
   212
	else if(aStepName == KSymmetricCipherBadIvLengthStep)
sl@0
   213
		testStep = new CSymmetricCipherBadIvLengthStep();
sl@0
   214
	else if(aStepName == KSymmetricCipherCtrModeOutOfOrderStep)
sl@0
   215
		testStep = new CSymmetricCipherCtrModeOutOfOrderStep();
sl@0
   216
	
sl@0
   217
	else if(aStepName == KASymmetricCipherPositiveObjectLoadStep)
sl@0
   218
		testStep = new CASymmetricCipherPositiveObjectLoadStep();
sl@0
   219
	else if(aStepName == KASymmetricCipherEncryptedDataCheckStep)
sl@0
   220
		testStep = new CASymmetricCipherEncryptedDataCheckStep();
sl@0
   221
	else if(aStepName == KASymmetricCipherEncryptDecryptStep)
sl@0
   222
		testStep = new CASymmetricCipherEncryptDecryptStep();
sl@0
   223
	
sl@0
   224
	else if(aStepName == KHashPositiveObjectLoadStep)
sl@0
   225
		testStep = new CHashPositiveObjectLoadStep();
sl@0
   226
	else if(aStepName == KHashBasicHashOfDataStep)
sl@0
   227
		testStep = new CHashBasicHashOfDataStep();
sl@0
   228
	else if(aStepName == KHashIncrementalHashStep)
sl@0
   229
		testStep = new CHashIncrementalHashStep();
sl@0
   230
	else if(aStepName == KHashIncrementalHashWithResetStep)
sl@0
   231
		testStep = new CHashIncrementalHashWithResetStep();
sl@0
   232
	else if(aStepName == KHashIncrementalHashWithCopyStep)
sl@0
   233
		testStep = new CHashIncrementalHashWithCopyStep();
sl@0
   234
	else if(aStepName == KHashIncrementalHashWithReplicateStep)
sl@0
   235
		testStep = new CHashIncrementalHashWithReplicateStep();	
sl@0
   236
	
sl@0
   237
	else if(aStepName == KHmacPositiveObjectLoadStep)
sl@0
   238
		testStep = new CHmacPositiveObjectLoadStep();
sl@0
   239
	else if(aStepName == KHmacBasicHashOfDataStep)
sl@0
   240
		testStep = new CHmacBasicHashOfDataStep();
sl@0
   241
	else if(aStepName == KHmacIncrementalHmacStep)
sl@0
   242
		testStep = new CHmacIncrementalHmacStep();
sl@0
   243
	else if(aStepName == KHmacIncrementalHmacWithResetStep)
sl@0
   244
		testStep = new CHmacIncrementalHmacWithResetStep();
sl@0
   245
	else if(aStepName == KHmacIncrementalHmacWithCopyStep)
sl@0
   246
		testStep = new CHmacIncrementalHmacWithCopyStep();
sl@0
   247
	else if(aStepName == KHmacIncrementalHmacWithReplicateStep)
sl@0
   248
		testStep = new CHmacIncrementalHmacWithReplicateStep();
sl@0
   249
	else if(aStepName == KHmacSetKeyCheckingStep)
sl@0
   250
		testStep = new CHmacSetKeyCheckingStep();
sl@0
   251
	else if(aStepName == KHmacSetOperationModeCheckingStep)
sl@0
   252
		testStep = new CHmacSetOperationModeCheckingStep(); 	
sl@0
   253
	
sl@0
   254
#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
sl@0
   255
	else if(aStepName == KHashPositiveLoadStep)
sl@0
   256
		testStep = new CHashPositiveLoadStep();
sl@0
   257
	else if(aStepName == KHashBasicDataStep)
sl@0
   258
		testStep = new CHashBasicDataStep();
sl@0
   259
	else if(aStepName == KHashIncrementalStep)
sl@0
   260
		testStep = new CHashIncrementalStep();
sl@0
   261
	else if(aStepName == KHashIncrementalWithCopyStep)
sl@0
   262
		testStep = new CHashIncrementalWithCopyStep();
sl@0
   263
	else if(aStepName == KHashIncrementalWithReplicateStep)
sl@0
   264
		testStep = new CHashIncrementalWithReplicateStep();	
sl@0
   265
	else if(aStepName == KHashIncrementalWithResetStep)
sl@0
   266
		testStep = new CHashIncrementalWithResetStep();
sl@0
   267
	
sl@0
   268
	else if(aStepName == KMacPositiveObjectLoadStep)
sl@0
   269
		testStep = new CMacPositiveObjectLoadStep();
sl@0
   270
	else if(aStepName == KMacBasicDataStep)
sl@0
   271
		testStep = new CMacBasicDataStep();
sl@0
   272
	else if(aStepName == KMacIncrementalStep)
sl@0
   273
		testStep = new CMacIncrementalStep();
sl@0
   274
	else if(aStepName == KMacIncrementalWithCopyStep)
sl@0
   275
		testStep = new CMacIncrementalWithCopyStep();
sl@0
   276
	else if(aStepName == KMacIncrementalWithReplicateStep)
sl@0
   277
		testStep = new CMacIncrementalWithReplicateStep();
sl@0
   278
	else if(aStepName == KMacIncrementalResetStep)
sl@0
   279
		testStep = new CMacIncrementalResetStep();
sl@0
   280
	else if(aStepName == KSymmetricMacBasicDataStep)
sl@0
   281
			testStep = new CSymmetricMacBasicDataStep();
sl@0
   282
	else if(aStepName == KSymmetricMacIncrementalWithReplicateStep)
sl@0
   283
			testStep = new CSymmetricMacIncrementalWithReplicateStep();
sl@0
   284
	else if(aStepName == KSymmetricMacIncrementalWithCopyStep)
sl@0
   285
			testStep = new CSymmetricMacIncrementalWithCopyStep();
sl@0
   286
	else if(aStepName == KSymmetricMacIncrementalResetStep)
sl@0
   287
			testStep = new CSymmetricMacIncrementalResetStep();
sl@0
   288
	else if(aStepName == KSymmetricMacIncrementalReInitStep)
sl@0
   289
				testStep = new CSymmetricMacIncrementalReInitStep();
sl@0
   290
sl@0
   291
	else if(aStepName == KSymmetricMacIncrementalStep)
sl@0
   292
			testStep = new CSymmetricMacIncrementalStep();
sl@0
   293
sl@0
   294
	else if(aStepName == KPluginCharsMacStep)
sl@0
   295
			testStep = new CPluginCharsMacStep();
sl@0
   296
	else if(aStepName == KPluginCharsNewHashStep)
sl@0
   297
		testStep = new CPluginCharsNewHashStep();
sl@0
   298
#endif
sl@0
   299
	
sl@0
   300
	else if(aStepName == KKeyExchangeSyncStep)
sl@0
   301
		testStep = new CKeyExchangeSyncStep();
sl@0
   302
	else if(aStepName == KKeyPairGeneratorPositiveObjectLoadStep)
sl@0
   303
		testStep = new CKeyPairGeneratorPositiveObjectLoadStep();
sl@0
   304
	else if(aStepName == KRandomNumberGeneratorGeneralUsageStep)
sl@0
   305
		testStep = new CRandomNumberGeneratorGeneralUsageStep();
sl@0
   306
	else if(aStepName == KSignerPositiveObjectLoadStep)
sl@0
   307
		testStep = new CSignerPositiveObjectLoadStep();
sl@0
   308
	else if(aStepName == KVerifierPositiveObjectLoadStep)
sl@0
   309
		testStep = new CVerifierPositiveObjectLoadStep();
sl@0
   310
	else if(aStepName == KSignerVerifierStep)
sl@0
   311
		testStep = new CSignerVerifierStep();
sl@0
   312
	
sl@0
   313
	else if(aStepName == KPluginLoadStep)
sl@0
   314
		testStep = new CPluginLoadStep();
sl@0
   315
	
sl@0
   316
	else if(aStepName == KPluginCharsCommonStep)
sl@0
   317
		testStep = new CPluginCharsCommonStep();
sl@0
   318
	else if(aStepName == KPluginCharsSymmetricCipherStep)
sl@0
   319
		testStep = new CPluginCharsSymmetricCipherStep();
sl@0
   320
	else if(aStepName == KPluginCharsAsymmetricCipherStep)
sl@0
   321
		testStep = new CPluginCharsAsymmetricCipherStep();
sl@0
   322
	else if(aStepName == KPluginCharsHashStep)
sl@0
   323
		testStep = new CPluginCharsHashStep();
sl@0
   324
	else if(aStepName == KPluginCharsRandomStep)
sl@0
   325
		testStep = new CPluginCharsRandomStep();
sl@0
   326
	else if(aStepName == KPluginCharsAsymSignStep)
sl@0
   327
		testStep = new CPluginCharsAsymSignStep();
sl@0
   328
	else if(aStepName == KPluginCharsKeyAgreeStep)
sl@0
   329
		testStep = new CPluginCharsKeyAgreeStep();
sl@0
   330
	else if(aStepName == KPluginCharsAsymKeyPairStep)
sl@0
   331
		testStep = new CPluginCharsAsymKeyPairStep();
sl@0
   332
	else if(aStepName == KPluginCharsExtendedStep)
sl@0
   333
		testStep = new CPluginCharsExtendedStep();
sl@0
   334
	
sl@0
   335
	else if(aStepName == KRuleSelectCommonStep)
sl@0
   336
		testStep = new CRuleSelectCommonStep();		
sl@0
   337
sl@0
   338
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
sl@0
   339
    else if(aStepName == KDummyEccCipherLoadStep)
sl@0
   340
        testStep = new CDummyEccCipherLoadStep();
sl@0
   341
	else if(aStepName == KDummyEccSignerLoadStep)
sl@0
   342
	        testStep = new CDummyEccSignerLoadStep();
sl@0
   343
#endif
sl@0
   344
	
sl@0
   345
	return testStep;
sl@0
   346
	}