cryptoservices/certificateandkeymgmt/inc/unifiedkeystore_v2.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2003-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 * UNIFIEDKEYSTORE.H
       
    16 * The unified key store implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file 
       
    25  @publishedPartner
       
    26  @released
       
    27 */
       
    28  
       
    29 #ifndef __UNIFIEDKEYSTORE_H__
       
    30 #define __UNIFIEDKEYSTORE_H__
       
    31 
       
    32 #include <f32file.h>
       
    33 #include <e32base.h>
       
    34 
       
    35 #include <mctkeystoremanager.h>
       
    36 
       
    37 /**
       
    38  * Unified KeyStore panics 
       
    39  *
       
    40  * @publishedPartner
       
    41  * @released
       
    42  */
       
    43 enum TUnifiedKeyStorePanic
       
    44 	{
       
    45 	EUnexpectedInitialise		= 1,	///< Unexpected initialise
       
    46 	EArrayAccessOutOfBounds		= 2,	///< Array access out of bounds
       
    47 	ETokensArrayAlreadyInUse	= 3,	///< Tokens array already in use
       
    48 	EUnrecognisedState			= 4,	///< Unrecognised state
       
    49 	};
       
    50 
       
    51 /**
       
    52  * The unified key store.
       
    53  * 
       
    54  * This class provides a key store whose contents are the sum of the contents of
       
    55  * all key store implementations on the device.  It is intended a single point
       
    56  * of access for clients wishing to access key stores.
       
    57  *
       
    58  * Since this class is intended for widespread use, capability checks relating
       
    59  * to key access are documented here even though the checks are actually made in
       
    60  * the individual key store implementations.
       
    61  * 
       
    62  * @publishedPartner
       
    63  * @released
       
    64  */
       
    65 NONSHARABLE_CLASS(CUnifiedKeyStore) : public CActive, public MKeyStore
       
    66 	{
       
    67  public:	
       
    68 	/**
       
    69 	 * Creates a new CUnifiedKeyStore object.
       
    70 	 * 
       
    71 	 * @param aFs	A file server session. It must already be open.
       
    72 	 * @return		A pointer to an instance of the CUnifiedKeyStore class.
       
    73 	 */
       
    74 	IMPORT_C static CUnifiedKeyStore* NewL(RFs& aFs);
       
    75 	
       
    76 	/**
       
    77 	 * Creates a new CUnifiedKeyStore object and and puts a pointer to the new object 
       
    78 	 * onto the cleanup stack.
       
    79 	 * 
       
    80 	 * @param aFs	A file server session. It must already be open.
       
    81 	 * @return		A pointer to an instance of the CUnifiedKeyStore class.
       
    82 	 */
       
    83 	IMPORT_C static CUnifiedKeyStore* NewLC(RFs& aFs);
       
    84 
       
    85 	/**
       
    86 	 * The destructor destroys all the resources owned by this object.
       
    87 	 */
       
    88 	IMPORT_C ~CUnifiedKeyStore();
       
    89 
       
    90 	/**
       
    91 	 * Initialises the manager.
       
    92 	 * 
       
    93 	 * It must be called after the manager has been constructed and before any call 
       
    94 	 * to the manager functions.
       
    95 	 * 
       
    96 	 * This is an asynchronous request.
       
    97 	 * 
       
    98 	 * @param aStatus	The request status object; contains the result of the Initialize() 
       
    99 	 * 					request when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   100 	 */
       
   101 	IMPORT_C void Initialize(TRequestStatus& aStatus);
       
   102 
       
   103 	/** 
       
   104 	 * Cancels an ongoing Initialize() operation.
       
   105 	 *
       
   106 	 * The operation completes with KErrCancel.
       
   107 	 */
       
   108 	IMPORT_C void CancelInitialize();
       
   109 	
       
   110 public:  // Implementation of MKeyStore interface
       
   111 	virtual void List(RMPointerArray<CCTKeyInfo>& aKeys, const TCTKeyAttributeFilter& aFilter, TRequestStatus& aStatus);
       
   112 	virtual void CancelList();
       
   113 	virtual void GetKeyInfo(TCTTokenObjectHandle aHandle, CCTKeyInfo*& aInfo,TRequestStatus& aStatus);
       
   114 	virtual void CancelGetKeyInfo();
       
   115 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
   116 					  MRSASigner*& aSigner,
       
   117 					  TRequestStatus& aStatus);
       
   118 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
   119 					  MDSASigner*& aSigner, 
       
   120 					  TRequestStatus& aStatus);
       
   121 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
   122 					  MCTDecryptor*& aDecryptor,
       
   123 					  TRequestStatus& aStatus);
       
   124 	virtual void Open(const TCTTokenObjectHandle& aHandle, 
       
   125 					  MCTDH*& aDH, TRequestStatus& aStatus);
       
   126 	virtual void CancelOpen();
       
   127 	virtual void ExportPublic(const TCTTokenObjectHandle& aHandle,
       
   128 							  HBufC8*& aPublicKey,
       
   129 							  TRequestStatus& aStatus);
       
   130 	virtual void CancelExportPublic();
       
   131 
       
   132 public:		//	For MCTKeyStoreManager except those (CreateKey, ImportKey, ImportEncryptedKey)
       
   133 			//	that require a caller-specified store
       
   134 	
       
   135 	/**
       
   136 	 * Exports a key pair in the clear.
       
   137 	 *
       
   138 	 * The key is exported as DER-encoded PKCS#8 data.
       
   139 	 *
       
   140 	 * @param aHandle	The handle of the key to export
       
   141 	 * @param aKey		A reference to a HBufC8 pointer.  The pointer will be set to
       
   142 	 *					a newly allocated buffer containing the key data.  It is the caller's
       
   143 	 *					responsibility to delete this buffer.
       
   144 	 * @param aStatus	The request status object; contains the result of the ExportKey() request 
       
   145 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   146 	 *				
       
   147 	 * @capability ReadUserData		Requires the caller to have ReadUserData capability
       
   148 	 * @leave KErrPermissionDenied	If the caller does not have ReadUserData capability, 
       
   149 	 *								or is not the owner of the key.
       
   150 	 * @leave KErrNotFound			If the key the handle referes to does not exist.
       
   151 	 * @leave KErrKeyAccess			If the sensitive flag is set for the key, or the
       
   152 	 *								exportable flag is not set.
       
   153 	 * @leave KErrKeyAlgorithm		If this type of key cannot be exported.
       
   154 	 */
       
   155 	IMPORT_C void ExportKey(TCTTokenObjectHandle aHandle, HBufC8*& aKey, TRequestStatus& aStatus);
       
   156 
       
   157 	/** 
       
   158 	 * Cancels an ongoing ExportKey() operation.
       
   159 	 *
       
   160 	 * The operation completes with KErrCancel.
       
   161 	 */
       
   162 	IMPORT_C void CancelExportKey();
       
   163 
       
   164 	/**
       
   165 	 * Exports an encrypted key pair.
       
   166 	 *
       
   167 	 * The key is exported as DER-encoded PKCS#5/PKCS#8 data.
       
   168 	 *
       
   169 	 * @param aHandle	The handle of the key to export
       
   170 	 * @param aKey		A reference to a HBufC8 pointer.  The pointer will be set to
       
   171 	 *					a newly allocated buffer containing the key data.
       
   172 	 * @param aParams	The PBE encryption parameters to use when encrypting the key.
       
   173 	 * @param aStatus	The request status object; contains the result of the ExportEncryptedKey() request 
       
   174 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   175 	 * 
       
   176 	 * @capability ReadUserData		Requires the caller to have ReadUserData capability
       
   177 	 * @leave KErrPermissionDenied	If the caller does not have ReadUserData capability,
       
   178 	 *								or is not the owner of the key.
       
   179 	 * @leave KErrNotFound			If the key the handle referes to does not exist. 
       
   180 	 * @leave KErrKeyAccess			If the exportable flag is not set for the key.
       
   181 	 * @leave KErrKeyAlgorithm		If this type of key cannot be exported.
       
   182 	 */
       
   183 	IMPORT_C void ExportEncryptedKey(TCTTokenObjectHandle aHandle, const CPBEncryptParms& aEncryptParams, 
       
   184 									 HBufC8*& aKey, TRequestStatus& aStatus);
       
   185 
       
   186 	/** 
       
   187 	 * Cancels an ongoing ExportEncryptedKey() operation.
       
   188 	 *
       
   189 	 * The operation completes with KErrCancel.
       
   190 	 */
       
   191 	IMPORT_C void CancelExportEncryptedKey();
       
   192 
       
   193 	/**
       
   194 	 * Deletes a key.
       
   195 	 * 
       
   196 	 * @param aHandle	The handle of the key to delete
       
   197 	 * @param aStatus	The request status object; contains the result of the DeleteKey() request 
       
   198 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   199 	 *	
       
   200 	 * @capability WriteUserData	Requires the caller to have WriteUserData capability
       
   201 	 * @leave KErrPermissionDenied	If the caller does not have WriteUserData capability,
       
   202 	 *								or is not the owner of the key.
       
   203 	 * @leave KErrNotFound			If the key the handle referes to does not exist. 
       
   204 	 * @leave KErrAccessDenied		If the calling process is not allowed to delete the key.
       
   205 	 * @leave KErrInUse				If another client is currently using the key.
       
   206 	 */
       
   207 	IMPORT_C void DeleteKey(TCTTokenObjectHandle aHandle, TRequestStatus& aStatus);
       
   208 
       
   209 	/** 
       
   210 	 * Cancels an ongoing DeleteKey() operation.
       
   211 	 *
       
   212 	 * The operation completes with KErrCancel.
       
   213 	 */
       
   214 	IMPORT_C void CancelDeleteKey();
       
   215 
       
   216 	/**
       
   217 	 * Sets the security policy for key use.
       
   218 	 *
       
   219 	 * Specifies which processes are allowed to use the key for cryptographic
       
   220 	 * operations.
       
   221 	 *
       
   222 	 * @param aHandle	The handle of the key
       
   223 	 * @param aPolicy	The new security policy.
       
   224 	 * @param aStatus	The request status object; contains the result of the SetUsePolicy() request 
       
   225 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   226 	 *	
       
   227 	 * @capability WriteUserData	Requires the caller to have WriteUserData capability
       
   228 	 * @leave KErrPermissionDenied	If the caller does not have WriteUserData capability,
       
   229 	 *								or is not the owner of the key.
       
   230 	 * @leave KErrNotFound			If the key the handle referes to does not exist.
       
   231 	 */
       
   232 	IMPORT_C void SetUsePolicy(TCTTokenObjectHandle aHandle,
       
   233 							  const TSecurityPolicy& aPolicy,
       
   234 							  TRequestStatus& aStatus);
       
   235 
       
   236 	/** 
       
   237 	 * Cancels an ongoing SetUsePolicy() operation.
       
   238 	 *
       
   239 	 * The operation completes with KErrCancel.
       
   240 	 */
       
   241 	IMPORT_C void CancelSetUsePolicy();
       
   242 
       
   243 	/**
       
   244 	 * Sets the security policy for key management.
       
   245 	 *
       
   246 	 * Specifies which processes are allowed to perform management operations on
       
   247 	 * the key.
       
   248 	 *
       
   249 	 * @param aHandle	The handle of the key
       
   250 	 * @param aPolicy	The new security policy.
       
   251 	 * @param aStatus	The request status object; contains the result of the SetManagementPolicy() request 
       
   252 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   253 	 *	
       
   254 	 * @capability WriteUserData	Requires the caller to have WriteUserData capability
       
   255 	 * @leave KErrPermissionDenied	If the caller does not have WriteUserData capability,
       
   256 	 *								or is not the owner of the key.
       
   257 	 * @leave KErrNotFound			If the key the handle referes to does not exist.
       
   258 	 */
       
   259 	IMPORT_C void SetManagementPolicy(TCTTokenObjectHandle aHandle,
       
   260 									  const TSecurityPolicy& aPolicy,
       
   261 									  TRequestStatus& aStatus);
       
   262 
       
   263 	/** 
       
   264 	 * Cancels an ongoing SetManagementPolicy() operation.
       
   265 	 *
       
   266 	 * The operation completes with KErrCancel.
       
   267 	 */
       
   268 	IMPORT_C void CancelSetManagementPolicy();
       
   269 
       
   270 	/**
       
   271 	 * Sets the passphrase timeout for all keys owned by this process.
       
   272 	 * 
       
   273 	 * @param aTimeout	The timeout in seconds. 0 means that the passphrase is
       
   274 	 *     				always asked for, and -1 means that it is never expired
       
   275 	 * @param aStatus	The request status object; contains the result of the SetPassphraseTimeout() request 
       
   276 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   277 	 *	
       
   278 	 * @capability WriteUserData	Requires the caller to have WriteUserData capability
       
   279 	 * @leave KErrPermissionDenied	If the caller does not have WriteUserData capability,
       
   280 	 *								or is not the owner of the key
       
   281 	 * @leave KErrArgument			If the timeout specified is invalid.
       
   282 	 */
       
   283 	IMPORT_C void SetPassphraseTimeout(TInt aTimeout, TRequestStatus& aStatus);
       
   284 
       
   285 	/** 
       
   286 	 * Cancels an ongoing SetPassphraseTimeout() operation. 
       
   287 	 *
       
   288 	 * The operation completes with KErrCancel.
       
   289 	 */
       
   290 	IMPORT_C void CancelSetPassphraseTimeout();
       
   291 
       
   292 	/** 
       
   293 	 * Re-locks the entire store (i.e., forget the passphrase).
       
   294 	 *
       
   295 	 * @param aStatus	The request status object; contains the result of the Relock() request 
       
   296 	 *					when complete. Set to KErrCancel if any outstanding request is cancelled.
       
   297 	 */
       
   298 	IMPORT_C void Relock(TRequestStatus& aStatus);
       
   299 	
       
   300 	/** 
       
   301 	 * Cancels an ongoing Relock() operation.
       
   302 	 *
       
   303 	 * The operation completes with KErrCancel.
       
   304 	 */
       
   305 	IMPORT_C void CancelRelock();
       
   306 	
       
   307 public:
       
   308 	/**
       
   309 	 * Generates a new key pair.
       
   310 	 *
       
   311 	 * For the software key store, the owner of the new key is set to the
       
   312 	 * calling process.  Users can subsequently be added by calling SetUsers().
       
   313 	 *	
       
   314 	 * @param aKeyStoreIndex  The index of the key store manager in which to
       
   315 	 *                        create the key.  Must be between zero and
       
   316 	 *	                      KeyStoreMangerCount() exclusive.		
       
   317 	 * @param aUsage		  The key usage flags in the PKCS#15 format.
       
   318 	 * @param aSize		      The size of the key in bits.
       
   319 	 * @param aLabel		  A textual label for the key.
       
   320 	 * @param aAlgorithm	  The type of key.
       
   321 	 * @param aAccessType     The key access type - a bitfield specifying key
       
   322 	 *	                      access requirements.  Allowed values are zero, or
       
   323 	 *	                      a comination of CCTKeyInfo::EKeyAccess::ESenstive
       
   324 	 *	                      and CCTKeyInfo::EKeyAccess::EExtractable
       
   325 	 * @param aStartDate	  The start of the validity period.
       
   326 	 * @param aEndDate		  The end of the validity period.	
       
   327 	 * @param aKeyInfoOut     A pointer that is set to a newly created key info
       
   328 	 *	                      object on successful completion.
       
   329 	 * @param aStatus		  The request status object; contains the result of
       
   330 	 *						  the CreateKey() request when complete. Set to 
       
   331 	 *						  KErrCancel if any outstanding request is cancelled.
       
   332 	 *   
       
   333 	 * @capability WriteUserData	Requires the caller to have WriteUserData capability
       
   334 	 * @leave KErrPermissionDenied	If the caller does not have WriteUserData capability
       
   335 	 * @leave KErrKeyUsage			If the key usage flags are not valid or not
       
   336 	 *								consistent with the key algorithm.
       
   337 	 * @leave KErrKeyValidity		If the validity start and end dates are specified
       
   338 	 *								but do not form a valid time period.
       
   339 	 * @panic						If aKeyStoreIndex does not specify a valid keystore manager.
       
   340 	 */
       
   341 	IMPORT_C void CreateKey(TInt aKeyStoreIndex, TKeyUsagePKCS15 aUsage,TUint aSize, 
       
   342 							const TDesC& aLabel, CCTKeyInfo::EKeyAlgorithm aAlgorithm, 
       
   343 							TInt aAccessType, TTime aStartDate, TTime aEndDate, 
       
   344 							CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus);
       
   345 	
       
   346 	/** 
       
   347 	 * Cancels an ongoing CreateKey() operation. 
       
   348 	 *
       
   349 	 * The operation completes with KErrCancel.
       
   350 	 */
       
   351 	IMPORT_C void CancelCreateKey();
       
   352 
       
   353 	/**
       
   354 	 * Imports a key pair.
       
   355 	 *
       
   356 	 * For the software key store, the owner of the new key is set to the
       
   357 	 * calling process.  Users can subsequently be added by calling SetUsers().
       
   358 	 *
       
   359 	 * The key data should be in PKCS#8 format.  Both encrypted and cleartext
       
   360 	 * versions are allowed.
       
   361 	 *
       
   362 	 * @param aKeyStoreIndex  The index of the key store manager in which to
       
   363 	 *	                      create the key.  Must be between zero and
       
   364 	 *	                      KeyStoreMangerCount() exclusive.			
       
   365 	 * @param aKeyData		  The key data to import, ASN.1 DER encoded PKCS#8.
       
   366 	 * @param aUsage		  The key usage flags in the PKCS#15 format.
       
   367 	 * @param aLabel		  A textual label for the key.
       
   368 	 * @param aAccessType     The key access type - a bitfield specifying key
       
   369 	 *	                      access requirements.  Allowed values are zero, or
       
   370 	 *	                      a comination of CCTKeyInfo::EKeyAccess::ESenstive
       
   371 	 *	                      and CCTKeyInfo::EKeyAccess::EExtractable
       
   372 	 * @param aStartDate	  The start of the validity period.
       
   373 	 * @param aEndDate		  The end of the validity period.	
       
   374 	 * @param aKeyInfoOut     A pointer that is set to a newly created key info
       
   375 	 *	                      object on successful completion.
       
   376 	 * @param aStatus		  The request status object; contains the result of
       
   377 	 *						  the ImportKey() request when complete. Set to 
       
   378 	 *						  KErrCancel if any outstanding request is cancelled.
       
   379 	 *	                      
       
   380 	 * @capability WriteUserData	Requires the caller to have WriteUserData capability
       
   381 	 * @leave KErrPermissionDenied	If the caller does not have WriteUserData capability
       
   382 	 * @leave KErrKeyUsage			If the key usage flags are not valid or not
       
   383 	 *								consistent with the key algorithm.
       
   384 	 * @leave KErrKeyValidity		If the validity start and end dates are specified
       
   385 	 *								but do not form a valid time period.
       
   386 	 * @leave KErrArgument			If the key data cannot be parsed.
       
   387 	 * @panic						If aKeyStoreIndex does not specify a valid keystore manager.
       
   388 	 */
       
   389 	IMPORT_C void ImportKey(TInt aKeyStoreIndex, const TDesC8& aKeyData,
       
   390 							TKeyUsagePKCS15 aUsage, const TDesC& aLabel, 
       
   391 							TInt aAccessType, TTime aStartDate, TTime aEndDate, 
       
   392 							CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus);
       
   393 	
       
   394 	/** 
       
   395 	 * Cancels an ongoing ImportKey() operation. 
       
   396 	 *
       
   397 	 * The operation completes with KErrCancel.
       
   398 	 */
       
   399 	IMPORT_C void CancelImportKey();
       
   400 	
       
   401 public:
       
   402 	
       
   403 	/**
       
   404 	 * Gets the number of available read-only key stores.
       
   405 	 * 
       
   406 	 * @return	The number of available read-only key stores.
       
   407 	 */
       
   408 	IMPORT_C TInt KeyStoreCount() const;
       
   409 	
       
   410 	/**
       
   411 	 * Gets a read-only interface to a key store.
       
   412 	 * 
       
   413 	 * @param aIndex				An ordinal number that identifies the key store.
       
   414 	 * @return						A read-only interface to the key store specified by aIndex.
       
   415 	 * 
       
   416 	 * @panic CUnifiedKeyStore 2    If aIndex is out of range, ie it is greater
       
   417 	 * 								than or equal to the value returned by KeyStoreCount().
       
   418 	 */
       
   419 	IMPORT_C MCTKeyStore& KeyStore(TInt aIndex);
       
   420 	
       
   421 	/**
       
   422 	 * Gets the number of available read-write key stores.
       
   423 	 * 
       
   424 	 * @return	The number of key stores that are open for read-write access.
       
   425 	 */
       
   426 	IMPORT_C TInt KeyStoreManagerCount() const;
       
   427 	
       
   428 	/**
       
   429 	 * Gets a read-write interface to the store specified by aIndex.
       
   430 	 * 
       
   431 	 * @param aIndex				An ordinal number that identifies the key store.
       
   432 	 * @return						A read-write interface to the key store specified by aIndex.
       
   433 	 * 
       
   434 	 * @panic CUnifiedKeyStore 2    If aIndex s out of range, ie it is greater than
       
   435 	 * 								or equal to the value returned by KeyStoreManagerCount().
       
   436 	 */
       
   437 	IMPORT_C MCTKeyStoreManager& KeyStoreManager(TInt aIndex);
       
   438 	
       
   439 private:
       
   440 	CUnifiedKeyStore(RFs& aFs);
       
   441 	void ConstructL();
       
   442 private:	//	From CActive
       
   443 	void RunL();
       
   444 	TInt RunError(TInt aError);
       
   445 	void DoCancel();
       
   446 private:
       
   447 	enum TState
       
   448 		{
       
   449 		EIdle,
       
   450 		EInitializeGetTokenList,
       
   451 		EInitializeGetToken,
       
   452 		EInitialiseGetKeyManagerInterface,
       
   453 		EInitializeGetKeyUserInterface,
       
   454 		EInitializeGetKeyUserInterfaceFinished,
       
   455 		EInitializeFinished,
       
   456 	//	----------------------------------------------
       
   457 		EList,
       
   458 		EGetKeyInfo,
       
   459 		EOpen,
       
   460 	//	----------------------------------------------
       
   461 		ECreateKey,
       
   462 		EImportKey,
       
   463 		EImportKeyEncrypted,
       
   464 		EExportKey,
       
   465 		EExportEncryptedKey,
       
   466 		EExportPublic,
       
   467 		EDeleteKey,
       
   468 		ESetUsePolicy,
       
   469 		ESetManagementPolicy,
       
   470 		ESetPassphraseTimeout,
       
   471 		ERelock
       
   472 		};
       
   473 private:
       
   474 	void StartAsyncOperation(TState aState, TRequestStatus& aStatus);
       
   475 	void DoInitializeL();
       
   476 	TBool DoOpen(const TCTTokenObjectHandle& aHandle, 
       
   477 				 TRequestStatus& aStatus);
       
   478 	void PrepareToCreateKeyL(TInt aKeyStoreIndex,
       
   479 							TKeyUsagePKCS15 aUsage, TUint aSize, 
       
   480 							const TDesC& aLabel,
       
   481 							CCTKeyInfo::EKeyAlgorithm aAlgorithm,
       
   482 							TInt aAccessType,
       
   483 							TTime aStartDate, TTime aEndDate,  
       
   484 							TRequestStatus& aStatus);
       
   485 	/**
       
   486 	 * A synchronous method to find the key store given a token object handle.
       
   487 	 * Returns NULL if none found.
       
   488 	 */
       
   489 	MCTKeyStore* FindKeyStore(const TCTTokenObjectHandle& aHandle);
       
   490 	/**
       
   491 	 * A synchronous method to find the key store manager given a token object
       
   492 	 * handle.  Returns NULL if none found.
       
   493 	 */
       
   494 	MCTKeyStoreManager* FindKeyStoreManager(const TCTTokenObjectHandle& aHandle);
       
   495 	/** Complete the user's request and clean up state. */
       
   496 	void Complete(TInt aError);
       
   497 	/** Clean up state. */
       
   498 	void Cleanup();
       
   499 	/** Cancel the outstanding request. */
       
   500 	void CancelOutstandingRequest();
       
   501 private:
       
   502 	/**
       
   503 	 * A wrapper around a keystore interface that remebers whether it is a
       
   504 	 * readonly or manager interface.
       
   505 	 */
       
   506 	class CKeyStoreIF
       
   507 	{
       
   508 	public:
       
   509 		CKeyStoreIF(MCTTokenInterface*, TBool);
       
   510 		~CKeyStoreIF();
       
   511 	public:
       
   512 		inline MCTTokenInterface* KeyStore() const {return (iKeyStore);};
       
   513 		inline TBool IsKeyManager() const {return (iIsKeyManager);};
       
   514 	private:
       
   515 		CKeyStoreIF(){};
       
   516 	private:
       
   517 		MCTTokenInterface* iKeyStore;
       
   518 		TBool iIsKeyManager;
       
   519 	};
       
   520 private:
       
   521 	RFs& iFs;
       
   522 	TState iState;
       
   523 	TRequestStatus* iOriginalRequestStatus;
       
   524 	RPointerArray<CKeyStoreIF> iKeyStoresHolder;
       
   525 
       
   526 	RCPointerArray<CCTTokenTypeInfo> iTokenTypes;
       
   527 	TInt iIndexTokenTypes;
       
   528 	MCTTokenType* iTokenType;	
       
   529 	MCTToken* iToken;
       
   530 	MCTTokenInterface* iTokenInterface;
       
   531 	TUid iRequestUid;	
       
   532 	RCPointerArray<HBufC> iTokens;
       
   533 	TInt iIndexTokens;
       
   534 	
       
   535 	MCTKeyStore* iKeyStore;               ///< The key store in use by the current operation or NULL
       
   536 	MCTKeyStoreManager* iKeyStoreManager; ///< The key store manager in use by the current operation or NULL
       
   537 	
       
   538 	RMPointerArray<CCTKeyInfo>* iKeyInfos;
       
   539 	TCTKeyAttributeFilter* iFilter;
       
   540 	CCTKeyInfo* iKeyInfo;
       
   541 	HBufC8* iKeyData;
       
   542 	CCTKeyInfo** iKeyInfoOut; 			 ///< Pointer to client's key info pointer
       
   543 	CPBEncryptParms* iPbeParams;     // PBE parameters for encrypted key export
       
   544 
       
   545 	TInt iIndex;
       
   546 	TInt iNewTimeout;
       
   547 };
       
   548 
       
   549 #endif