370 { |
370 { |
371 Cancel(); |
371 Cancel(); |
372 } |
372 } |
373 } |
373 } |
374 |
374 |
375 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT |
|
376 void CUnifiedKeyStore::Open(const TCTTokenObjectHandle& aHandle, |
|
377 CryptoSpi::CSigner*& aSigner, |
|
378 TRequestStatus& aStatus) |
|
379 { |
|
380 if (DoOpen(aHandle, aStatus)) |
|
381 { |
|
382 iKeyStore->Open(aHandle, aSigner, iStatus); |
|
383 } |
|
384 } |
|
385 |
|
386 void CUnifiedKeyStore::Open(const TCTTokenObjectHandle& aHandle, |
|
387 CryptoSpi:: CAsymmetricCipher*& asymmetricCipherObj, |
|
388 TRequestStatus& aStatus) |
|
389 { |
|
390 if (DoOpen(aHandle, aStatus)) |
|
391 { |
|
392 iKeyStore->Open(aHandle, asymmetricCipherObj, iStatus); |
|
393 } |
|
394 } |
|
395 |
|
396 void CUnifiedKeyStore::Decrypt(const TCTTokenObjectHandle& aHandle, |
|
397 const TDesC8& aCiphertext, |
|
398 HBufC8*& aPlaintextPtr, |
|
399 TRequestStatus& aStatus) |
|
400 { |
|
401 if (DoOpen(aHandle, aStatus)) |
|
402 { |
|
403 iKeyStore->Decrypt(aHandle, aCiphertext, aPlaintextPtr, iStatus); |
|
404 } |
|
405 } |
|
406 |
|
407 void CUnifiedKeyStore::Sign(const TCTTokenObjectHandle& aHandle, |
|
408 const TDesC8& aPlaintext, |
|
409 CryptoSpi::CCryptoParams*& aSignature, |
|
410 TRequestStatus& aStatus) |
|
411 { |
|
412 if (DoOpen(aHandle, aStatus)) |
|
413 { |
|
414 iKeyStore->Sign(aHandle, aPlaintext, aSignature, iStatus); |
|
415 } |
|
416 } |
|
417 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT |
|
418 |
375 |
419 // ************************************************************************ |
376 // ************************************************************************ |
420 // MKeyStoreManager |
377 // MKeyStoreManager |
421 // ************************************************************************ |
378 // ************************************************************************ |
422 |
379 |
635 } |
592 } |
636 __ASSERT_ALWAYS(result != NULL, User::Panic(KUnifiedKeyStore, EArrayAccessOutOfBounds)); |
593 __ASSERT_ALWAYS(result != NULL, User::Panic(KUnifiedKeyStore, EArrayAccessOutOfBounds)); |
637 return *result; |
594 return *result; |
638 } |
595 } |
639 |
596 |
640 #ifdef SYMBIAN_AUTH_SERVER |
|
641 |
|
642 EXPORT_C void CUnifiedKeyStore::CreateKey( TInt aKeyStoreIndex, TKeyUsagePKCS15 aUsage,TUint aSize, |
|
643 const TDesC& aLabel, CCTKeyInfo::EKeyAlgorithm aAlgorithm, |
|
644 TInt aAccessType, TTime aStartDate, TTime aEndDate, |
|
645 const TDesC& aAuthenticationString, TInt aFreshness, |
|
646 CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus) |
|
647 { |
|
648 |
|
649 StartAsyncOperation(ECreateKey, aStatus); |
|
650 TRAPD(err, PrepareToCreateKeyL(aKeyStoreIndex, aUsage, aSize, aLabel, aAlgorithm, aAccessType, |
|
651 aStartDate, aEndDate, aStatus)); |
|
652 if (KErrNone != err) |
|
653 { |
|
654 Complete(err); |
|
655 return; |
|
656 } |
|
657 |
|
658 iKeyInfoOut = &aKeyInfoOut; |
|
659 aKeyInfoOut = NULL; |
|
660 iKeyStoreManager->CreateKey(aAuthenticationString, aFreshness, iKeyInfo, iStatus); |
|
661 SetActive(); |
|
662 |
|
663 } |
|
664 |
|
665 |
|
666 EXPORT_C void CUnifiedKeyStore::ImportKey( TInt aKeyStoreIndex, const TDesC8& aKeyData, |
|
667 TKeyUsagePKCS15 aUsage, const TDesC& aLabel, |
|
668 TInt aAccessType, TTime aStartDate, TTime aEndDate, |
|
669 const TDesC& aAuthenticationString, TInt aFreshness, |
|
670 CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus) |
|
671 { |
|
672 TBool isEncrypted = TASN1DecPKCS8::IsEncryptedPKCS8Data(aKeyData); |
|
673 StartAsyncOperation(isEncrypted ? EImportKeyEncrypted : EImportKey, aStatus); |
|
674 |
|
675 ASSERT(!iKeyData); |
|
676 iKeyData = aKeyData.Alloc(); |
|
677 if (!iKeyData) // OOM or some other catastrophe |
|
678 { |
|
679 Complete(KErrNoMemory); |
|
680 return; |
|
681 } |
|
682 |
|
683 TRAPD(err, PrepareToCreateKeyL(aKeyStoreIndex, aUsage, 0, aLabel, CCTKeyInfo::EInvalidAlgorithm, aAccessType, |
|
684 aStartDate, aEndDate, aStatus)); |
|
685 if (KErrNone != err) |
|
686 { |
|
687 Complete(err); |
|
688 return; |
|
689 } |
|
690 |
|
691 iKeyInfoOut = &aKeyInfoOut; |
|
692 aKeyInfoOut = NULL; |
|
693 |
|
694 if (isEncrypted) |
|
695 { |
|
696 iKeyStoreManager->ImportEncryptedKey(*iKeyData, aAuthenticationString, aFreshness, iKeyInfo, iStatus); |
|
697 } |
|
698 else |
|
699 { |
|
700 iKeyStoreManager->ImportKey(*iKeyData, aAuthenticationString, aFreshness, iKeyInfo, iStatus); |
|
701 } |
|
702 SetActive(); |
|
703 } |
|
704 |
|
705 EXPORT_C void CUnifiedKeyStore::SetAuthenticationPolicy( const TCTTokenObjectHandle aHandle, |
|
706 const TDesC& aAuthenticationString, |
|
707 TInt aFreshness, |
|
708 TRequestStatus& aStatus) |
|
709 { |
|
710 StartAsyncOperation(ESetAuthenticationPolicy, aStatus); |
|
711 |
|
712 ASSERT(!iKeyStoreManager); |
|
713 iKeyStoreManager = FindKeyStoreManager(aHandle); |
|
714 if (!iKeyStoreManager) |
|
715 { |
|
716 Complete(KErrNotFound); |
|
717 return; |
|
718 } |
|
719 |
|
720 iKeyStoreManager->SetAuthenticationPolicy(aHandle, aAuthenticationString, aFreshness, iStatus); |
|
721 SetActive(); |
|
722 |
|
723 } |
|
724 |
|
725 EXPORT_C void CUnifiedKeyStore::GetAuthenticationPolicy( const TCTTokenObjectHandle aHandle, |
|
726 HBufC*& aAuthenticationString, |
|
727 TInt& aFreshness, |
|
728 TRequestStatus& aStatus) |
|
729 { |
|
730 StartAsyncOperation(EGetAuthenticationPolicy, aStatus); |
|
731 |
|
732 ASSERT(!iKeyStoreManager); |
|
733 iKeyStoreManager = FindKeyStoreManager(aHandle); |
|
734 if (!iKeyStoreManager) |
|
735 { |
|
736 Complete(KErrNotFound); |
|
737 return; |
|
738 } |
|
739 |
|
740 iKeyStoreManager->GetAuthenticationPolicy(aHandle, aAuthenticationString, aFreshness, iStatus); |
|
741 SetActive(); |
|
742 |
|
743 } |
|
744 |
|
745 #endif // SYMBIAN_AUTH_SERVER |
|
746 |
597 |
747 CUnifiedKeyStore::CUnifiedKeyStore(RFs& aFs) |
598 CUnifiedKeyStore::CUnifiedKeyStore(RFs& aFs) |
748 : CActive(EPriorityNormal), iFs(aFs), iState(EIdle) |
599 : CActive(EPriorityNormal), iFs(aFs), iState(EIdle) |
749 {// Currently defaults to always try for key store manager interface |
600 {// Currently defaults to always try for key store manager interface |
750 // This may change (add parameter to NewL for required interface) |
601 // This may change (add parameter to NewL for required interface) |