wim/inc/WimKeyDetails.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:  Interface which fetches all keyInfos from WIM -card.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef WIMKEYDETAILS_H
       
    21 #define WIMKEYDETAILS_H
       
    22 
       
    23 
       
    24 #include "WimClsv.h"
       
    25 #include <ct.h>
       
    26 #include <mctkeystore.h>
       
    27 #include <e32base.h>
       
    28 
       
    29 
       
    30 //FORWARD DECLARATION
       
    31 class RWimCertMgmt;
       
    32 
       
    33 
       
    34 //CLASS DECLARATION
       
    35 /**
       
    36 *  This class lists all keyInfos found from WIM -card.
       
    37 *  @lib WimClient
       
    38 *  @since Series60 2.1
       
    39 */
       
    40 class CWimKeyDetails: public CActive
       
    41     {
       
    42     public:
       
    43 
       
    44         /**
       
    45         * Two-phased constructor.
       
    46         * @param aToken -Reference to current token
       
    47         */
       
    48         IMPORT_C static CWimKeyDetails* NewL( MCTToken& aToken );
       
    49         
       
    50         /**
       
    51         * Destructor
       
    52         */
       
    53         IMPORT_C virtual ~CWimKeyDetails();
       
    54 
       
    55 
       
    56         /** 
       
    57         * Lists all the keys in the WIM and creates CCTKeyInfo objects 
       
    58         * from received information. CCTKeyInfo objects are inserted to array 
       
    59         * aKeys.
       
    60         * @param aKeys      -Array where keyInfos are 
       
    61         *                   inserted. Caller is responsible 
       
    62         *                   to deallocate Array.(OUT)
       
    63         * @param aKeyNumbers -Array where keynumbers are inserted. Each key
       
    64         *                   has its own number. This number helps to solve 
       
    65         *                   which key is associated with which PIN.
       
    66         *                    Caller is responsible to 
       
    67         *                   deallocate Array. (OUT)
       
    68         * @aStatus          -TRequestStatus from caller (IN/OUT)
       
    69         * @return void
       
    70         */
       
    71         IMPORT_C void GetKeyList( RPointerArray<CCTKeyInfo>& aKeys,
       
    72                                   CArrayFixFlat<TUint8>& aKeyNumbers,
       
    73                                   TRequestStatus& aStatus );
       
    74         
       
    75         /* 
       
    76         * Cancels outgoing listing operation
       
    77         * @return void
       
    78         */
       
    79         IMPORT_C void CancelList();
       
    80 
       
    81         /*  
       
    82         * Sign some data. Authentication is handled by server.
       
    83         * @since Series 60 2.6
       
    84         * @param aData    The data to be signed - this should be some 
       
    85         *                 form of hash of the actual message to be signed.  
       
    86         *                 If the data is too long, this method will return 
       
    87         *                 KErrOverflow through aStatus. (IN)
       
    88         * @param aSignature Signature which is given back to caller. (OUT)
       
    89         * @param aKeyId.  KeyId for signing operation.(IN)
       
    90         * @param aStatus    Caller's status (IN/OUT)
       
    91         * @return void
       
    92         */
       
    93         IMPORT_C void Sign( const TDesC8& aData,
       
    94                             TDesC8& aKeyId,
       
    95                             HBufC8*& aSignature,
       
    96                             TRequestStatus& aStatus );
       
    97 
       
    98         /** 
       
    99         * Cancel signing operation
       
   100         * @since Series 60 2.6
       
   101         * @return void
       
   102         */
       
   103         IMPORT_C void CancelSign();
       
   104 
       
   105         /** 
       
   106         * Export public key
       
   107         * @since Series 60 2.6
       
   108         * @param aKeyId  -The KeyId of the key to be exported (IN)
       
   109         * @param aPublicKey -DER Encoded public key. Must be allocated
       
   110         *                    by caller(OUT)
       
   111         * @param aStatus    -Caller's status (IN/OUT)
       
   112         */
       
   113         IMPORT_C void ExportPublicKeyL( TDesC8& aKeyId, 
       
   114                                         HBufC8*& aPublicKey,
       
   115                                         TRequestStatus& aStatus );
       
   116 
       
   117         /** 
       
   118         * Cancels ongoing export operation
       
   119         * @since Series 60 2.6
       
   120         * @return void
       
   121         */
       
   122         IMPORT_C void CancelExport();
       
   123 
       
   124     private:
       
   125         /** 
       
   126         * Allocates memory for Array which is filled by server.
       
   127         * @return void
       
   128         */
       
   129         void AllocMemoryForKeyListL();
       
   130         
       
   131         /** 
       
   132         * Deallocates memory from the Array which was filled by server.
       
   133         * @return void
       
   134         */
       
   135         void DeallocMemoryFromKeyList();
       
   136 
       
   137         
       
   138         /** 
       
   139         * Allocates memory for Keyinfo structure.
       
   140         * @param aKeyInfo   -Struct where allocated pointers are inserted.
       
   141         * @return void
       
   142         */
       
   143         void AllocMemoryForKeyInfoL( TKeyInfo& aKeyInfo );   
       
   144  
       
   145         /** 
       
   146         * Deallocates memory from Keyinfo structure.
       
   147         * @return void
       
   148         */
       
   149         void DeallocMemoryFromKeyInfo();
       
   150 
       
   151         /** 
       
   152         * Allocates memory for data to be signed
       
   153         * @param aData -Data to be signed
       
   154         * @param aKeyId -KeyId of the key to be used for sign
       
   155         * @return void
       
   156         */
       
   157         void AllocMemoryForSignL( const TDesC8& aData, const TDesC8& aKeyId );
       
   158 
       
   159         /** 
       
   160         * Deallocates previously allocated data after signing operation.
       
   161         * @return void
       
   162         */
       
   163         void DeallocMemoryFromSign();
       
   164         
       
   165         
       
   166         /**
       
   167         * Sets own iStatus to KRequestPending, and signals it 
       
   168         * with User::RequestComplete() -request. This gives chance 
       
   169         * to activescheduler to run other active objects. After a quick
       
   170         * visit in activescheduler, signal returns to RunL() and starts next
       
   171         * phase of operation. 
       
   172         * @return void
       
   173         */
       
   174         void SignalOwnStatusAndComplete();
       
   175 
       
   176         /** 
       
   177         * Converts key list parameters. Extracts data out from key list 
       
   178         * & key number. Extracted data is inserted to an RArray.
       
   179         * @return void
       
   180         */
       
   181         void ConvertKeyListL();
       
   182 
       
   183         /*  
       
   184         * Converts key usage to match new key usage requirement
       
   185         * @param aKeyUsage  -Value to be converted
       
   186         * @return TKeyUsagePKCS15 -New form of key usage
       
   187         */
       
   188         TKeyUsagePKCS15 ConvertKeyUsage( TUint16 aKeyUsage );
       
   189 
       
   190 
       
   191     private: //from CActive
       
   192         
       
   193         /**
       
   194         * Different phases are handled here.
       
   195         * @return void
       
   196         */
       
   197         void RunL();
       
   198 
       
   199         /**
       
   200         * Cancellation function
       
   201         * Deallocates member variables and completes client status with
       
   202         * KErrCancel error code.
       
   203         * @return void
       
   204         */
       
   205         void DoCancel();
       
   206 
       
   207         /**
       
   208         * The active scheduler calls this function if this active 
       
   209         * object's RunL() function leaves. 
       
   210         * Handles necessary cleanup and completes request with
       
   211         * received error code.
       
   212         * @param aError -Error which caused this event
       
   213         * @return TInt  -Error code to activescheduler, is always KErrNone.
       
   214         */ 
       
   215         TInt RunError( TInt aError );
       
   216 
       
   217     private:
       
   218 
       
   219         /**
       
   220         * Default constructor is private.
       
   221         */
       
   222         void ConstructL();
       
   223         
       
   224         /** 
       
   225         * Default constructor
       
   226         * @param aToken -Reference to current token
       
   227         */
       
   228         CWimKeyDetails( MCTToken& aToken );
       
   229 
       
   230     private:
       
   231 
       
   232         /** 
       
   233         * Seven different phases which handles list, sign and export public
       
   234         * key operations
       
   235         */
       
   236         enum TPhase
       
   237             {
       
   238             EGetKeyList,
       
   239             EConvertParams,
       
   240             EGetKeyInfo,
       
   241             ESign,
       
   242             ESignCompleted,
       
   243             EExportPublicKey
       
   244             };
       
   245         
       
   246     private:
       
   247         //Reference to current token. Needed in CCTCertInfo creation.
       
   248         MCTToken&                       iToken;
       
   249 
       
   250         //Handle to connection with server. Owned.
       
   251         RWimCertMgmt*                   iConnectionHandle;
       
   252 
       
   253         //Client status is stored here while operation
       
   254         //on the server side is done.        
       
   255         TRequestStatus*                 iClientStatus;
       
   256 
       
   257         //Used to handle different phases in RunL()
       
   258         TPhase                          iPhase;
       
   259 
       
   260         //Array which is used to contain key list.
       
   261         //Not owned. Caller is responsible to destroy array.
       
   262         RPointerArray<CCTKeyInfo>*      iKeys;
       
   263 
       
   264         //Buffer which is used to contain keyreference information. Owned.
       
   265         HBufC8*                         iKeyList;
       
   266 
       
   267         //Pointer to iKeylist. Owned.
       
   268         TPtr8*                          iKeyListPtr;
       
   269 
       
   270         // The number of keys
       
   271         TInt                            iKeyNumber;
       
   272 
       
   273         //Buffer which is used for keys label when constructing new keyinfo
       
   274         //-objects. Owned.
       
   275         HBufC8*                         iLabel;
       
   276      
       
   277         //Pointer to iLabel. Owned.
       
   278         TPtr8*                          iLabelPtr;
       
   279 
       
   280         //Buffer which is used to contain unique modifier for a key. Used when
       
   281         //constructing new keyinfo -objects. Owned.
       
   282         HBufC8*                         iKeyId;
       
   283      
       
   284         //Pointer to iKeyId. Owned.
       
   285         TPtr8*                          iKeyIdPtr;
       
   286         
       
   287         //Array which holds keyReferences. These references are needed when
       
   288         //getting keyinfo for a single key.Owned.
       
   289         RArray<TInt32>                  iKeyReferences;
       
   290 
       
   291         //Array which hold keyNumber for each CCTKeyInfo -object, which are
       
   292         //created and inserted to iKeys -array. Not owned.
       
   293         CArrayFixFlat<TUint8>*          iKeyNumberArray;   
       
   294         
       
   295         //counter which informs how many keyinfos have been created.
       
   296         TInt                            iFetchedKeyInfos;
       
   297 
       
   298         //Struct which is used when signing data.
       
   299         TKeySignParameters              iKeySignParameters;
       
   300 
       
   301         //Struct which is used when exporting a key.
       
   302         TExportPublicKey                iExportPublicKey;
       
   303 
       
   304         //Buffer which holds data to be signed. Owned.
       
   305         HBufC8*                         iSigningData;
       
   306         
       
   307         //Pointer to iSigningData. Owned.
       
   308         TPtr8*                          iSigningDataPtr;
       
   309 
       
   310         //Holds information which key is used for signing
       
   311         TInt                            iSignKeyHandle;
       
   312         
       
   313         //Buffer which holds received signature from WIM, if signing was
       
   314         //succesful. Not owned
       
   315         HBufC8*                         iSignature;
       
   316 
       
   317         //Pointer to iSignature. Owned.
       
   318         TPtr8*                          iSignaturePtr;
       
   319 
       
   320         //Buffer which holds DER encoded public key. Not owned.
       
   321         HBufC8*                         iPublicKey;
       
   322 
       
   323         //Pointer to iPublicKey.Owned
       
   324         TPtr8*                          iPublicKeyPtr;
       
   325         
       
   326         //The pack to store key number
       
   327         TPckg<TInt>                     iPckg;
       
   328 
       
   329     };
       
   330 
       
   331 
       
   332 #endif  //WIMKEYDETAILS_H
       
   333 
       
   334 
       
   335 
       
   336 
       
   337 
       
   338 
       
   339 
       
   340 
       
   341 
       
   342 
       
   343 
       
   344 
       
   345 
       
   346 
       
   347 
       
   348 
       
   349 
       
   350 
       
   351 
       
   352 
       
   353