24 #include <asn1dec.h> |
24 #include <asn1dec.h> |
25 #include <x509cert.h> |
25 #include <x509cert.h> |
26 #include <x509keys.h> |
26 #include <x509keys.h> |
27 #include <asymmetrickeys.h> |
27 #include <asymmetrickeys.h> |
28 |
28 |
|
29 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
30 #include <cryptospidef.h> |
|
31 #include "cryptoasymmetriccipherapi.h" |
|
32 #include "cryptosignatureapi.h" |
|
33 #include <cryptospi/cryptoparams.h> |
|
34 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC && SYMBIAN_ENABLE_SDP_ECC |
|
35 |
29 /*static*/ CTestAction* COpenKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec) |
36 /*static*/ CTestAction* COpenKey::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec) |
30 { |
37 { |
31 CTestAction* self = COpenKey::NewLC(aFs, aConsole, aOut, aTestActionSpec); |
38 CTestAction* self = COpenKey::NewLC(aFs, aConsole, aOut, aTestActionSpec); |
32 CleanupStack::Pop(self); |
39 CleanupStack::Pop(self); |
33 return self; |
40 return self; |
87 keyStore->Open(*keyInfo, iDecryptor, aStatus); |
98 keyStore->Open(*keyInfo, iDecryptor, aStatus); |
88 break; |
99 break; |
89 case EDH: |
100 case EDH: |
90 keyStore->Open(*keyInfo, iDH, aStatus); |
101 keyStore->Open(*keyInfo, iDH, aStatus); |
91 break; |
102 break; |
|
103 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
104 case EECC: |
|
105 { |
|
106 ASSERT(iHardwareType); |
|
107 if(iOperationType == ESigning) |
|
108 { |
|
109 keyStore->Open(keyInfo->Handle(),iSigner,aStatus); |
|
110 } |
|
111 if(iOperationType == EDecryption) |
|
112 { |
|
113 keyStore->Open(keyInfo->Handle(),iDecrypt,aStatus); |
|
114 } |
|
115 break; |
|
116 } |
|
117 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
92 } |
118 } |
93 break; |
119 break; |
94 } |
120 } |
95 } |
121 } |
96 iState = EFinished; |
|
97 if (i == keyCount) |
122 if (i == keyCount) |
98 { |
123 { |
99 TRequestStatus* status = &aStatus; |
124 TRequestStatus* status = &aStatus; |
100 User::RequestComplete(status, KErrNotFound); |
125 User::RequestComplete(status, KErrNotFound); |
101 } |
126 } |
|
127 |
|
128 iState = EFinished; |
|
129 |
102 } |
130 } |
103 break; |
131 break; |
104 |
132 |
105 case EFinished: |
133 case EFinished: |
106 { |
134 { |
|
135 TInt completionCode = aStatus.Int(); |
107 HBufC* label = 0; |
136 HBufC* label = 0; |
108 iKeys.Close(); |
137 iKeys.Close(); |
109 if (aStatus.Int() == KErrNone) |
138 if (aStatus.Int() == KErrNone) |
110 { |
139 { |
111 switch (iType) |
140 switch (iType) |
112 { |
141 { |
113 case ERSASign: |
142 case ERSASign: |
114 if (iRSASigner) |
143 if (iRSASigner) |
|
144 { |
|
145 label = iRSASigner->Label().AllocLC(); |
|
146 iRSASigner->Release(); |
|
147 } |
|
148 break; |
|
149 case EDSASign: |
|
150 if (iDSASigner) |
|
151 { |
|
152 label = iDSASigner->Label().AllocLC(); |
|
153 iDSASigner->Release(); |
|
154 } |
|
155 break; |
|
156 case EDecrypt: |
|
157 if (iDecryptor) |
|
158 { |
|
159 label = iDecryptor->Label().AllocLC(); |
|
160 iDecryptor->Release(); |
|
161 } |
|
162 case EDH: |
|
163 if (iDH) |
|
164 { |
|
165 label = iDH->Label().AllocLC(); |
|
166 iDH->Release(); |
|
167 } |
|
168 break; |
|
169 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
170 case EECC: |
115 { |
171 { |
116 label = iRSASigner->Label().AllocLC(); |
172 ASSERT(iHardwareType); |
117 iRSASigner->Release(); |
173 if(iOperationType == ESigning && iSigner == NULL |
|
174 || iOperationType == EDecryption && iDecrypt == NULL) |
|
175 { |
|
176 completionCode = KErrGeneral; |
|
177 } |
|
178 break; |
118 } |
179 } |
119 break; |
180 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
120 case EDSASign: |
181 } // switch |
121 if (iDSASigner) |
182 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
122 { |
183 if(iHardwareType == 0) |
123 label = iDSASigner->Label().AllocLC(); |
184 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
124 iDSASigner->Release(); |
185 { |
125 } |
186 if (*label != *iLabel) |
126 break; |
187 aStatus = KErrBadName; |
127 case EDecrypt: |
188 CleanupStack::PopAndDestroy(label); |
128 if (iDecryptor) |
|
129 { |
|
130 label = iDecryptor->Label().AllocLC(); |
|
131 iDecryptor->Release(); |
|
132 } |
|
133 case EDH: |
|
134 if (iDH) |
|
135 { |
|
136 label = iDH->Label().AllocLC(); |
|
137 iDH->Release(); |
|
138 } |
|
139 break; |
|
140 } |
189 } |
141 if (*label != *iLabel) |
|
142 aStatus = KErrBadName; |
|
143 CleanupStack::PopAndDestroy(label); |
|
144 } |
190 } |
145 TRequestStatus* status = &aStatus; |
191 TRequestStatus* status = &aStatus; |
146 User::RequestComplete(status, aStatus.Int()); |
192 User::RequestComplete(status, completionCode); |
|
193 |
147 if (aStatus.Int()==iExpectedResult) |
194 if (aStatus.Int()==iExpectedResult) |
148 { |
195 { |
149 iResult = ETrue; |
196 iResult = ETrue; |
150 } |
197 } |
151 else |
198 else |
255 |
308 |
256 void COpenKey::ConstructL(const TTestActionSpec& aTestActionSpec) |
309 void COpenKey::ConstructL(const TTestActionSpec& aTestActionSpec) |
257 { |
310 { |
258 TInt pos = 0, err = 0; |
311 TInt pos = 0, err = 0; |
259 CKeyStoreTestAction::ConstructL(aTestActionSpec); |
312 CKeyStoreTestAction::ConstructL(aTestActionSpec); |
260 SetKeyType(Input::ParseElement(aTestActionSpec.iActionBody, KOpenStart, KOpenEnd, pos, err)); |
313 |
|
314 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
315 pos = 0; |
|
316 TPtrC8 operationType = Input::ParseElement(aTestActionSpec.iActionBody, KOperationTypeStart, KOperationTypeEnd, pos, err); |
|
317 if(operationType.Compare(_L8("sign")) == 0) |
|
318 { |
|
319 iOperationType = ESigning; |
|
320 } |
|
321 else if (operationType.Compare(_L8("decrypt")) == 0) |
|
322 { |
|
323 iOperationType = EDecryption; |
|
324 } |
|
325 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
|
326 |
261 iState = EListKeysPreOpen; |
327 iState = EListKeysPreOpen; |
262 |
328 |
263 } |
329 } |
264 void COpenKey::SetKeyType(const TDesC8& aKeyType) |
|
265 { |
|
266 if (aKeyType.Compare(KAlgRSA)==0) |
|
267 { |
|
268 iType = ERSASign; |
|
269 } |
|
270 else if (aKeyType.Compare(KAlgDSA)==0) |
|
271 { |
|
272 iType = EDSASign; |
|
273 } |
|
274 else if (aKeyType.Compare(KDecryptUsage)==0) |
|
275 { |
|
276 iType = EDecrypt; |
|
277 } |
|
278 else if (aKeyType.Compare(KAlgDH)==0) |
|
279 { |
|
280 iType = EDH; |
|
281 } |
|
282 } |
|
283 |
|
284 |
330 |
285 //////////////////////////////////// |
331 //////////////////////////////////// |
286 // CSign |
332 // CSign |
287 //////////////////////////////////// |
333 //////////////////////////////////// |
288 /*static*/ CTestAction* CSign::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec) |
334 /*static*/ CTestAction* CSign::NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, const TTestActionSpec& aTestActionSpec) |
317 { |
367 { |
318 iState=EFinished; |
368 iState=EFinished; |
319 } |
369 } |
320 |
370 |
321 switch (iState) |
371 switch (iState) |
322 { |
372 { |
323 case EListKeysPreOpen: |
373 case EListKeysPreOpen: |
324 { |
374 { |
325 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
375 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
326 ASSERT(keyStore); // Flag it up |
376 ASSERT(keyStore); // Flag it up |
327 if (keyStore) |
377 if (keyStore) |
328 keyStore->List(iKeys, iFilter, aStatus); |
378 keyStore->List(iKeys, iFilter, aStatus); |
329 |
|
330 iState = EOpenKey; |
379 iState = EOpenKey; |
331 } |
380 |
332 break; |
381 } |
|
382 break; |
333 |
383 |
334 case EOpenKey: |
384 case EOpenKey: |
335 { |
385 { |
336 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
386 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
337 ASSERT(keyStore); // Flag it up |
387 ASSERT(keyStore); // Flag it up |
338 |
388 TInt keyCount = iKeys.Count(); |
339 TInt keyCount = iKeys.Count(); |
389 |
340 |
390 TInt i; |
341 TInt i; |
391 for (i = 0; i < keyCount; i++) |
342 for (i = 0; i < keyCount; i++) |
392 { |
343 { |
393 CCTKeyInfo* keyInfo = iKeys[i]; |
344 CCTKeyInfo* keyInfo = iKeys[i]; |
394 |
345 |
395 if (keyInfo->Label() == *iLabel) |
346 if (keyInfo->Label() == *iLabel) |
396 { |
347 { |
397 switch (iType) |
348 switch (iType) |
398 { |
349 { |
|
350 case ERSASign: |
399 case ERSASign: |
351 keyStore->Open(*keyInfo, iRSASigner, aStatus); |
400 keyStore->Open(*keyInfo, iRSASigner, aStatus); |
352 break; |
401 break; |
353 case EDSASign: |
402 case EDSASign: |
354 keyStore->Open(*keyInfo, iDSASigner, aStatus); |
403 keyStore->Open(*keyInfo, iDSASigner, aStatus); |
355 break; |
404 break; |
356 case EDH: |
405 case EDH: |
357 case EDecrypt: |
406 case EDecrypt: |
358 break; // Nothing to do, for the compiler |
407 break; // Nothing to do, for the compiler |
|
408 |
|
409 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
410 case EECC: |
|
411 { |
|
412 iTokenHandle = keyInfo->Handle(); |
|
413 if(iHardwareType == 0) |
|
414 { |
|
415 keyStore->Open(iTokenHandle, iSigner, aStatus); |
|
416 } |
|
417 else |
|
418 { |
|
419 TRequestStatus* status = &aStatus; |
|
420 User::RequestComplete(status, KErrNone); |
|
421 } |
359 } |
422 } |
360 break; |
423 break; |
361 } |
424 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
362 } |
425 } |
363 iState = ESign; |
426 } // if |
364 if (i == keyCount) |
427 if (i == keyCount) |
365 { |
428 { |
366 TRequestStatus* status = &aStatus; |
429 TRequestStatus* status = &aStatus; |
367 User::RequestComplete(status, KErrNotFound); |
430 User::RequestComplete(status, KErrNotFound); |
368 } |
431 } |
369 } |
432 }// for |
|
433 iState = ESign; |
|
434 |
|
435 } |
370 break; |
436 break; |
371 |
437 |
372 case ESign: |
438 case ESign: |
373 { |
439 { |
374 switch (iType) |
440 switch (iType) |
401 { |
467 { |
402 iDSASigner->Sign(*iReadText,iDSASignature,aStatus); |
468 iDSASigner->Sign(*iReadText,iDSASignature,aStatus); |
403 } |
469 } |
404 } |
470 } |
405 break; |
471 break; |
|
472 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
473 case EECC: |
|
474 { |
|
475 TRAPD(err, iSpiSignature = CryptoSpi::CCryptoParams::NewL()); |
|
476 if(err == KErrNone) |
|
477 { |
|
478 if(iHardwareType) |
|
479 { |
|
480 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
|
481 ASSERT(keyStore); // Flag it up |
|
482 keyStore->Sign(iTokenHandle, *iReadText, iSpiSignature, aStatus); |
|
483 } |
|
484 else |
|
485 { |
|
486 if(iSigner) |
|
487 { |
|
488 TRAP(err, iSigner->SignL(*iReadText, *iSpiSignature)); |
|
489 aStatus = err; |
|
490 } |
|
491 TRequestStatus* status = &aStatus; |
|
492 User::RequestComplete(status, aStatus.Int()); |
|
493 } |
|
494 } |
|
495 else |
|
496 { |
|
497 aStatus = err; |
|
498 TRequestStatus* status = &aStatus; |
|
499 User::RequestComplete(status, aStatus.Int()); |
|
500 } |
|
501 } |
|
502 break; |
|
503 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
|
504 |
406 default: |
505 default: |
407 ASSERT(EFalse); |
506 ASSERT(EFalse); |
408 } |
507 } |
409 iState = EExportPublic; |
508 iState = EExportPublic; |
410 } |
509 } |
411 break; |
510 break; |
412 |
511 |
|
512 |
413 case EExportPublic: |
513 case EExportPublic: |
414 { |
514 { |
415 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
515 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
416 ASSERT(keyStore); // Flag it up |
516 ASSERT(keyStore); // Flag it up |
|
517 |
417 TInt keyCount = iKeys.Count(); |
518 TInt keyCount = iKeys.Count(); |
418 TInt i; |
519 TInt i; |
419 for (i = 0; i < keyCount; i++) |
520 for (i = 0; i < keyCount; i++) |
420 { |
521 { |
421 CCTKeyInfo* keyInfo = iKeys[i]; |
522 CCTKeyInfo* keyInfo = iKeys[i]; |
424 { |
525 { |
425 iExportHandle = keyInfo->Handle(); |
526 iExportHandle = keyInfo->Handle(); |
426 |
527 |
427 switch (iType) |
528 switch (iType) |
428 { |
529 { |
429 case ERSASign: |
530 case ERSASign: |
430 keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus); |
531 keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus); |
431 break; |
532 break; |
432 case EDSASign: |
533 case EDSASign: |
433 keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus); |
534 keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus); |
434 break; |
535 break; |
435 case EDH: |
536 case EDH: |
436 case EDecrypt: |
537 case EDecrypt: |
437 break; // Nothing to do, for the compiler |
538 break; // Nothing to do, for the compiler |
|
539 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
540 case EECC: |
|
541 { |
|
542 keyStore->ExportPublic(iExportHandle, iExportedPublicKey, aStatus); |
|
543 iState = EVerify; |
|
544 } |
|
545 break; |
|
546 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
438 } |
547 } |
439 break; |
548 break; |
440 } |
549 } |
441 } |
550 } |
442 iState = EVerify; |
551 iState = EVerify; |
512 iOut.writeNewLine(); |
624 iOut.writeNewLine(); |
513 CleanupStack::PopAndDestroy(verifier); |
625 CleanupStack::PopAndDestroy(verifier); |
514 CleanupStack::PopAndDestroy(key); |
626 CleanupStack::PopAndDestroy(key); |
515 } |
627 } |
516 break; |
628 break; |
|
629 |
|
630 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
631 case EECC: |
|
632 { |
|
633 iVerifyResult = EFalse; |
|
634 if (iSpiSignature && iSpiSignature->IsPresent(CryptoSpi::KEccKeyTypeUid)) |
|
635 { |
|
636 TDesC8* actualSignature = NULL; |
|
637 TRAPD(err, actualSignature = const_cast<TDesC8*>(&(iSpiSignature->GetTDesC8L(CryptoSpi::KEccKeyTypeUid)))); |
|
638 if(err == KErrNone) |
|
639 { |
|
640 if(iExportedPublicKey->Des() == *actualSignature) |
|
641 { |
|
642 iVerifyResult = ETrue; |
|
643 } |
|
644 } |
|
645 else |
|
646 { |
|
647 aStatus = err; |
|
648 } |
|
649 } |
|
650 _LIT(KReturned, "Returned... "); |
|
651 iOut.writeString(KReturned); |
|
652 iOut.writeNewLine(); |
|
653 } |
|
654 break; |
|
655 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
517 default: |
656 default: |
518 ASSERT(EFalse); |
657 ASSERT(EFalse); |
519 |
658 |
520 } |
659 } |
521 CleanupStack::PopAndDestroy(ki); |
660 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
661 if(iType != EECC) |
|
662 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
|
663 CleanupStack::PopAndDestroy(ki); |
522 } |
664 } |
523 } |
665 } |
|
666 |
524 iState = EFinished; |
667 iState = EFinished; |
525 TRequestStatus* status = &aStatus; |
668 TRequestStatus* status = &aStatus; |
526 if (!iVerifyResult) |
669 if (!iVerifyResult) |
527 { |
670 { |
528 _LIT(KVerifyFail, "**Verify failed**"); |
671 _LIT(KVerifyFail, "**Verify failed**"); |
639 iExportedPublicKey = NULL; |
781 iExportedPublicKey = NULL; |
640 delete iRSASignature; |
782 delete iRSASignature; |
641 iRSASignature = NULL; |
783 iRSASignature = NULL; |
642 delete iDSASignature; |
784 delete iDSASignature; |
643 iDSASignature = NULL; |
785 iDSASignature = NULL; |
|
786 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
787 delete iSigner; |
|
788 iSigner = NULL; |
|
789 delete iSpiSignature; |
|
790 iSpiSignature = NULL; |
|
791 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
644 } |
792 } |
645 |
793 |
646 void CSign::DoReportAction() |
794 void CSign::DoReportAction() |
647 { |
795 { |
648 _LIT(KSigning, "Signing... "); |
796 _LIT(KSigning, "Signing... "); |
691 |
839 |
692 void CSign::ConstructL(const TTestActionSpec& aTestActionSpec) |
840 void CSign::ConstructL(const TTestActionSpec& aTestActionSpec) |
693 { |
841 { |
694 CKeyStoreTestAction::ConstructL(aTestActionSpec); |
842 CKeyStoreTestAction::ConstructL(aTestActionSpec); |
695 |
843 |
696 SetKeyType(Input::ParseElement(aTestActionSpec.iActionBody, KOpenStart)); |
|
697 SetDigestSignL(Input::ParseElement(aTestActionSpec.iActionBody, KSignDigestStart)); |
844 SetDigestSignL(Input::ParseElement(aTestActionSpec.iActionBody, KSignDigestStart)); |
698 SetSignText(Input::ParseElement(aTestActionSpec.iActionBody, KTextStart, KTextEnd)); |
845 SetSignText(Input::ParseElement(aTestActionSpec.iActionBody, KTextStart, KTextEnd)); |
699 |
846 |
700 iFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys; |
847 iFilter.iPolicyFilter = TCTKeyAttributeFilter::EAllKeys; |
701 |
848 |
702 iState = EListKeysPreOpen; |
849 iState = EListKeysPreOpen; |
703 } |
850 |
704 |
|
705 |
|
706 void CSign::SetKeyType(const TDesC8& aKeyType) |
|
707 { |
|
708 if (aKeyType.Compare(KAlgRSA)==0) |
|
709 { |
|
710 iType = ERSASign; |
|
711 } |
|
712 else if (aKeyType.Compare(KAlgDSA)==0) |
|
713 { |
|
714 iType = EDSASign; |
|
715 } |
|
716 else if (aKeyType.Compare(KDecryptUsage)==0) |
|
717 { |
|
718 iType = EDecrypt; |
|
719 } |
|
720 else if (aKeyType.Compare(KAlgDH)==0) |
|
721 { |
|
722 iType = EDH; |
|
723 } |
|
724 } |
851 } |
725 |
852 |
726 void CSign::SetDigestSignL(const TDesC8& aSignDigestDesc) |
853 void CSign::SetDigestSignL(const TDesC8& aSignDigestDesc) |
727 { |
854 { |
728 TLex8 lexer(aSignDigestDesc); |
855 TLex8 lexer(aSignDigestDesc); |
782 } |
912 } |
783 |
913 |
784 switch (iState) |
914 switch (iState) |
785 { |
915 { |
786 case EListKeysPreOpen: |
916 case EListKeysPreOpen: |
787 {// Currently uses the first store, change to check the script for a specific store |
917 {// Currently uses the first store, change to check the script for a specific store |
788 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
918 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
789 ASSERT(keyStore); // Flag it up |
919 ASSERT(keyStore); // Flag it up |
790 if (keyStore) |
920 if (keyStore) |
791 keyStore->List(iKeys, iFilter, aStatus); |
921 keyStore->List(iKeys, iFilter, aStatus); |
792 |
922 |
793 iState = EOpenKey; |
923 iState = EOpenKey; |
794 } |
924 } |
795 break; |
925 break; |
796 |
926 |
797 case EOpenKey: |
927 case EOpenKey: |
798 { |
928 { |
799 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
929 CUnifiedKeyStore* keyStore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore); |
800 ASSERT(keyStore); // Flag it up |
930 ASSERT(keyStore); // Flag it up |
801 |
931 |
802 TInt keyCount = iKeys.Count(); |
932 TInt keyCount = iKeys.Count(); |
803 |
|
804 TInt i; |
933 TInt i; |
805 for (i = 0; i < keyCount; i++) |
934 for (i = 0; i < keyCount; i++) |
806 { |
935 { |
807 CCTKeyInfo* keyInfo = iKeys[i]; |
936 CCTKeyInfo* keyInfo = iKeys[i]; |
808 |
937 |
809 if (keyInfo->Label() == *iLabel) |
938 if (keyInfo->Label() == *iLabel) |
810 { |
939 { |
811 keyStore->Open(*keyInfo, iDecryptor, aStatus); |
940 switch(iType) |
|
941 { |
|
942 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
|
943 case EECC: |
|
944 if(iHardwareType == 0) |
|
945 { |
|
946 keyStore->Open(keyInfo->Handle(), iDecrypt, aStatus); |
|
947 } |
|
948 else if(iHardwareType == 1 ) |
|
949 { |
|
950 /** |
|
951 * Call the decrypt of hardware directly. iPlainText |
|
952 * would be populated. |
|
953 */ |
|
954 keyStore->Decrypt(keyInfo->Handle(), *iReadText, iPlainText, aStatus); |
|
955 } |
|
956 break; |
|
957 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
|
958 default: |
|
959 { |
|
960 keyStore->Open(*keyInfo, iDecryptor, aStatus); |
|
961 } |
|
962 } // switch |
812 break; |
963 break; |
813 } |
964 } // if |
814 } |
965 } // for |
|
966 |
815 iState = EExportPublic; |
967 iState = EExportPublic; |
816 if (i == keyCount) |
968 if (i == keyCount) |
817 { |
969 { |
818 TRequestStatus* status = &aStatus; |
970 TRequestStatus* status = &aStatus; |
819 User::RequestComplete(status, KErrNotFound); |
971 User::RequestComplete(status, KErrNotFound); |
870 iState=EFinished; |
1022 iState=EFinished; |
871 TRequestStatus* status = &aStatus; |
1023 TRequestStatus* status = &aStatus; |
872 User::RequestComplete(status, aStatus.Int()); |
1024 User::RequestComplete(status, aStatus.Int()); |
873 break; |
1025 break; |
874 } |
1026 } |
875 |
1027 switch(iType) |
876 CX509SubjectPublicKeyInfo* ki = |
1028 { |
877 CX509SubjectPublicKeyInfo::NewLC(*iPublic); |
1029 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
878 |
1030 case EECC: |
879 TX509KeyFactory factory; |
1031 { |
880 CRSAPublicKey* key = factory.RSAPublicKeyL(ki->KeyData()); |
1032 if(iHardwareType) |
881 CleanupStack::PushL(key); |
1033 { |
882 |
1034 if(*iPlainText == *iPublic) |
883 // Encrypt with public key |
1035 { |
884 CRSAPKCS1v15Encryptor* encryptor = CRSAPKCS1v15Encryptor::NewLC(*key); |
1036 aStatus = KErrNone; |
885 HBufC8* cipherText = HBufC8::NewLC(encryptor->MaxOutputLength()); |
1037 } |
886 TPtr8 cipherTextPtr = cipherText->Des(); |
1038 else |
887 |
1039 { |
888 encryptor->EncryptL(*iReadText, cipherTextPtr); |
1040 aStatus = KErrGeneral; |
889 |
1041 } |
890 // Now decrypt again |
1042 } |
891 iPlainText = HBufC8::NewMaxL(100); |
1043 else |
892 iPlainTextPtr.Set(iPlainText->Des()); |
1044 { |
893 iDecryptor->Decrypt(*cipherText, iPlainTextPtr, aStatus); |
1045 aStatus = KErrGeneral; |
894 |
1046 if (iDecrypt) |
895 CleanupStack::PopAndDestroy(cipherText); |
1047 { |
896 CleanupStack::PopAndDestroy(encryptor); |
1048 HBufC8* decryptedText = NULL; |
897 CleanupStack::PopAndDestroy(key); |
1049 TRAPD(err, decryptedText = HBufC8::NewL(iDecrypt->GetMaximumOutputLengthL())); |
898 CleanupStack::PopAndDestroy(ki); |
1050 |
899 |
1051 if (err == KErrNone) |
900 iState = EFinished; |
1052 { |
901 } |
1053 CleanupStack::PushL(decryptedText); |
902 break; |
1054 TPtr8 decryptedTextPtr = decryptedText->Des(); |
|
1055 |
|
1056 TRAP(err, (iDecrypt->ProcessL(*iReadText, decryptedTextPtr))); |
|
1057 if(err != KErrNone) |
|
1058 { |
|
1059 aStatus = err; |
|
1060 } |
|
1061 if ((err == KErrNone) && (decryptedTextPtr |
|
1062 == iPublic->Des())) |
|
1063 { |
|
1064 aStatus = KErrNone; |
|
1065 } |
|
1066 CleanupStack::PopAndDestroy(decryptedText); |
|
1067 } |
|
1068 else |
|
1069 { |
|
1070 aStatus = err; |
|
1071 } |
|
1072 } |
|
1073 } |
|
1074 iState = EFinished; |
|
1075 TRequestStatus* status = &aStatus; |
|
1076 User::RequestComplete(status, aStatus.Int()); |
|
1077 } |
|
1078 break; |
|
1079 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
|
1080 default: |
|
1081 { |
|
1082 CX509SubjectPublicKeyInfo* ki = |
|
1083 CX509SubjectPublicKeyInfo::NewLC(*iPublic); |
|
1084 |
|
1085 TX509KeyFactory factory; |
|
1086 CRSAPublicKey* key = factory.RSAPublicKeyL(ki->KeyData()); |
|
1087 CleanupStack::PushL(key); |
|
1088 |
|
1089 // Encrypt with public key |
|
1090 CRSAPKCS1v15Encryptor* encryptor = CRSAPKCS1v15Encryptor::NewLC(*key); |
|
1091 HBufC8* cipherText = HBufC8::NewLC(encryptor->MaxOutputLength()); |
|
1092 TPtr8 cipherTextPtr = cipherText->Des(); |
|
1093 |
|
1094 encryptor->EncryptL(*iReadText, cipherTextPtr); |
|
1095 |
|
1096 // Now decrypt again |
|
1097 iPlainText = HBufC8::NewMaxL(100); |
|
1098 iPlainTextPtr.Set(iPlainText->Des()); |
|
1099 iDecryptor->Decrypt(*cipherText, iPlainTextPtr, aStatus); |
|
1100 |
|
1101 CleanupStack::PopAndDestroy(cipherText); |
|
1102 CleanupStack::PopAndDestroy(encryptor); |
|
1103 CleanupStack::PopAndDestroy(key); |
|
1104 CleanupStack::PopAndDestroy(ki); |
|
1105 |
|
1106 iState = EFinished; |
|
1107 } |
|
1108 } // switch |
|
1109 } |
|
1110 break; |
903 |
1111 |
904 case EFinished: |
1112 case EFinished: |
905 { |
1113 { |
906 if (aStatus == KErrNone && (!iPlainText || |
1114 #if (defined(SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT) && defined(SYMBIAN_ENABLE_SDP_ECC)) |
907 *iPlainText != *iReadText)) |
1115 if(iType == EECC) |
908 { |
1116 { |
909 aStatus = KErrGeneral; // Decryption failed |
1117 iActionState = EPostrequisite; |
910 } |
1118 iResult = (aStatus.Int() == iExpectedResult); |
911 |
1119 |
912 iActionState = EPostrequisite; |
1120 TRequestStatus* status = &aStatus; |
913 iResult = (aStatus.Int() == iExpectedResult); |
1121 User::RequestComplete(status, aStatus.Int()); |
914 |
1122 } |
915 if (iDecryptor) |
1123 else |
916 { |
1124 #endif // SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT && SYMBIAN_ENABLE_SDP_ECC |
917 iDecryptor->Release(); |
1125 { |
918 } |
1126 if (aStatus == KErrNone && (!iPlainText || |
919 TRequestStatus* status = &aStatus; |
1127 *iPlainText != *iReadText)) |
920 User::RequestComplete(status, aStatus.Int()); |
1128 { |
|
1129 aStatus = KErrGeneral; // Decryption failed |
|
1130 } |
|
1131 |
|
1132 iActionState = EPostrequisite; |
|
1133 iResult = (aStatus.Int() == iExpectedResult); |
|
1134 |
|
1135 if (iDecryptor) |
|
1136 { |
|
1137 iDecryptor->Release(); |
|
1138 } |
|
1139 TRequestStatus* status = &aStatus; |
|
1140 User::RequestComplete(status, aStatus.Int()); |
|
1141 } |
921 } |
1142 } |
922 break; |
1143 break; |
923 default: |
1144 default: |
924 ASSERT(EFalse); |
1145 ASSERT(EFalse); |
925 } |
1146 } |