vpnengine/pkiservice/inc/keyoperationprovider.h
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2008 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 "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:   PKI server main module
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_KEYOPERATIONPROVIDER_H
       
    22 #define C_KEYOPERATIONPROVIDER_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <f32file.h>
       
    26 #include <unifiedkeystore.h>
       
    27 #include "pkidefs.h"
       
    28 
       
    29 class CUnifiedKeyStore;
       
    30 class CPKISession;
       
    31 class CPkiServiceSigner;
       
    32 class CPkiServiceDecryptor;
       
    33 class CLogonServices;
       
    34 class CKeyManager;
       
    35 class CKeyOperationQueue;
       
    36     
       
    37 /**
       
    38 * A class that collects all the keyoperation functionality.
       
    39 *
       
    40 * The instance of this class is owned by CKeyOperationQueue, which
       
    41 * calls the methods according to the client request. When an operation
       
    42 * is completed the CKeyPairOperationProvider calls the associated callback
       
    43 * from CKeyOperationQueue.
       
    44 *
       
    45 * The Initialize operation must be completed succesfully, before any other
       
    46 * requests can be made to this class.
       
    47 *
       
    48 * Any current time, there can be only one request under process.
       
    49 */
       
    50 class CKeyPairOperationProvider : public CActive
       
    51     {
       
    52 public:
       
    53     static CKeyPairOperationProvider* NewL(CKeyOperationQueue& aKeyOperationQueue);
       
    54      ~CKeyPairOperationProvider();
       
    55 
       
    56     /**
       
    57      * Initializes the keystore.
       
    58      * This is an asynchronous method. 
       
    59      * CPKISession::KeyStoreInitComplete is called when this
       
    60      * request is completed.
       
    61      */
       
    62     void Initialize();         
       
    63     void GetKeyPairList(const TPKIKeyIdentifier& aKeyId, TInt aUsedKeyStore);
       
    64                    
       
    65     /**
       
    66      * Decrypts the data using key specified in aKeyId.
       
    67      * The key has to be stored in the store defined by
       
    68      * method SetKeyStore.
       
    69      */
       
    70     void Decrypt(const TPKIKeyIdentifier& aKeyId,
       
    71                  TInt aUsedKeyStore,
       
    72                  HBufC8* aEncryptedData,
       
    73                  TInt aOutputLength);  
       
    74                  
       
    75     void Sign(const TPKIKeyIdentifier& aKeyId,
       
    76               TInt aUsedKeyStore,
       
    77               HBufC8* aDataToBeSigned);  
       
    78        
       
    79     void GetPublicKey(const TPKIKeyIdentifier& aKeyId, TInt aUsedKeyStore);        
       
    80             
       
    81     void Logon();
       
    82     void Logoff();
       
    83     void ChangePassword();
       
    84     
       
    85     void RemoveKeyPair(const TPKIKeyIdentifier& aKeyId, TInt aUsedKeyStore);        
       
    86     void GenerateKeyPair(const TUint aKeySize, TPKIKeyAlgorithm aKeyAlgorithm, TInt aUsedKeyStore);   
       
    87             
       
    88     void ImportKeyPair(HBufC8* aKeyData, TInt aUsedKeyStore);   //Takes the ownership of the data
       
    89     
       
    90 protected:
       
    91 	void RunL();
       
    92 	void DoCancel();
       
    93 	TInt RunError(TInt aError);
       
    94     
       
    95 private:
       
    96 	enum TKeyOperation
       
    97 		{
       
    98 		EKeyOperationIdle = 0,
       
    99 		EKeyOperationInitialize,
       
   100 		EKeyOperationSetPassPhraseTimeout,
       
   101 		EKeyOperationGetKeyList,
       
   102 		EKeyOperationGetKeyDetails,
       
   103 		EKeyOperationDecrypting,
       
   104 		EKeyOperationSigning,		
       
   105 		EKeyOperationPublicKeyExport,
       
   106 		EKeyOperationLogon,
       
   107 		EKeyOperationLogoff,
       
   108 		EKeyOperationLogonForChangePassword,
       
   109 		EKeyOperationChangingPassword,
       
   110 		EKeyOperationRemoveKeyPair,
       
   111 		EKeyOperationGeneratingKeyPair,
       
   112 		EKeyOperationImportingKeyPair
       
   113 		};
       
   114 
       
   115     CKeyPairOperationProvider(CKeyOperationQueue& aKeyOperationQueue);
       
   116     void ConstructL();
       
   117 
       
   118 
       
   119     void DecryptL(const TPKIKeyIdentifier& aKeyId,
       
   120                   TInt aUsedKeyStore,
       
   121                   HBufC8* aEncryptedData,
       
   122                   TInt aOutputLength);                                    
       
   123 
       
   124     void CleanupCryptoOperation();
       
   125 
       
   126     CArrayFixFlat<TKeyListEntry>* MakeKeyEntryListL(RMPointerArray<CCTKeyInfo> aKeysList,
       
   127                                                     TInt aUsedKeyStore) const;
       
   128 
       
   129     TBool 				 iIsInitialized;
       
   130     TKeyOperation        iKeyOperation;
       
   131 
       
   132     CKeyOperationQueue&     iKeyOperationQueue;
       
   133     RFs 				    iFileServer;
       
   134     CUnifiedKeyStore* 	    iUnifiedKeyStore; 
       
   135     TInt                    iUsedKeyStore; //Not owned by this instance.
       
   136     
       
   137     RMPointerArray<CCTKeyInfo> iKeysList;
       
   138     
       
   139     HBufC8*                    iInputData;  //Used by Decrypt and Sign operations.
       
   140     HBufC8*                    iOutputData; //Used by Decrypt and Sign operations.
       
   141     TPtr8                      iOutputDataPtr;
       
   142     
       
   143     TPKIKeyIdentifier          iKeyId; //Used by store and generate keypair
       
   144     
       
   145     CPkiServiceDecryptor*      iPkiDecryptor;    
       
   146     CPkiServiceSigner*         iPkiSigner;
       
   147     CLogonServices*            iLogonService;
       
   148     CKeyManager*               iKeyManager;
       
   149     };
       
   150 
       
   151 #endif // C_KEYOPERATIONPROVIDER_H