sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-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 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include "t_keystore_actions.h"
|
sl@0
|
21 |
#include "t_keystore_defs.h"
|
sl@0
|
22 |
#include "t_input.h"
|
sl@0
|
23 |
#include <asn1enc.h>
|
sl@0
|
24 |
#include <asn1dec.h>
|
sl@0
|
25 |
#include <x509cert.h>
|
sl@0
|
26 |
#include <x509keys.h>
|
sl@0
|
27 |
#include <asymmetrickeys.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
30 |
#include <cryptospidef.h>
|
sl@0
|
31 |
#include "cryptoasymmetriccipherapi.h"
|
sl@0
|
32 |
#include "cryptosignatureapi.h"
|
sl@0
|
33 |
#include <cryptospi/cryptoparams.h>
|
sl@0
|
34 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
35 |
|
sl@0
|
36 |
/*static*/ CTestAction* COpenKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
CTestAction* self = COpenKey::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
39 |
CleanupStack::Pop(self);
|
sl@0
|
40 |
return self;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
/*static*/ CTestAction* COpenKey::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
COpenKey* self = new (ELeave) COpenKey(aFs, aConsole, aOut);
|
sl@0
|
46 |
CleanupStack::PushL(self);
|
sl@0
|
47 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
48 |
return self;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
COpenKey::~COpenKey()
|
sl@0
|
52 |
{
|
sl@0
|
53 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
54 |
delete iSigner;
|
sl@0
|
55 |
delete iDecrypt;
|
sl@0
|
56 |
#endif
|
sl@0
|
57 |
iKeys.Close();
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
void COpenKey::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
switch (iState)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
case EListKeysPreOpen:
|
sl@0
|
65 |
{// Currently uses the first store, change to check the script for a specific store
|
sl@0
|
66 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
67 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
68 |
if (keyStore)
|
sl@0
|
69 |
keyStore->List(iKeys, iFilter, aStatus);
|
sl@0
|
70 |
|
sl@0
|
71 |
iState = EOpenKey;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
break;
|
sl@0
|
74 |
|
sl@0
|
75 |
case EOpenKey:
|
sl@0
|
76 |
{
|
sl@0
|
77 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
78 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
79 |
|
sl@0
|
80 |
TInt keyCount = iKeys.Count();
|
sl@0
|
81 |
TInt i;
|
sl@0
|
82 |
|
sl@0
|
83 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
86 |
|
sl@0
|
87 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
switch (iType)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
case ERSASign:
|
sl@0
|
92 |
keyStore->Open(*keyInfo, iRSASigner, aStatus);
|
sl@0
|
93 |
break;
|
sl@0
|
94 |
case EDSASign:
|
sl@0
|
95 |
keyStore->Open(*keyInfo, iDSASigner, aStatus);
|
sl@0
|
96 |
break;
|
sl@0
|
97 |
case EDecrypt:
|
sl@0
|
98 |
keyStore->Open(*keyInfo, iDecryptor, aStatus);
|
sl@0
|
99 |
break;
|
sl@0
|
100 |
case EDH:
|
sl@0
|
101 |
keyStore->Open(*keyInfo, iDH, aStatus);
|
sl@0
|
102 |
break;
|
sl@0
|
103 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
104 |
case EECC:
|
sl@0
|
105 |
{
|
sl@0
|
106 |
ASSERT(iHardwareType);
|
sl@0
|
107 |
if(iOperationType == ESigning)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
keyStore->Open(keyInfo->Handle(),iSigner,aStatus);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
if(iOperationType == EDecryption)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
keyStore->Open(keyInfo->Handle(),iDecrypt,aStatus);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
break;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
118 |
}
|
sl@0
|
119 |
break;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
}
|
sl@0
|
122 |
if (i == keyCount)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
TRequestStatus* status = &aStatus;
|
sl@0
|
125 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
iState = EFinished;
|
sl@0
|
129 |
|
sl@0
|
130 |
}
|
sl@0
|
131 |
break;
|
sl@0
|
132 |
|
sl@0
|
133 |
case EFinished:
|
sl@0
|
134 |
{
|
sl@0
|
135 |
TInt completionCode = aStatus.Int();
|
sl@0
|
136 |
HBufC* label = 0;
|
sl@0
|
137 |
iKeys.Close();
|
sl@0
|
138 |
if (aStatus.Int() == KErrNone)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
switch (iType)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
case ERSASign:
|
sl@0
|
143 |
if (iRSASigner)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
label = iRSASigner->Label().AllocLC();
|
sl@0
|
146 |
iRSASigner->Release();
|
sl@0
|
147 |
}
|
sl@0
|
148 |
break;
|
sl@0
|
149 |
case EDSASign:
|
sl@0
|
150 |
if (iDSASigner)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
label = iDSASigner->Label().AllocLC();
|
sl@0
|
153 |
iDSASigner->Release();
|
sl@0
|
154 |
}
|
sl@0
|
155 |
break;
|
sl@0
|
156 |
case EDecrypt:
|
sl@0
|
157 |
if (iDecryptor)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
label = iDecryptor->Label().AllocLC();
|
sl@0
|
160 |
iDecryptor->Release();
|
sl@0
|
161 |
}
|
sl@0
|
162 |
case EDH:
|
sl@0
|
163 |
if (iDH)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
label = iDH->Label().AllocLC();
|
sl@0
|
166 |
iDH->Release();
|
sl@0
|
167 |
}
|
sl@0
|
168 |
break;
|
sl@0
|
169 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
170 |
case EECC:
|
sl@0
|
171 |
{
|
sl@0
|
172 |
ASSERT(iHardwareType);
|
sl@0
|
173 |
if(iOperationType == ESigning && iSigner == NULL
|
sl@0
|
174 |
|| iOperationType == EDecryption && iDecrypt == NULL)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
completionCode = KErrGeneral;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
break;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
181 |
} // switch
|
sl@0
|
182 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
183 |
if(iHardwareType == 0)
|
sl@0
|
184 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
185 |
{
|
sl@0
|
186 |
if (*label != *iLabel)
|
sl@0
|
187 |
aStatus = KErrBadName;
|
sl@0
|
188 |
CleanupStack::PopAndDestroy(label);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
}
|
sl@0
|
191 |
TRequestStatus* status = &aStatus;
|
sl@0
|
192 |
User::RequestComplete(status, completionCode);
|
sl@0
|
193 |
|
sl@0
|
194 |
if (aStatus.Int()==iExpectedResult)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
iResult = ETrue;
|
sl@0
|
197 |
}
|
sl@0
|
198 |
else
|
sl@0
|
199 |
{
|
sl@0
|
200 |
iResult = EFalse;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
iActionState = EPostrequisite;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
break;
|
sl@0
|
206 |
default:
|
sl@0
|
207 |
ASSERT(EFalse);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
void COpenKey::PerformCancel()
|
sl@0
|
213 |
{
|
sl@0
|
214 |
CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
215 |
ASSERT(keystore);
|
sl@0
|
216 |
|
sl@0
|
217 |
switch (iState)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
case EOpenKey:
|
sl@0
|
220 |
keystore->CancelList();
|
sl@0
|
221 |
break;
|
sl@0
|
222 |
|
sl@0
|
223 |
case EFinished:
|
sl@0
|
224 |
keystore->CancelOpen();
|
sl@0
|
225 |
break;
|
sl@0
|
226 |
|
sl@0
|
227 |
default:
|
sl@0
|
228 |
break;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
void COpenKey::Reset()
|
sl@0
|
233 |
{
|
sl@0
|
234 |
iState = EListKeysPreOpen;
|
sl@0
|
235 |
iKeys.Close();
|
sl@0
|
236 |
if (iRSASigner)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
iRSASigner->Release();
|
sl@0
|
239 |
iRSASigner = NULL;
|
sl@0
|
240 |
}
|
sl@0
|
241 |
if (iDSASigner)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
iDSASigner->Release();
|
sl@0
|
244 |
iDSASigner = NULL;
|
sl@0
|
245 |
}
|
sl@0
|
246 |
if (iDecryptor)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
iDecryptor->Release();
|
sl@0
|
249 |
iDecryptor = NULL;
|
sl@0
|
250 |
}
|
sl@0
|
251 |
if (iDH)
|
sl@0
|
252 |
{
|
sl@0
|
253 |
iDH->Release();
|
sl@0
|
254 |
iDH = NULL;
|
sl@0
|
255 |
}
|
sl@0
|
256 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
257 |
delete iSigner;
|
sl@0
|
258 |
iSigner = NULL;
|
sl@0
|
259 |
delete iDecrypt;
|
sl@0
|
260 |
iDecrypt = NULL;
|
sl@0
|
261 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
262 |
}
|
sl@0
|
263 |
|
sl@0
|
264 |
void COpenKey::DoReportAction()
|
sl@0
|
265 |
{
|
sl@0
|
266 |
_LIT(KDeleting, "Opening...");
|
sl@0
|
267 |
iOut.writeString(KDeleting);
|
sl@0
|
268 |
iOut.writeNewLine();
|
sl@0
|
269 |
}
|
sl@0
|
270 |
|
sl@0
|
271 |
void COpenKey::DoCheckResult(TInt aError)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
if (iFinished)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
TBuf<256> buf;
|
sl@0
|
276 |
if (aError == KErrNone)
|
sl@0
|
277 |
{
|
sl@0
|
278 |
_LIT(KSuccessful, "Key open success\n");
|
sl@0
|
279 |
buf.Format(KSuccessful);
|
sl@0
|
280 |
iConsole.Write(buf);
|
sl@0
|
281 |
iOut.writeString(buf);
|
sl@0
|
282 |
iOut.writeNewLine();
|
sl@0
|
283 |
}
|
sl@0
|
284 |
else
|
sl@0
|
285 |
{
|
sl@0
|
286 |
if (aError!=iExpectedResult)
|
sl@0
|
287 |
{
|
sl@0
|
288 |
_LIT(KFailed, "!!!Key open failure %d!!!\n");
|
sl@0
|
289 |
buf.Format(KFailed, aError);
|
sl@0
|
290 |
iConsole.Write(buf);
|
sl@0
|
291 |
iOut.writeString(buf);
|
sl@0
|
292 |
}
|
sl@0
|
293 |
else
|
sl@0
|
294 |
{
|
sl@0
|
295 |
_LIT(KFailed, "Key open failed, but expected\n");
|
sl@0
|
296 |
iConsole.Write(KFailed);
|
sl@0
|
297 |
iOut.writeString(KFailed);
|
sl@0
|
298 |
}
|
sl@0
|
299 |
|
sl@0
|
300 |
iOut.writeNewLine();
|
sl@0
|
301 |
}
|
sl@0
|
302 |
}
|
sl@0
|
303 |
}
|
sl@0
|
304 |
|
sl@0
|
305 |
COpenKey::COpenKey(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
sl@0
|
306 |
: CKeyStoreTestAction(aFs, aConsole, aOut)
|
sl@0
|
307 |
{}
|
sl@0
|
308 |
|
sl@0
|
309 |
void COpenKey::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
312 |
|
sl@0
|
313 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
314 |
TInt pos = 0, err = 0;
|
sl@0
|
315 |
TPtrC8 operationType = Input::ParseElement(aTestActionSpec.iActionBody, KOperationTypeStart, KOperationTypeEnd, pos, err);
|
sl@0
|
316 |
if(operationType.Compare(_L8("sign")) == 0)
|
sl@0
|
317 |
{
|
sl@0
|
318 |
iOperationType = ESigning;
|
sl@0
|
319 |
}
|
sl@0
|
320 |
else if (operationType.Compare(_L8("decrypt")) == 0)
|
sl@0
|
321 |
{
|
sl@0
|
322 |
iOperationType = EDecryption;
|
sl@0
|
323 |
}
|
sl@0
|
324 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
325 |
|
sl@0
|
326 |
iState = EListKeysPreOpen;
|
sl@0
|
327 |
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
////////////////////////////////////
|
sl@0
|
331 |
// CSign
|
sl@0
|
332 |
////////////////////////////////////
|
sl@0
|
333 |
/*static*/ CTestAction* CSign::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
334 |
{
|
sl@0
|
335 |
CTestAction* self = CSign::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
336 |
CleanupStack::Pop(self);
|
sl@0
|
337 |
return self;
|
sl@0
|
338 |
}
|
sl@0
|
339 |
|
sl@0
|
340 |
/*static*/ CTestAction* CSign::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
341 |
{
|
sl@0
|
342 |
CSign* self = new (ELeave) CSign(aFs, aConsole, aOut);
|
sl@0
|
343 |
CleanupStack::PushL(self);
|
sl@0
|
344 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
345 |
return self;
|
sl@0
|
346 |
}
|
sl@0
|
347 |
|
sl@0
|
348 |
CSign::~CSign()
|
sl@0
|
349 |
{
|
sl@0
|
350 |
iKeys.Close();
|
sl@0
|
351 |
delete iReadText;
|
sl@0
|
352 |
delete iExportedPublicKey;
|
sl@0
|
353 |
delete iRSASignature;
|
sl@0
|
354 |
delete iDSASignature;
|
sl@0
|
355 |
delete iHash;
|
sl@0
|
356 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
357 |
delete iSigner;
|
sl@0
|
358 |
delete iSpiSignature;
|
sl@0
|
359 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
void CSign::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
// Jump straight to final state if an error occured
|
sl@0
|
365 |
if (aStatus.Int()!=KErrNone)
|
sl@0
|
366 |
{
|
sl@0
|
367 |
iState=EFinished;
|
sl@0
|
368 |
}
|
sl@0
|
369 |
|
sl@0
|
370 |
switch (iState)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
case EListKeysPreOpen:
|
sl@0
|
373 |
{
|
sl@0
|
374 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
375 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
376 |
if (keyStore)
|
sl@0
|
377 |
keyStore->List(iKeys, iFilter, aStatus);
|
sl@0
|
378 |
iState = EOpenKey;
|
sl@0
|
379 |
|
sl@0
|
380 |
}
|
sl@0
|
381 |
break;
|
sl@0
|
382 |
|
sl@0
|
383 |
case EOpenKey:
|
sl@0
|
384 |
{
|
sl@0
|
385 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
386 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
387 |
TInt keyCount = iKeys.Count();
|
sl@0
|
388 |
|
sl@0
|
389 |
TInt i;
|
sl@0
|
390 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
391 |
{
|
sl@0
|
392 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
393 |
|
sl@0
|
394 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
395 |
{
|
sl@0
|
396 |
switch (iType)
|
sl@0
|
397 |
{
|
sl@0
|
398 |
case ERSASign:
|
sl@0
|
399 |
keyStore->Open(*keyInfo, iRSASigner, aStatus);
|
sl@0
|
400 |
break;
|
sl@0
|
401 |
case EDSASign:
|
sl@0
|
402 |
keyStore->Open(*keyInfo, iDSASigner, aStatus);
|
sl@0
|
403 |
break;
|
sl@0
|
404 |
case EDH:
|
sl@0
|
405 |
case EDecrypt:
|
sl@0
|
406 |
break; // Nothing to do, for the compiler
|
sl@0
|
407 |
|
sl@0
|
408 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
409 |
case EECC:
|
sl@0
|
410 |
{
|
sl@0
|
411 |
iTokenHandle = keyInfo->Handle();
|
sl@0
|
412 |
if(iHardwareType == 0)
|
sl@0
|
413 |
{
|
sl@0
|
414 |
keyStore->Open(iTokenHandle, iSigner, aStatus);
|
sl@0
|
415 |
}
|
sl@0
|
416 |
else
|
sl@0
|
417 |
{
|
sl@0
|
418 |
TRequestStatus* status = &aStatus;
|
sl@0
|
419 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
420 |
}
|
sl@0
|
421 |
}
|
sl@0
|
422 |
break;
|
sl@0
|
423 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
424 |
}
|
sl@0
|
425 |
} // if
|
sl@0
|
426 |
if (i == keyCount)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
TRequestStatus* status = &aStatus;
|
sl@0
|
429 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
430 |
}
|
sl@0
|
431 |
}// for
|
sl@0
|
432 |
iState = ESign;
|
sl@0
|
433 |
|
sl@0
|
434 |
}
|
sl@0
|
435 |
break;
|
sl@0
|
436 |
|
sl@0
|
437 |
case ESign:
|
sl@0
|
438 |
{
|
sl@0
|
439 |
switch (iType)
|
sl@0
|
440 |
{
|
sl@0
|
441 |
case ERSASign:
|
sl@0
|
442 |
{
|
sl@0
|
443 |
if (iHash)
|
sl@0
|
444 |
{
|
sl@0
|
445 |
if (iFailHashDigest) // Don't hash it, fail deliberately
|
sl@0
|
446 |
iRSASigner->Sign(*iReadText,iRSASignature,aStatus);
|
sl@0
|
447 |
else // message gets signed by the keystore
|
sl@0
|
448 |
iRSASigner->SignMessage(*iReadText,iRSASignature,aStatus);
|
sl@0
|
449 |
}
|
sl@0
|
450 |
else
|
sl@0
|
451 |
{
|
sl@0
|
452 |
iRSASigner->Sign(*iReadText,iRSASignature,aStatus);
|
sl@0
|
453 |
}
|
sl@0
|
454 |
}
|
sl@0
|
455 |
break;
|
sl@0
|
456 |
case EDSASign:
|
sl@0
|
457 |
{
|
sl@0
|
458 |
if (iHash)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
if (iFailHashDigest) // Don't hash it, deliberately fail it
|
sl@0
|
461 |
iDSASigner->Sign(*iReadText,iDSASignature,aStatus);
|
sl@0
|
462 |
else // message gets signed by the keystore
|
sl@0
|
463 |
iDSASigner->SignMessage(*iReadText,iDSASignature,aStatus);
|
sl@0
|
464 |
}
|
sl@0
|
465 |
else
|
sl@0
|
466 |
{
|
sl@0
|
467 |
iDSASigner->Sign(*iReadText,iDSASignature,aStatus);
|
sl@0
|
468 |
}
|
sl@0
|
469 |
}
|
sl@0
|
470 |
break;
|
sl@0
|
471 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
472 |
case EECC:
|
sl@0
|
473 |
{
|
sl@0
|
474 |
TRAPD(err, iSpiSignature = CryptoSpi::CCryptoParams::NewL());
|
sl@0
|
475 |
if(err == KErrNone)
|
sl@0
|
476 |
{
|
sl@0
|
477 |
if(iHardwareType)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
480 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
481 |
keyStore->Sign(iTokenHandle, *iReadText, iSpiSignature, aStatus);
|
sl@0
|
482 |
}
|
sl@0
|
483 |
else
|
sl@0
|
484 |
{
|
sl@0
|
485 |
if(iSigner)
|
sl@0
|
486 |
{
|
sl@0
|
487 |
TRAP(err, iSigner->SignL(*iReadText, *iSpiSignature));
|
sl@0
|
488 |
aStatus = err;
|
sl@0
|
489 |
}
|
sl@0
|
490 |
TRequestStatus* status = &aStatus;
|
sl@0
|
491 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
492 |
}
|
sl@0
|
493 |
}
|
sl@0
|
494 |
else
|
sl@0
|
495 |
{
|
sl@0
|
496 |
aStatus = err;
|
sl@0
|
497 |
TRequestStatus* status = &aStatus;
|
sl@0
|
498 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
499 |
}
|
sl@0
|
500 |
}
|
sl@0
|
501 |
break;
|
sl@0
|
502 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
503 |
|
sl@0
|
504 |
default:
|
sl@0
|
505 |
ASSERT(EFalse);
|
sl@0
|
506 |
}
|
sl@0
|
507 |
iState = EExportPublic;
|
sl@0
|
508 |
}
|
sl@0
|
509 |
break;
|
sl@0
|
510 |
|
sl@0
|
511 |
|
sl@0
|
512 |
case EExportPublic:
|
sl@0
|
513 |
{
|
sl@0
|
514 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
515 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
516 |
|
sl@0
|
517 |
TInt keyCount = iKeys.Count();
|
sl@0
|
518 |
TInt i;
|
sl@0
|
519 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
520 |
{
|
sl@0
|
521 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
522 |
|
sl@0
|
523 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
iExportHandle = keyInfo->Handle();
|
sl@0
|
526 |
|
sl@0
|
527 |
switch (iType)
|
sl@0
|
528 |
{
|
sl@0
|
529 |
case ERSASign:
|
sl@0
|
530 |
keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus);
|
sl@0
|
531 |
break;
|
sl@0
|
532 |
case EDSASign:
|
sl@0
|
533 |
keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus);
|
sl@0
|
534 |
break;
|
sl@0
|
535 |
case EDH:
|
sl@0
|
536 |
case EDecrypt:
|
sl@0
|
537 |
break; // Nothing to do, for the compiler
|
sl@0
|
538 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
539 |
case EECC:
|
sl@0
|
540 |
{
|
sl@0
|
541 |
keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus);
|
sl@0
|
542 |
iState = EVerify;
|
sl@0
|
543 |
}
|
sl@0
|
544 |
break;
|
sl@0
|
545 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
546 |
}
|
sl@0
|
547 |
break;
|
sl@0
|
548 |
}
|
sl@0
|
549 |
}
|
sl@0
|
550 |
iState = EVerify;
|
sl@0
|
551 |
if (i == keyCount)
|
sl@0
|
552 |
{
|
sl@0
|
553 |
TRequestStatus* status = &aStatus;
|
sl@0
|
554 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
555 |
}
|
sl@0
|
556 |
}
|
sl@0
|
557 |
break;
|
sl@0
|
558 |
|
sl@0
|
559 |
case EVerify:
|
sl@0
|
560 |
{
|
sl@0
|
561 |
TInt keyCount = iKeys.Count();
|
sl@0
|
562 |
TInt i;
|
sl@0
|
563 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
564 |
{
|
sl@0
|
565 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
566 |
|
sl@0
|
567 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
568 |
{
|
sl@0
|
569 |
iExportHandle = keyInfo->Handle();
|
sl@0
|
570 |
CX509SubjectPublicKeyInfo* ki = NULL;
|
sl@0
|
571 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
572 |
if(iType != EECC)
|
sl@0
|
573 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
574 |
ki = CX509SubjectPublicKeyInfo::NewLC(*iExportedPublicKey);
|
sl@0
|
575 |
|
sl@0
|
576 |
switch (iType)
|
sl@0
|
577 |
{
|
sl@0
|
578 |
case ERSASign:
|
sl@0
|
579 |
{
|
sl@0
|
580 |
TX509KeyFactory factory;
|
sl@0
|
581 |
CRSAPublicKey* key = factory.RSAPublicKeyL(ki->KeyData());
|
sl@0
|
582 |
CleanupStack::PushL(key);
|
sl@0
|
583 |
|
sl@0
|
584 |
CRSAPKCS1v15Verifier* verifier = NULL;
|
sl@0
|
585 |
|
sl@0
|
586 |
if (iHash) // Must compare with hash of original data
|
sl@0
|
587 |
{
|
sl@0
|
588 |
verifier = CRSAPKCS1v15Verifier::NewLC(*key);
|
sl@0
|
589 |
iHash->Reset();
|
sl@0
|
590 |
iVerifyResult = verifier->VerifyL(iHash->Final(*iReadText), *iRSASignature);
|
sl@0
|
591 |
}
|
sl@0
|
592 |
else
|
sl@0
|
593 |
{
|
sl@0
|
594 |
verifier = CRSAPKCS1v15Verifier::NewLC(*key);
|
sl@0
|
595 |
iVerifyResult = verifier->VerifyL(*iReadText, *iRSASignature);
|
sl@0
|
596 |
}
|
sl@0
|
597 |
|
sl@0
|
598 |
_LIT(KReturned, "Returned... ");
|
sl@0
|
599 |
iOut.writeString(KReturned);
|
sl@0
|
600 |
iOut.writeNewLine();
|
sl@0
|
601 |
|
sl@0
|
602 |
CleanupStack::PopAndDestroy(2, key);
|
sl@0
|
603 |
}
|
sl@0
|
604 |
break;
|
sl@0
|
605 |
case EDSASign:
|
sl@0
|
606 |
{
|
sl@0
|
607 |
TX509KeyFactory factory;
|
sl@0
|
608 |
CDSAPublicKey* key = factory.DSAPublicKeyL(ki->EncodedParams(), ki->KeyData());
|
sl@0
|
609 |
CleanupStack::PushL(key);
|
sl@0
|
610 |
|
sl@0
|
611 |
CDSAVerifier* verifier = CDSAVerifier::NewLC(*key);
|
sl@0
|
612 |
if (iHash) // Must compare with hash of original value
|
sl@0
|
613 |
{
|
sl@0
|
614 |
iHash->Reset();
|
sl@0
|
615 |
iVerifyResult = verifier->VerifyL(iHash->Final(*iReadText),*iDSASignature);
|
sl@0
|
616 |
}
|
sl@0
|
617 |
else
|
sl@0
|
618 |
{
|
sl@0
|
619 |
iVerifyResult = verifier->VerifyL(*iReadText,*iDSASignature);
|
sl@0
|
620 |
}
|
sl@0
|
621 |
_LIT(KReturned, "Returned... ");
|
sl@0
|
622 |
iOut.writeString(KReturned);
|
sl@0
|
623 |
iOut.writeNewLine();
|
sl@0
|
624 |
CleanupStack::PopAndDestroy(verifier);
|
sl@0
|
625 |
CleanupStack::PopAndDestroy(key);
|
sl@0
|
626 |
}
|
sl@0
|
627 |
break;
|
sl@0
|
628 |
|
sl@0
|
629 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
630 |
case EECC:
|
sl@0
|
631 |
{
|
sl@0
|
632 |
iVerifyResult = EFalse;
|
sl@0
|
633 |
if (iSpiSignature && iSpiSignature->IsPresent(CryptoSpi::KEccKeyTypeUid))
|
sl@0
|
634 |
{
|
sl@0
|
635 |
TDesC8* actualSignature = NULL;
|
sl@0
|
636 |
TRAPD(err, actualSignature = const_cast<TDesC8*>(&(iSpiSignature->GetTDesC8L(CryptoSpi::KEccKeyTypeUid))));
|
sl@0
|
637 |
if(err == KErrNone)
|
sl@0
|
638 |
{
|
sl@0
|
639 |
if(iExportedPublicKey->Des() == *actualSignature)
|
sl@0
|
640 |
{
|
sl@0
|
641 |
iVerifyResult = ETrue;
|
sl@0
|
642 |
}
|
sl@0
|
643 |
}
|
sl@0
|
644 |
else
|
sl@0
|
645 |
{
|
sl@0
|
646 |
aStatus = err;
|
sl@0
|
647 |
}
|
sl@0
|
648 |
}
|
sl@0
|
649 |
_LIT(KReturned, "Returned... ");
|
sl@0
|
650 |
iOut.writeString(KReturned);
|
sl@0
|
651 |
iOut.writeNewLine();
|
sl@0
|
652 |
}
|
sl@0
|
653 |
break;
|
sl@0
|
654 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
655 |
default:
|
sl@0
|
656 |
ASSERT(EFalse);
|
sl@0
|
657 |
|
sl@0
|
658 |
}
|
sl@0
|
659 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
660 |
if(iType != EECC)
|
sl@0
|
661 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
662 |
CleanupStack::PopAndDestroy(ki);
|
sl@0
|
663 |
}
|
sl@0
|
664 |
}
|
sl@0
|
665 |
|
sl@0
|
666 |
iState = EFinished;
|
sl@0
|
667 |
TRequestStatus* status = &aStatus;
|
sl@0
|
668 |
if (!iVerifyResult)
|
sl@0
|
669 |
{
|
sl@0
|
670 |
_LIT(KVerifyFail, "**Verify failed**");
|
sl@0
|
671 |
iOut.writeString(KVerifyFail);
|
sl@0
|
672 |
iOut.writeNewLine();
|
sl@0
|
673 |
|
sl@0
|
674 |
// Flat verify failed as KErrGeneral
|
sl@0
|
675 |
if (aStatus.Int() == KErrNone)
|
sl@0
|
676 |
{
|
sl@0
|
677 |
aStatus = KErrGeneral;
|
sl@0
|
678 |
}
|
sl@0
|
679 |
}
|
sl@0
|
680 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
681 |
}
|
sl@0
|
682 |
break;
|
sl@0
|
683 |
|
sl@0
|
684 |
case EFinished:
|
sl@0
|
685 |
{
|
sl@0
|
686 |
iActionState = EPostrequisite;
|
sl@0
|
687 |
iResult = (aStatus.Int() == iExpectedResult);
|
sl@0
|
688 |
|
sl@0
|
689 |
if ((aStatus.Int() != KErrNone)&&(aStatus!=KErrNoMemory))
|
sl@0
|
690 |
{
|
sl@0
|
691 |
_LIT(KExportFail," !Failed when exporting public key! ");
|
sl@0
|
692 |
iOut.writeString(KExportFail);
|
sl@0
|
693 |
}
|
sl@0
|
694 |
|
sl@0
|
695 |
iKeys.Close();
|
sl@0
|
696 |
switch (iType)
|
sl@0
|
697 |
{
|
sl@0
|
698 |
case ERSASign:
|
sl@0
|
699 |
if (iRSASigner)
|
sl@0
|
700 |
iRSASigner->Release();
|
sl@0
|
701 |
break;
|
sl@0
|
702 |
case EDSASign:
|
sl@0
|
703 |
if (iDSASigner)
|
sl@0
|
704 |
iDSASigner->Release();
|
sl@0
|
705 |
break;
|
sl@0
|
706 |
case EDecrypt:
|
sl@0
|
707 |
if (iDecryptor)
|
sl@0
|
708 |
iDecryptor->Release();
|
sl@0
|
709 |
case EDH:
|
sl@0
|
710 |
if (iDH)
|
sl@0
|
711 |
iDH->Release();
|
sl@0
|
712 |
break;
|
sl@0
|
713 |
}
|
sl@0
|
714 |
TRequestStatus* status = &aStatus;
|
sl@0
|
715 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
716 |
}
|
sl@0
|
717 |
break;
|
sl@0
|
718 |
default:
|
sl@0
|
719 |
ASSERT(EFalse);
|
sl@0
|
720 |
}
|
sl@0
|
721 |
}
|
sl@0
|
722 |
|
sl@0
|
723 |
void CSign::PerformCancel()
|
sl@0
|
724 |
{
|
sl@0
|
725 |
CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
726 |
ASSERT(keystore);
|
sl@0
|
727 |
|
sl@0
|
728 |
switch (iState)
|
sl@0
|
729 |
{
|
sl@0
|
730 |
case EOpenKey:
|
sl@0
|
731 |
keystore->CancelList();
|
sl@0
|
732 |
break;
|
sl@0
|
733 |
|
sl@0
|
734 |
case ESign:
|
sl@0
|
735 |
keystore->CancelOpen();
|
sl@0
|
736 |
break;
|
sl@0
|
737 |
|
sl@0
|
738 |
case EExportPublic:
|
sl@0
|
739 |
switch (iType)
|
sl@0
|
740 |
{
|
sl@0
|
741 |
case ERSASign:
|
sl@0
|
742 |
ASSERT(iRSASigner);
|
sl@0
|
743 |
iRSASigner->CancelSign();
|
sl@0
|
744 |
break;
|
sl@0
|
745 |
|
sl@0
|
746 |
case EDSASign:
|
sl@0
|
747 |
ASSERT(iDSASigner);
|
sl@0
|
748 |
iDSASigner->CancelSign();
|
sl@0
|
749 |
break;
|
sl@0
|
750 |
|
sl@0
|
751 |
default:
|
sl@0
|
752 |
break;
|
sl@0
|
753 |
}
|
sl@0
|
754 |
break;
|
sl@0
|
755 |
|
sl@0
|
756 |
case EVerify:
|
sl@0
|
757 |
keystore->CancelExportPublic();
|
sl@0
|
758 |
break;
|
sl@0
|
759 |
|
sl@0
|
760 |
default:
|
sl@0
|
761 |
break;
|
sl@0
|
762 |
}
|
sl@0
|
763 |
}
|
sl@0
|
764 |
|
sl@0
|
765 |
void CSign::Reset()
|
sl@0
|
766 |
{
|
sl@0
|
767 |
iState = EListKeysPreOpen;
|
sl@0
|
768 |
iKeys.Close();
|
sl@0
|
769 |
if (iRSASigner)
|
sl@0
|
770 |
{
|
sl@0
|
771 |
iRSASigner->Release();
|
sl@0
|
772 |
iRSASigner = NULL;
|
sl@0
|
773 |
}
|
sl@0
|
774 |
if (iDSASigner)
|
sl@0
|
775 |
{
|
sl@0
|
776 |
iDSASigner->Release();
|
sl@0
|
777 |
iDSASigner = NULL;
|
sl@0
|
778 |
}
|
sl@0
|
779 |
delete iExportedPublicKey;
|
sl@0
|
780 |
iExportedPublicKey = NULL;
|
sl@0
|
781 |
delete iRSASignature;
|
sl@0
|
782 |
iRSASignature = NULL;
|
sl@0
|
783 |
delete iDSASignature;
|
sl@0
|
784 |
iDSASignature = NULL;
|
sl@0
|
785 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
786 |
delete iSigner;
|
sl@0
|
787 |
iSigner = NULL;
|
sl@0
|
788 |
delete iSpiSignature;
|
sl@0
|
789 |
iSpiSignature = NULL;
|
sl@0
|
790 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
791 |
}
|
sl@0
|
792 |
|
sl@0
|
793 |
void CSign::DoReportAction()
|
sl@0
|
794 |
{
|
sl@0
|
795 |
_LIT(KSigning, "Signing... ");
|
sl@0
|
796 |
iOut.writeString(KSigning);
|
sl@0
|
797 |
iOut.writeNewLine();
|
sl@0
|
798 |
}
|
sl@0
|
799 |
|
sl@0
|
800 |
void CSign::DoCheckResult(TInt aError)
|
sl@0
|
801 |
{
|
sl@0
|
802 |
if (iFinished)
|
sl@0
|
803 |
{
|
sl@0
|
804 |
TBuf<256> buf;
|
sl@0
|
805 |
if (aError == KErrNone)
|
sl@0
|
806 |
{
|
sl@0
|
807 |
iOut.writeNewLine();
|
sl@0
|
808 |
_LIT(KSuccessful, "Sign success\n");
|
sl@0
|
809 |
buf.Format(KSuccessful);
|
sl@0
|
810 |
iConsole.Write(buf);
|
sl@0
|
811 |
iOut.writeString(buf);
|
sl@0
|
812 |
iOut.writeNewLine();
|
sl@0
|
813 |
}
|
sl@0
|
814 |
else
|
sl@0
|
815 |
{
|
sl@0
|
816 |
if (aError!=iExpectedResult)
|
sl@0
|
817 |
{
|
sl@0
|
818 |
_LIT(KFailed, "!!!Sign failure %d!!!\n");
|
sl@0
|
819 |
buf.Format(KFailed, aError);
|
sl@0
|
820 |
iConsole.Write(buf);
|
sl@0
|
821 |
iOut.writeString(buf);
|
sl@0
|
822 |
}
|
sl@0
|
823 |
else
|
sl@0
|
824 |
{
|
sl@0
|
825 |
_LIT(KFailed, "Sign failed, but expected\n");
|
sl@0
|
826 |
iConsole.Write(KFailed);
|
sl@0
|
827 |
iOut.writeString(KFailed);
|
sl@0
|
828 |
}
|
sl@0
|
829 |
|
sl@0
|
830 |
iOut.writeNewLine();
|
sl@0
|
831 |
}
|
sl@0
|
832 |
}
|
sl@0
|
833 |
}
|
sl@0
|
834 |
|
sl@0
|
835 |
CSign::CSign(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
sl@0
|
836 |
: CKeyStoreTestAction(aFs, aConsole, aOut)
|
sl@0
|
837 |
{}
|
sl@0
|
838 |
|
sl@0
|
839 |
void CSign::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
840 |
{
|
sl@0
|
841 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
842 |
|
sl@0
|
843 |
SetDigestSignL(Input::ParseElement(aTestActionSpec.iActionBody, KSignDigestStart));
|
sl@0
|
844 |
SetSignText(Input::ParseElement(aTestActionSpec.iActionBody, KTextStart, KTextEnd));
|
sl@0
|
845 |
|
sl@0
|
846 |
iFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
|
sl@0
|
847 |
|
sl@0
|
848 |
iState = EListKeysPreOpen;
|
sl@0
|
849 |
|
sl@0
|
850 |
}
|
sl@0
|
851 |
|
sl@0
|
852 |
void CSign::SetDigestSignL(const TDesC8& aSignDigestDesc)
|
sl@0
|
853 |
{
|
sl@0
|
854 |
TLex8 lexer(aSignDigestDesc);
|
sl@0
|
855 |
TInt digest = 0;
|
sl@0
|
856 |
lexer.Val(digest);
|
sl@0
|
857 |
|
sl@0
|
858 |
if (digest > 0)
|
sl@0
|
859 |
iHash = CMessageDigestFactory::NewDigestL(CMessageDigest::ESHA1);
|
sl@0
|
860 |
|
sl@0
|
861 |
if (digest==2)
|
sl@0
|
862 |
iFailHashDigest = ETrue;
|
sl@0
|
863 |
}
|
sl@0
|
864 |
|
sl@0
|
865 |
void CSign::SetSignText(const TDesC8& aText)
|
sl@0
|
866 |
{
|
sl@0
|
867 |
iReadText = HBufC8::NewMax(aText.Size());
|
sl@0
|
868 |
if (iReadText)
|
sl@0
|
869 |
{
|
sl@0
|
870 |
TPtr8 theText(iReadText->Des());
|
sl@0
|
871 |
theText.FillZ();
|
sl@0
|
872 |
theText.Copy(aText);
|
sl@0
|
873 |
}
|
sl@0
|
874 |
}
|
sl@0
|
875 |
|
sl@0
|
876 |
////////////////////////////////////
|
sl@0
|
877 |
// CDecrypt
|
sl@0
|
878 |
////////////////////////////////////
|
sl@0
|
879 |
/*static*/ CTestAction* CDecrypt::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
880 |
{
|
sl@0
|
881 |
CTestAction* self = CDecrypt::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
882 |
CleanupStack::Pop(self);
|
sl@0
|
883 |
return self;
|
sl@0
|
884 |
}
|
sl@0
|
885 |
|
sl@0
|
886 |
/*static*/ CTestAction* CDecrypt::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
887 |
{
|
sl@0
|
888 |
CDecrypt* self = new (ELeave) CDecrypt(aFs, aConsole, aOut);
|
sl@0
|
889 |
CleanupStack::PushL(self);
|
sl@0
|
890 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
891 |
return self;
|
sl@0
|
892 |
}
|
sl@0
|
893 |
|
sl@0
|
894 |
CDecrypt::~CDecrypt()
|
sl@0
|
895 |
{
|
sl@0
|
896 |
iKeys.Close();
|
sl@0
|
897 |
delete iReadText;
|
sl@0
|
898 |
delete iPlainText;
|
sl@0
|
899 |
delete iPublic;
|
sl@0
|
900 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
901 |
delete iDecrypt;
|
sl@0
|
902 |
#endif
|
sl@0
|
903 |
}
|
sl@0
|
904 |
|
sl@0
|
905 |
void CDecrypt::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
906 |
{
|
sl@0
|
907 |
// Jump straight to final state if an error occured
|
sl@0
|
908 |
if (aStatus.Int()!=KErrNone)
|
sl@0
|
909 |
{
|
sl@0
|
910 |
iState=EFinished;
|
sl@0
|
911 |
}
|
sl@0
|
912 |
|
sl@0
|
913 |
switch (iState)
|
sl@0
|
914 |
{
|
sl@0
|
915 |
case EListKeysPreOpen:
|
sl@0
|
916 |
{// Currently uses the first store, change to check the script for a specific store
|
sl@0
|
917 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
918 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
919 |
if (keyStore)
|
sl@0
|
920 |
keyStore->List(iKeys, iFilter, aStatus);
|
sl@0
|
921 |
|
sl@0
|
922 |
iState = EOpenKey;
|
sl@0
|
923 |
}
|
sl@0
|
924 |
break;
|
sl@0
|
925 |
|
sl@0
|
926 |
case EOpenKey:
|
sl@0
|
927 |
{
|
sl@0
|
928 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
929 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
930 |
|
sl@0
|
931 |
TInt keyCount = iKeys.Count();
|
sl@0
|
932 |
TInt i;
|
sl@0
|
933 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
934 |
{
|
sl@0
|
935 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
936 |
|
sl@0
|
937 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
938 |
{
|
sl@0
|
939 |
switch(iType)
|
sl@0
|
940 |
{
|
sl@0
|
941 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
942 |
case EECC:
|
sl@0
|
943 |
if(iHardwareType == 0)
|
sl@0
|
944 |
{
|
sl@0
|
945 |
keyStore->Open(keyInfo->Handle(), iDecrypt, aStatus);
|
sl@0
|
946 |
}
|
sl@0
|
947 |
else if(iHardwareType == 1 )
|
sl@0
|
948 |
{
|
sl@0
|
949 |
/**
|
sl@0
|
950 |
* Call the decrypt of hardware directly. iPlainText
|
sl@0
|
951 |
* would be populated.
|
sl@0
|
952 |
*/
|
sl@0
|
953 |
keyStore->Decrypt(keyInfo->Handle(), *iReadText, iPlainText, aStatus);
|
sl@0
|
954 |
}
|
sl@0
|
955 |
break;
|
sl@0
|
956 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
957 |
default:
|
sl@0
|
958 |
{
|
sl@0
|
959 |
keyStore->Open(*keyInfo, iDecryptor, aStatus);
|
sl@0
|
960 |
}
|
sl@0
|
961 |
} // switch
|
sl@0
|
962 |
break;
|
sl@0
|
963 |
} // if
|
sl@0
|
964 |
} // for
|
sl@0
|
965 |
|
sl@0
|
966 |
iState = EExportPublic;
|
sl@0
|
967 |
if (i == keyCount)
|
sl@0
|
968 |
{
|
sl@0
|
969 |
TRequestStatus* status = &aStatus;
|
sl@0
|
970 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
971 |
}
|
sl@0
|
972 |
}
|
sl@0
|
973 |
break;
|
sl@0
|
974 |
|
sl@0
|
975 |
case EExportPublic:
|
sl@0
|
976 |
{
|
sl@0
|
977 |
if (aStatus.Int()!=KErrNone)
|
sl@0
|
978 |
{
|
sl@0
|
979 |
_LIT(KSignFail," !Failed when opening! ");
|
sl@0
|
980 |
iOut.writeString(KSignFail);
|
sl@0
|
981 |
iState=EFinished;
|
sl@0
|
982 |
// need to set it to true so that test is true if some error was expected
|
sl@0
|
983 |
iVerifyResult=ETrue;
|
sl@0
|
984 |
TRequestStatus* status = &aStatus;
|
sl@0
|
985 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
986 |
break;
|
sl@0
|
987 |
}
|
sl@0
|
988 |
|
sl@0
|
989 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
990 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
991 |
|
sl@0
|
992 |
TInt keyCount = iKeys.Count();
|
sl@0
|
993 |
TInt i;
|
sl@0
|
994 |
|
sl@0
|
995 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
996 |
{
|
sl@0
|
997 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
998 |
|
sl@0
|
999 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
1000 |
{
|
sl@0
|
1001 |
iExportHandle = keyInfo->Handle();
|
sl@0
|
1002 |
|
sl@0
|
1003 |
keyStore->ExportPublic(iExportHandle, iPublic, aStatus);
|
sl@0
|
1004 |
break;
|
sl@0
|
1005 |
}
|
sl@0
|
1006 |
}
|
sl@0
|
1007 |
iState = EDecrypt;
|
sl@0
|
1008 |
if (i == keyCount)
|
sl@0
|
1009 |
{
|
sl@0
|
1010 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1011 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
1012 |
}
|
sl@0
|
1013 |
}
|
sl@0
|
1014 |
break;
|
sl@0
|
1015 |
|
sl@0
|
1016 |
case EDecrypt:
|
sl@0
|
1017 |
{
|
sl@0
|
1018 |
|
sl@0
|
1019 |
if (aStatus.Int()!=KErrNone)
|
sl@0
|
1020 |
{
|
sl@0
|
1021 |
iState=EFinished;
|
sl@0
|
1022 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1023 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
1024 |
break;
|
sl@0
|
1025 |
}
|
sl@0
|
1026 |
switch(iType)
|
sl@0
|
1027 |
{
|
sl@0
|
1028 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
1029 |
case EECC:
|
sl@0
|
1030 |
{
|
sl@0
|
1031 |
if(iHardwareType)
|
sl@0
|
1032 |
{
|
sl@0
|
1033 |
if(*iPlainText == *iPublic)
|
sl@0
|
1034 |
{
|
sl@0
|
1035 |
aStatus = KErrNone;
|
sl@0
|
1036 |
}
|
sl@0
|
1037 |
else
|
sl@0
|
1038 |
{
|
sl@0
|
1039 |
aStatus = KErrGeneral;
|
sl@0
|
1040 |
}
|
sl@0
|
1041 |
}
|
sl@0
|
1042 |
else
|
sl@0
|
1043 |
{
|
sl@0
|
1044 |
aStatus = KErrGeneral;
|
sl@0
|
1045 |
if (iDecrypt)
|
sl@0
|
1046 |
{
|
sl@0
|
1047 |
HBufC8* decryptedText = NULL;
|
sl@0
|
1048 |
TRAPD(err, decryptedText = HBufC8::NewL(iDecrypt->GetMaximumOutputLengthL()));
|
sl@0
|
1049 |
|
sl@0
|
1050 |
if (err == KErrNone)
|
sl@0
|
1051 |
{
|
sl@0
|
1052 |
CleanupStack::PushL(decryptedText);
|
sl@0
|
1053 |
TPtr8 decryptedTextPtr = decryptedText->Des();
|
sl@0
|
1054 |
|
sl@0
|
1055 |
TRAP(err, (iDecrypt->ProcessL(*iReadText, decryptedTextPtr)));
|
sl@0
|
1056 |
if(err != KErrNone)
|
sl@0
|
1057 |
{
|
sl@0
|
1058 |
aStatus = err;
|
sl@0
|
1059 |
}
|
sl@0
|
1060 |
if ((err == KErrNone) && (decryptedTextPtr
|
sl@0
|
1061 |
== iPublic->Des()))
|
sl@0
|
1062 |
{
|
sl@0
|
1063 |
aStatus = KErrNone;
|
sl@0
|
1064 |
}
|
sl@0
|
1065 |
CleanupStack::PopAndDestroy(decryptedText);
|
sl@0
|
1066 |
}
|
sl@0
|
1067 |
else
|
sl@0
|
1068 |
{
|
sl@0
|
1069 |
aStatus = err;
|
sl@0
|
1070 |
}
|
sl@0
|
1071 |
}
|
sl@0
|
1072 |
}
|
sl@0
|
1073 |
iState = EFinished;
|
sl@0
|
1074 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1075 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
1076 |
}
|
sl@0
|
1077 |
break;
|
sl@0
|
1078 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
1079 |
default:
|
sl@0
|
1080 |
{
|
sl@0
|
1081 |
CX509SubjectPublicKeyInfo* ki =
|
sl@0
|
1082 |
CX509SubjectPublicKeyInfo::NewLC(*iPublic);
|
sl@0
|
1083 |
|
sl@0
|
1084 |
TX509KeyFactory factory;
|
sl@0
|
1085 |
CRSAPublicKey* key = factory.RSAPublicKeyL(ki->KeyData());
|
sl@0
|
1086 |
CleanupStack::PushL(key);
|
sl@0
|
1087 |
|
sl@0
|
1088 |
// Encrypt with public key
|
sl@0
|
1089 |
CRSAPKCS1v15Encryptor* encryptor = CRSAPKCS1v15Encryptor::NewLC(*key);
|
sl@0
|
1090 |
HBufC8* cipherText = HBufC8::NewLC(encryptor->MaxOutputLength());
|
sl@0
|
1091 |
TPtr8 cipherTextPtr = cipherText->Des();
|
sl@0
|
1092 |
|
sl@0
|
1093 |
encryptor->EncryptL(*iReadText, cipherTextPtr);
|
sl@0
|
1094 |
|
sl@0
|
1095 |
// Now decrypt again
|
sl@0
|
1096 |
iPlainText = HBufC8::NewMaxL(100);
|
sl@0
|
1097 |
iPlainTextPtr.Set(iPlainText->Des());
|
sl@0
|
1098 |
iDecryptor->Decrypt(*cipherText, iPlainTextPtr, aStatus);
|
sl@0
|
1099 |
|
sl@0
|
1100 |
CleanupStack::PopAndDestroy(cipherText);
|
sl@0
|
1101 |
CleanupStack::PopAndDestroy(encryptor);
|
sl@0
|
1102 |
CleanupStack::PopAndDestroy(key);
|
sl@0
|
1103 |
CleanupStack::PopAndDestroy(ki);
|
sl@0
|
1104 |
|
sl@0
|
1105 |
iState = EFinished;
|
sl@0
|
1106 |
}
|
sl@0
|
1107 |
} // switch
|
sl@0
|
1108 |
}
|
sl@0
|
1109 |
break;
|
sl@0
|
1110 |
|
sl@0
|
1111 |
case EFinished:
|
sl@0
|
1112 |
{
|
sl@0
|
1113 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
1114 |
if(iType == EECC)
|
sl@0
|
1115 |
{
|
sl@0
|
1116 |
iActionState = EPostrequisite;
|
sl@0
|
1117 |
iResult = (aStatus.Int() == iExpectedResult);
|
sl@0
|
1118 |
|
sl@0
|
1119 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1120 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
1121 |
}
|
sl@0
|
1122 |
else
|
sl@0
|
1123 |
#endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC
|
sl@0
|
1124 |
{
|
sl@0
|
1125 |
if (aStatus == KErrNone && (!iPlainText ||
|
sl@0
|
1126 |
*iPlainText != *iReadText))
|
sl@0
|
1127 |
{
|
sl@0
|
1128 |
aStatus = KErrGeneral; // Decryption failed
|
sl@0
|
1129 |
}
|
sl@0
|
1130 |
|
sl@0
|
1131 |
iActionState = EPostrequisite;
|
sl@0
|
1132 |
iResult = (aStatus.Int() == iExpectedResult);
|
sl@0
|
1133 |
|
sl@0
|
1134 |
if (iDecryptor)
|
sl@0
|
1135 |
{
|
sl@0
|
1136 |
iDecryptor->Release();
|
sl@0
|
1137 |
}
|
sl@0
|
1138 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1139 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
1140 |
}
|
sl@0
|
1141 |
}
|
sl@0
|
1142 |
break;
|
sl@0
|
1143 |
default:
|
sl@0
|
1144 |
ASSERT(EFalse);
|
sl@0
|
1145 |
}
|
sl@0
|
1146 |
|
sl@0
|
1147 |
}
|
sl@0
|
1148 |
|
sl@0
|
1149 |
void CDecrypt::PerformCancel()
|
sl@0
|
1150 |
{
|
sl@0
|
1151 |
CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
1152 |
ASSERT(keystore);
|
sl@0
|
1153 |
|
sl@0
|
1154 |
switch (iState)
|
sl@0
|
1155 |
{
|
sl@0
|
1156 |
case EOpenKey:
|
sl@0
|
1157 |
keystore->CancelList();
|
sl@0
|
1158 |
break;
|
sl@0
|
1159 |
|
sl@0
|
1160 |
case EExportPublic:
|
sl@0
|
1161 |
keystore->CancelOpen();
|
sl@0
|
1162 |
break;
|
sl@0
|
1163 |
|
sl@0
|
1164 |
case EDecrypt:
|
sl@0
|
1165 |
keystore->CancelExportPublic();
|
sl@0
|
1166 |
break;
|
sl@0
|
1167 |
|
sl@0
|
1168 |
case EFinished:
|
sl@0
|
1169 |
ASSERT(iDecryptor);
|
sl@0
|
1170 |
iDecryptor->CancelDecrypt();
|
sl@0
|
1171 |
break;
|
sl@0
|
1172 |
|
sl@0
|
1173 |
default:
|
sl@0
|
1174 |
break;
|
sl@0
|
1175 |
}
|
sl@0
|
1176 |
}
|
sl@0
|
1177 |
|
sl@0
|
1178 |
void CDecrypt::Reset()
|
sl@0
|
1179 |
{
|
sl@0
|
1180 |
iState = EListKeysPreOpen;
|
sl@0
|
1181 |
iKeys.Close();
|
sl@0
|
1182 |
if (iDecryptor)
|
sl@0
|
1183 |
{
|
sl@0
|
1184 |
iDecryptor->Release();
|
sl@0
|
1185 |
iDecryptor = NULL;
|
sl@0
|
1186 |
}
|
sl@0
|
1187 |
delete iPlainText;
|
sl@0
|
1188 |
iPlainText = NULL;
|
sl@0
|
1189 |
delete iPublic;
|
sl@0
|
1190 |
iPublic = NULL;
|
sl@0
|
1191 |
#if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC))
|
sl@0
|
1192 |
delete iDecrypt;
|
sl@0
|
1193 |
iDecrypt = NULL;
|
sl@0
|
1194 |
#endif
|
sl@0
|
1195 |
}
|
sl@0
|
1196 |
|
sl@0
|
1197 |
void CDecrypt::DoReportAction()
|
sl@0
|
1198 |
{
|
sl@0
|
1199 |
_LIT(KSigning, "Decrypting... ");
|
sl@0
|
1200 |
iOut.writeString(KSigning);
|
sl@0
|
1201 |
iOut.writeNewLine();
|
sl@0
|
1202 |
}
|
sl@0
|
1203 |
|
sl@0
|
1204 |
void CDecrypt::DoCheckResult(TInt aError)
|
sl@0
|
1205 |
{
|
sl@0
|
1206 |
if (iFinished)
|
sl@0
|
1207 |
{
|
sl@0
|
1208 |
TBuf<256> buf;
|
sl@0
|
1209 |
if (aError == KErrNone)
|
sl@0
|
1210 |
{
|
sl@0
|
1211 |
iOut.writeNewLine();
|
sl@0
|
1212 |
_LIT(KSuccessful, "Decrypt success\n");
|
sl@0
|
1213 |
buf.Format(KSuccessful);
|
sl@0
|
1214 |
iConsole.Write(buf);
|
sl@0
|
1215 |
iOut.writeString(buf);
|
sl@0
|
1216 |
iOut.writeNewLine();
|
sl@0
|
1217 |
}
|
sl@0
|
1218 |
else
|
sl@0
|
1219 |
{
|
sl@0
|
1220 |
if (aError!=iExpectedResult)
|
sl@0
|
1221 |
{
|
sl@0
|
1222 |
_LIT(KFailed, "!!!Decrypt failure %d!!!\n");
|
sl@0
|
1223 |
buf.Format(KFailed, aError);
|
sl@0
|
1224 |
iConsole.Write(buf);
|
sl@0
|
1225 |
iOut.writeString(buf);
|
sl@0
|
1226 |
}
|
sl@0
|
1227 |
else
|
sl@0
|
1228 |
{
|
sl@0
|
1229 |
_LIT(KFailed, "Decrypt failed, but expected\n");
|
sl@0
|
1230 |
iConsole.Write(KFailed);
|
sl@0
|
1231 |
iOut.writeString(KFailed);
|
sl@0
|
1232 |
}
|
sl@0
|
1233 |
|
sl@0
|
1234 |
iOut.writeNewLine();
|
sl@0
|
1235 |
}
|
sl@0
|
1236 |
}
|
sl@0
|
1237 |
}
|
sl@0
|
1238 |
|
sl@0
|
1239 |
CDecrypt::CDecrypt(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
sl@0
|
1240 |
: CKeyStoreTestAction(aFs, aConsole, aOut), iPlainTextPtr(0,0)
|
sl@0
|
1241 |
{}
|
sl@0
|
1242 |
|
sl@0
|
1243 |
void CDecrypt::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
1244 |
{
|
sl@0
|
1245 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
1246 |
|
sl@0
|
1247 |
SetSignText(Input::ParseElement(aTestActionSpec.iActionBody, KTextStart));
|
sl@0
|
1248 |
iFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
|
sl@0
|
1249 |
|
sl@0
|
1250 |
iState = EListKeysPreOpen;
|
sl@0
|
1251 |
}
|
sl@0
|
1252 |
|
sl@0
|
1253 |
void CDecrypt::SetSignText(const TDesC8& aText)
|
sl@0
|
1254 |
{
|
sl@0
|
1255 |
iReadText = HBufC8::NewMax(aText.Size());
|
sl@0
|
1256 |
if (iReadText)
|
sl@0
|
1257 |
{
|
sl@0
|
1258 |
TPtr8 theText(iReadText->Des());
|
sl@0
|
1259 |
theText.FillZ();
|
sl@0
|
1260 |
theText.Copy(aText);
|
sl@0
|
1261 |
}
|
sl@0
|
1262 |
}
|
sl@0
|
1263 |
|
sl@0
|
1264 |
////////////////////////////////////
|
sl@0
|
1265 |
// CDerive
|
sl@0
|
1266 |
////////////////////////////////////
|
sl@0
|
1267 |
|
sl@0
|
1268 |
/*static*/ CTestAction* CDerive::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
1269 |
{
|
sl@0
|
1270 |
CTestAction* self = CDerive::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
1271 |
CleanupStack::Pop(self);
|
sl@0
|
1272 |
return self;
|
sl@0
|
1273 |
}
|
sl@0
|
1274 |
|
sl@0
|
1275 |
/*static*/ CTestAction* CDerive::NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
1276 |
{
|
sl@0
|
1277 |
CDerive* self = new (ELeave) CDerive(aFs, aConsole, aOut);
|
sl@0
|
1278 |
CleanupStack::PushL(self);
|
sl@0
|
1279 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
1280 |
return self;
|
sl@0
|
1281 |
}
|
sl@0
|
1282 |
|
sl@0
|
1283 |
CDerive::~CDerive()
|
sl@0
|
1284 |
{
|
sl@0
|
1285 |
iKeys.Close();
|
sl@0
|
1286 |
iN.Close();
|
sl@0
|
1287 |
iG.Close();
|
sl@0
|
1288 |
if (iDH)
|
sl@0
|
1289 |
{
|
sl@0
|
1290 |
iDH->Release();
|
sl@0
|
1291 |
}
|
sl@0
|
1292 |
delete iPublicKey;
|
sl@0
|
1293 |
delete iOutput;
|
sl@0
|
1294 |
delete iRemote;
|
sl@0
|
1295 |
}
|
sl@0
|
1296 |
|
sl@0
|
1297 |
void CDerive::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
1298 |
{
|
sl@0
|
1299 |
// Jump straight to final state if an error occured
|
sl@0
|
1300 |
if (aStatus.Int()!=KErrNone)
|
sl@0
|
1301 |
{
|
sl@0
|
1302 |
iState=EFinished;
|
sl@0
|
1303 |
}
|
sl@0
|
1304 |
|
sl@0
|
1305 |
switch (iState)
|
sl@0
|
1306 |
{
|
sl@0
|
1307 |
case EListKeysPreOpen:
|
sl@0
|
1308 |
{
|
sl@0
|
1309 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
1310 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
1311 |
if (keyStore)
|
sl@0
|
1312 |
keyStore->List(iKeys, iFilter, aStatus);
|
sl@0
|
1313 |
|
sl@0
|
1314 |
iState = EOpenKey;
|
sl@0
|
1315 |
}
|
sl@0
|
1316 |
break;
|
sl@0
|
1317 |
|
sl@0
|
1318 |
case EOpenKey:
|
sl@0
|
1319 |
{
|
sl@0
|
1320 |
CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
1321 |
ASSERT(keyStore); // Flag it up
|
sl@0
|
1322 |
|
sl@0
|
1323 |
TInt keyCount = iKeys.Count();
|
sl@0
|
1324 |
|
sl@0
|
1325 |
TInt i;
|
sl@0
|
1326 |
for (i = 0; i < keyCount; i++)
|
sl@0
|
1327 |
{
|
sl@0
|
1328 |
CCTKeyInfo* keyInfo = iKeys[i];
|
sl@0
|
1329 |
|
sl@0
|
1330 |
if (keyInfo->Label() == *iLabel)
|
sl@0
|
1331 |
{
|
sl@0
|
1332 |
keyStore->Open(*keyInfo, iDH, aStatus);
|
sl@0
|
1333 |
break;
|
sl@0
|
1334 |
}
|
sl@0
|
1335 |
}
|
sl@0
|
1336 |
iState = EExportPublic;
|
sl@0
|
1337 |
if (i == keyCount)
|
sl@0
|
1338 |
{
|
sl@0
|
1339 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1340 |
User::RequestComplete(status, KErrNotFound);
|
sl@0
|
1341 |
}
|
sl@0
|
1342 |
}
|
sl@0
|
1343 |
break;
|
sl@0
|
1344 |
|
sl@0
|
1345 |
case EExportPublic:
|
sl@0
|
1346 |
{
|
sl@0
|
1347 |
ASSERT(iDH);
|
sl@0
|
1348 |
iDH->PublicKey(iN, iG, iPublicKey, aStatus);
|
sl@0
|
1349 |
iState = EDerive;
|
sl@0
|
1350 |
}
|
sl@0
|
1351 |
break;
|
sl@0
|
1352 |
|
sl@0
|
1353 |
case EDerive:
|
sl@0
|
1354 |
{
|
sl@0
|
1355 |
if (aStatus.Int()!=KErrNone)
|
sl@0
|
1356 |
{
|
sl@0
|
1357 |
iState=EFinished;
|
sl@0
|
1358 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1359 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
1360 |
break;
|
sl@0
|
1361 |
}
|
sl@0
|
1362 |
|
sl@0
|
1363 |
ASSERT(iPublicKey);
|
sl@0
|
1364 |
iDH->Agree(iRemote->PublicKey(), iOutput, aStatus);
|
sl@0
|
1365 |
|
sl@0
|
1366 |
iState = EFinished;
|
sl@0
|
1367 |
}
|
sl@0
|
1368 |
break;
|
sl@0
|
1369 |
|
sl@0
|
1370 |
case EFinished:
|
sl@0
|
1371 |
{
|
sl@0
|
1372 |
if (aStatus.Int()==KErrNone)
|
sl@0
|
1373 |
{
|
sl@0
|
1374 |
CDH* dh = CDH::NewLC(iRemote->PrivateKey());
|
sl@0
|
1375 |
const HBufC8* output = dh->AgreeL(*iPublicKey);
|
sl@0
|
1376 |
CleanupStack::PopAndDestroy(dh);
|
sl@0
|
1377 |
|
sl@0
|
1378 |
if (aStatus == KErrNone && (!iOutput ||
|
sl@0
|
1379 |
*iOutput != *output))
|
sl@0
|
1380 |
{
|
sl@0
|
1381 |
aStatus = KErrGeneral; // Agree failed
|
sl@0
|
1382 |
}
|
sl@0
|
1383 |
|
sl@0
|
1384 |
delete const_cast<HBufC8*>(output);
|
sl@0
|
1385 |
}
|
sl@0
|
1386 |
|
sl@0
|
1387 |
iActionState = EPostrequisite;
|
sl@0
|
1388 |
iResult = (aStatus.Int() == iExpectedResult);
|
sl@0
|
1389 |
|
sl@0
|
1390 |
if (aStatus != KErrNone)
|
sl@0
|
1391 |
{
|
sl@0
|
1392 |
_LIT(KSignFail," !Failed when agreeing key!");
|
sl@0
|
1393 |
iOut.writeString(KSignFail);
|
sl@0
|
1394 |
}
|
sl@0
|
1395 |
|
sl@0
|
1396 |
TRequestStatus* status = &aStatus;
|
sl@0
|
1397 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
1398 |
}
|
sl@0
|
1399 |
break;
|
sl@0
|
1400 |
default:
|
sl@0
|
1401 |
ASSERT(EFalse);
|
sl@0
|
1402 |
}
|
sl@0
|
1403 |
}
|
sl@0
|
1404 |
|
sl@0
|
1405 |
void CDerive::PerformCancel()
|
sl@0
|
1406 |
{
|
sl@0
|
1407 |
CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
|
sl@0
|
1408 |
ASSERT(keystore);
|
sl@0
|
1409 |
|
sl@0
|
1410 |
switch (iState)
|
sl@0
|
1411 |
{
|
sl@0
|
1412 |
case EOpenKey:
|
sl@0
|
1413 |
keystore->CancelList();
|
sl@0
|
1414 |
break;
|
sl@0
|
1415 |
|
sl@0
|
1416 |
case EExportPublic:
|
sl@0
|
1417 |
keystore->CancelOpen();
|
sl@0
|
1418 |
break;
|
sl@0
|
1419 |
|
sl@0
|
1420 |
case EDerive:
|
sl@0
|
1421 |
keystore->CancelExportPublic();
|
sl@0
|
1422 |
break;
|
sl@0
|
1423 |
|
sl@0
|
1424 |
case EFinished:
|
sl@0
|
1425 |
ASSERT(iDH);
|
sl@0
|
1426 |
iDH->CancelAgreement();
|
sl@0
|
1427 |
break;
|
sl@0
|
1428 |
|
sl@0
|
1429 |
default:
|
sl@0
|
1430 |
break;
|
sl@0
|
1431 |
}
|
sl@0
|
1432 |
}
|
sl@0
|
1433 |
|
sl@0
|
1434 |
void CDerive::Reset()
|
sl@0
|
1435 |
{
|
sl@0
|
1436 |
iState = EListKeysPreOpen;
|
sl@0
|
1437 |
iKeys.Close();
|
sl@0
|
1438 |
if (iDH)
|
sl@0
|
1439 |
{
|
sl@0
|
1440 |
iDH->Release();
|
sl@0
|
1441 |
iDH = NULL;
|
sl@0
|
1442 |
}
|
sl@0
|
1443 |
delete iPublicKey;
|
sl@0
|
1444 |
iPublicKey = NULL;
|
sl@0
|
1445 |
delete iOutput;
|
sl@0
|
1446 |
iOutput = NULL;
|
sl@0
|
1447 |
}
|
sl@0
|
1448 |
|
sl@0
|
1449 |
void CDerive::DoReportAction()
|
sl@0
|
1450 |
{
|
sl@0
|
1451 |
_LIT(KSigning, "Deriving key... ");
|
sl@0
|
1452 |
iOut.writeString(KSigning);
|
sl@0
|
1453 |
iOut.writeNewLine();
|
sl@0
|
1454 |
}
|
sl@0
|
1455 |
|
sl@0
|
1456 |
void CDerive::DoCheckResult(TInt aError)
|
sl@0
|
1457 |
{
|
sl@0
|
1458 |
if (iFinished)
|
sl@0
|
1459 |
{
|
sl@0
|
1460 |
TBuf<256> buf;
|
sl@0
|
1461 |
if (aError == KErrNone)
|
sl@0
|
1462 |
{
|
sl@0
|
1463 |
iOut.writeNewLine();
|
sl@0
|
1464 |
_LIT(KSuccessful, "Derive success\n");
|
sl@0
|
1465 |
buf.Format(KSuccessful);
|
sl@0
|
1466 |
iConsole.Write(buf);
|
sl@0
|
1467 |
iOut.writeString(buf);
|
sl@0
|
1468 |
iOut.writeNewLine();
|
sl@0
|
1469 |
}
|
sl@0
|
1470 |
else
|
sl@0
|
1471 |
{
|
sl@0
|
1472 |
if (aError!=iExpectedResult)
|
sl@0
|
1473 |
{
|
sl@0
|
1474 |
_LIT(KFailed, "!!!Derive failure %d!!!\n");
|
sl@0
|
1475 |
buf.Format(KFailed, aError);
|
sl@0
|
1476 |
iConsole.Write(buf);
|
sl@0
|
1477 |
iOut.writeString(buf);
|
sl@0
|
1478 |
}
|
sl@0
|
1479 |
else
|
sl@0
|
1480 |
{
|
sl@0
|
1481 |
_LIT(KFailed, "Derive failed, but expected\n");
|
sl@0
|
1482 |
iConsole.Write(KFailed);
|
sl@0
|
1483 |
iOut.writeString(KFailed);
|
sl@0
|
1484 |
}
|
sl@0
|
1485 |
|
sl@0
|
1486 |
iOut.writeNewLine();
|
sl@0
|
1487 |
}
|
sl@0
|
1488 |
}
|
sl@0
|
1489 |
}
|
sl@0
|
1490 |
|
sl@0
|
1491 |
CDerive::CDerive(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
sl@0
|
1492 |
: CKeyStoreTestAction(aFs, aConsole, aOut)
|
sl@0
|
1493 |
{}
|
sl@0
|
1494 |
|
sl@0
|
1495 |
void CDerive::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
1496 |
{
|
sl@0
|
1497 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
1498 |
|
sl@0
|
1499 |
// Set parameters
|
sl@0
|
1500 |
HBufC8* nData = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<n>"));
|
sl@0
|
1501 |
CleanupStack::PushL(nData);
|
sl@0
|
1502 |
iN = RInteger::NewL(*nData);
|
sl@0
|
1503 |
CleanupStack::PopAndDestroy(nData);
|
sl@0
|
1504 |
HBufC8* gData = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<g>"));
|
sl@0
|
1505 |
CleanupStack::PushL(gData);
|
sl@0
|
1506 |
iG = RInteger::NewL(*gData);
|
sl@0
|
1507 |
CleanupStack::PopAndDestroy(gData);
|
sl@0
|
1508 |
|
sl@0
|
1509 |
// Generate 'remote' key pair
|
sl@0
|
1510 |
RInteger n = RInteger::NewL(iN);
|
sl@0
|
1511 |
CleanupStack::PushL(n);
|
sl@0
|
1512 |
RInteger g = RInteger::NewL(iG);
|
sl@0
|
1513 |
CleanupStack::PushL(g);
|
sl@0
|
1514 |
iRemote = CDHKeyPair::NewL(n, g);
|
sl@0
|
1515 |
CleanupStack::Pop(2); // n, g
|
sl@0
|
1516 |
|
sl@0
|
1517 |
iFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys;
|
sl@0
|
1518 |
|
sl@0
|
1519 |
iState = EListKeysPreOpen;
|
sl@0
|
1520 |
}
|