sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * This class implements the reference Crypto Token Hardware Abstraction sl@0: * Interface (HAI). It is just intended to show how operations using sl@0: * device keys can be performed using crypto token framework. In the sl@0: * real world scenario, this HAI should be replaced by device drivers sl@0: * by the licensees. In such a case, all the operations performed by sl@0: * the replacing class would be performed in Kernel Space. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: * @file sl@0: * @internalComponent sl@0: * @released sl@0: */ sl@0: #ifndef CCRYPTOTOKENHAI_H sl@0: #define CCRYPTOTOKENHAI_H sl@0: sl@0: #include <e32base.h> sl@0: #include <f32file.h> sl@0: #include <S32FILE.H> sl@0: #include <mctkeystore.h> sl@0: sl@0: class CKeyDetails; sl@0: class MCTToken; sl@0: sl@0: namespace CryptoSpi sl@0: { sl@0: class CSigner; sl@0: } sl@0: sl@0: NONSHARABLE_CLASS(CCryptoTokenHai) : public CBase sl@0: { sl@0: public: sl@0: IMPORT_C static CCryptoTokenHai* NewLC(MCTToken* aToken); sl@0: IMPORT_C static CCryptoTokenHai* NewL(MCTToken* aToken); sl@0: IMPORT_C ~CCryptoTokenHai(); sl@0: sl@0: public: sl@0: IMPORT_C void DecryptL(TInt aHandle, sl@0: const TDesC8& aCiphertext, sl@0: HBufC8*& aPlaintext ); sl@0: sl@0: IMPORT_C void SignL( TInt aHandle, sl@0: const TDesC8& aPlaintext, sl@0: HBufC8*& aSignature ); sl@0: sl@0: IMPORT_C TInt KeyPresent( TInt aHandle ); sl@0: IMPORT_C void ExportPrivateKeyL( TInt aHandle, HBufC8*& aKey ); sl@0: IMPORT_C void ExportPublicKeyL( TInt aHandle, HBufC8*& aKey ); sl@0: IMPORT_C void ImportKeyL( const TDesC& aLabel, const TDesC8& aPrivateKey, const TDesC8& aPublicKey ); sl@0: IMPORT_C void ListL(const TCTKeyAttributeFilter& aFilter, RPointerArray<CCTKeyInfo>& aKeys) const; sl@0: sl@0: private: sl@0: void ConstructL(); sl@0: CCryptoTokenHai(MCTToken& aToken); sl@0: void OpenStoreL(); sl@0: void OpenStoreInFileL(const TDesC& aFile); sl@0: void CreateStoreInFileL(const TDesC& aFile); sl@0: void MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut); sl@0: void EnsurePathL(RFs& aFs, const TDesC& aFile); sl@0: void MakePrivateROMFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut); sl@0: void CopyL(RFs& aFs, const TDesC& aSouce, const TDesC& aDest); sl@0: void CompactStore(); sl@0: static void RevertStore(TAny* aStore); sl@0: void ReadKeysFromStoreL(); sl@0: TBool KeyMatchesFilterL(const CKeyDetails& aInfo, const TCTKeyAttributeFilter& aFilter) const; sl@0: void CopyStoreFromROML(const TDesC& fullPath, TInt result); sl@0: void WriteKeysToStoreL(RStoreWriteStream& aRootStream); sl@0: sl@0: private: sl@0: RPointerArray<CKeyDetails> iKeys; sl@0: RFs iFs; sl@0: CPermanentFileStore* iFileStore; sl@0: TStreamId iRootStreamId; sl@0: MCTToken& iToken; sl@0: }; sl@0: sl@0: #endif // CCRYPTOTOKENHAI_H