Update contrib.
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include "ruleselectcommonstep.h"
24 #include "plugincharschecker.h"
25 #include <cryptospi/cryptosymmetriccipherapi.h>
26 #include <cryptospi/cryptoasymmetriccipherapi.h>
27 #include <cryptospi/cryptohashapi.h>
28 #include <cryptospi/cryptorandomapi.h>
29 #include <cryptospi/cryptosignatureapi.h>
30 #include <cryptospi/cryptokeyagreementapi.h>
31 #include <cryptospi/cryptokeypairgeneratorapi.h>
32 #include <cryptospi/keypair.h>
33 #include <cryptospi/keys.h>
35 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
36 #include <cryptospi/cryptomacapi.h>
39 #include <cryptospi/cryptospistateapi.h>
40 #include <cryptospi/ruleselector.h>
42 using namespace CryptoSpi;
44 CRuleSelectCommonStep::~CRuleSelectCommonStep()
48 CRuleSelectCommonStep::CRuleSelectCommonStep()
50 SetTestStepName(KRuleSelectCommonStep);
53 TVerdict CRuleSelectCommonStep::doTestStepPreambleL()
55 SetTestStepResult(EPass);
56 return TestStepResult();
59 TVerdict CRuleSelectCommonStep::doTestStepL()
62 INFO_PRINTF1(_L("Rule Selection - Common Characteristics Selection"));
63 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
65 if (TestStepResult()==EPass)
70 //Create Default Selection Rules Object
71 CSelectionRules* rules = CSelectionRules::NewL();
72 CleanupStack::PushL(rules);
74 //*************SELECTION RULE CREATION AND ADDITION**************
76 //Boolean to determine whether there are more rules to apply
80 //Itterator representing the current rule. Appended to the end of each selection
85 //Total number of selection rules added to the CSelectionRules object
89 TVariantPtrC interfaceScope;
90 TVariantPtrC algorithmScope;
92 TVariantPtrC compareOperator;
93 TVariantPtrC charValue;
94 TVariantPtrC charValueType;
98 //Whilst there are selection rules present in the INI file that have yet to be
99 //added to the CSelectionRules object
102 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
104 //Constructs each of the parameter names required to extract the necessary
105 //selection rule data from the specified INI configuration file
106 TBuf<KMaxConfigParamStringSize> interfaceScopeStr(KConfigInterfaceScopeBase);
107 interfaceScopeStr.AppendNum(currentRule);
108 INFO_PRINTF2(_L("interfaceScopeStr = %S"), &interfaceScopeStr);
110 TBuf<KMaxConfigParamStringSize> algorithmScopeStr(KConfigAlgorithmScopeBase);
111 algorithmScopeStr.AppendNum(currentRule);
112 INFO_PRINTF2(_L("algorithmScopeStr = %S"), &algorithmScopeStr);
114 TBuf<KMaxConfigParamStringSize> charUidStr(KConfigCharUidBase);
115 charUidStr.AppendNum(currentRule);
116 INFO_PRINTF2(_L("charUidStr = %S"), &charUidStr);
118 TBuf<KMaxConfigParamStringSize> compareOperatorStr(KConfigCompareOperatorBase);
119 compareOperatorStr.AppendNum(currentRule);
120 INFO_PRINTF2(_L("compareOperatorStr = %S"), &compareOperatorStr);
122 TBuf<KMaxConfigParamStringSize> charValueStr(KConfigCharValueBase);
123 charValueStr.AppendNum(currentRule);
124 INFO_PRINTF2(_L("charValueStr = %S"), &charValueStr);
126 TBuf<KMaxConfigParamStringSize> charValueTypeStr(KConfigCharValueTypeBase);
127 charValueTypeStr.AppendNum(currentRule);
128 INFO_PRINTF2(_L("charValueTypeStr = %S"), &charValueTypeStr);
130 TBuf<KMaxConfigParamStringSize> isOptionalStr(KConfigIsOptionalBase);
131 isOptionalStr.AppendNum(currentRule);
132 INFO_PRINTF2(_L("isOptionalStr = %S"), &isOptionalStr);
135 //Extracts the parameter data for a single rule from the specified INI file
136 if(!GetStringFromConfig(ConfigSection(),interfaceScopeStr,interfaceScope) ||
137 !GetStringFromConfig(ConfigSection(),algorithmScopeStr,algorithmScope) ||
138 !GetStringFromConfig(ConfigSection(),charUidStr,charUid) ||
139 !GetStringFromConfig(ConfigSection(),compareOperatorStr,compareOperator) ||
140 !GetStringFromConfig(ConfigSection(),charValueTypeStr,charValueType) ||
141 !GetBoolFromConfig(ConfigSection(),isOptionalStr,isOptional))
148 //Creates a pointer to store the address of the newly created selection rule
149 CSelectionRuleContent* rule = NULL;
151 //Creates a pointer to store the contents of the rule value parameter, so that
152 //it can be passed in at construction of the selection rule.
153 CCryptoParam* ruleValueParam = NULL;
155 //Depending on the 'RuleValueType' parameter read in from the INI file, the 'RuleValue'
156 //parameter will either be read in as an Integer,String or a Boolean.
157 switch(charValueType)
159 case ERuleValueInteger:
163 if(!GetIntFromConfig(ConfigSection(),charValueStr,charValue))
165 //Should the integer value be represented by a constant..
166 TVariantPtrC strCharValue;
168 if(!GetStringFromConfig(ConfigSection(),charValueStr,strCharValue))
170 ERR_PRINTF1(_L("** .INI Error: INTEGER Rule Value Not Initialised Correctly **"));
171 SetTestStepResult(EFail);
175 ruleValueParam = CCryptoIntParam::NewL(TInt(strCharValue),TUid(charUid));
180 //The Integer Rule Value is encapsulated as a CCryptoIntParam object so that it can be passed in as
181 //a parameter when constructing the selection rule
182 ruleValueParam = CCryptoIntParam::NewL(charValue,charUid);
192 if(!GetStringFromConfig(ConfigSection(),charValueStr,charValue))
194 ERR_PRINTF1(_L("** .INI Error: STRING Rule Value Not Initialised Correctly **"));
195 SetTestStepResult(EFail);
199 //Convert encryption key to an 8 Bit Descriptor
200 HBufC8* charStr = HBufC8::NewLC(charValue.Length());
201 TPtr8 charStrPtr = charStr->Des();
203 charStrPtr.Copy(charValue);
205 //The String Rule Value is encapsulated as a CCryptoDesC8Param object so that it can be passed in as
206 //a parameter when constructing the selection rule
207 ruleValueParam = CCryptoDesC8Param::NewL(charStrPtr,charUid);
209 CleanupStack::PopAndDestroy(charStr);
215 case ERuleValueDes16:
219 if(!GetStringFromConfig(ConfigSection(),charValueStr,charValue))
221 ERR_PRINTF1(_L("** .INI Error: STRING Rule Value Not Initialised Correctly **"));
222 SetTestStepResult(EFail);
226 //The String Rule Value is encapsulated as a CCryptoDesC8Param object so that it can be passed in as
227 //a parameter when constructing the selection rule
228 ruleValueParam = CCryptoDesC16Param::NewL(charValue,charUid);
234 case ERuleValueBoolean:
238 if(!GetBoolFromConfig(ConfigSection(),charValueStr,charValue))
240 ERR_PRINTF1(_L("** .INI Error: BOOLEAN Rule Value Not Initialised Correctly **"));
241 SetTestStepResult(EFail);
245 //The Boolean Rule Value is encapsulated as a CCryptoInt8Param object so that it can be passed in as
246 //a parameter when constructing the selection rule
247 ruleValueParam = CCryptoIntParam::NewL(charValue,charUid);
255 ERR_PRINTF1(_L("** .INI Error: Rule Value Type Unknown **"));
256 SetTestStepResult(EFail);
262 if(TestStepResult() == EPass)
265 //Creates the CSelectionRuleContent object, passing in all the parameters read in
266 //from the specified INI configuration file
268 TRAP_LOG(err, rule = CSelectionRuleContent::NewL(interfaceScope,
271 TRuleOperator((TInt)compareOperator),
275 //Add the newly created selection rule to the CSelectionRules collection by
276 //calling the 'AddSelectionRule' method and passing in the address of the rule
277 TRAP_LOG(err,rules->AddSelectionRuleL(rule));
281 INFO_PRINTF2(_L("Rule %d Created, Added and Destoryed"), currentRule);
288 ERR_PRINTF2(_L("RULE FAILURE: Failed to Add Selection Rule %d "), currentRule);
290 SetTestStepResult(EFail);
295 ERR_PRINTF2(_L("RULE FAILURE: Failed to Create Selection Rule %d "), currentRule);
297 SetTestStepResult(EFail);
309 //If 1 or more selection rule objects were added successfully without error, the test step
310 //can proceed to the next phase
311 if((TestStepResult() == EPass) && (totalRules > 0))
313 INFO_PRINTF2(_L("Successfully Added Selection Rules: %d"), totalRules);
315 else if((TestStepResult() == EFail) && (totalRules > 0))
317 ERR_PRINTF1(_L("** .INI Error: Errornous Selection Rule Data **"));
318 SetTestStepResult(EFail);
322 ERR_PRINTF1(_L("** NO VALID SELECTION RULE DATA FOUND **"));
325 //**************************************************************
327 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
329 if(TestStepResult()==EPass)
332 //Assume faliure, unless all is successful
333 SetTestStepResult(EFail);
335 //Create Rule Selector Object
336 CRuleSelector* ruleSelector = CRuleSelector::NewL(rules);
337 CleanupStack::Pop(rules);
338 CleanupStack::PushL(ruleSelector);
340 //Set the Selector Passing in a pointer to the Rule Selector and SPI State
341 CCryptoSpiStateApi::SetSelector(ruleSelector);
343 //Define a pointer of type CCryptoBase to store the address ofthe instantiated encryption object
344 CCryptoBase* plugin = NULL;
346 TVariantPtrC interfaceType;
348 //Extract the Encryption Type parameter from the specified INI file
349 if(!GetStringFromConfig(ConfigSection(),KConfigInterfaceType,interfaceType))
351 ERR_PRINTF1(_L("** .INI Error: Encryption Type Data Not Located **"));
352 SetTestStepResult(EFail);
356 //Depending on the Interface Type retrieved, the appropriate factory object
357 //is created and assigned to the previously CCryptoBase plugin pointer
358 switch(interfaceType)
360 case KAsymmetricCipherInterface:
364 TVariantPtrC keyType;
365 TVariantPtrC algorithmUid;
366 TVariantPtrC cryptoMode;
367 TVariantPtrC paddingMode;
368 TVariantPtrC algorithmParams;
370 //Each of the individual parameters required to create the Asymmetric Cipher object
371 //are read in from the specified INI configuration file
372 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
373 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
374 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
375 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
377 ERR_PRINTF1(_L("** .INI Error: Asymmetric Cipher Arguments Not Located **"));
378 SetTestStepResult(EFail);
383 //********** Rule Selector Unselcted to Create Key Pair ************
384 CCryptoSpiStateApi::UnsetSelector();
386 CCryptoParams* keyParams = CCryptoParams::NewLC();
388 //Create Key Pair and Key Pair Generator Objects
389 CKeyPair* keyPair = NULL;
390 CKeyPairGenerator * keypairImpl = NULL;
392 INFO_PRINTF1(_L("Generating RSA keys"));
394 // create an RSA key pair
395 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
396 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
398 // create a key pair generator implementation interface
399 TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(
401 KRSAKeyPairGeneratorUid,
404 CleanupStack::PushL(keypairImpl);
407 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
409 CleanupStack::PushL(keyPair);
411 CCryptoSpiStateApi::SetSelector(ruleSelector);
412 //******************************************************************
414 CAsymmetricCipher* asymmetricCipherImpl;
416 TRAP_LOG(err,CAsymmetricCipherFactory::CreateAsymmetricCipherL(asymmetricCipherImpl,
418 keyPair->PublicKey(),
423 if(asymmetricCipherImpl && (err == KErrNone))
425 plugin = static_cast<CCryptoBase*>(asymmetricCipherImpl);
427 INFO_PRINTF1(_L("** Successfully Loaded Asymmetric Cipher Object **"));
428 SetTestStepResult(EPass);
432 ERR_PRINTF2(_L("** Error: Loading Asymmetric Cipher Object - %d **"), err);
433 SetTestStepResult(EFail);
436 CleanupStack::PopAndDestroy(3,keyParams);
442 case KSymmetricCipherInterface:
446 TVariantPtrC keyType;
447 TVariantPtrC algorithmUid;
448 TVariantPtrC cryptoMode;
449 TVariantPtrC operationMode;
450 TVariantPtrC paddingMode;
451 TVariantPtrC algorithmParams;
453 //Each of the individual parameters required to create the Symmetric Cipher object
454 //are read in from the specified INI configuration file
455 if(!GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
456 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType) ||
457 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
458 !GetStringFromConfig(ConfigSection(),KConfigCryptoMode,cryptoMode) ||
459 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
460 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
461 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
463 ERR_PRINTF1(_L("** .INI Error: Symmetric Cipher Arguments Not Located **"));
464 SetTestStepResult(EFail);
468 //Convert encryption key to an 8 Bit Descriptor
469 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
470 TPtr8 keyStrPtr = keyStr->Des();
472 keyStrPtr.Copy(encryptKey);
474 //Create an new CryptoParams object to encapsulate the key type and secret key string
475 CCryptoParams* keyParams = CCryptoParams::NewL();
476 CleanupStack::PushL(keyParams);
477 keyParams->AddL(*keyStr,keyType);
480 TKeyProperty keyProperty;
481 CKey* key=CKey::NewL(keyProperty,*keyParams);
482 CleanupStack::PushL(key);
484 CSymmetricCipher* symmetricCipherImpl = NULL;
486 TRAP_LOG(err,CSymmetricCipherFactory::CreateSymmetricCipherL(symmetricCipherImpl,
495 if(symmetricCipherImpl && (err == KErrNone))
498 plugin = static_cast<CCryptoBase*>(symmetricCipherImpl);
500 INFO_PRINTF1(_L("** Successfully Loaded Symmetric Cipher Object **"));
501 SetTestStepResult(EPass);
505 ERR_PRINTF2(_L("** Error: Loading Symmetric Cipher Object - %d **"), err);
506 SetTestStepResult(EFail);
509 CleanupStack::PopAndDestroy(3,keyStr);
517 TVariantPtrC algorithmUid;
518 TVariantPtrC operationMode;
519 TVariantPtrC algorithmParams;
521 //Each of the individual parameters required to create the Hash object
522 //are read in from the specified INI configuration file
523 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
524 #ifndef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
525 !GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode) ||
527 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
529 ERR_PRINTF1(_L("** .INI Error: Hash Arguments Not Located **"));
530 SetTestStepResult(EFail);
534 CHash* hashImpl = NULL;
535 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
536 if (GetStringFromConfig(ConfigSection(),KConfigOperationMode,operationMode))
538 TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
546 TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
551 TRAP_LOG(err,CHashFactory::CreateHashL(hashImpl,
558 if(hashImpl && (err == KErrNone))
560 plugin = static_cast<CCryptoBase*>(hashImpl);
562 INFO_PRINTF1(_L("** Successfully Loaded Hash Object **"));
563 SetTestStepResult(EPass);
567 ERR_PRINTF2(_L("** Error: Loading Hash Object - %d **"), err);
568 SetTestStepResult(EFail);
575 #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT
578 TVariantPtrC algorithmUid;
580 TVariantPtrC keyType;
582 //Each of the individual parameters required to create the Mac object
583 //are read in from the specified INI configuration file
584 if (!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
585 !GetStringFromConfig(ConfigSection(),KConfigEncryptKey,encryptKey) ||
586 !GetStringFromConfig(ConfigSection(),KConfigEncryptKeyType,keyType))
588 ERR_PRINTF1(_L("** .INI Error: Mac Arguments Not Located **"));
589 SetTestStepResult(EFail);
593 CMac* macImpl = NULL;
595 //Convert encryption key to an 8 Bit Descriptor
596 HBufC8* keyStr = HBufC8::NewLC(encryptKey.Length());
597 TPtr8 keyStrPtr = keyStr->Des();
599 keyStrPtr.Copy(encryptKey);
601 //Create an new CryptoParams object to encapsulate the key type and secret key string
602 CCryptoParams* keyParams = CCryptoParams::NewL();
603 CleanupStack::PushL(keyParams);
604 keyParams->AddL(*keyStr,keyType);
607 TKeyProperty keyProperty;
608 CKey* key=CKey::NewL(keyProperty,*keyParams);
609 CleanupStack::PushL(key);
611 TRAP_LOG(err,CMacFactory::CreateMacL(macImpl,
616 if(macImpl && (err == KErrNone))
618 plugin = static_cast<CCryptoBase*>(macImpl);
620 INFO_PRINTF1(_L("** Successfully Loaded Mac Object **"));
621 SetTestStepResult(EPass);
626 ERR_PRINTF2(_L("** Error: Loading Mac Object - %d **"), err);
627 SetTestStepResult(EFail);
630 CleanupStack::PopAndDestroy(3,keyStr);
637 case KRandomInterface:
640 TVariantPtrC algorithmUid;
641 TVariantPtrC algorithmParams;
643 //Each of the individual parameters required to create the Random object
644 //are read in from the specified INI configuration file
645 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
646 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
648 ERR_PRINTF1(_L("** .INI Error: Random Arguments Not Located **"));
649 SetTestStepResult(EFail);
653 CryptoSpi::CRandom* randomImpl = NULL;
655 TRAP_LOG(err,CRandomFactory::CreateRandomL(randomImpl,
659 if(randomImpl && (err == KErrNone))
661 plugin = static_cast<CCryptoBase*>(randomImpl);
663 INFO_PRINTF1(_L("** Successfully Loaded Random Object **"));
664 SetTestStepResult(EPass);
668 ERR_PRINTF2(_L("** Error: Loading Random Object - %d **"), err);
669 SetTestStepResult(EFail);
677 case KSignerInterface:
679 TVariantPtrC algorithmUid;
680 TVariantPtrC paddingMode;
681 TVariantPtrC algorithmParams;
683 //Each of the individual parameters required to create the Signer object
684 //are read in from the specified INI configuration file
685 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
686 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
687 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
689 ERR_PRINTF1(_L("** .INI Error: Signer Arguments Not Located **"));
690 SetTestStepResult(EFail);
695 //********** Rule Selector Unselected to Create Key Pair ************
696 CCryptoSpiStateApi::UnsetSelector();
698 CCryptoParams* keyParams = CCryptoParams::NewLC();
700 //Create Key Pair and Key Pair Generator Objects
701 CKeyPair* keyPair = NULL;
702 CKeyPairGenerator * keypairImpl = NULL;
704 INFO_PRINTF1(_L("Generating RSA keys"));
706 // create an RSA key pair
707 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
708 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
710 // create a key pair generator implementation interface
711 TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
712 KRSAKeyPairGeneratorUid,
715 CleanupStack::PushL(keypairImpl);
718 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
720 CleanupStack::PushL(keyPair);
722 CCryptoSpiStateApi::SetSelector(ruleSelector);
723 //******************************************************************
725 CSigner* signerImpl = NULL;
727 TRAP_LOG(err,CSignatureFactory::CreateSignerL(signerImpl,
729 keyPair->PrivateKey(),
733 if(signerImpl && (err == KErrNone))
735 plugin = static_cast<CCryptoBase*>(signerImpl);
737 INFO_PRINTF1(_L("** Successfully Loaded Signer Object **"));
738 SetTestStepResult(EPass);
742 ERR_PRINTF2(_L("** Error: Loading Signer Object - %d **"), err);
743 SetTestStepResult(EFail);
746 CleanupStack::PopAndDestroy(3,keyParams);
752 case KVerifierInterface:
754 TVariantPtrC algorithmUid;
755 TVariantPtrC paddingMode;
756 TVariantPtrC algorithmParams;
758 //Each of the individual parameters required to create the Verifier object
759 //are read in from the specified INI configuration file
760 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
761 !GetStringFromConfig(ConfigSection(),KConfigPaddingMode,paddingMode) ||
762 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
764 ERR_PRINTF1(_L("** .INI Error: Verifier Arguments Not Located **"));
765 SetTestStepResult(EFail);
770 //********** Rule Selector Unselected to Create Key Pair ************
771 CCryptoSpiStateApi::UnsetSelector();
773 CCryptoParams* keyParams = CCryptoParams::NewLC();
775 //Create Key Pair and Key Pair Generator Objects
776 CKeyPair* keyPair = NULL;
777 CKeyPairGenerator * keypairImpl = NULL;
779 INFO_PRINTF1(_L("Generating RSA keys"));
781 // create an RSA key pair
782 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
783 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
785 // create a key pair generator implementation interface
786 TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
787 KRSAKeyPairGeneratorUid,
790 CleanupStack::PushL(keypairImpl);
793 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, *keyParams, keyPair));
795 CleanupStack::PushL(keyPair);
797 CCryptoSpiStateApi::SetSelector(ruleSelector);
798 //******************************************************************
800 CVerifier* verifierImpl = NULL;
802 TRAP_LOG(err,CSignatureFactory::CreateVerifierL(verifierImpl,
804 keyPair->PublicKey(),
808 if(verifierImpl && (err == KErrNone))
810 plugin = static_cast<CCryptoBase*>(verifierImpl);
812 INFO_PRINTF1(_L("** Successfully Loaded Verifier Object **"));
813 SetTestStepResult(EPass);
817 ERR_PRINTF2(_L("** Error: Loading Verifier Object - %d **"), err);
818 SetTestStepResult(EFail);
821 CleanupStack::PopAndDestroy(3,keyParams);
827 case KKeypairGeneratorInterface:
829 TVariantPtrC algorithmUid;
830 TVariantPtrC algorithmParams;
832 //Each of the individual parameters required to create the Key Pair Generator object
833 //are read in from the specified INI configuration file
834 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
835 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
837 ERR_PRINTF1(_L("** .INI Error: Key Pair Generator Arguments Not Located **"));
838 SetTestStepResult(EFail);
843 CCryptoParams* keyParams = CCryptoParams::NewLC();
845 //Create Key Pair and Key Pair Generator Objects
846 CKeyPairGenerator * keypairImpl = NULL;
848 INFO_PRINTF1(_L("Generating RSA keys"));
850 // create an RSA key pair
851 keyParams->AddL(KKeyExponent, KRsaKeyParameterEUid);
852 keyParams->AddL(KRsaPrivateKeyStandard, KRsaKeyTypeUid);
854 // create a key pair generator implementation interface
855 TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
859 if(keypairImpl && (err == KErrNone))
861 plugin = static_cast<CCryptoBase*>(keypairImpl);
863 INFO_PRINTF1(_L("** Successfully Loaded Key Pair Generator Object **"));
864 SetTestStepResult(EPass);
868 ERR_PRINTF2(_L("** Error: Loading Key Pair Generator Object - %d **"), err);
869 SetTestStepResult(EFail);
872 CleanupStack::PopAndDestroy(keyParams);
878 case KKeyAgreementInterface:
880 TVariantPtrC algorithmUid;
881 TVariantPtrC algorithmParams;
883 //Each of the individual parameters required to create the Key Agreement object
884 //are read in from the specified INI configuration file
885 if(!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid,algorithmUid) ||
886 !GetStringFromConfig(ConfigSection(),KConfigAlgorithmParams,algorithmParams))
888 ERR_PRINTF1(_L("** .INI Error: Key Agreement Arguments Not Located **"));
889 SetTestStepResult(EFail);
893 //********** Rule Selector Unselected to Create Key Pair ************
894 CCryptoSpiStateApi::UnsetSelector();
896 RInteger DH_N = RInteger::NewPrimeL(64);
897 CleanupClosePushL(DH_N);
899 RInteger DH_N_MinusOne = RInteger::NewL(DH_N);
900 CleanupClosePushL(DH_N_MinusOne);
903 RInteger DH_G = RInteger::NewRandomL(TInteger::Two(), DH_N_MinusOne);
904 CleanupClosePushL(DH_G);
906 CCryptoParams* keyParams = CCryptoParams::NewLC();
908 TRAP_LOG(err,keyParams->AddL(DH_N, KDhKeyParameterNUid));
909 TRAP_LOG(err,keyParams->AddL(DH_G, KDhKeyParameterGUid));
911 //Create Key Pair and Key Pair Generator Objects
912 CKeyPair* keyPair = NULL;
913 CKeyPairGenerator * keypairImpl = NULL;
915 INFO_PRINTF1(_L("Generating Key Pair..."));
917 // create a key pair generator implementation interface
918 TRAP_LOG(err,CKeyPairGeneratorFactory::CreateKeyPairGeneratorL(keypairImpl,
919 KDHKeyPairGeneratorUid,
921 CleanupStack::PushL(keypairImpl);
924 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(NULL, *keyParams, keyPair));
926 CleanupStack::PushL(keyPair);
928 CCryptoSpiStateApi::SetSelector(ruleSelector);
929 //******************************************************************
931 CKeyAgreement* keyAgreementImpl = NULL;
933 TRAP_LOG(err,CKeyAgreementFactory::CreateKeyAgreementL(keyAgreementImpl,
935 keyPair->PrivateKey(),
938 if(keyAgreementImpl && (err == KErrNone))
940 plugin = static_cast<CCryptoBase*>(keyAgreementImpl);
942 INFO_PRINTF1(_L("** Successfully Loaded Key Agreement Object **"));
943 SetTestStepResult(EPass);
947 ERR_PRINTF2(_L("** Error: Loading Key Agreement Object - %d **"), err);
948 SetTestStepResult(EFail);
951 CleanupStack::PopAndDestroy(6,&DH_N);
959 ERR_PRINTF1(_L("** .INI Error: Interface Type Unknown **"));
960 SetTestStepResult(EFail);
967 if(TestStepResult()==EPass)
969 //Push the selected implementation onto the Cleanup Stack
970 CleanupStack::PushL(plugin);
972 //Assume faliure, unless all is successful
973 SetTestStepResult(EFail);
975 //Define a pointer of type TCharacteristics in order to store the appropriate
976 //encryption object's characterisctics
977 const TCharacteristics* characteristics(NULL);
979 //Retrieve the characteristics for the symmetric cipher implementation object
980 TRAP_LOG(err, plugin->GetCharacteristicsL(characteristics));
982 TVariantPtrC exAlgorithmUid;
983 TVariantPtrC exImplementationUid;
985 if(!GetStringFromConfig(ConfigSection(),KConfigExAlgorithmUid,exAlgorithmUid) ||
986 !GetStringFromConfig(ConfigSection(),KConfigExImplementationUid,exImplementationUid))
988 ERR_PRINTF1(_L("** .INI Error: Expected Algorithm Arguments Not Located **"));
989 SetTestStepResult(EFail);
993 INFO_PRINTF1(_L("Checking Plug-in Selection..."));
995 CPluginCharsChecker* pluginCheck = CPluginCharsChecker::NewLC();
999 //Perform plug-in Check
1000 if(pluginCheck->checkSelectedPlugin(characteristics,
1002 exImplementationUid,
1005 INFO_PRINTF1(_L("** PASS: Correct Plugin Implementation Selected **"));
1006 SetTestStepResult(EPass);
1010 ERR_PRINTF2(_L("** FAIL: Wrong Plugin Implementation Selected - %S **"),&errorMessage);
1013 CleanupStack::PopAndDestroy(pluginCheck);
1016 CleanupStack::PopAndDestroy(plugin);
1019 //Unselect Rule Selector
1020 CCryptoSpiStateApi::UnsetSelector();
1022 //Pop and Destroy Rule Selector from the Cleanup Stack
1023 CleanupStack::PopAndDestroy(ruleSelector);
1027 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
1028 return TestStepResult();
1032 TVerdict CRuleSelectCommonStep::doTestStepPostambleL()
1034 return TestStepResult();