wim/WimClient/src/WimKeyDetails.cpp
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:  Gets keydetails from WIM -card
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "WimCertMgmt.h"
       
    21 #include "WimKeyDetails.h"
       
    22 #include "WimTrace.h"
       
    23 
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // CWimKeyDetails::CWimKeyDetails()
       
    27 // Default constructor
       
    28 // -----------------------------------------------------------------------------
       
    29 CWimKeyDetails::CWimKeyDetails( MCTToken& aToken ):
       
    30 CActive( EPriorityStandard ), iToken( aToken ), iPckg( iKeyNumber )
       
    31     {
       
    32     }
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CWimKeyDetails::NewL()
       
    36 // Symbian 2nd phase constructor can leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 EXPORT_C CWimKeyDetails* CWimKeyDetails::NewL( MCTToken& aToken )
       
    39     {
       
    40     _WIMTRACE ( _L( "CWimKeyDetails::NewL()" ) );
       
    41     CWimKeyDetails* self = new( ELeave ) CWimKeyDetails( aToken );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self ); //self
       
    45     return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CWimKeyDetails::ConstructL()
       
    50 // Second phase
       
    51 // -----------------------------------------------------------------------------
       
    52 void CWimKeyDetails::ConstructL()
       
    53     {
       
    54     _WIMTRACE ( _L( "CWimKeyDetails::ConstructL()" ) );
       
    55     CActiveScheduler::Add( this );
       
    56     iConnectionHandle = RWimCertMgmt::ClientSessionL();
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CWimKeyDetails::~CWimKeyDetails()
       
    61 // Allocated memory is released.
       
    62 // -----------------------------------------------------------------------------
       
    63 EXPORT_C CWimKeyDetails::~CWimKeyDetails()
       
    64     {
       
    65     _WIMTRACE ( _L( "CWimKeyDetails::~CWimKeyDetails()" ) );
       
    66     Cancel();
       
    67     iConnectionHandle->Close();
       
    68     delete iConnectionHandle;
       
    69     iKeyReferences.Close();
       
    70     DeallocMemoryFromSign();
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CWimKeyDetails::GetKeyList()
       
    75 // Starts to list all keys found from WIM -card
       
    76 // -----------------------------------------------------------------------------
       
    77 EXPORT_C void CWimKeyDetails::GetKeyList( RPointerArray<CCTKeyInfo>& aKeys,
       
    78                                           CArrayFixFlat<TUint8>& aKeyNumbers,
       
    79                                           TRequestStatus& aStatus )
       
    80     {
       
    81     _WIMTRACE ( _L( "CWimKeyDetails::GetKeyList()" ) );
       
    82     iClientStatus = &aStatus;
       
    83     aStatus = KRequestPending;
       
    84     iKeys = &aKeys;
       
    85     iKeyNumberArray = &aKeyNumbers;
       
    86     iPhase = EGetKeyList;
       
    87     SignalOwnStatusAndComplete();
       
    88     iFetchedKeyInfos = 0;
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CWimKeyDetails::CancelList()
       
    93 // Cancels listing operation.
       
    94 // -----------------------------------------------------------------------------
       
    95 EXPORT_C void CWimKeyDetails::CancelList()
       
    96     {
       
    97     _WIMTRACE ( _L( "CWimKeyDetails::CancelList()" ) );
       
    98     Cancel();
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CWimKeyDetails::Sign()
       
   103 // Sign some data. Authentication is handled by server.
       
   104 // -----------------------------------------------------------------------------
       
   105 
       
   106 EXPORT_C void CWimKeyDetails::Sign( const TDesC8& aData, 
       
   107                                    TDesC8& aKeyId, 
       
   108                                    HBufC8*& aSignature, 
       
   109                                    TRequestStatus& aStatus )
       
   110     {
       
   111     _WIMTRACE ( _L( "CWimKeyDetails::Sign()" ) );
       
   112 
       
   113     aStatus = KRequestPending;
       
   114     iClientStatus = &aStatus;
       
   115     
       
   116     if ( aKeyId.Length() )
       
   117         {
       
   118         //Check that the data is not too long
       
   119         if ( aData.Length() > KMaxRSADigestSize )
       
   120             {
       
   121             User::RequestComplete( iClientStatus, KErrOverflow );
       
   122             }
       
   123         else
       
   124             {     
       
   125             iSignature = aSignature; 
       
   126             TRAPD( err, AllocMemoryForSignL( aData, aKeyId ) );
       
   127             if ( err )
       
   128                 {
       
   129                 User::RequestComplete( iClientStatus, err );
       
   130                 }
       
   131             else
       
   132                 {
       
   133                 iPhase = ESign;
       
   134                 SignalOwnStatusAndComplete();
       
   135                 }
       
   136             }
       
   137         }
       
   138     else
       
   139         {
       
   140         User::RequestComplete( iClientStatus, KErrArgument );
       
   141         }
       
   142     }
       
   143   
       
   144 // -----------------------------------------------------------------------------
       
   145 // CWimKeyDetails::CancelSign()
       
   146 // Cancels outgoing signing operation 
       
   147 // -----------------------------------------------------------------------------
       
   148 EXPORT_C void CWimKeyDetails::CancelSign()
       
   149     {
       
   150     _WIMTRACE ( _L( "CWimKeyDetails::CancelSign()" ) );
       
   151     Cancel();
       
   152     }
       
   153 
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CWimKeyDetails::ExportPublicKeyL()
       
   157 // Export public key
       
   158 // -----------------------------------------------------------------------------
       
   159 EXPORT_C void CWimKeyDetails::ExportPublicKeyL( TDesC8& aKeyId, 
       
   160                                                 HBufC8*& aPublicKey, 
       
   161                                                 TRequestStatus& aStatus )
       
   162     {
       
   163     _WIMTRACE ( _L( "CWimKeyDetails::ExportPublicKeyL()" ) );
       
   164 
       
   165     iClientStatus = &aStatus;
       
   166     aStatus = KRequestPending;
       
   167     
       
   168     if ( aKeyId.Length() )
       
   169         {   
       
   170         //KeyId from Plugin 
       
   171         iKeyId = aKeyId.AllocL();
       
   172         iKeyIdPtr = new( ELeave ) TPtr8( iKeyId->Des() );
       
   173         iExportPublicKey.iKeyId.Copy( iKeyIdPtr->Ptr(), iKeyIdPtr->Length() );
       
   174     
       
   175         //Exported key from Server
       
   176         iPublicKey = aPublicKey;
       
   177         iPublicKeyPtr = new( ELeave ) TPtr8( iPublicKey->Des() );
       
   178         iExportPublicKey.iPublicKey = iPublicKeyPtr;
       
   179     
       
   180         //Request to Server
       
   181         iConnectionHandle->ExportPublicKeyL( iExportPublicKey, 
       
   182                                              iStatus );
       
   183         iPhase = EExportPublicKey;
       
   184         SetActive();
       
   185         }
       
   186     else 
       
   187         {
       
   188         User::RequestComplete( iClientStatus, KErrArgument );
       
   189         }
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CWimKeyDetails::CancelExport()
       
   194 // Cancel public key export
       
   195 // -----------------------------------------------------------------------------
       
   196 EXPORT_C void CWimKeyDetails::CancelExport()
       
   197     {
       
   198     _WIMTRACE ( _L( "CWimKeyDetails::CancelExport()" ) );
       
   199     Cancel();
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CWimKeyDetails::AllocMemoryForSignL()
       
   204 // Allocates memory for signing operation
       
   205 // -----------------------------------------------------------------------------
       
   206 void CWimKeyDetails::AllocMemoryForSignL( const TDesC8& aData,
       
   207                                           const TDesC8& aKeyId )
       
   208     {
       
   209     _WIMTRACE ( _L( "CWimKeyDetails::AllocMemoryForSignL()" ) );
       
   210 
       
   211     iSigningData = aData.AllocL(); //Data to be signed
       
   212     iSigningDataPtr = new( ELeave ) TPtr8( iSigningData->Des() );
       
   213 
       
   214     iKeyId = aKeyId.AllocL(); //KeyId used to match correct signing key
       
   215     iKeyIdPtr = new( ELeave ) TPtr8( iKeyId->Des() );
       
   216 
       
   217     //Alloc pointer for signature buffer, which is owned by keystore
       
   218     iSignaturePtr = new( ELeave ) TPtr8( iSignature->Des() );
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CWimKeyDetails::DeallocMemoryFromSign()
       
   223 // Deallocates memory after signing  operation
       
   224 // -----------------------------------------------------------------------------
       
   225 void CWimKeyDetails::DeallocMemoryFromSign()
       
   226     {
       
   227     _WIMTRACE ( _L( "CWimKeyDetails::DeallocMemoryFromSign()" ) );
       
   228 
       
   229     delete iSigningData;
       
   230     delete iSigningDataPtr;
       
   231     delete iSignaturePtr;
       
   232     delete iKeyId;
       
   233     delete iKeyIdPtr;
       
   234     iSigningData = NULL;
       
   235     iSigningDataPtr = NULL;
       
   236     iSignaturePtr = NULL;
       
   237     iKeyId = NULL;
       
   238     iKeyIdPtr = NULL;
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CWimKeyDetails::SignalOwnStatusAndComplete()       
       
   243 // Sets own iStatus to KRequestPending, and signals it 
       
   244 // with User::RequestComplete() -request. This gives chance 
       
   245 // active scheduler to run other active objects. After a quick
       
   246 // visit in active scheduler, signal returns to RunL() and starts next
       
   247 // phase of operation. 
       
   248 // @return void
       
   249 // -----------------------------------------------------------------------------
       
   250 void CWimKeyDetails::SignalOwnStatusAndComplete()
       
   251     {
       
   252     _WIMTRACE ( _L( "CWimKeyDetails::SignalOwnStatusAndComplete()" ) );
       
   253     iStatus = KRequestPending;
       
   254     SetActive();
       
   255     TRequestStatus* status = &iStatus;
       
   256     User::RequestComplete( status, KErrNone );
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CWimKeyDetails::RunL()
       
   261 // EGetKeyList: Get the number of keys key and references to each key.
       
   262 // EConvertParams: Gets key references from string and puts them to RArray
       
   263 // EGetKeyInfo: Fetches a single keyinfo. According to received values, a new
       
   264 //              CCTKeyInfo -object is created and inserted to an Array. Received
       
   265 //              parameters requires a little bit conversion. 
       
   266 // ESign:       Sends signing request with data to be signed to server.
       
   267 // ESignCompleted: Sign is done 
       
   268 // EExportPublicKey: Sends Export public key request to server. Receives 
       
   269 //              exported public key.
       
   270 // -----------------------------------------------------------------------------
       
   271 void CWimKeyDetails::RunL()
       
   272     {
       
   273 	//Check for error
       
   274     if ( iStatus.Int() != KErrNone )
       
   275         {
       
   276         if ( iPhase == EConvertParams )
       
   277             {
       
   278             DeallocMemoryFromKeyList();
       
   279             }
       
   280         else if ( iPhase == ESignCompleted )
       
   281             {
       
   282             iConnectionHandle->DeallocKeySignPckgBuf();
       
   283             DeallocMemoryFromSign();
       
   284             }
       
   285         else if ( iPhase == EExportPublicKey )
       
   286             {
       
   287             iConnectionHandle->DeallocExportPublicKeyPckgBuf();
       
   288             DeallocMemoryFromKeyInfo();
       
   289             delete iPublicKeyPtr;
       
   290             iPublicKey = NULL;      // no delete, ownership moved to caller
       
   291             iPublicKeyPtr = NULL;
       
   292             }
       
   293         User::RequestComplete( iClientStatus, iStatus.Int() );
       
   294         }
       
   295     else
       
   296         {
       
   297         switch ( iPhase )
       
   298             {
       
   299             case EGetKeyList:
       
   300                 {
       
   301                 AllocMemoryForKeyListL();
       
   302                 iConnectionHandle->KeyList( *iKeyListPtr, 
       
   303                                             iPckg,
       
   304                                             iStatus );  
       
   305                 iPhase = EConvertParams;
       
   306                 SetActive();
       
   307                 _WIMTRACE ( _L( "CWimKeyDetails::RunL(),\
       
   308                         case:EGetKeyList" ) );
       
   309                 break;
       
   310                 }
       
   311             case EConvertParams: //Convert previously fetched parameters
       
   312                 {                //and put them to an RArray.
       
   313                 ConvertKeyListL();
       
   314                 DeallocMemoryFromKeyList(); //We don't need keylist anymore
       
   315                 iPhase = EGetKeyInfo;
       
   316                 SignalOwnStatusAndComplete();
       
   317                 _WIMTRACE ( _L( "CWimKeyDetails::RunL(),EConvertParams" ) );
       
   318                 break;
       
   319                 }
       
   320             case EGetKeyInfo: //Now we can fetch details for every key.
       
   321                 {
       
   322                 //Are all keyinfo -objects fetched?
       
   323                 if ( iFetchedKeyInfos < iKeyReferences.Count() )
       
   324                     { //No, get next keyinfo..
       
   325                     TKeyInfo keyInfo;
       
   326                     AllocMemoryForKeyInfoL( keyInfo );
       
   327                     TInt ret = iConnectionHandle->GetKeyInfo(
       
   328                               iKeyReferences.operator[]( iFetchedKeyInfos ),
       
   329                               keyInfo );
       
   330 
       
   331                     if ( ret != KErrNone )//Something went wrong
       
   332                         {
       
   333                         DeallocMemoryFromKeyInfo();
       
   334                         User::RequestComplete( iClientStatus, ret );
       
   335                         }
       
   336                     else
       
   337                         {
       
   338                         TKeyUsagePKCS15 keyUsage;
       
   339                         keyUsage = ConvertKeyUsage( keyInfo.iUsage );
       
   340 
       
   341                         //Convert key type to support only RSA signing or
       
   342                         //invalidAlgorithm
       
   343                         if ( keyInfo.iType != CKeyInfoBase::ERSA )
       
   344                             {
       
   345                             keyInfo.iType = 
       
   346                                   ( TUint8 )CKeyInfoBase::EInvalidAlgorithm;
       
   347                             }
       
   348                         //Create new KeyInfo -object and put it into array.
       
   349                         CCTKeyInfo* cctKeyInfo = NULL;
       
   350 
       
   351                         // Create a 16 bit heap-based buffer descriptor and a
       
   352                         // pointer to it
       
   353                         HBufC16* label16 = HBufC16::NewLC( KLabelLen );
       
   354                         // 16 bit modifiable pointer descriptor to object 
       
   355                         // above in order to manipulate data
       
   356                         TPtr16 labelPtr16 = label16->Des();
       
   357                         
       
   358                         labelPtr16.Copy( keyInfo.iLabel.Left(
       
   359                                                     keyInfo.iLabel.Length() ) );
       
   360                        
       
   361 						TTime nullTime( _L( "00000000:" ) );
       
   362 #ifdef __SECURITY_PLATSEC_ARCH__
       
   363 						TSecurityPolicy usePolicy; 
       
   364                         TSecurityPolicy managementPolicy;
       
   365 
       
   366                         cctKeyInfo = CCTKeyInfo::NewL( 
       
   367                                    keyInfo.iKeyId,      //Key ID
       
   368                                    keyUsage,            //Key usage
       
   369                                    keyInfo.iLength,     //Key length
       
   370                                    NULL,                //protector
       
   371                                    label16,             //Key label
       
   372                                    iToken,              //token
       
   373                                    keyInfo.iKeyNumber,  //Key number
       
   374                                    usePolicy,			//
       
   375 								   managementPolicy,	//
       
   376                                    ( CKeyInfoBase::EKeyAlgorithm )keyInfo.iType,
       
   377                                    CKeyInfoBase::EInvalidAccess, //bitf. access
       
   378                                    ETrue,               //Always Native
       
   379                                    nullTime,            //NULL time
       
   380                                    nullTime );          //NULL time
       
   381 #else
       
   382                         RArray<TUid> array;
       
   383 
       
   384                         cctKeyInfo = CCTKeyInfo::NewL( 
       
   385                                    keyInfo.iKeyId,      //Key ID
       
   386                                    keyUsage,            //Key usage
       
   387                                    keyInfo.iLength,     //Key length
       
   388                                    NULL,                //protector
       
   389                                    label16,             //Key label
       
   390                                    iToken,              //token
       
   391                                    keyInfo.iKeyNumber,  //Key number
       
   392 								   KWimServerUid, //WimServer owns all keys
       
   393                                    array,               //Null array
       
   394                                    ( CKeyInfoBase::EKeyAlgorithm )keyInfo.iType,
       
   395                                    CKeyInfoBase::EInvalidAccess, //bitf. access
       
   396                                    ETrue,               //Always Native
       
   397                                    nullTime,            //NULL time
       
   398                                    nullTime );          //NULL time
       
   399 #endif
       
   400 
       
   401                          _WIMTRACE ( _L( "CWimKeyDetails::RunL(),EGetKeyInfo | CCTKeyInfo is initialized " ) );
       
   402 
       
   403                         ret =  iKeys->Append( cctKeyInfo );
       
   404 
       
   405                         if ( ret != KErrNone )
       
   406                             {
       
   407                             CleanupStack::Pop( label16 );
       
   408                             cctKeyInfo->Release();
       
   409                             User::Leave( ret );
       
   410                             }
       
   411                        
       
   412                          //Append corresponding pinnumber to array.
       
   413                         iKeyNumberArray->AppendL( keyInfo.iPinNumber );  
       
   414                          
       
   415                         //We must not destroy label16, because CCTKeyInfo 
       
   416                         //-object takes ownership.
       
   417                         CleanupStack::Pop( label16 );
       
   418                         //Increase counter, we have successfully fetched 
       
   419                         //infos for single key and corresponding CCTKeyInfo 
       
   420                         //is created
       
   421                         iFetchedKeyInfos++;
       
   422                         //Cleanup label and keyid modifiers.
       
   423                         DeallocMemoryFromKeyInfo();
       
   424                         iPhase = EGetKeyInfo;
       
   425                         SignalOwnStatusAndComplete();
       
   426                         _WIMTRACE ( _L( "CWimKeyDetails::RunL(),\
       
   427                             case:EGetKeyInfo" ) );
       
   428                             }
       
   429                         }
       
   430                     else//Yep, All done.
       
   431                         {
       
   432                         iFetchedKeyInfos = 0;
       
   433                         //Don't need key references anymore
       
   434                         iKeyReferences.Close(); 
       
   435                         User::RequestComplete( iClientStatus, iStatus.Int() );
       
   436                         }
       
   437                 break;
       
   438                 }
       
   439             case ESign:
       
   440                 {
       
   441                 iPhase = ESignCompleted;
       
   442                 iKeySignParameters.iSigningData = iSigningDataPtr;
       
   443                 iKeySignParameters.iSignature = iSignaturePtr;
       
   444                 iKeySignParameters.iKeyId.Copy( iKeyIdPtr->Ptr(), iKeyIdPtr->Length() );
       
   445                 iConnectionHandle->SignL( iKeySignParameters, iStatus );
       
   446                 SetActive();
       
   447                 break;
       
   448                 }
       
   449             case ESignCompleted:
       
   450                 {
       
   451                 //signature data is copied by now to plugins memory.   
       
   452                 iConnectionHandle->DeallocKeySignPckgBuf();
       
   453                 DeallocMemoryFromSign();
       
   454                 User::RequestComplete( iClientStatus, iStatus.Int() );
       
   455                 break;
       
   456                 }
       
   457             case EExportPublicKey:
       
   458                 {
       
   459                 iConnectionHandle->DeallocExportPublicKeyPckgBuf();
       
   460                 DeallocMemoryFromKeyInfo();
       
   461                 delete iPublicKeyPtr;
       
   462                 iPublicKeyPtr = NULL;
       
   463                 User::RequestComplete( iClientStatus, iStatus.Int() );
       
   464                 break;
       
   465                 }
       
   466             default:
       
   467                 {
       
   468                 break;
       
   469                 }    
       
   470             }
       
   471         }
       
   472     }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CWimKeyDetails::ConvertKeyUsage()
       
   476 // Converts keyUsage to new form. All keyUsages loaded from WIM are treated
       
   477 // as private keys.
       
   478 // -----------------------------------------------------------------------------
       
   479 TKeyUsagePKCS15 CWimKeyDetails::ConvertKeyUsage( TUint16 aKeyUsage )
       
   480     {
       
   481     _WIMTRACE ( _L( "CWimKeyDetails::ConvertKeyUsage()" ) );
       
   482 
       
   483     TKeyUsagePKCS15 usage = EPKCS15UsageNone;
       
   484     switch ( aKeyUsage ) 
       
   485         {
       
   486         case KPkcs15KeyUsageFlagsDecrypt:
       
   487             {
       
   488             usage = EPKCS15UsageDecrypt;
       
   489             break;
       
   490             }
       
   491         case KPkcs15KeyUsageFlagsSign:
       
   492             {
       
   493             usage = EPKCS15UsageSign;
       
   494             break;
       
   495             }
       
   496         case KPkcs15KeyUsageFlagsSignRecover:
       
   497             {
       
   498             usage = EPKCS15UsageSignRecover;
       
   499             break;
       
   500             }
       
   501         case KPkcs15KeyUsageFlagsUnwrap:
       
   502             {
       
   503             usage = EPKCS15UsageUnwrap;
       
   504             break;
       
   505             }
       
   506         case KPkcs15KeyUsageFlagsDerive:
       
   507             {
       
   508             usage = EPKCS15UsageDerive;
       
   509             break;
       
   510             }
       
   511         case KPkcs15KeyUsageFlagsNonRepudiation:
       
   512             {
       
   513             usage = EPKCS15UsageNonRepudiation;
       
   514             break;
       
   515             }
       
   516         default:
       
   517             {
       
   518             break;
       
   519             }
       
   520         }
       
   521     return usage;
       
   522     }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // CWimKeyDetails::AllocMemoryForKeyListL()
       
   526 // Allocates memory for Array which is filled by server.
       
   527 // -----------------------------------------------------------------------------
       
   528 void CWimKeyDetails::AllocMemoryForKeyListL()
       
   529     {
       
   530     _WIMTRACE ( _L( "CWimKeyDetails::AllocMemoryForKeyListL()" ) );
       
   531 
       
   532     iKeyList = HBufC8::NewL( KLabelLen );
       
   533     iKeyListPtr = new( ELeave ) TPtr8( iKeyList->Des() );
       
   534     }
       
   535 
       
   536 // -----------------------------------------------------------------------------
       
   537 // CWimKeyDetails::DeallocMemoryFromKeyList()
       
   538 // Deallocates memory from Array which was filled by server.
       
   539 // -----------------------------------------------------------------------------
       
   540 void CWimKeyDetails::DeallocMemoryFromKeyList()
       
   541     {
       
   542     _WIMTRACE ( _L( "CWimKeyDetails::DeallocMemoryFromKeyList()" ) );
       
   543 
       
   544     delete iKeyList;
       
   545     delete iKeyListPtr;
       
   546     iKeyList = NULL;
       
   547     iKeyListPtr = NULL;
       
   548     }
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CWimKeyDetails::ConvertKeyListL()
       
   552 // Converts keylist parameters. Extracts data out from keylist & keynumber.
       
   553 // Extracted data is inserted to RArray.
       
   554 // -----------------------------------------------------------------------------
       
   555 void CWimKeyDetails::ConvertKeyListL()
       
   556     {
       
   557     _WIMTRACE ( _L( "CWimKeyDetails::ConvertKeyListL()" ) );
       
   558 
       
   559     TInt32 output = 0;
       
   560     
       
   561     TLex8 lex8( iKeyListPtr->Ptr() );
       
   562     for ( TInt i = 0; i < iKeyNumber; i++ ) //Put keyreferences to array.
       
   563         {
       
   564         lex8.SkipSpaceAndMark();
       
   565         lex8.Val( output );
       
   566         User::LeaveIfError( iKeyReferences.Append( output ) );
       
   567         }
       
   568     }
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 // CWimKeyDetails::AllocMemoryForKeyInfoL()
       
   572 // Allocates memory for label and keyid.
       
   573 // -----------------------------------------------------------------------------
       
   574 void CWimKeyDetails::AllocMemoryForKeyInfoL( TKeyInfo& aKeyInfo )
       
   575     {
       
   576     _WIMTRACE ( _L( "CWimKeyDetails::AllocMemoryForKeyInfoL()" ) );
       
   577 
       
   578     iLabel = HBufC8::NewL( KLabelLen ); //Label
       
   579     iLabelPtr = new( ELeave ) TPtr8( iLabel->Des() );
       
   580     aKeyInfo.iLabel.Copy( iLabelPtr->Ptr(), iLabelPtr->Length() );
       
   581    
       
   582     iKeyId = HBufC8::NewL( KKeyIdLen ); //KeyId
       
   583     iKeyIdPtr = new( ELeave ) TPtr8( iKeyId->Des() );
       
   584     aKeyInfo.iKeyId.Copy( iKeyIdPtr->Ptr(), iKeyIdPtr->Length() ); 
       
   585     }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // CWimKeyDetails::DeallocMemoryFromKeyInfo()
       
   589 // Deallocates memory from label and keyid.
       
   590 // -----------------------------------------------------------------------------
       
   591 void CWimKeyDetails::DeallocMemoryFromKeyInfo()
       
   592     {
       
   593     _WIMTRACE ( _L( "CWimKeyDetails::DeallocMemoryFromKeyInfo()" ) );
       
   594 
       
   595     delete iLabel;
       
   596     delete iLabelPtr;
       
   597     delete iKeyId;
       
   598     delete iKeyIdPtr;
       
   599     iLabel = NULL;
       
   600     iLabelPtr = NULL;
       
   601     iKeyId = NULL;
       
   602     iKeyIdPtr = NULL;
       
   603     }
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // CWimKeyDetails::RunError()                                        
       
   607 // The active scheduler calls this function if this active object's RunL() 
       
   608 // function leaves. This gives this active object the opportunity to perform 
       
   609 // any necessary cleanup.
       
   610 // After array's cleanup, complete request with received error code.
       
   611 // -----------------------------------------------------------------------------
       
   612 TInt CWimKeyDetails::RunError( TInt aError )
       
   613     {  
       
   614     _WIMTRACE ( _L( "CWimKeyDetails::RunError()" ) );
       
   615     DeallocMemoryFromKeyInfo();
       
   616     DeallocMemoryFromKeyList();
       
   617     User::RequestComplete( iClientStatus, aError );
       
   618     return KErrNone;
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CWimKeyDetails::DoCancel()
       
   623 // Deallocates member variables and completes client status with
       
   624 // KErrCancel error code.
       
   625 // -----------------------------------------------------------------------------
       
   626 void CWimKeyDetails::DoCancel()
       
   627     {    
       
   628     _WIMTRACE ( _L( "CWimKeyDetails::DoCancel()" ) );
       
   629 
       
   630     if ( iConnectionHandle && iPhase == ESignCompleted )
       
   631         {
       
   632         iConnectionHandle->DeallocKeySignPckgBuf();
       
   633         }
       
   634     else if ( iConnectionHandle && iPhase == EExportPublicKey )
       
   635         {
       
   636         delete iPublicKeyPtr;
       
   637         iPublicKey = NULL;
       
   638         iPublicKeyPtr = NULL;
       
   639         iConnectionHandle->DeallocExportPublicKeyPckgBuf();
       
   640         }
       
   641     DeallocMemoryFromKeyList();
       
   642     DeallocMemoryFromKeyInfo();
       
   643     DeallocMemoryFromSign();
       
   644     iKeyReferences.Close();
       
   645     User::RequestComplete( iClientStatus, KErrCancel );
       
   646     }
       
   647 
       
   648 // End of File