wim/inc/WimCertConverter.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 handles certificate related operations
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef WIMCERTCONVERTER_H
       
    21 #define WIMCERTCONVERTER_H
       
    22 
       
    23 
       
    24 //INCLUDES
       
    25 #include "WimClsv.h"        
       
    26 #include <e32base.h>
       
    27 #include <ct.h> 
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class RWimCertMgmt;
       
    31 class CWimCertInfo;
       
    32 class CCTCertInfo;
       
    33 
       
    34 // CONSTANTS
       
    35 typedef HBufC8* PHBufC8;
       
    36 typedef TPtr8* PTPtr8;
       
    37 
       
    38 
       
    39 
       
    40 //CLASS DECLARATION
       
    41 /**
       
    42 *  Interface which handles certificate related operations 
       
    43 *  with WimServer.
       
    44 *  Caller can add a certificate, remove a certificate,
       
    45 *  list a certificate and get certificate details.
       
    46 *
       
    47 *  @lib WimClient
       
    48 *  @since Series60 2.1
       
    49 */
       
    50 class CWimCertConverter: public CActive
       
    51     {
       
    52 
       
    53     public:
       
    54 
       
    55         /**
       
    56         * Two-phased constructor.
       
    57         * @param aToken -Reference to current token
       
    58         */
       
    59         IMPORT_C static CWimCertConverter* NewL( MCTToken& aToken );
       
    60 
       
    61         
       
    62         /**
       
    63         * Restores certificates from WIM cache. If Restore cannot find
       
    64         * any certificate, it will return KErrNotFound to caller.
       
    65         * @param  aArray    -Array where new certificates are 
       
    66         *                   inserted. Caller is responsible 
       
    67         *                   to deallocate CWimCertInfo -objects
       
    68         *                   by calling ResetAndDestroy.(IN/OUT)
       
    69         * @param  aStatus   -Status from caller.         
       
    70         * @return void
       
    71         */
       
    72         IMPORT_C void Restore( RPointerArray<CWimCertInfo>& aArray, 
       
    73                                TRequestStatus& aStatus );
       
    74 
       
    75         
       
    76         /** 
       
    77         * Cancels outgoing Restore operation. Sets an internal flag to true. 
       
    78         * After necessary cleanup, caller is signalled with KErrCancel 
       
    79         * -error code.
       
    80         * @return void
       
    81         */
       
    82         IMPORT_C void CancelRestore();
       
    83         
       
    84         /**
       
    85         * Retrieves the actual certificate. In case of other cert than
       
    86         * Url cert the binary encoded certificate is written into the 
       
    87         * aEncodedCert parameter. In case of Url cert the data is 
       
    88         * the actual url.
       
    89         * @param  aIndex. Used to point iCertRefLst and iCertInfoArr 
       
    90         *         -arrays for correct certificate.
       
    91         * @param  aEncodedCert. A buffer to put the certificate in. 
       
    92         * @param  aStatus. A request status that is completed when the 
       
    93         *         operation has finished.(IN/OUT)
       
    94         * @return void
       
    95         */
       
    96         IMPORT_C void RetrieveCertByIndexL( const TInt aIndex,
       
    97                                            TDes8& aEncodedCert, 
       
    98                                            TRequestStatus& aStatus );
       
    99 
       
   100         /**
       
   101         * Cancels an ongoing Retrieve operation.
       
   102         * If retrieve is cancelled, then operation is completed with 
       
   103         * KErrCancel -error code.
       
   104         * @return void
       
   105         */
       
   106         IMPORT_C void CancelRetrieve();
       
   107 
       
   108         
       
   109         /** 
       
   110         * Adds a certificate to the cert store.
       
   111         * The caller of this function owns all its parameters.
       
   112         * @since Series 60 2.6
       
   113         * @param  aLabel  -The label of the certificate to add 
       
   114         * @param  aFormat  -The format of the certificate. Supported formats are
       
   115                            EX509Certificate, EWTLSCertificate,
       
   116                            EX509CertificateUrl and EWTLSCertificateUrl 
       
   117         * @param  aCertificateOwnerType  -The owner type. Supported types are
       
   118                                         ECACertificate and EUserCertificate.
       
   119         * @param  aSubjectKeyId  -The Subject key ID
       
   120         * @param  aIssuerKeyId  -The issuer key ID
       
   121         * @param  aCert  -The certificate to add
       
   122         * @param  aStatus  This is completed with the return result 
       
   123         *         when the add has completed (IN/OUT)
       
   124         * @return  void
       
   125         */
       
   126         IMPORT_C void AddCertificate( const TDesC& aLabel, 
       
   127                               const TCertificateFormat aFormat,
       
   128                               const TCertificateOwnerType aCertificateOwnerType, 
       
   129                               const TKeyIdentifier& aSubjectKeyId,
       
   130                               const TKeyIdentifier& aIssuerKeyId,
       
   131                               const TDesC8& aCert, 
       
   132                               TRequestStatus& aStatus );
       
   133         
       
   134         /**
       
   135         * Cancels an ongoing add operation.
       
   136         * @since Series 60 2.6
       
   137         * @return void
       
   138         */
       
   139         IMPORT_C void CancelAddCertificate();
       
   140 
       
   141         /** 
       
   142         * Removes a certificate from WIM.
       
   143         * @since Series 60 2.6
       
   144         * @param aIndex     -Used to point iCertInfoArr 
       
   145         *                   for the certificate to be removed.
       
   146         * @param aStatus    -Status from caller 
       
   147         * @return void      
       
   148         */
       
   149         IMPORT_C void RemoveL( const TInt aIndex, TRequestStatus& aStatus );
       
   150 
       
   151         /** 
       
   152         * Cancels ongoing remove operation.
       
   153         * @since Series 60 2.6
       
   154         * @return void
       
   155         */
       
   156         IMPORT_C void CancelRemove();
       
   157 
       
   158         /**
       
   159         * Destructor
       
   160         */
       
   161         IMPORT_C virtual ~CWimCertConverter();
       
   162 
       
   163     private:
       
   164 
       
   165         /**
       
   166         * By default Symbian 2nd phase constructor is private.
       
   167         */
       
   168         void ConstructL();
       
   169 
       
   170         /**
       
   171         * C++ default constructor.
       
   172         * @param aToken -Reference to current token
       
   173         */
       
   174         CWimCertConverter( MCTToken& aToken );
       
   175 
       
   176     private: //from CActive
       
   177         
       
   178         /**
       
   179         * Different phases are handled here.
       
   180         * @return void
       
   181         */
       
   182         void RunL();
       
   183 
       
   184         /**
       
   185         * Cancellation function
       
   186         * Deallocates member variables and completes client status with
       
   187         * KErrCancel error code.
       
   188         * @return void
       
   189         */
       
   190         void DoCancel();
       
   191 
       
   192         /**
       
   193         * The active scheduler calls this function if this active 
       
   194         * object's RunL() function leaves. 
       
   195         * Handles necessary cleanup and completes request with
       
   196         * received error code.
       
   197         * @param aError -The error code which caused this function call.
       
   198         * @return TInt  -Error code to activescheduler, is always KErrNone.
       
   199         */ 
       
   200         TInt RunError( TInt aError );
       
   201         
       
   202     private:
       
   203         
       
   204         /**
       
   205         * Allocates memory for the array which is filled by server.
       
   206         * @param  aWimCertInfoArr    -Array to be initialized 
       
   207         * @param  aCount             -Count of elements in the array         
       
   208         * @return void
       
   209         */
       
   210         void AllocWimCertInfoL( TWimCertInfo* aWimCertInfoArr, TInt aCount );  
       
   211         
       
   212         /**
       
   213         * Deallocates memory from the array.
       
   214         * @return void
       
   215         */
       
   216         void DeallocWimCertInfo();   
       
   217         
       
   218         /**
       
   219         * Allocates memory for a struct which is filled by server.
       
   220         * @return void
       
   221         */
       
   222         void AllocMemoryForCertDetailsL();
       
   223 
       
   224         /**
       
   225         * Creates new certificate objects which can be returned to the caller.
       
   226         * @return void
       
   227         */
       
   228         void CreateNewCertObjectsL();
       
   229         
       
   230         /**
       
   231         * Creates new wim certificate objects.
       
   232         * @return void
       
   233         */
       
   234         void CreateNewWimCertObjectL();
       
   235 
       
   236         /**
       
   237         * Gets trusted usages.
       
   238         * @return void
       
   239         */
       
   240         void GetTrustedUsagesL();
       
   241 
       
   242         /**
       
   243         * Completion of trusted usages.
       
   244         * @return void
       
   245         */
       
   246         void TrustedUsagesDoneL();
       
   247 
       
   248         /**
       
   249         * Sets own iStatus to KRequestPending, and signals it 
       
   250         * with User::RequestComplete() -request. This gives chance 
       
   251         * to activescheduler to run other active objects. After a quick
       
   252         * visit in activescheduler, signal returns to RunL() and starts next
       
   253         * phase of operation. 
       
   254         * @return void
       
   255         */
       
   256         void SignalOwnStatusAndComplete();
       
   257         
       
   258         /**
       
   259         * Allocates memory for member variables, which are needed when adding
       
   260         * a certificate asynchronously to WIM.
       
   261         * @param aLabel -certificate label (IN)
       
   262         * @param aIssuerKeyId -Issuer KeyId of a certificate 
       
   263         * @param aSubjectKeyId -Subject KeyId of a certificate
       
   264         * @param aCert -certificate data
       
   265         * @return void
       
   266         */
       
   267         void AllocMemoryForAddCertL( const TDesC& aLabel, 
       
   268                             const TKeyIdentifier& aIssuerKeyId, 
       
   269                             const TKeyIdentifier& aSubjectKeyId,
       
   270                             const TDesC8& aCert );
       
   271 
       
   272         /**
       
   273         * Copies data to caller's buffer by using pointer.
       
   274         * @return void
       
   275         */
       
   276         void CopyRetrievedCertData();
       
   277 
       
   278 
       
   279         /**
       
   280         * DeAllocates memory from member variables, which are used
       
   281         * when communicating with WIM.
       
   282         * @return void
       
   283         */
       
   284         void DeallocCertHBufs();
       
   285 
       
   286         /**
       
   287         * If user has cancelled initialization process, dealloc references 
       
   288         * from loaded certs. 
       
   289         * @return void
       
   290         */
       
   291         void DeallocReferences();
       
   292 
       
   293         /**
       
   294         * Returns certificate format according to received index.
       
   295         * @param aIndex -index of the certificate to be returned.
       
   296         * @return TCertificateFormat -format of the certificate
       
   297         */
       
   298         TCertificateFormat GetCertFormatByIndex( TInt aIndex );
       
   299 
       
   300     private:
       
   301 
       
   302         /**
       
   303         * Ten different phases, which are used to 
       
   304         * Read certificates from WIM cache, create new certificate objects,
       
   305         * retrieve certificate, add certificate and remove certificate.
       
   306         */
       
   307         enum TPhase
       
   308             {
       
   309             EListCertsFromWim,
       
   310             ECreateNewCertObjects,
       
   311             EGetTrustedUsages,
       
   312             ECertObjectsDone,
       
   313             ETrustedUsagesDone,
       
   314             ERetrieveCertificate,
       
   315             ERetrievingCompleted,
       
   316             EAddCertificate,
       
   317             EAddCertificateCompleted,
       
   318             ERemove,
       
   319             ERemoveCompleted
       
   320             };
       
   321                    
       
   322     private:
       
   323               
       
   324         //Client status is stored here while operation
       
   325         //on the server side is done.
       
   326         TRequestStatus*                 iClientStatus;
       
   327         
       
   328         //Array which is used to contain new certificate objects.
       
   329         //Not owned. Caller is responsible to destroy array.
       
   330         RPointerArray<CWimCertInfo>*    iArray;
       
   331         
       
   332         //Details of the certificate. Owned.
       
   333         TWimCertDetails                 iWimCertDetails;
       
   334         
       
   335         //Struct which is used when adding a certificate
       
   336         //to WIM.
       
   337         TWimCertAddParameters           iParam;
       
   338 
       
   339         //Struct which is used when removing a certificate for WIM.
       
   340         TWimCertRemoveAddr              iWimCertRemoveAddr;    
       
   341         
       
   342         //Reference to current token. Needed in CCTCertInfo creation.
       
   343         MCTToken&                       iToken;
       
   344         
       
   345         //Handle to connection with server. Owned.
       
   346         RWimCertMgmt*                   iConnectionHandle;
       
   347         
       
   348         //Typedefs for the reference to certificate. Owned.
       
   349         TCertificateAddressList         iCertRefLst; 
       
   350         
       
   351         // Certificate information structure. Owned.
       
   352         TWimCertInfo*                    iCertInfoArr;
       
   353         
       
   354         //Used to handle different phases.
       
   355         TPhase                          iPhase;
       
   356                 
       
   357         //Index to point which certificate we want to be retrieved
       
   358         TInt                            iCertRetrieveIndex;
       
   359                  
       
   360         //Used to inform the size of the array, needed in array construction/
       
   361         //destruction.
       
   362         TInt                            iArraySize;
       
   363         
       
   364         //The count of certificates
       
   365         TUint8                          iCertCount;
       
   366 
       
   367         //Pointer to HBufC8*. This is used as an array when listing every 
       
   368         //certificate from WIM to an array during startup. Owned.
       
   369         PHBufC8*                        iLabel;
       
   370 
       
   371         //Pointer to HBufC8*. This is used as an array when listing every 
       
   372         //certificate from WIM to an array during startup. Owned.
       
   373         PHBufC8*                        iKeyId;
       
   374 
       
   375         //Pointer to HBufC8*. This is used as an array when listing every 
       
   376         //certificate from WIM to an array during startup. Owned.
       
   377         PHBufC8*                        iCAId;
       
   378 
       
   379         //Pointer to HBufC8*. This is used as an array when listing every 
       
   380         //certificate from WIM to an array during startup. Owned.
       
   381         PHBufC8*                        iIssuerHash;
       
   382 
       
   383         //Pointer to iLabel. Also used as an array. Owned.        
       
   384         PTPtr8*                         iLabelPtr;
       
   385 
       
   386         //Pointer to iKeyId. Also used as an array. Owned.        
       
   387         PTPtr8*                         iKeyIdPtr;
       
   388 
       
   389         //Pointer to iCAId. Also used as an array. Owned.        
       
   390         PTPtr8*                         iCAIdPtr;
       
   391 
       
   392         //Pointer to iIssuerHash. Also used as an array. Owned.
       
   393         PTPtr8*                         iIssuerHashPtr;
       
   394             
       
   395         //Modifiable 8-bit descriptor which points
       
   396         //to caller's descriptor. We copy retrieved certificate
       
   397         //data to this descriptor. Owned.
       
   398         TDes8*                          iEncodedCert;
       
   399 
       
   400         //Buffer which is used to contain certificate data. Owned.
       
   401         HBufC8*                         iCertHBufOne;
       
   402         //Pointer to iCertHBufOne. Owned.
       
   403         TPtr8*                          iCertHBufOnePtr;
       
   404 
       
   405         //Buffer which is used to contain certificate data. Owned.        
       
   406         HBufC8*                         iCertHBufTwo;
       
   407         //Pointer to iCertHBufTwo. Owned.
       
   408         TPtr8*                          iCertHBufTwoPtr;
       
   409 
       
   410         //Buffer which is used to contain certificate data. Owned.        
       
   411         HBufC8*                         iCertHBufThree;
       
   412         //Pointer to iCertHBufThree. Owned.
       
   413         TPtr8*                          iCertHBufThreePtr;
       
   414 
       
   415         //Buffer which is used to contain certificate data. Owned.        
       
   416         HBufC8*                         iCertHBufFour;
       
   417         //Pointer to iCertHBufFour. Owned.
       
   418         TPtr8*                          iCertHBufFourPtr;
       
   419         //ActiveSchedulerWaiter for certificate extra information
       
   420         //fetching.
       
   421         CActiveSchedulerWait            iActiveSchedulerWait;
       
   422         //Pointer for trusted usage buffer
       
   423         HBufC*                          iTrustedUsages;
       
   424         //Pointer to trusted usage buffer pointer
       
   425         TPtr*                           iTrustedUsagesPtr;
       
   426         //Index pointing to certificate elements
       
   427         TUint8                          iIndex;
       
   428         //Pointer to one certificate info, owned
       
   429         CCTCertInfo*                    iCert;
       
   430         //Pointer to one WIM specific certificate info, owned
       
   431         CWimCertInfo*                   iCertInfo;
       
   432         //An array of trusted usage oids
       
   433         RArray<HBufC*>*                 iOids;
       
   434         //Package structure for certificate extra info
       
   435         TCertExtrasInfo                 iCertExtrasInfo;
       
   436         //Pointer for key identifier buffer
       
   437         HBufC8*                         iKeyIdBuf;
       
   438         //Used to point right keyId when retrieving extra data
       
   439         TPtr8*                          iKeyIdPointer;
       
   440 
       
   441     };
       
   442 
       
   443 
       
   444 #endif  //WIMCERTCONVERTER_H