wim/WimPlugin/inc/WimKeyStore.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  An implementation of single key store interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CWIMKEYSTORE_H
       
    20 #define CWIMKEYSTORE_H
       
    21 
       
    22 //  INCLUDES
       
    23 
       
    24 #include <mctkeystore.h>
       
    25 #include <e32base.h>
       
    26 
       
    27 // FORWARD DECLARATION
       
    28 
       
    29 class CWimKeyDetails;
       
    30 class MCTAuthenticationObjectList;
       
    31 class CWimToken;
       
    32 class CWimPin;
       
    33 class CWimRSASigner;
       
    34 
       
    35 
       
    36 // CLASS DECLARATION
       
    37 
       
    38 /**
       
    39 *  Represents read only key store.
       
    40 *
       
    41 *  @lib   WimPlugin
       
    42 *  @since Series60 2.1
       
    43 */
       
    44 
       
    45 class CWimKeyStore : public CActive, public MCTKeyStore 
       
    46     {
       
    47     public: // Constructor and destructor
       
    48 
       
    49         /**
       
    50         * Constructor
       
    51         * @param  aToken   (IN) A reference to current token
       
    52         * @return An instance of this class
       
    53         */
       
    54         static CWimKeyStore* NewL( CWimToken& aToken );
       
    55     public: // Function from base class MCTTokenInterface
       
    56         
       
    57         /**
       
    58         * Returns a reference to current token
       
    59         * @return A Reference to current token
       
    60         */
       
    61         MCTToken& Token();
       
    62 
       
    63     public: // Functions from base class MKeyStore
       
    64         
       
    65         /**
       
    66         * Lists all the keys in the store that match the filter
       
    67         * The caller of this function owns all given parameters
       
    68         * @param  aKeys    (OUT) An array to which the returned keys 
       
    69         *         are appended.
       
    70         * @param  aFilter  (IN) A filter controlling which keys are returned
       
    71         * @param  aStatus  (IN/OUT) This will be completed with the final 
       
    72         *         status code. Caller should set it to value TRequestPending
       
    73         *         KErrNone, if no errors detected. Note: if no keys are found,
       
    74         *         it is also KErrNone
       
    75         *         KErrArgument, if aKeys array is NULL
       
    76         *         KErrHardwareNotAvailable, if Wim card suddenly removed
       
    77         *         Any other system wide error code (e.g. KErrNoMemory)
       
    78         * @return void
       
    79         */
       
    80         void List( RMPointerArray<CCTKeyInfo>& aKeys, 
       
    81                    const TCTKeyAttributeFilter& aFilter, 
       
    82                    TRequestStatus& aStatus );
       
    83 
       
    84         /**
       
    85         * Cancels an ongoing List operation
       
    86         * @return void
       
    87         */
       
    88         void CancelList();
       
    89 
       
    90         /**
       
    91         * Retrieves a reference to pointer of key depending on given 
       
    92         * handle (aHandle). The caller of this function owns all given 
       
    93         * parameters.
       
    94         * @param  aHandle   The handle of the required key.
       
    95         * @param  aInfo     The returned key info.
       
    96         * @param  aStatus   Async request notification.
       
    97         *         KErrNone, if no errors detected
       
    98         *         KErrArgument, if aHandle is not current token's handle
       
    99         *         KErrNotFound, if aInfo not found
       
   100         *         KErrHardwareNotAvailable, if Wim card suddenly removed
       
   101         *         Any other system wide error code (e.g. KErrNoMemory)
       
   102         * @return void
       
   103         */
       
   104         void GetKeyInfo( TCTTokenObjectHandle aHandle, 
       
   105                          CCTKeyInfo*& aInfo,
       
   106                          TRequestStatus& aStatus );
       
   107 
       
   108         /**
       
   109         * Cancels an ongoing GetKeyInfo operation
       
   110         * @return void
       
   111         */
       
   112         void CancelGetKeyInfo();
       
   113 
       
   114         /** 
       
   115         * Open an RSA key for signing
       
   116         * @param aHandle The handle of the key to be opened
       
   117         * This must be the handle of a RSA key on this store that is
       
   118         * usable for signing by this process or the operation will fail.
       
   119         * @param aSigner The returned signer object
       
   120         * @param aStatus Asynchronous request notification.
       
   121         * @return void
       
   122         */
       
   123         void Open( const TCTTokenObjectHandle& aHandle, 
       
   124                    MRSASigner*& aSigner,
       
   125                    TRequestStatus& aStatus );
       
   126         
       
   127         /** 
       
   128         * Open a DSA key for signing
       
   129         * @param aHandle -The handle of the key to be opened
       
   130         * This must be the handle of a DSA key on this store that is
       
   131         * usable by this process for signing or the operation will fail.
       
   132         * @param aSigner -The returned signer object
       
   133         * @param aStatus -Asynchronous request notification.
       
   134         * @return void
       
   135         */
       
   136         void Open( const TCTTokenObjectHandle& aHandle, 
       
   137                    MDSASigner*& aSigner, 
       
   138                    TRequestStatus& aStatus );
       
   139 
       
   140         /** 
       
   141         * Open a RSA key for private decryption
       
   142         * @param aHandle -The handle of the key to be opened
       
   143         * This must be the handle of a RSA key on this store that is
       
   144         * usable by this process for decryption or the operation will fail.
       
   145         * @param aDecryptor -The returned decryptor object
       
   146         * @param aStatus -Asynchronous request notification.
       
   147         * @return void
       
   148         */
       
   149         void Open( const TCTTokenObjectHandle& aHandle, 
       
   150                    MCTDecryptor*& aDecryptor,
       
   151                    TRequestStatus& aStatus );
       
   152 
       
   153         /** 
       
   154         * Open a DH key for key agreement
       
   155         * @param aHandle -The handle of the key to be opened
       
   156         * This must be the handle of a DH key on this store that is
       
   157         * usable by this process for decryption or the operation will fail.
       
   158         * @param aDH    -The returned agreement object
       
   159         * @param aStatus -Asynchronous request notification.
       
   160         * @return void
       
   161         */
       
   162         void Open( const TCTTokenObjectHandle& aHandle, 
       
   163                    MCTDH*& aDH, 
       
   164                    TRequestStatus& aStatus );
       
   165 
       
   166         /** 
       
   167         * Cancels an ongoing Open operation
       
   168         * @return void
       
   169         */
       
   170         void CancelOpen();
       
   171 
       
   172         /** 
       
   173         * Returns the public key in DER-encoded ASN-1
       
   174         * @param aHandle    -The handle of the key to be opened
       
   175         * @param aPublicKey -returned key
       
   176         * @param aStatus    -Asynchronous request notification.
       
   177         * @return void
       
   178         */
       
   179         void ExportPublic( const TCTTokenObjectHandle& aHandle,
       
   180                            HBufC8*& aPublicKey,
       
   181                            TRequestStatus& aStatus );
       
   182         
       
   183         /**  
       
   184         * Cancels an ongoing Export operation
       
   185         * @return void
       
   186         */
       
   187         void CancelExportPublic();
       
   188 
       
   189        
       
   190         /** 
       
   191         * Perform signing operation.
       
   192         * @param  aObject -The handle of signer object. 
       
   193         * @param  aDigest -The data to be signed.   
       
   194         * @param  aSignature -The returned signature. This remains owned
       
   195         *         by the signer, and is valid until the signer is released or
       
   196         *         until the next Sign.
       
   197         * @param aStatus -Async status notification
       
   198         * @return void
       
   199         */ 
       
   200         void NonRepudiableRSASign( const TCTTokenObjectHandle& aObject, 
       
   201                                    const TDesC8& aDigest, 
       
   202                                    CRSASignature*& aSignature, 
       
   203                                    TRequestStatus& aStatus );
       
   204 
       
   205     protected:  // From base class MCTTokenInterface
       
   206         
       
   207         virtual void DoRelease();
       
   208 
       
   209     private: // Constructors
       
   210 
       
   211         /**
       
   212         * Default constructor
       
   213         * @param  aToken   (IN) A reference to current token
       
   214         */
       
   215         CWimKeyStore( CWimToken& aToken );
       
   216 
       
   217         // Second phase constructor
       
   218         void ConstructL();
       
   219 
       
   220         // Destructor
       
   221         virtual ~CWimKeyStore();
       
   222 
       
   223     private:
       
   224 
       
   225         /**
       
   226         * Starts initialization on this class.
       
   227         * @return void
       
   228         */
       
   229         void Initialize();
       
   230 
       
   231         /**
       
   232         * Creates one key info for list or get key info operation
       
   233         * @param   aIndex (IN) An index value of current key info in
       
   234         *          the internal array
       
   235         * @return  A pointer to created key info
       
   236         */
       
   237 
       
   238         CCTKeyInfo* CreateKeyInfoL( TInt aIndex );
       
   239 
       
   240         /**
       
   241         * Leavable function to filter keys in list operation.
       
   242         * @return void
       
   243         */
       
   244         void DoFilterKeysL();
       
   245 
       
   246         /**
       
   247         * Leavable function for key creation.
       
   248         * @param   aHandle (IN) Handle of desired authentication object.
       
   249         * @return  A pointer to created authentication object
       
   250         */
       
   251         MCTAuthenticationObject* MakeAuthObjectL( TInt aHandle );
       
   252 
       
   253         /**
       
   254         * Returns boolean value true or false indicating if token is removed
       
   255         * @return  Boolean value: true, if token removed, false if not
       
   256         */
       
   257         TBool TokenRemoved();
       
   258 
       
   259         
       
   260         /**
       
   261         * Checks if token is removed or is this object active
       
   262         * @return  Boolean value: true if allowed, false if not
       
   263         */
       
   264         TBool EnteringAllowed( TRequestStatus& aStatus );
       
   265 
       
   266 
       
   267     private: // From base class CActive
       
   268 
       
   269         void RunL();
       
   270         
       
   271         /** 
       
   272         * Leaves in RunL are handled here.
       
   273         * @param  aError  Leaving code
       
   274         * @return An integer that should be KErrNone if leave was handled.
       
   275         */
       
   276         TInt RunError( TInt aError );
       
   277         
       
   278         void DoCancel();
       
   279 
       
   280     private: // Data
       
   281 
       
   282         // A reference to current token of this interface
       
   283         CWimToken& iToken;
       
   284 
       
   285         // State flag for RunL
       
   286         enum TPhase
       
   287             {
       
   288             EIdle,
       
   289             EOpenAuthObjectsInterface,
       
   290             EListAuthObjects,
       
   291             EGetKeyList,
       
   292             ECheckGetKeyList,
       
   293             EFilterKeys,
       
   294             EGetKey,
       
   295             ECreateRSASignerObject,
       
   296             EStartNonRepudiableRSASign,
       
   297             ESignCompleted,
       
   298             EStartExportPublicKey,
       
   299             EExportPublicKeyDone
       
   300             };
       
   301 
       
   302         // Flag for internal state machine
       
   303         TPhase iPhase;
       
   304 
       
   305         // Flag for internal state machine
       
   306         TPhase iPhaseOriginal;
       
   307 
       
   308         // The pointed object acts as a converter between
       
   309         // CWimCertStore/CWimKeyStore interface and WimClient
       
   310         // This class owns the pointed object
       
   311         CWimKeyDetails* iCWimKeyDetails;
       
   312 
       
   313         // Used for saving caller status in asynchronous call
       
   314         // This class don't own the pointed object
       
   315         TRequestStatus* iOriginalRequestStatus;
       
   316 
       
   317         // Temporal array for key info pointers
       
   318         // This array is used to append key infos in List operation
       
   319         // This class don't own the pointed objects
       
   320         RPointerArray<CCTKeyInfo>* iKeyList;
       
   321 
       
   322         // Temporal array for key infos. 
       
   323         // This array is used to fetch key infos from WimClient.
       
   324         RPointerArray<CCTKeyInfo> iKeyInfos;
       
   325 
       
   326         // Used with list operation to filter keys
       
   327         TCTKeyAttributeFilter iKeyFilter;   
       
   328 
       
   329         // Index for going through all keys asynchronously 
       
   330         // in list operation.
       
   331         TInt iKeyIndex;
       
   332 
       
   333         // Used to fetch one key info from wimclient
       
   334         // This class don't own the pointed object.
       
   335         CCTKeyInfo** iInfo;
       
   336 
       
   337         // Key value for key object. Used in asynchronous call of
       
   338         // getting one key info.
       
   339         TInt iHandle;
       
   340         
       
   341         // Array for key info keys fetched from wimclient
       
   342         CArrayFixFlat<TUint8>* iKeyNumbers;
       
   343 
       
   344         // Array of pointers to PIN-NRs.This class don't own the pointed
       
   345         // objects
       
   346         const CArrayPtrFlat<CWimPin>* iPinNRs; 
       
   347 
       
   348         // Is key list done or not already. Set to true value in the first
       
   349         // key list.
       
   350         TBool iListDone;
       
   351 
       
   352         //Signer object, which is returned to caller. Not Owned.
       
   353         CWimRSASigner*              iSigner;
       
   354               
       
   355         //Handle stored during opening new RSA signer object.
       
   356         TCTTokenObjectHandle        iOpenSigninKeyHandle;
       
   357 
       
   358         //Buffer, which holds received signature from server. Owned.
       
   359         HBufC8*                     iSignature;
       
   360         
       
   361         //Signature object which is filled with data received from server.
       
   362         //Not owned.
       
   363         CRSASignature**              iRSASignature; 
       
   364         
       
   365         //Buffer used to contain KeyId in Sign and public key export
       
   366         //operations. Owned.
       
   367         HBufC8*                     iKeyId;
       
   368 
       
   369         //Buffer to hold public key data during public key export. Not Owned.
       
   370         HBufC8*                     iPublicKey;
       
   371 
       
   372         // The index of exported key
       
   373         TInt                        iExportKeyIdIndex;
       
   374         
       
   375         TInt                        iRSAKeyIdIndex;
       
   376         
       
   377         const TDesC8*               iDigest;
       
   378         
       
   379     };
       
   380 
       
   381 #endif      // CWIMKEYSTORE_H   
       
   382             
       
   383 // End of File