|
1 /* |
|
2 * Copyright (c) 2007-2009 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 "verifierpositiveobjectloadstep.h" |
|
25 |
|
26 #include "keys.h" |
|
27 #include "keypair.h" |
|
28 #include "cryptosignatureapi.h" |
|
29 #include "cryptokeypairgeneratorapi.h" |
|
30 |
|
31 using namespace CryptoSpi; |
|
32 |
|
33 CVerifierPositiveObjectLoadStep::~CVerifierPositiveObjectLoadStep() |
|
34 { |
|
35 } |
|
36 |
|
37 CVerifierPositiveObjectLoadStep::CVerifierPositiveObjectLoadStep() |
|
38 { |
|
39 SetTestStepName(KVerifierPositiveObjectLoadStep); |
|
40 } |
|
41 |
|
42 TVerdict CVerifierPositiveObjectLoadStep::doTestStepPreambleL() |
|
43 { |
|
44 SetTestStepResult(EPass); |
|
45 return TestStepResult(); |
|
46 } |
|
47 |
|
48 |
|
49 TVerdict CVerifierPositiveObjectLoadStep::doTestStepL() |
|
50 { |
|
51 INFO_PRINTF1(_L("*** Verifier - 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 CleanupStack::PushL(keypairImpl); |
|
86 |
|
87 |
|
88 // Generate a Key Pair |
|
89 INFO_PRINTF1(_L("Generating Key Pair...")); |
|
90 |
|
91 CKeyPair* keyPair = NULL; |
|
92 |
|
93 TRAP_LOG(err,keypairImpl->GenerateKeyPairL(1024, |
|
94 *keyParams, |
|
95 keyPair)); |
|
96 |
|
97 CleanupStack::PushL(keyPair); |
|
98 |
|
99 |
|
100 // Creating Verifier 1 with necessary values from the ini file |
|
101 INFO_PRINTF1(_L("Constructing Verifier 1 (No Padding)...")); |
|
102 |
|
103 CVerifier * impl1 = NULL; |
|
104 TRAP_LOG(err,CSignatureFactory::CreateVerifierL |
|
105 (impl1, |
|
106 KRsaVerifierUid, |
|
107 keyPair->PrivateKey(), |
|
108 KPaddingModeNoneUid, |
|
109 keyParams)); |
|
110 |
|
111 CleanupStack::PushL(impl1); |
|
112 |
|
113 |
|
114 // Creating Verifier 2 with the necessary values from the ini file |
|
115 INFO_PRINTF1(_L("Constructing Verifier 1 (No Padding)...")); |
|
116 |
|
117 CVerifier * impl2 = NULL; |
|
118 TRAP_LOG(err,CSignatureFactory::CreateVerifierL |
|
119 (impl2, |
|
120 KRsaVerifierUid, |
|
121 keyPair->PrivateKey(), |
|
122 KPaddingModePkcs1_v1_5_SignatureUid, |
|
123 keyParams)); |
|
124 |
|
125 CleanupStack::PushL(impl2); |
|
126 |
|
127 if((impl1) && (impl2) && (err == KErrNone)) |
|
128 { |
|
129 // This is a basic test for load positivity |
|
130 // from the Factory |
|
131 INFO_PRINTF1(_L("PASS: Verifier - Positive Object Load")); |
|
132 SetTestStepResult(EPass); |
|
133 } |
|
134 else |
|
135 { |
|
136 ERR_PRINTF2(_L("FAIL: Verifier Object Construction Failure - %d"), err); |
|
137 SetTestStepResult(EFail); |
|
138 } |
|
139 |
|
140 CleanupStack::PopAndDestroy(impl2); |
|
141 CleanupStack::PopAndDestroy(impl1); |
|
142 |
|
143 CleanupStack::PopAndDestroy(keyPair); |
|
144 CleanupStack::PopAndDestroy(keypairImpl); |
|
145 CleanupStack::PopAndDestroy(keyParams); |
|
146 } |
|
147 |
|
148 INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells()); |
|
149 |
|
150 } |
|
151 return TestStepResult(); |
|
152 } |
|
153 |
|
154 |
|
155 |
|
156 TVerdict CVerifierPositiveObjectLoadStep::doTestStepPostambleL() |
|
157 { |
|
158 return TestStepResult(); |
|
159 } |