os/security/cryptoservices/filebasedcertificateandkeystores/test/tcryptotokenhai/tcryptotokenhai.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 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 * This class implements the reference Crypto Token Hardware Abstraction 
    16 * Interface (HAI). It is just intended to show how operations using 
    17 * device keys can be performed using crypto token framework. In the 
    18 * real world scenario, this HAI should be replaced by device drivers 
    19 * by the licensees. In such a case, all the operations performed by 
    20 * the replacing class would be performed in Kernel Space.
    21 *
    22 */
    23 
    24 
    25 /**
    26  * @file
    27  * @internalComponent
    28  * @released
    29  */
    30 #ifndef CCRYPTOTOKENHAI_H
    31 #define CCRYPTOTOKENHAI_H
    32 
    33 #include <e32base.h>
    34 #include <f32file.h>
    35 #include <S32FILE.H>
    36 #include <mctkeystore.h>
    37 
    38 class CKeyDetails;
    39 class MCTToken;
    40 
    41 namespace CryptoSpi
    42 	{
    43 	class CSigner;
    44 	}
    45 
    46 NONSHARABLE_CLASS(CCryptoTokenHai) : public CBase
    47 	{
    48 	public:
    49 		IMPORT_C static CCryptoTokenHai* NewLC(MCTToken* aToken);
    50 		IMPORT_C static CCryptoTokenHai* NewL(MCTToken* aToken);
    51 		IMPORT_C ~CCryptoTokenHai();
    52 		
    53 	public:
    54 		IMPORT_C void DecryptL(TInt aHandle,
    55 								const TDesC8& aCiphertext,
    56 								HBufC8*& aPlaintext );
    57 	
    58 		IMPORT_C void SignL( 	TInt aHandle,
    59 								const TDesC8& aPlaintext,
    60 								HBufC8*& aSignature );
    61 	
    62 		IMPORT_C TInt KeyPresent( TInt aHandle );
    63 		IMPORT_C void ExportPrivateKeyL( TInt aHandle, HBufC8*& aKey );
    64 		IMPORT_C void ExportPublicKeyL( TInt aHandle, HBufC8*& aKey );
    65 		IMPORT_C void ImportKeyL( const TDesC& aLabel, const TDesC8& aPrivateKey, const TDesC8& aPublicKey );
    66 		IMPORT_C void ListL(const TCTKeyAttributeFilter& aFilter, RPointerArray<CCTKeyInfo>& aKeys) const;
    67 		
    68 	private:
    69 		void ConstructL();
    70 		CCryptoTokenHai(MCTToken& aToken);
    71 	    void OpenStoreL();
    72 	    void OpenStoreInFileL(const TDesC& aFile);
    73 	    void CreateStoreInFileL(const TDesC& aFile);
    74 	    void MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut);
    75 		void EnsurePathL(RFs& aFs, const TDesC& aFile);
    76 		void MakePrivateROMFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut);
    77 		void CopyL(RFs& aFs, const TDesC& aSouce, const TDesC& aDest);
    78 		void CompactStore();
    79 		static void RevertStore(TAny* aStore);
    80 		void ReadKeysFromStoreL();
    81 		TBool KeyMatchesFilterL(const CKeyDetails& aInfo, const TCTKeyAttributeFilter& aFilter) const;
    82 		void CopyStoreFromROML(const TDesC& fullPath, TInt result);
    83 		void WriteKeysToStoreL(RStoreWriteStream& aRootStream);
    84 		
    85 	private:
    86 		RPointerArray<CKeyDetails> iKeys;
    87 		RFs iFs;
    88 		CPermanentFileStore* iFileStore;
    89 		TStreamId iRootStreamId;
    90 		MCTToken& iToken;
    91 	};
    92 
    93 #endif	//	CCRYPTOTOKENHAI_H