1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tcryptospi/src/te_cryptospiserver.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,346 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 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 file/test code to demonstrate how to develop a TestExecute Server
1.19 +* Developers should take this project as a template and substitute their own
1.20 +* for (WINS && !EKA2) versions will be xxxServer.Dll and require a thread to be started
1.21 +* in the process of the client. The client initialises the server by calling the
1.22 +* one and only ordinal.
1.23 +*
1.24 +*/
1.25 +
1.26 +
1.27 +/**
1.28 + @file
1.29 + @internalTechnology
1.30 +*/
1.31 +
1.32 +#include "te_cryptospiserver.h"
1.33 +
1.34 +#include "symmetriccipherpositiveobjectloadstep.h"
1.35 +#include "symmetriccipherencrypteddatacheckstep.h"
1.36 +#include "symmetriccipherencryptdecryptstep.h"
1.37 +#include "symmetriccipherincrementalencryptdecryptstep.h"
1.38 +#include "symmetriccipherobjectreusestep.h"
1.39 +#include "symmetriccipherprocessbeforeivsetstep.h"
1.40 +#include "symmetriccipherbadivlengthstep.h"
1.41 +#include "symmetriccipherctrmodeoutoforderstep.h"
1.42 +
1.43 +#include "asymmetriccipherpositiveobjectloadstep.h"
1.44 +#include "asymmetriccipherencrypteddatacheckstep.h"
1.45 +#include "asymmetriccipherencryptdecryptstep.h"
1.46 +
1.47 +#include "hashpositiveobjectloadstep.h"
1.48 +#include "hashbasichashofdatastep.h"
1.49 +#include "hashincrementalhashstep.h"
1.50 +#include "hashincrementalhashwithresetstep.h"
1.51 +#include "hashincrementalhashwithcopystep.h"
1.52 +#include "hashincrementalhashwithreplicatestep.h"
1.53 +
1.54 +#include "hmacpositiveobjectloadstep.h"
1.55 +#include "hmacbasichashofdatastep.h"
1.56 +#include "hmacincrementalhmacstep.h"
1.57 +#include "hmacincrementalhmacwithresetstep.h"
1.58 +#include "hmacincrementalhmacwithcopystep.h"
1.59 +#include "hmacincrementalhmacwithreplicatestep.h"
1.60 +#include "hmacsetkeycheckingstep.h"
1.61 +#include "hmacsetoperationmodecheckingstep.h"
1.62 +
1.63 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.64 +#include "hash_basic_data_step.h"
1.65 +#include "hash_incremental_step.h"
1.66 +#include "hash_incremental_with_copy_step.h"
1.67 +#include "hash_incremental_with_replicate_step.h"
1.68 +#include "hash_incremental_with_reset_step.h"
1.69 +#include "hash_positive_object_load_step.h"
1.70 +
1.71 +#include "mac_basic_data_step.h"
1.72 +#include "mac_incremental_with_copy_step.h"
1.73 +#include "mac_incremental_with_replicate_step.h"
1.74 +#include "mac_incremental_reset_step.h"
1.75 +#include "mac_incremental_step.h"
1.76 +#include "mac_positive_object_load_step.h"
1.77 +#include "symmetric_mac_basic_data_step.h"
1.78 +#include "symmetric_mac_incremental_with_replicate_step.h"
1.79 +#include "symmetric_mac_incremental_with_copy_step.h"
1.80 +#include "symmetric_mac_incremental_reset_step.h"
1.81 +#include "symmetric_mac_incremental_re_init_step.h"
1.82 +#include "symmetric_mac_incremental_step.h"
1.83 +
1.84 +#include "plugincharsmacstep.h"
1.85 +
1.86 +#include "plugin_chars_new_hash_step.h"
1.87 +#endif
1.88 +
1.89 +#include "randomnumbergeneratorgeneralusagestep.h"
1.90 +
1.91 +#include "keyexchangesyncstep.h"
1.92 +#include "keypairgeneratorpositiveobjectloadstep.h"
1.93 +#include "signerpositiveobjectloadstep.h"
1.94 +#include "verifierpositiveobjectloadstep.h"
1.95 +#include "signerverifierstep.h"
1.96 +
1.97 +#include "pluginloadstep.h"
1.98 +
1.99 +#include "plugincharscommonstep.h"
1.100 +#include "plugincharssymmetriccipherstep.h"
1.101 +#include "plugincharsasymmetriccipherstep.h"
1.102 +#include "plugincharshashstep.h"
1.103 +#include "plugincharsrandomstep.h"
1.104 +#include "plugincharsasymsignstep.h"
1.105 +#include "plugincharskeyagreestep.h"
1.106 +#include "plugincharsasymkeypairstep.h"
1.107 +#include "plugincharsextendedstep.h"
1.108 +
1.109 +#include "ruleselectcommonstep.h"
1.110 +
1.111 +#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
1.112 +#include "dummyecccipherloadstep.h"
1.113 +#include "dummyeccsignerloadstep.h"
1.114 +#endif
1.115 +//#include "pluginruleselectstep.h"
1.116 +
1.117 +_LIT(KServerName,"Te_CryptoSpi");
1.118 +CTe_CryptoSpi* CTe_CryptoSpi::NewL()
1.119 +/**
1.120 + * @return - Instance of the test server
1.121 + * Same code for Secure and non-secure variants
1.122 + * Called inside the MainL() function to create and start the
1.123 + * CTestServer derived server.
1.124 + */
1.125 + {
1.126 + CTe_CryptoSpi * server = new (ELeave) CTe_CryptoSpi();
1.127 + CleanupStack::PushL(server);
1.128 +
1.129 + server->ConstructL(KServerName);
1.130 + CleanupStack::Pop(server);
1.131 + return server;
1.132 + }
1.133 +
1.134 +
1.135 +// Secure variants much simpler
1.136 +// For EKA2, just an E32Main and a MainL()
1.137 +LOCAL_C void MainL()
1.138 +/**
1.139 + * Secure variant
1.140 + * Much simpler, uses the new Rendezvous() call to sync with the client
1.141 + */
1.142 + {
1.143 + // Leave the hooks in for platform security
1.144 +#if (defined __DATA_CAGING__)
1.145 + RProcess().DataCaging(RProcess::EDataCagingOn);
1.146 + RProcess().DataCaging(RProcess::ESecureApiOn);
1.147 +#endif
1.148 + CActiveScheduler* sched=NULL;
1.149 + sched=new(ELeave) CActiveScheduler;
1.150 + CActiveScheduler::Install(sched);
1.151 + CTe_CryptoSpi* server = NULL;
1.152 + // Create the CTestServer derived server
1.153 + TRAPD(err,server = CTe_CryptoSpi::NewL());
1.154 + if(!err)
1.155 + {
1.156 + // Sync with the client and enter the active scheduler
1.157 + RProcess::Rendezvous(KErrNone);
1.158 + sched->Start();
1.159 + }
1.160 + delete server;
1.161 + delete sched;
1.162 + }
1.163 +
1.164 +
1.165 +
1.166 +GLDEF_C TInt E32Main()
1.167 +/**
1.168 + * @return - Standard Epoc error code on process exit
1.169 + * Secure variant only
1.170 + * Process entry point. Called by client using RProcess API
1.171 + */
1.172 + {
1.173 + __UHEAP_MARK;
1.174 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.175 + if(cleanup == NULL)
1.176 + {
1.177 + return KErrNoMemory;
1.178 + }
1.179 + TRAPD(err,MainL());
1.180 + delete cleanup;
1.181 + __UHEAP_MARKEND;
1.182 + return err;
1.183 + }
1.184 +
1.185 +
1.186 +CTestStep* CTe_CryptoSpi::CreateTestStep(const TDesC& aStepName)
1.187 +/**
1.188 + * @return - A CTestStep derived instance
1.189 + * Secure and non-secure variants
1.190 + * Implementation of CTestServer pure virtual
1.191 + */
1.192 + {
1.193 + CTestStep* testStep = NULL;
1.194 +
1.195 + if(aStepName == KSymmetricCipherPositiveObjectLoadStep)
1.196 + testStep = new CSymmetricCipherPositiveObjectLoadStep();
1.197 + else if(aStepName == KSymmetricCipherEncryptDecryptStep)
1.198 + testStep = new CSymmetricCipherEncryptDecryptStep();
1.199 + else if(aStepName == KSymmetricCipherEncryptedDataCheckStep)
1.200 + testStep = new CSymmetricCipherEncryptedDataCheckStep();
1.201 + else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptStep)
1.202 + testStep = new CSymmetricCipherIncrementalEncryptDecryptStep();
1.203 + else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptMinus1ByteStep)
1.204 + testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(-1);
1.205 + else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptMinus3BytesStep)
1.206 + testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(-3);
1.207 + else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptPlus1ByteStep)
1.208 + testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(1);
1.209 + else if(aStepName == KSymmetricCipherIncrementalEncryptDecryptPlus3BytesStep)
1.210 + testStep = new CSymmetricCipherIncrementalEncryptDecryptStep(3);
1.211 + else if(aStepName == KSymmetricCipherObjectReuseStep)
1.212 + testStep = new CSymmetricCipherObjectReuseStep();
1.213 + else if(aStepName == KSymmetricCipherProcessBeforeIvSetStep)
1.214 + testStep = new CSymmetricCipherProcessBeforeIvSetStep();
1.215 + else if(aStepName == KSymmetricCipherBadIvLengthStep)
1.216 + testStep = new CSymmetricCipherBadIvLengthStep();
1.217 + else if(aStepName == KSymmetricCipherCtrModeOutOfOrderStep)
1.218 + testStep = new CSymmetricCipherCtrModeOutOfOrderStep();
1.219 +
1.220 + else if(aStepName == KASymmetricCipherPositiveObjectLoadStep)
1.221 + testStep = new CASymmetricCipherPositiveObjectLoadStep();
1.222 + else if(aStepName == KASymmetricCipherEncryptedDataCheckStep)
1.223 + testStep = new CASymmetricCipherEncryptedDataCheckStep();
1.224 + else if(aStepName == KASymmetricCipherEncryptDecryptStep)
1.225 + testStep = new CASymmetricCipherEncryptDecryptStep();
1.226 +
1.227 + else if(aStepName == KHashPositiveObjectLoadStep)
1.228 + testStep = new CHashPositiveObjectLoadStep();
1.229 + else if(aStepName == KHashBasicHashOfDataStep)
1.230 + testStep = new CHashBasicHashOfDataStep();
1.231 + else if(aStepName == KHashIncrementalHashStep)
1.232 + testStep = new CHashIncrementalHashStep();
1.233 + else if(aStepName == KHashIncrementalHashWithResetStep)
1.234 + testStep = new CHashIncrementalHashWithResetStep();
1.235 + else if(aStepName == KHashIncrementalHashWithCopyStep)
1.236 + testStep = new CHashIncrementalHashWithCopyStep();
1.237 + else if(aStepName == KHashIncrementalHashWithReplicateStep)
1.238 + testStep = new CHashIncrementalHashWithReplicateStep();
1.239 +
1.240 + else if(aStepName == KHmacPositiveObjectLoadStep)
1.241 + testStep = new CHmacPositiveObjectLoadStep();
1.242 + else if(aStepName == KHmacBasicHashOfDataStep)
1.243 + testStep = new CHmacBasicHashOfDataStep();
1.244 + else if(aStepName == KHmacIncrementalHmacStep)
1.245 + testStep = new CHmacIncrementalHmacStep();
1.246 + else if(aStepName == KHmacIncrementalHmacWithResetStep)
1.247 + testStep = new CHmacIncrementalHmacWithResetStep();
1.248 + else if(aStepName == KHmacIncrementalHmacWithCopyStep)
1.249 + testStep = new CHmacIncrementalHmacWithCopyStep();
1.250 + else if(aStepName == KHmacIncrementalHmacWithReplicateStep)
1.251 + testStep = new CHmacIncrementalHmacWithReplicateStep();
1.252 + else if(aStepName == KHmacSetKeyCheckingStep)
1.253 + testStep = new CHmacSetKeyCheckingStep();
1.254 + else if(aStepName == KHmacSetOperationModeCheckingStep)
1.255 + testStep = new CHmacSetOperationModeCheckingStep();
1.256 +
1.257 +#ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
1.258 + else if(aStepName == KHashPositiveLoadStep)
1.259 + testStep = new CHashPositiveLoadStep();
1.260 + else if(aStepName == KHashBasicDataStep)
1.261 + testStep = new CHashBasicDataStep();
1.262 + else if(aStepName == KHashIncrementalStep)
1.263 + testStep = new CHashIncrementalStep();
1.264 + else if(aStepName == KHashIncrementalWithCopyStep)
1.265 + testStep = new CHashIncrementalWithCopyStep();
1.266 + else if(aStepName == KHashIncrementalWithReplicateStep)
1.267 + testStep = new CHashIncrementalWithReplicateStep();
1.268 + else if(aStepName == KHashIncrementalWithResetStep)
1.269 + testStep = new CHashIncrementalWithResetStep();
1.270 +
1.271 + else if(aStepName == KMacPositiveObjectLoadStep)
1.272 + testStep = new CMacPositiveObjectLoadStep();
1.273 + else if(aStepName == KMacBasicDataStep)
1.274 + testStep = new CMacBasicDataStep();
1.275 + else if(aStepName == KMacIncrementalStep)
1.276 + testStep = new CMacIncrementalStep();
1.277 + else if(aStepName == KMacIncrementalWithCopyStep)
1.278 + testStep = new CMacIncrementalWithCopyStep();
1.279 + else if(aStepName == KMacIncrementalWithReplicateStep)
1.280 + testStep = new CMacIncrementalWithReplicateStep();
1.281 + else if(aStepName == KMacIncrementalResetStep)
1.282 + testStep = new CMacIncrementalResetStep();
1.283 + else if(aStepName == KSymmetricMacBasicDataStep)
1.284 + testStep = new CSymmetricMacBasicDataStep();
1.285 + else if(aStepName == KSymmetricMacIncrementalWithReplicateStep)
1.286 + testStep = new CSymmetricMacIncrementalWithReplicateStep();
1.287 + else if(aStepName == KSymmetricMacIncrementalWithCopyStep)
1.288 + testStep = new CSymmetricMacIncrementalWithCopyStep();
1.289 + else if(aStepName == KSymmetricMacIncrementalResetStep)
1.290 + testStep = new CSymmetricMacIncrementalResetStep();
1.291 + else if(aStepName == KSymmetricMacIncrementalReInitStep)
1.292 + testStep = new CSymmetricMacIncrementalReInitStep();
1.293 +
1.294 + else if(aStepName == KSymmetricMacIncrementalStep)
1.295 + testStep = new CSymmetricMacIncrementalStep();
1.296 +
1.297 + else if(aStepName == KPluginCharsMacStep)
1.298 + testStep = new CPluginCharsMacStep();
1.299 + else if(aStepName == KPluginCharsNewHashStep)
1.300 + testStep = new CPluginCharsNewHashStep();
1.301 +#endif
1.302 +
1.303 + else if(aStepName == KKeyExchangeSyncStep)
1.304 + testStep = new CKeyExchangeSyncStep();
1.305 + else if(aStepName == KKeyPairGeneratorPositiveObjectLoadStep)
1.306 + testStep = new CKeyPairGeneratorPositiveObjectLoadStep();
1.307 + else if(aStepName == KRandomNumberGeneratorGeneralUsageStep)
1.308 + testStep = new CRandomNumberGeneratorGeneralUsageStep();
1.309 + else if(aStepName == KSignerPositiveObjectLoadStep)
1.310 + testStep = new CSignerPositiveObjectLoadStep();
1.311 + else if(aStepName == KVerifierPositiveObjectLoadStep)
1.312 + testStep = new CVerifierPositiveObjectLoadStep();
1.313 + else if(aStepName == KSignerVerifierStep)
1.314 + testStep = new CSignerVerifierStep();
1.315 +
1.316 + else if(aStepName == KPluginLoadStep)
1.317 + testStep = new CPluginLoadStep();
1.318 +
1.319 + else if(aStepName == KPluginCharsCommonStep)
1.320 + testStep = new CPluginCharsCommonStep();
1.321 + else if(aStepName == KPluginCharsSymmetricCipherStep)
1.322 + testStep = new CPluginCharsSymmetricCipherStep();
1.323 + else if(aStepName == KPluginCharsAsymmetricCipherStep)
1.324 + testStep = new CPluginCharsAsymmetricCipherStep();
1.325 + else if(aStepName == KPluginCharsHashStep)
1.326 + testStep = new CPluginCharsHashStep();
1.327 + else if(aStepName == KPluginCharsRandomStep)
1.328 + testStep = new CPluginCharsRandomStep();
1.329 + else if(aStepName == KPluginCharsAsymSignStep)
1.330 + testStep = new CPluginCharsAsymSignStep();
1.331 + else if(aStepName == KPluginCharsKeyAgreeStep)
1.332 + testStep = new CPluginCharsKeyAgreeStep();
1.333 + else if(aStepName == KPluginCharsAsymKeyPairStep)
1.334 + testStep = new CPluginCharsAsymKeyPairStep();
1.335 + else if(aStepName == KPluginCharsExtendedStep)
1.336 + testStep = new CPluginCharsExtendedStep();
1.337 +
1.338 + else if(aStepName == KRuleSelectCommonStep)
1.339 + testStep = new CRuleSelectCommonStep();
1.340 +
1.341 +#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
1.342 + else if(aStepName == KDummyEccCipherLoadStep)
1.343 + testStep = new CDummyEccCipherLoadStep();
1.344 + else if(aStepName == KDummyEccSignerLoadStep)
1.345 + testStep = new CDummyEccSignerLoadStep();
1.346 +#endif
1.347 +
1.348 + return testStep;
1.349 + }