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