cryptoservices/filebasedcertificateandkeystores/test/thwkeystore/client/thwkeystoreclient.h
changeset 15 da2ae96f639b
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
       
     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 * Implements the MCTKeyStoreManager interface.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  * @file
       
    22  * @internalComponent
       
    23  * @released
       
    24  */
       
    25 #ifndef CHARDWAREKEYSTORECLIENT_H
       
    26 #define CHARDWAREKEYSTORECLIENT_H
       
    27 
       
    28 #include <mctkeystoremanager.h>
       
    29 
       
    30 #include "cryptoasymmetriccipherapi.h"
       
    31 #include <asymmetric.h>
       
    32 #include <cryptospi/cryptoparams.h>
       
    33 #include "thwkeystoredefs.h"
       
    34 #include "tcryptotokenhai.h"
       
    35 
       
    36 /**
       
    37  * Implements the MCTKeyStoreManager interface.
       
    38  *
       
    39  * The class implements the keystore manager token interface for the software
       
    40  * keystore.  It will be created and owned by the unified keystore.
       
    41  */
       
    42 NONSHARABLE_CLASS(CHardwareKeyStoreClient) : public CActive, public MCTKeyStoreManager
       
    43 {
       
    44 public:
       
    45 	static MCTTokenInterface* NewKeyStoreInterfaceL(MCTToken& aToken);
       
    46 
       
    47 public:
       
    48 	virtual ~CHardwareKeyStoreClient();
       
    49 	void AddRef();
       
    50 
       
    51 public:
       
    52 	void RunL();
       
    53 	virtual void DoCancel();
       
    54 	TInt RunError(TInt aError);
       
    55 	
       
    56 public:
       
    57 //	MKeyStore
       
    58 	virtual void List(RMPointerArray<CCTKeyInfo>& aKeys, const TCTKeyAttributeFilter& aFilter, TRequestStatus& aStatus);
       
    59 	virtual void CancelList();
       
    60 	virtual void GetKeyInfo(TCTTokenObjectHandle aHandle, CCTKeyInfo*& aInfo, TRequestStatus& aStatus);
       
    61 	virtual void CancelGetKeyInfo();
       
    62 	
       
    63 	// Open an RSA key for signing
       
    64 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
    65 					  MRSASigner*& aSigner,
       
    66 					  TRequestStatus& aStatus);
       
    67 	// Open a DSA key for signing
       
    68 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
    69 					  MDSASigner*& aSigner, 
       
    70 					  TRequestStatus& aStatus);
       
    71 	// Open a RSA key for private decryption
       
    72 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
    73 					  MCTDecryptor*& aDecryptor,
       
    74 					  TRequestStatus& aStatus);
       
    75 	// Open a DH key for key agreement
       
    76 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
    77 					  MCTDH*& aDH, TRequestStatus& aStatus);
       
    78 
       
    79 
       
    80 	// Cancels an ongoing open request
       
    81 	virtual void CancelOpen();
       
    82 	
       
    83 	// Returns the public key in DER-encoded ASN-1
       
    84 	virtual void ExportPublic(const TCTTokenObjectHandle& aHandle,
       
    85 							  HBufC8*& aPublicKey,
       
    86 							  TRequestStatus& aStatus);
       
    87 	virtual void CancelExportPublic();
       
    88 
       
    89 	virtual void Open(const TCTTokenObjectHandle& aHandle,
       
    90 		                  CryptoSpi::CSigner*& aSigner,
       
    91 		                  TRequestStatus& aStatus);
       
    92 	
       
    93 	virtual void Open(const TCTTokenObjectHandle& aHandle,
       
    94 		                  CryptoSpi::CAsymmetricCipher*& asymmetricCipherObj,
       
    95 		                  TRequestStatus& aStatus);
       
    96 	
       
    97 	virtual void Decrypt(const TCTTokenObjectHandle& aHandle,
       
    98                             const TDesC8& aCiphertext,
       
    99 		                       HBufC8*& aPlaintextPtr,
       
   100 		                       TRequestStatus& aStatus);
       
   101 	
       
   102 	virtual void Sign(const TCTTokenObjectHandle& aHandle,
       
   103                            const TDesC8& aPlaintext,
       
   104 		                    CryptoSpi::CCryptoParams*& aSignature,
       
   105 		                    TRequestStatus& aStatus);
       
   106 
       
   107 public:
       
   108 //	MCTKeyStoreManager
       
   109 	virtual void CreateKey(CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus);
       
   110 	virtual void CancelCreateKey();
       
   111 	virtual void ImportKey(const TDesC8& aKey, CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus);
       
   112 	virtual void CancelImportKey();
       
   113 	virtual void ImportEncryptedKey(const TDesC8& aKey, CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus);
       
   114 	virtual void CancelImportEncryptedKey();
       
   115 	virtual void ExportKey(TCTTokenObjectHandle aHandle, HBufC8*& aKey, TRequestStatus& aStatus); 
       
   116 	virtual void CancelExportKey();
       
   117 	virtual void ExportEncryptedKey(TCTTokenObjectHandle aHandle, const CPBEncryptParms& aParams, HBufC8*& aKey, TRequestStatus& aStatus);
       
   118 	virtual void CancelExportEncryptedKey();
       
   119 	virtual void DeleteKey(TCTTokenObjectHandle aHandle, TRequestStatus& aStatus);
       
   120 	virtual void CancelDeleteKey();	
       
   121 	virtual void SetUsePolicy(TCTTokenObjectHandle aHandle, const TSecurityPolicy& aPolicy, TRequestStatus& aStatus);
       
   122 	virtual void CancelSetUsePolicy();
       
   123 	virtual void SetManagementPolicy(TCTTokenObjectHandle aHandle, const TSecurityPolicy& aPolicy, TRequestStatus& aStatus);
       
   124 	virtual void CancelSetManagementPolicy();
       
   125 	virtual void SetPassphraseTimeout(TInt aTimeout, TRequestStatus& aStatus);
       
   126 	virtual void CancelSetPassphraseTimeout();	
       
   127 	virtual void Relock(TRequestStatus& aStatus);
       
   128 	virtual void CancelRelock();	
       
   129 
       
   130 	void ReleaseObject(const TCTTokenObjectHandle& aObject);
       
   131 
       
   132 public:
       
   133 	/**
       
   134 	 * this method os not a part of the framework, has been added so 
       
   135 	 * that addition of keys to the hardware can be simulated for 
       
   136 	 * testing purposes.
       
   137 	 */ 
       
   138 	void ImportKey(	TPtr aLabel, TPtr8 aPrivateKey, 
       
   139 					TPtr8 aPublicKey , TRequestStatus& aStatus);
       
   140 
       
   141 public:	
       
   142 //	From MCTTokenInterface
       
   143 	virtual MCTToken& Token();
       
   144 
       
   145 protected:
       
   146 //	From MCTTokenInterface
       
   147 	virtual void DoRelease();
       
   148 
       
   149 protected:
       
   150 	CHardwareKeyStoreClient(MCTToken& aToken);
       
   151 	virtual void ConstructL();
       
   152 
       
   153 private:
       
   154 	TInt iRefCount;
       
   155 	MCTToken& iToken;					// The token we belong to
       
   156 	THwKeystoreMessages iState;
       
   157 	TRequestStatus* iClientStatus;
       
   158 	TCTTokenObjectHandle iHandle;
       
   159 	RPointerArray<CCTKeyInfo>* iKeys;
       
   160 	TBuf8<256> iBuffer;
       
   161 	CCryptoTokenHai* iCryptoTokenHai;
       
   162 	HBufC8** iPublicKey;
       
   163 	const TDesC8* iPtr; 
       
   164 	TCTKeyAttributeFilter iFilter;
       
   165 	union
       
   166 	{
       
   167 	CryptoSpi::CSigner** iSigner;
       
   168 	CryptoSpi::CAsymmetricCipher** iAsymmetricCipher;
       
   169 	CryptoSpi::CCryptoParams* iSignature;
       
   170 	HBufC8** decryptedText;
       
   171 	}iClientBuffer;
       
   172 	
       
   173 };
       
   174 
       
   175 #endif	//	CHARDWAREKEYSTORECLIENT_H