pkiutilities/CertmanUi/SRC/CertmanuiCertificateHelper.cpp
changeset 0 164170e6151a
child 12 a005fc61b02a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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:   Implementation of class CCertManUICertificateHelper
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <X509CertNameParser.h>
       
    20 #include <certmanui.rsg>
       
    21 #include <hash.h>                   // MD5 fingerprint
       
    22 #include <aknmessagequerydialog.h>
       
    23 #include <pkixcertchain.h>          // for validation
       
    24 #include <aknnotewrappers.h>        // for warning & information notes
       
    25 #include <sysutil.h>
       
    26 #include <ErrorUI.h>
       
    27 #include <unifiedkeystore.h>
       
    28 #include <TrustedSitesStore.h>
       
    29 #include <x509keys.h>               // TX509KeyFactory
       
    30 #include <e32math.h>                // Pow
       
    31 #include "Certmanui.hrh"
       
    32 #include "CertmanuiCertificateHelper.h"
       
    33 #include "CertmanuiCommon.h"
       
    34 #include "CertmanuiSyncWrapper.h"
       
    35 #include "CertManUILogger.h"
       
    36 
       
    37 const TInt KFileCertStoreUid( 0x101F501A );
       
    38 const TInt KTrustedServerCertStoreUid( 0x101FB66F );
       
    39 const TInt KDeviceCertStoreUid( 0x101FB668 );
       
    40 const TInt KDeviceKeyStoreUid( 0x101FB66A );
       
    41 
       
    42 _LIT( KBlockSeparator, " " );
       
    43 
       
    44 template <class T>
       
    45 class CleanupResetAndDestroy
       
    46     {
       
    47 public:
       
    48     inline static void PushL( T& aRef );
       
    49 private:
       
    50     static void ResetAndDestroy( TAny *aPtr );
       
    51     };
       
    52 
       
    53 template <class T>
       
    54 inline void CleanupResetAndDestroyPushL( T& aRef );
       
    55 
       
    56 template <class T>
       
    57 inline void CleanupResetAndDestroy<T>::PushL( T& aRef )
       
    58     {
       
    59     CleanupStack::PushL( TCleanupItem( &ResetAndDestroy, &aRef ) );
       
    60     }
       
    61 
       
    62 template <class T>
       
    63 void CleanupResetAndDestroy<T>::ResetAndDestroy( TAny *aPtr )
       
    64     {
       
    65     if( aPtr )
       
    66         {
       
    67         static_cast<T*>( aPtr )->ResetAndDestroy();
       
    68         }
       
    69     }
       
    70 
       
    71 template <class T>
       
    72 inline void CleanupResetAndDestroyPushL( T& aRef )
       
    73     {
       
    74     CleanupResetAndDestroy<T>::PushL( aRef );
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CCertManUICertificateHelper::CCertManUICertificateHelper()
       
    80 // Default C++ Constructor
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 CCertManUICertificateHelper::CCertManUICertificateHelper( CCertManUIKeeper& aKeeper )
       
    84 : iKeeper(aKeeper)
       
    85     {
       
    86   }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CCertManUICertificateHelper::~CCertManUICertificateHelper()
       
    90 // Destructor
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 CCertManUICertificateHelper::~CCertManUICertificateHelper()
       
    94     {
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------
       
    98 // CCertManUICertificateHelper::CutCertificateField(TPtrC aField)
       
    99 // If CertLabel, Issuer and Owner length is over 80 characters,
       
   100 // cut it down to 80
       
   101 // Returns the cut certificate field.
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 TPtrC CCertManUICertificateHelper::CutCertificateField( TPtrC aField )
       
   105     {
       
   106     CERTMANUILOGGER_ENTERFN(
       
   107          "CCertManUICertificateHelper::CutCertificateField" );
       
   108 
       
   109     TInt fieldLength = aField.Length();
       
   110     if ( fieldLength >= KMaxLengthTextCertLabelVisible )
       
   111         {
       
   112         TPtrC cutCertLabel = aField.Mid( 0, KMaxLengthTextCertLabelVisible );
       
   113 
       
   114         CERTMANUILOGGER_LEAVEFN(
       
   115            "CCertManUICertificateHelper::CutCertificateField" );
       
   116 
       
   117         return cutCertLabel;
       
   118         }
       
   119 
       
   120     CERTMANUILOGGER_LEAVEFN(
       
   121         "CCertManUICertificateHelper::CutCertificateField" );
       
   122 
       
   123     return aField;
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CCertManUICertificateHelper::IsCertificateDeletable
       
   128 // Check whether certificate is deletable
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 TBool CCertManUICertificateHelper::IsCertificateDeletable( TInt aIndex,
       
   132     TInt aType ) const
       
   133     {
       
   134     CERTMANUILOGGER_ENTERFN(
       
   135         "CCertManUICertificateHelper::IsCertificateDeletable" );
       
   136     TBool ret = ETrue;
       
   137 
       
   138     // If wim has not been enabled and certificate resides in smart card
       
   139     // we cannot delete it since we don't have smart card certificate
       
   140     // delete functionality in non WIM builds. So in non WIM builds all
       
   141     // smart card certificates are marked read-only.
       
   142     if( aIndex > -1 )
       
   143         {
       
   144         CCTCertInfo* entry;
       
   145         if ( aType == KCertTypeAuthority )
       
   146             {
       
   147             entry = iKeeper.iCALabelEntries[ aIndex ]->iCAEntry;
       
   148             }
       
   149         else if( aType == KCertTypeTrustedSite )
       
   150             {
       
   151             entry = iKeeper.iPeerLabelEntries[ aIndex ]->iPeerEntry;
       
   152             }
       
   153         else if( aType == KCertTypeDevice )
       
   154             {
       
   155             entry = iKeeper.iDeviceLabelEntries[ aIndex ]->iDeviceEntry;
       
   156             }
       
   157         else
       
   158             {
       
   159             entry = iKeeper.iUserLabelEntries[ aIndex ]->iUserEntry;
       
   160             }
       
   161         if ( !entry->IsDeletable() )
       
   162             {
       
   163             ret = EFalse;
       
   164             }
       
   165         }
       
   166 
       
   167     CERTMANUILOGGER_LEAVEFN(
       
   168         "CCertManUICertificateHelper::IsCertificateDeletable" );
       
   169     return ret;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------
       
   173 // CCertManUICertificateHelper::IsOneMarkedCertificateDeletable
       
   174 // Check whether one marked certificate is deletable, or
       
   175 // if none certificate is marked, check if the highlighted
       
   176 // certificate is deletable
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 TBool CCertManUICertificateHelper::IsOneMarkedCertificateDeletable
       
   180     ( CEikColumnListBox* aListBox, TInt aType ) const
       
   181     {
       
   182     CERTMANUILOGGER_ENTERFN(
       
   183         "CCertManUICertificateHelper::IsOneMarkedCertificateDeletable" );
       
   184 
       
   185     const CArrayFix<TInt>* array  = aListBox->SelectionIndexes();
       
   186     TInt markedCount = array->Count();
       
   187     TBool oneIsDeletable = EFalse;
       
   188 
       
   189     if ( 0 == markedCount )
       
   190         {
       
   191         TInt currentItem = aListBox->CurrentItemIndex();
       
   192         return IsCertificateDeletable( currentItem, aType );
       
   193         }
       
   194 
       
   195     for ( TInt i = 0; !oneIsDeletable && i < markedCount; i++ )
       
   196         {
       
   197         oneIsDeletable = IsCertificateDeletable( (*array)[i], aType );
       
   198         }
       
   199 
       
   200     CERTMANUILOGGER_LEAVEFN(
       
   201         "CCertManUICertificateHelper::IsOneMarkedCertificateDeletable" );
       
   202 
       
   203     return oneIsDeletable;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------
       
   207 // CCertManUICertificateHelper::MessageQueryViewDetailsL(TInt aIndex)
       
   208 // Creates the whole of certificate details view
       
   209 // Appends strings from both resources and CertManAPI to one
       
   210 // message body text and displays it.
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 void CCertManUICertificateHelper::MessageQueryViewDetailsL( TInt aIndex,
       
   214     TInt aType,
       
   215     CEikonEnv* aEikonEnv )
       
   216     {
       
   217     CERTMANUILOGGER_ENTERFN(
       
   218         "CCertManUICertificateHelper::MessageQueryViewDetailsL" );
       
   219      LOG_WRITE_FORMAT( "certificate index %i", aIndex );
       
   220 
       
   221     iKeeper.StartWaitDialogL( ECertmanUiWaitDialog );
       
   222 
       
   223     HBufC* message = HBufC::NewLC( KMaxLengthTextDetailsBody );
       
   224     TRAPD( err, CreateMessageBodyTextL( aIndex, aType, aEikonEnv, *message ) );
       
   225 
       
   226     iKeeper.CloseWaitDialogL();
       
   227     User::LeaveIfError( err );
       
   228 
       
   229     if( message->Length() )
       
   230         {
       
   231         HBufC* header = StringLoader::LoadLC( R_TEXT_RESOURCE_DETAILS_VIEW_HEADER );
       
   232         CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message );
       
   233         dlg->PrepareLC( R_MESSAGE_QUERY_DETAILS_VIEW );
       
   234         dlg->QueryHeading()->SetTextL( *header );
       
   235         dlg->RunLD();
       
   236         CleanupStack::PopAndDestroy( header );
       
   237         }
       
   238 
       
   239     CleanupStack::PopAndDestroy( message );
       
   240 
       
   241     CERTMANUILOGGER_LEAVEFN(
       
   242         "CCertManUICertificateHelper::MessageQueryViewDetailsL" );
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CCertManUIViewAuthority::ValidateCertificateL(
       
   247 // Checks if the certificate is corrupted
       
   248 // Checks the validity period of the certificate
       
   249 // Display only one warning note, in the following order:
       
   250 // 1) Expired/Not yet valid
       
   251 // 2) Corrupted
       
   252 // 3) Not trusted
       
   253 // ---------------------------------------------------------
       
   254 //
       
   255 void CCertManUICertificateHelper::ValidateCertificateL(
       
   256     TInt aIndex, CCertificate* aDetails, const CCTCertInfo& aCertInfo, TInt aType )
       
   257     {
       
   258     CERTMANUILOGGER_ENTERFN(
       
   259         "CCertManUICertificateHelper::ValidateCertificateL" );
       
   260 
       
   261     TInt poppableItems = 0;
       
   262     // Check allways first the validity period
       
   263     // Show Expired/Not yet valid notes
       
   264     const CValidityPeriod& validityPeriod = aDetails->ValidityPeriod();
       
   265     const TTime& startValue = validityPeriod.Start();
       
   266     const TTime& finishValue = validityPeriod.Finish();
       
   267     TTime current;
       
   268     current.UniversalTime();
       
   269 
       
   270     if ( startValue > current )
       
   271         {
       
   272         // certificate is not valid yet
       
   273         HBufC* string = StringLoader::LoadLC(
       
   274             R_WARNING_NOTE_TEXT_CERTIFICATE_NOT_VALID_YET );
       
   275         DisplayWarningNoteLD(string);
       
   276         }
       
   277     else if ( finishValue < current )
       
   278         {
       
   279         // certificate is expired
       
   280         HBufC* string = StringLoader::LoadLC(
       
   281             R_WARNING_NOTE_TEXT_CERTIFICATE_EXPIRED );
       
   282         DisplayWarningNoteLD( string );
       
   283         }
       
   284     else
       
   285         {
       
   286         // put here check for certificate status, show warning notes if needed
       
   287         TBool noValidationError = ETrue;
       
   288         CArrayFixFlat<TValidationError>* status = NULL;
       
   289         TCertificateFormat certificateFormat;
       
   290 
       
   291         if ( aType == KCertTypeAuthority )
       
   292             {
       
   293             certificateFormat = iKeeper.iCALabelEntries[aIndex]->
       
   294                                         iCAEntry->CertificateFormat();
       
   295             }
       
   296         else if ( aType == KCertTypeTrustedSite )
       
   297             {
       
   298             certificateFormat = iKeeper.iPeerLabelEntries[aIndex]->
       
   299                                         iPeerEntry->CertificateFormat();
       
   300             }
       
   301         else if ( aType == KCertTypeDevice )
       
   302             {
       
   303             certificateFormat = iKeeper.iDeviceLabelEntries[aIndex]->
       
   304                                         iDeviceEntry->CertificateFormat();
       
   305             }
       
   306         else
       
   307             {
       
   308             certificateFormat = iKeeper.iUserLabelEntries[aIndex]->
       
   309                                         iUserEntry->CertificateFormat();
       
   310             }
       
   311 
       
   312         switch ( certificateFormat )
       
   313             {
       
   314             case EX509Certificate:
       
   315                 {
       
   316                 status = ValidateX509CertificateL(
       
   317                     (CX509Certificate*)aDetails );
       
   318                 break;
       
   319                 }
       
   320             default:
       
   321                 {
       
   322                 status = new ( ELeave) CArrayFixFlat<TValidationError>( 1 );
       
   323                 break;
       
   324                 }
       
   325             }
       
   326         CleanupStack::PushL( status );
       
   327         poppableItems++;
       
   328 
       
   329         TInt errorCount = status->Count();
       
   330         TBool ready = EFalse;
       
   331         for ( TInt i = 0; i < errorCount && !ready; i++ )
       
   332             {
       
   333             TValidationError errorType = status->At(i);
       
   334 
       
   335             switch ( errorType )
       
   336                 {
       
   337                 case EValidatedOK:
       
   338                 case EChainHasNoRoot:
       
   339                 case EBadKeyUsage:
       
   340                 // Ignore these errors
       
   341                     LOG_WRITE( "Ignored certificate validation error" );
       
   342                     break;
       
   343 
       
   344                 default:
       
   345                 // certificate is corrupted
       
   346                 noValidationError = EFalse;
       
   347                 HBufC* string = StringLoader::LoadLC(
       
   348                     R_WARNING_NOTE_TEXT_CERTIFICATE_CORRUPTED );
       
   349                 DisplayWarningNoteLD( string );
       
   350                 ready = ETrue;
       
   351                     break;
       
   352                 }
       
   353             }
       
   354 
       
   355         if ( noValidationError  && (aType == KCertTypeAuthority ))
       
   356         // Check for last if the CA certificate has no clients,
       
   357         // ie. the trust state of every client is No
       
   358         // For user certificates we don't do the check
       
   359             {
       
   360 
       
   361             RArray<TUid> trusterUids;
       
   362             CleanupClosePushL( trusterUids );
       
   363             poppableItems++;
       
   364 
       
   365             iKeeper.iWrapper->GetApplicationsL(
       
   366                 iKeeper.CertManager(), aCertInfo, trusterUids );
       
   367 
       
   368             if ( trusterUids.Count() == 0)
       
   369                 {
       
   370                 HBufC* string = StringLoader::LoadLC(
       
   371                     R_WARNING_NOTE_TEXT_CERTIFICATE_NOT_TRUSTED );
       
   372                 DisplayWarningNoteLD( string );
       
   373                 }
       
   374             }
       
   375         }
       
   376     CleanupStack::PopAndDestroy( poppableItems );
       
   377 
       
   378     CERTMANUILOGGER_LEAVEFN(
       
   379         "CCertManUICertificateHelper::ValidateCertificateL" );
       
   380     }
       
   381 
       
   382 // ---------------------------------------------------------
       
   383 // CCertManUICertificateHelper::DetailsFieldDynamicL(
       
   384 // Appends a field that has string from resources and string from CertManAPI
       
   385 // to the details view message body
       
   386 // ---------------------------------------------------------
       
   387 //
       
   388 void CCertManUICertificateHelper::DetailsFieldDynamicL(
       
   389     HBufC& aMessage, TPtrC aValue, TInt aResourceOne, TInt aResourceTwo )
       
   390     {
       
   391     CERTMANUILOGGER_ENTERFN(
       
   392         "CCertManUICertificateHelper::DetailsFieldDynamicL" );
       
   393 
       
   394     DetailsResourceL( aMessage, aResourceOne );
       
   395     DetailsDynamicL( aMessage, aValue, aResourceTwo );
       
   396     aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
   397 
       
   398     CERTMANUILOGGER_LEAVEFN(
       
   399         "CCertManUICertificateHelper::DetailsFieldDynamicL" );
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------
       
   403 // CCertManUICertificateHelper::DetailsResourceL(
       
   404 // Reads line from resources
       
   405 // ---------------------------------------------------------
       
   406 //
       
   407 void CCertManUICertificateHelper::DetailsResourceL(
       
   408     HBufC& aMessage, TInt aResourceOne )
       
   409     {
       
   410     CERTMANUILOGGER_ENTERFN(
       
   411         "CCertManUICertificateHelper::DetailsResourceL" );
       
   412 
       
   413     HBufC* stringHolder = StringLoader::LoadLC( aResourceOne );
       
   414     aMessage.Des().Append( stringHolder->Des() );
       
   415     CleanupStack::PopAndDestroy();  // stringHolder
       
   416     aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
   417 
       
   418     CERTMANUILOGGER_LEAVEFN(
       
   419         "CCertManUICertificateHelper::DetailsResourceL" );
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------
       
   423 // CCertManUICertificateHelper::DetailsFieldResourceL(
       
   424 // Appends a field that has two strings from resources
       
   425 // to the details view message body
       
   426 // ---------------------------------------------------------
       
   427 //
       
   428 void CCertManUICertificateHelper::DetailsFieldResourceL(
       
   429     HBufC& aMessage, TInt aResourceOne,
       
   430     TInt aResourceTwo)
       
   431     {
       
   432     CERTMANUILOGGER_ENTERFN(
       
   433         "CCertManUICertificateHelper::DetailsFieldResourceL" );
       
   434 
       
   435     DetailsResourceL( aMessage, aResourceOne );
       
   436     DetailsResourceL( aMessage, aResourceTwo );
       
   437     aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
   438 
       
   439     CERTMANUILOGGER_LEAVEFN(
       
   440         "CCertManUICertificateHelper::DetailsFieldResourceL" );
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------
       
   444 // CCertManUICertificateHelper::DevideToBlocks
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 void CCertManUICertificateHelper::DevideToBlocks( const TDesC8& aInput, TPtr aOutput )
       
   448     {
       
   449     const TInt KBlockLength = 2;
       
   450     TInt blockIndex = 0;
       
   451     for ( TInt j = 0 ; j < aInput.Length() ; j++ )
       
   452         {
       
   453         if ( blockIndex == KBlockLength )
       
   454             {
       
   455             aOutput.Append( KBlockSeparator );
       
   456             blockIndex = 0;
       
   457             }
       
   458         aOutput.AppendNumFixedWidthUC( (TUint)(aInput[ j ]), EHex, 2 );
       
   459         ++blockIndex;
       
   460         }
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------
       
   464 // CCertManUICertificateHelper::DisplayWarningNoteLD(HBufC* aString)
       
   465 // Displays the warning note for corrupted/expired/not yet valid certificate
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CCertManUICertificateHelper::DisplayWarningNoteLD( HBufC* aString )
       
   469     {
       
   470     CERTMANUILOGGER_ENTERFN(
       
   471         "CCertManUICertificateHelper::DisplayWarningNoteLD" );
       
   472 
       
   473     CAknWarningNote* note = new ( ELeave ) CAknWarningNote( ETrue );
       
   474     note->ExecuteLD( *aString );
       
   475     CleanupStack::PopAndDestroy();  // aString
       
   476 
       
   477     CERTMANUILOGGER_LEAVEFN(
       
   478         "CCertManUICertificateHelper::DisplayWarningNoteLD" );
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------
       
   482 // CCertManUICertificateHelper::ValidateX509CertificateL(CX509Certificate* aDetails)
       
   483 // Checks if the certificate is corrupted
       
   484 // Checks the validity period of the certificate
       
   485 // Display only one warning note, in the following order:
       
   486 // 1) Expired/Not yet valid
       
   487 // 2) Corrupted
       
   488 // 3) Not trusted
       
   489 // ---------------------------------------------------------
       
   490 //
       
   491 CArrayFixFlat<TValidationError>* CCertManUICertificateHelper::
       
   492     ValidateX509CertificateL( CX509Certificate* aDetails )
       
   493     {
       
   494     TInt poppableItems = 0;
       
   495     CArrayFixFlat<TValidationError>* status =
       
   496         new ( ELeave ) CArrayFixFlat<TValidationError>( 1 );
       
   497     CleanupStack::PushL( status ); //This is returned, so it isn't destroyed at the end.
       
   498 
       
   499     TTime GMTTime;
       
   500     GMTTime.UniversalTime(); // Get Universal Time
       
   501     RPointerArray<CX509Certificate> certArray( &aDetails, 1 );
       
   502 
       
   503     CPKIXCertChain* chain = CPKIXCertChain::NewLC(
       
   504         iKeeper.iRfs, aDetails->Encoding(), certArray );
       
   505     poppableItems++;
       
   506 
       
   507     CPKIXValidationResult* result = CPKIXValidationResult::NewLC();
       
   508     poppableItems++;
       
   509     iKeeper.iWrapper->ValidateX509RootCertificateL( result, GMTTime, chain );
       
   510 
       
   511     TValidationStatus validationStatus = result->Error();
       
   512     //Set reserve space. One for error, other for warnings.
       
   513     status->SetReserveL( 1 + result->Warnings().Count() );
       
   514     status->AppendL(validationStatus.iReason);
       
   515     for ( TUint8 i = 0; i < result->Warnings().Count(); i++ )
       
   516         {
       
   517         status->AppendL( result->Warnings().At(0).iReason );
       
   518         }
       
   519 
       
   520     CleanupStack::PopAndDestroy( poppableItems );    //  All but status.
       
   521     CleanupStack::Pop();        //  status
       
   522     return status;
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------
       
   526 // CCertManUICertificateHelper::DetailsDynamicL(
       
   527 // HBufC& aMessage, TPtrC aValue, TInt aResourceOne)
       
   528 // Reads dynamic text from CertManAPI, if the string is empty
       
   529 // put a not defined text from the resource in its place
       
   530 // KMaxLengthTextCertLabel = 510, used by CertLabel(), Issuer(), Owner()
       
   531 // ---------------------------------------------------------
       
   532 //
       
   533 void CCertManUICertificateHelper::DetailsDynamicL(
       
   534     HBufC& aMessage, TPtrC aValue, TInt aResourceOne )
       
   535     {
       
   536     CERTMANUILOGGER_ENTERFN(
       
   537         "CCertManUICertificateHelper::DetailsDynamicL" );
       
   538 
       
   539     HBufC* buf = HBufC::NewLC( KMaxLengthTextCertLabel );
       
   540     buf->Des() = aValue;
       
   541     buf->Des().TrimLeft();
       
   542     // Cut CertLabel after fourth semi colon
       
   543     TPtrC trimmedCertLabel = CutCertificateField( buf->Des() );
       
   544     buf->Des().Copy( trimmedCertLabel );
       
   545     TInt length = buf->Des().Length();
       
   546     if ( length == 0 )
       
   547         {
       
   548         DetailsResourceL( aMessage, aResourceOne );
       
   549         }
       
   550     else
       
   551         {
       
   552         //LRM (Left-to-Right mark 200E)
       
   553         const TInt KLRMark = 0x200E;
       
   554         aMessage.Des().Append( buf->Des() );
       
   555         aMessage.Des().Append(KLRMark);
       
   556         aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
   557         }
       
   558     CleanupStack::PopAndDestroy();  // buf
       
   559 
       
   560     CERTMANUILOGGER_LEAVEFN(
       
   561         "CCertManUICertificateHelper::DetailsDynamicL" );
       
   562     }
       
   563 
       
   564 // ---------------------------------------------------------
       
   565 // CCertManUIViewAuthority::ConfirmationQueryDeleteCertL()
       
   566 // Deletes either certificate in focus if there are no marked items,
       
   567 // or deletes the marked items
       
   568 // Shows read-only information notes if certificates are not deletable
       
   569 // Returns ETrue if at least one certificate is deleted
       
   570 // ---------------------------------------------------------
       
   571 //
       
   572 TBool CCertManUICertificateHelper::ConfirmationQueryDeleteCertL(
       
   573     TInt aType,
       
   574     CEikColumnListBox* aListBox )
       
   575     {
       
   576     CERTMANUILOGGER_ENTERFN(
       
   577         "CCertManUICertificateHelper::ConfirmationQueryDeleteCertL" );
       
   578 
       
   579     TBool result = EFalse;
       
   580 
       
   581     const CArrayFix<TInt>* array = aListBox->SelectionIndexes();
       
   582     TInt focusPosition = aListBox->CurrentItemIndex();
       
   583     CCTCertInfo* entry;
       
   584     TInt queryOk = 0;
       
   585     // comes here when there is no selection, can be read-only
       
   586     // certificate if Clear key is pressed, must check
       
   587     if ( array->Count() == 0 && IsCertificateDeletable( focusPosition, aType ) )
       
   588         {
       
   589         if( aType == KCertTypeAuthority )
       
   590             {
       
   591             entry = iKeeper.iCALabelEntries[ focusPosition ]->iCAEntry;
       
   592             }
       
   593         else if( aType == KCertTypeTrustedSite )
       
   594             {
       
   595             entry = iKeeper.iPeerLabelEntries[ focusPosition ]->iPeerEntry;
       
   596             }
       
   597         else if( aType == KCertTypeDevice )
       
   598             {
       
   599             entry = iKeeper.iDeviceLabelEntries[ focusPosition ]->iDeviceEntry;
       
   600             }
       
   601         else
       
   602             {
       
   603             entry = iKeeper.iUserLabelEntries[ focusPosition ]->iUserEntry;
       
   604             }
       
   605         queryOk = DeleteSingleItemQueryL( *entry );
       
   606         if ( queryOk )
       
   607             {
       
   608             if (IsCertificateDeletable( focusPosition, aType ))
       
   609                 {
       
   610                 DeleteSingleItemL( *entry, focusPosition, aListBox, aType );
       
   611 
       
   612 
       
   613                 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   614                     aListBox, focusPosition, ETrue );
       
   615                 result = ETrue;
       
   616                 }
       
   617             else
       
   618                 {
       
   619                 ReadOnlySingleItemNoteL( *entry );
       
   620                 }
       
   621             }
       
   622         }
       
   623     else if ( IsOneMarkedCertificateDeletable(aListBox, aType) ) //if (array->Count()=>1)
       
   624         {
       
   625         if ( aType == KCertTypeAuthority )
       
   626             {
       
   627             entry = iKeeper.iCALabelEntries[ array->At(0) ]->iCAEntry;
       
   628             }
       
   629         else if ( aType == KCertTypeTrustedSite )
       
   630             {
       
   631             entry = iKeeper.iPeerLabelEntries[ array->At(0) ]->iPeerEntry;
       
   632             }
       
   633         else if( aType == KCertTypeDevice )
       
   634             {
       
   635             entry = iKeeper.iDeviceLabelEntries[ array->At(0) ]->iDeviceEntry;
       
   636             }
       
   637         else
       
   638             {
       
   639             entry = iKeeper.iUserLabelEntries[ array->At(0) ]->iUserEntry;
       
   640             }
       
   641 
       
   642         if (array->Count()==1)
       
   643             {
       
   644             queryOk = DeleteSingleItemQueryL( *entry );
       
   645             }
       
   646         else
       
   647             {
       
   648             HBufC* prompt = StringLoader::LoadLC(
       
   649                 R_CONFIRMATION_QUERY_DELETE_CERT_PLURAL, array->Count() );
       
   650             queryOk = DisplayConfirmationLD( prompt );
       
   651             }
       
   652         if ( queryOk )
       
   653             {
       
   654             TInt readonlyCount = 0;
       
   655             TInt singleReadOnlyPosition = 0;
       
   656             TInt markedPosition = 0;
       
   657             TKeyArrayFix ownKey( 0, ECmpTInt );
       
   658             CONST_CAST(CArrayFix<int>*, array)->Sort( ownKey ); //lint !e665 expression macro param ok
       
   659             TInt markedCount = array->Count();
       
   660             CArrayFixFlat<TInt>* deletedIndexes = new (ELeave)CArrayFixFlat<TInt>( 4 );
       
   661             CleanupStack::PushL( deletedIndexes );
       
   662 
       
   663             iKeeper.StartWaitDialogL( ECertmanUiDeleteDialog );
       
   664             CleanupCloseWaitDialogPushL( iKeeper );
       
   665 
       
   666             for ( TInt i = markedCount; i > 0; i-- )
       
   667                 {
       
   668                 markedPosition = array->At( i-1 );
       
   669                 // move focus up the list if marked items were
       
   670                 // between focus and the beginning of the list
       
   671                 if ( focusPosition > markedPosition )
       
   672                     {
       
   673                     focusPosition--;
       
   674                     }
       
   675 
       
   676                 // Check whether certificate is deletable
       
   677 
       
   678                 if( aType == KCertTypeAuthority )
       
   679                     {
       
   680                     entry = iKeeper.iCALabelEntries[ markedPosition ]->iCAEntry;
       
   681                     }
       
   682                 else if( aType == KCertTypeTrustedSite )
       
   683                     {
       
   684                     entry = iKeeper.iPeerLabelEntries[ markedPosition ]->iPeerEntry;
       
   685                     }
       
   686                 else if( aType == KCertTypeDevice )
       
   687                     {
       
   688                     entry = iKeeper.iDeviceLabelEntries[ markedPosition ]->iDeviceEntry;
       
   689                     }
       
   690                 else
       
   691                     {
       
   692                     entry = iKeeper.iUserLabelEntries[ markedPosition ]->iUserEntry;
       
   693                     }
       
   694 
       
   695                 if (IsCertificateDeletable(markedPosition, aType))
       
   696                     {
       
   697                     DeleteSingleItemL( *entry, markedPosition, aListBox, aType );
       
   698                     deletedIndexes->AppendL(markedPosition);
       
   699                     result = ETrue;
       
   700                     }
       
   701                 else // Cannot be deleted
       
   702                     {
       
   703                     readonlyCount++;
       
   704                     singleReadOnlyPosition = markedPosition;
       
   705                     }
       
   706                 }
       
   707 
       
   708             CleanupStack::PopAndDestroy();    // closes wait dialog
       
   709 
       
   710             if ( readonlyCount == 1 )
       
   711                 {
       
   712                 if( aType == KCertTypeAuthority  )
       
   713                     {
       
   714                     entry = iKeeper.iCALabelEntries[ singleReadOnlyPosition ]->iCAEntry;
       
   715                     }
       
   716                 else if( aType == KCertTypeTrustedSite  )
       
   717                     {
       
   718                     entry = iKeeper.iPeerLabelEntries[ singleReadOnlyPosition ]->iPeerEntry;
       
   719                     }
       
   720                 else if( aType == KCertTypeDevice )
       
   721                     {
       
   722                     entry = iKeeper.iDeviceLabelEntries[ singleReadOnlyPosition ]->iDeviceEntry;
       
   723                     }
       
   724                 else
       
   725                     {
       
   726                     entry = iKeeper.iUserLabelEntries[ singleReadOnlyPosition ]->iUserEntry;
       
   727                     }
       
   728 
       
   729                 ReadOnlySingleItemNoteL( *entry );
       
   730                 }
       
   731             else if ( readonlyCount > 1 )
       
   732                 {
       
   733                 HBufC* string = StringLoader::LoadLC(
       
   734                     R_INFO_NOTE_TEXT_CERTIFICATE_READ_ONLY_MULTIPLE,
       
   735                     readonlyCount );
       
   736                 DisplayNoteLD( string );
       
   737                 }
       
   738             else
       
   739                 { // For lint
       
   740                 }
       
   741 
       
   742             aListBox->ClearSelection();
       
   743             AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   744                 aListBox, focusPosition, *deletedIndexes);
       
   745             CleanupStack::PopAndDestroy(deletedIndexes);
       
   746 
       
   747             }
       
   748         }
       
   749     else
       
   750         {
       
   751         result = EFalse;
       
   752         }
       
   753 
       
   754     aListBox->DrawNow();//lint !e539
       
   755 
       
   756     CERTMANUILOGGER_LEAVEFN(
       
   757         "CCertManUICertificateHelper::ConfirmationQueryDeleteCertL" );
       
   758 
       
   759 
       
   760     return result;
       
   761     }
       
   762 
       
   763 // ---------------------------------------------------------
       
   764 // CCertManUIViewAuthority::DeleteSingleItemQueryL(CCTCertInfo& aEntry)
       
   765 // Gets the certificate name (or No label/No subject) for the Confirmation note
       
   766 // ---------------------------------------------------------
       
   767 //
       
   768 TInt CCertManUICertificateHelper::DeleteSingleItemQueryL( CCTCertInfo& aEntry )
       
   769     {
       
   770     CERTMANUILOGGER_ENTERFN(
       
   771         "CCertManUICertificateHelper::DeleteSingleItemQueryL" );
       
   772 
       
   773     TInt selection = 0;
       
   774 
       
   775     HBufC* buf = HBufC::NewLC( KMaxLengthTextCertLabel );
       
   776     buf->Des() = aEntry.Label();
       
   777     buf->Des().TrimLeft();
       
   778     // Cut CertLabel after fourth semi colon
       
   779     TPtrC trimmedCertLabel = CutCertificateField( buf->Des() );
       
   780     buf->Des().Copy(trimmedCertLabel);
       
   781     TInt length = buf->Des().Length();
       
   782     if ( length == 0 )
       
   783         {
       
   784         // here the resource name is _NO_LABEL, but it returns only "Delete certificate?"
       
   785         // not any "No label" or "No subject" string
       
   786         HBufC* prompt = StringLoader::LoadLC(
       
   787             R_CONFIRMATION_QUERY_DELETE_CERT_NO_LABEL );
       
   788         selection = DisplayConfirmationLD( prompt );
       
   789         }
       
   790     else
       
   791         {
       
   792         HBufC* prompt = StringLoader::LoadLC(
       
   793             R_CONFIRMATION_QUERY_DELETE_CERT, buf->Des() );
       
   794         selection = DisplayConfirmationLD(prompt);
       
   795         }
       
   796     CleanupStack::PopAndDestroy();  // buf
       
   797 
       
   798     CERTMANUILOGGER_LEAVEFN(
       
   799         "CCertManUICertificateHelper::DeleteSingleItemQueryL" );
       
   800 
       
   801     return selection;
       
   802     }
       
   803 
       
   804 
       
   805 // ---------------------------------------------------------
       
   806 // CCertManUICertificateHelper::DeleteSingleItemL(CCrCertEntry& aEntry, TInt aPosition, TInt aType)
       
   807 // Deletes one item from CertManAPI and from listbox
       
   808 // ---------------------------------------------------------
       
   809 //
       
   810 void CCertManUICertificateHelper::DeleteSingleItemL( CCTCertInfo& aEntry,
       
   811     TInt aPosition,
       
   812     CEikColumnListBox* aListBox,
       
   813     TInt aType )
       
   814     {
       
   815     CERTMANUILOGGER_ENTERFN(
       
   816         "CCertManUICertificateHelper::DeleteSingleItemL" );
       
   817 
       
   818     TInt status( KErrNone );
       
   819 
       
   820     if ( aType == KCertTypeTrustedSite )
       
   821         {
       
   822         status = iKeeper.iWrapper->DeleteCertL(
       
   823                                               iKeeper.CertManager(),
       
   824                                               aEntry,
       
   825                                               KCMTrustedServerTokenUid
       
   826                                               );
       
   827         }
       
   828     else if( aType == KCertTypeDevice )
       
   829         {
       
   830         status = iKeeper.iWrapper->DeleteCertL(
       
   831                                               iKeeper.CertManager(),
       
   832                                               aEntry,
       
   833                                               KCMDeviceCertStoreTokenUid
       
   834                                               );
       
   835         }
       
   836     else
       
   837         {
       
   838         status = iKeeper.iWrapper->DeleteCertL( iKeeper.CertManager(), aEntry );
       
   839         }
       
   840 
       
   841     // Update the list after delete. In case of a error, a note show inside DeleteCertL.
       
   842     if ( status == KErrNone )
       
   843         {
       
   844         MDesCArray *itemList = aListBox->Model()->ItemTextArray();
       
   845         CDesCArray* itemArray = STATIC_CAST( CDesCArray*, itemList );
       
   846         itemArray->Delete( aPosition );
       
   847         }
       
   848 
       
   849     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::DeleteSingleItemL" ); //lint !e539
       
   850     }
       
   851 
       
   852 
       
   853 // ---------------------------------------------------------
       
   854 // CCertManUICertificateHelper::MoveKeyL(const TCTKeyAttributeFilter& aFilter,
       
   855 //                       TUid aSourceStore, TUid aSourceStore )
       
   856 // Moves a key from one store to another
       
   857 // ---------------------------------------------------------
       
   858 //
       
   859 void CCertManUICertificateHelper::MoveKeyL(
       
   860     const TCTKeyAttributeFilter& aFilter,
       
   861     const TUid aSourceStore,
       
   862     const TUid aTargetStore )
       
   863     {
       
   864     CERTMANUILOGGER_ENTERFN(
       
   865         "CCertManUICertificateHelper::MoveCertL" );
       
   866 
       
   867     iKeeper.iWrapper->MoveKeyL( iKeeper.KeyManager(), aFilter, aSourceStore, aTargetStore );
       
   868 
       
   869     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::MoveCertL" );
       
   870     }
       
   871 
       
   872 
       
   873 // ---------------------------------------------------------
       
   874 // CCertManUICertificateHelper::MoveCertL(CCrCertEntry& aEntry,
       
   875 //                        TInt aPosition, CEikColumnListBox* aListBox,
       
   876 //                        TUid aSourceStore, TUid aSourceStore )
       
   877 // Moves a certificate from one store to another
       
   878 // ---------------------------------------------------------
       
   879 //
       
   880 void CCertManUICertificateHelper::MoveCertL( CCTCertInfo& aEntry,
       
   881     TInt aPosition,
       
   882     CEikColumnListBox* aListBox,
       
   883     const TUid aSourceStore,
       
   884     const TUid aTargetStore )
       
   885     {
       
   886     CERTMANUILOGGER_ENTERFN(
       
   887         "CCertManUICertificateHelper::MoveCertL" );
       
   888 
       
   889     TInt certCount(0);
       
   890 
       
   891     TRAPD( err, certCount = iKeeper.iWrapper->MoveCertL( iKeeper.CertManager(), aEntry, aSourceStore, aTargetStore ));
       
   892 
       
   893     // Update the list after moving the certificate
       
   894     if ( err == KErrNone )
       
   895         {
       
   896         MDesCArray *itemList = aListBox->Model()->ItemTextArray();
       
   897         CDesCArray* itemArray = STATIC_CAST( CDesCArray*, itemList );
       
   898         if ( certCount == 1  )
       
   899             {
       
   900             // Delete single item
       
   901             itemArray->Delete( aPosition );
       
   902             AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   903                           aListBox, aPosition, ETrue );
       
   904             }
       
   905          else
       
   906             {
       
   907             // More than one certificate moved. Empty listbox items.
       
   908             // It will be updated later
       
   909             itemArray->Reset();
       
   910             }
       
   911         }
       
   912     else
       
   913         {
       
   914         User::Leave( err );
       
   915         }
       
   916 
       
   917     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::MoveCertL" );
       
   918     }
       
   919 
       
   920 
       
   921 // ---------------------------------------------------------
       
   922 // CCertManUICertificateHelper::ReadOnlySingleItemNoteL(CCTCertInfo& aEntry)
       
   923 // Gets the certificate name (or No label/No subject) for the read-only note
       
   924 // ---------------------------------------------------------
       
   925 //
       
   926 void CCertManUICertificateHelper::ReadOnlySingleItemNoteL(CCTCertInfo& aEntry )
       
   927     {
       
   928     CERTMANUILOGGER_ENTERFN( "CCertManUICertificateHelper::ReadOnlySingleItemNoteL" );
       
   929 
       
   930     HBufC* buf = HBufC::NewLC( KMaxLengthTextCertLabel );
       
   931     buf->Des() = aEntry.Label();
       
   932     buf->Des().TrimLeft();
       
   933     // Cut CertLabel after fourth semi colon
       
   934     TPtrC trimmedCertLabel = CutCertificateField( buf->Des() );
       
   935     buf->Des().Copy(trimmedCertLabel);
       
   936     TInt length = buf->Des().Length();
       
   937     if ( length == 0 )
       
   938         {
       
   939         // here the resource name is _NO_LABEL, but it returns only "Cannot delete certificate"
       
   940         // not any "No label" or "No subject" string
       
   941         HBufC* stringHolder = StringLoader::LoadLC(
       
   942                                 R_INFO_NOTE_TEXT_CERTIFICATE_READ_ONLY_NO_LABEL );
       
   943         DisplayNoteLD( stringHolder );
       
   944         }
       
   945     else
       
   946         {
       
   947         HBufC* stringHolder = StringLoader::LoadLC(
       
   948                                 R_INFO_NOTE_TEXT_CERTIFICATE_READ_ONLY, buf->Des() );
       
   949         DisplayNoteLD( stringHolder );
       
   950         }
       
   951     CleanupStack::PopAndDestroy();  // buf
       
   952 
       
   953 
       
   954     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::ReadOnlySingleItemNoteL" );
       
   955     }
       
   956 // ---------------------------------------------------------
       
   957 // CCertManUICertificateHelper::DisplayConfirmationLD(HBufC* aString)
       
   958 // Displays Delete yes/no confirmation notes
       
   959 // ---------------------------------------------------------
       
   960 //
       
   961 TInt CCertManUICertificateHelper::DisplayConfirmationLD( HBufC* aString )
       
   962     {
       
   963     CERTMANUILOGGER_ENTERFN( "CCertManUICertificateHelper::DisplayConfirmationLD" );
       
   964 
       
   965     CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
   966     TInt selection = dlg->ExecuteLD( R_CERTMANUI_CONFIRMATION_QUERY_YES_NO, *aString );
       
   967     // Takes ownership and destroys aString
       
   968     CleanupStack::PopAndDestroy();  // aString
       
   969 
       
   970     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::DisplayConfirmationLD" );
       
   971 
       
   972     return selection;
       
   973     }
       
   974 
       
   975 // ---------------------------------------------------------
       
   976 // CCertManUICertificateHelper::DisplayNoteLD(HBufC* aString)
       
   977 // Displays read-only information notes
       
   978 // ---------------------------------------------------------
       
   979 //
       
   980 void CCertManUICertificateHelper::DisplayNoteLD(HBufC* aString)
       
   981     {
       
   982     CERTMANUILOGGER_ENTERFN( "CCertManUICertificateHelper::DisplayNoteLD" );
       
   983 
       
   984     CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   985     note->ExecuteLD( *aString );
       
   986     CleanupStack::PopAndDestroy();  // aString
       
   987 
       
   988     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::DisplayNoteLD" );
       
   989     }
       
   990 
       
   991 // ---------------------------------------------------------
       
   992 // CCertManUICertificateHelper::FFSSpaceBelowCriticalLevelL
       
   993 // Handle deleting when disk is getting full
       
   994 // ---------------------------------------------------------
       
   995 //
       
   996 TBool CCertManUICertificateHelper::FFSSpaceBelowCriticalLevelL(
       
   997     TBool aShowErrorNote, TInt aBytesToWrite )
       
   998     {
       
   999     CERTMANUILOGGER_ENTERFN(
       
  1000         "CCertManUICertificateHelper::FFSSpaceBelowCriticalLevelL" );
       
  1001 
       
  1002     TBool ret = EFalse;
       
  1003     if ( SysUtil::FFSSpaceBelowCriticalLevelL(
       
  1004         &(CCoeEnv::Static()->FsSession()), aBytesToWrite ) )
       
  1005         {
       
  1006         ret = ETrue;
       
  1007         if ( aShowErrorNote )
       
  1008             {
       
  1009             CErrorUI* errorUi = CErrorUI::NewLC( *(CCoeEnv::Static()) );
       
  1010             errorUi->ShowGlobalErrorNoteL( KErrDiskFull );
       
  1011             CleanupStack::PopAndDestroy();  // errorUi
       
  1012             }
       
  1013         }
       
  1014 
       
  1015     CERTMANUILOGGER_LEAVEFN(
       
  1016         "CCertManUICertificateHelper::FFSSpaceBelowCriticalLevelL" );
       
  1017 
       
  1018     return ret;
       
  1019     }
       
  1020 // ---------------------------------------------------------
       
  1021 // CCertManUICertificateHelper::HandleMarkableListCommandL( TInt aCommand )
       
  1022 // Handles marking and unmarking of the list.
       
  1023 // ---------------------------------------------------------
       
  1024 //
       
  1025 void CCertManUICertificateHelper::HandleMarkableListCommandL( TInt aCommand,
       
  1026                                                     CEikColumnListBox* aListBox )
       
  1027     {
       
  1028     CERTMANUILOGGER_ENTERFN(
       
  1029         "CCertManUICertificateHelper::HandleMarkableListCommandL" );
       
  1030 
       
  1031     TInt index;
       
  1032     switch ( aCommand )
       
  1033         {
       
  1034         case ECertManUICmdMark:
       
  1035             {
       
  1036             index = aListBox->CurrentItemIndex();
       
  1037             if ( index >= 0 )
       
  1038                 {
       
  1039                 // This is done to make sure listbox updates its state
       
  1040                 // to make shift+arrow work correctly after shift+ok
       
  1041                 aListBox->View()->UpdateSelectionL( CListBoxView::EDisjointSelection );
       
  1042                 aListBox->View()->SelectItemL( index );
       
  1043                 }
       
  1044             break;
       
  1045             }
       
  1046         case ECertManUICmdUnmark:
       
  1047             {
       
  1048             index = aListBox->CurrentItemIndex();
       
  1049             if ( index >= 0 )
       
  1050                 {
       
  1051                 // This is done to make sure listbox updates its state
       
  1052                 // to make shift+arrow work correctly after shift+ok
       
  1053                 aListBox->View()->UpdateSelectionL(
       
  1054                       CListBoxView::EDisjointSelection );
       
  1055                 aListBox->View()->DeselectItem( index );
       
  1056                 }
       
  1057             break;
       
  1058             }
       
  1059         case ECertManUICmdMarkAll:
       
  1060             {
       
  1061             aListBox->ClearSelection();
       
  1062             TInt count = aListBox->Model()->NumberOfItems();
       
  1063             if ( count )
       
  1064                 {
       
  1065                 CArrayFixFlat<TInt>* selection =
       
  1066                     new( ELeave ) CArrayFixFlat<TInt>( 1 );
       
  1067                 CleanupStack::PushL( selection );
       
  1068                 selection->SetReserveL( count );
       
  1069                 for( TInt i = 0; i < count; i++ )
       
  1070                     {
       
  1071                     selection->AppendL( i );
       
  1072                     }
       
  1073                 aListBox->SetSelectionIndexesL( selection );
       
  1074                 CleanupStack::PopAndDestroy();  // selection
       
  1075                 }
       
  1076             break;
       
  1077             }
       
  1078         case ECertManUICmdUnmarkAll:
       
  1079             {
       
  1080             aListBox->ClearSelection();
       
  1081             break;
       
  1082             }
       
  1083         default:
       
  1084       break;
       
  1085       }
       
  1086 
       
  1087     CERTMANUILOGGER_LEAVEFN(
       
  1088         "CCertManUICertificateHelper::HandleMarkableListCommandL" );
       
  1089     }
       
  1090 
       
  1091 // ---------------------------------------------------------
       
  1092 // CCertManUICertificateHelper::GetKeyUsageAndLocationL( CCTCertInfo* aCertEntry,
       
  1093 //                                                      TUid* aKeyLocation)
       
  1094 // Returns key usage and location.
       
  1095 // ---------------------------------------------------------
       
  1096 //
       
  1097 TKeyUsagePKCS15 CCertManUICertificateHelper::GetKeyUsageAndLocationL( CCTCertInfo* aCertEntry,
       
  1098                                                                      TUid* aKeyLocation )
       
  1099     {
       
  1100     TKeyUsagePKCS15 keyUsage;
       
  1101 
       
  1102     CERTMANUILOGGER_ENTERFN( "CCertManUICertificateHelper::GetKeyUsageAndLocationL" );
       
  1103 
       
  1104     // Check whether we have key for this certificate
       
  1105     RMPointerArray<CCTKeyInfo> keyEntry;
       
  1106     TCTKeyAttributeFilter filter;
       
  1107     filter.iKeyId = aCertEntry->SubjectKeyId();
       
  1108 
       
  1109     iKeeper.iWrapper->ListL( iKeeper.KeyManager(), &keyEntry, filter );
       
  1110 
       
  1111     if (keyEntry.Count())
       
  1112         {
       
  1113         keyUsage = keyEntry[0]->Usage();
       
  1114         // Get Location
       
  1115         aKeyLocation->iUid = keyEntry[0]->Token().TokenType().Type().iUid ;
       
  1116         }
       
  1117     else
       
  1118         {
       
  1119         keyUsage = EPKCS15UsageNone;
       
  1120         }
       
  1121 
       
  1122     keyEntry.Close();
       
  1123     LOG_WRITE_FORMAT( "Key usage : %X", keyUsage );
       
  1124     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::GetKeyUsageAndLocationL" );
       
  1125     return keyUsage;
       
  1126     }
       
  1127 
       
  1128 // ---------------------------------------------------------
       
  1129 // CCertManUICertificateHelper::SetLocationInfoL( (HBufC& aMessage,
       
  1130 //                                               TBool aCertificate,
       
  1131 //                                               TUid* aLocUid)
       
  1132 // Adds certificate/private key's location info to certificate details
       
  1133 // ---------------------------------------------------------
       
  1134 //
       
  1135 void CCertManUICertificateHelper::SetLocationInfoL(
       
  1136     HBufC& aMessage,
       
  1137     TBool aCertificate,
       
  1138     TUid* aLocUid)
       
  1139     {
       
  1140     TInt location = 0;
       
  1141     TInt locationRes = 0;
       
  1142 
       
  1143     CERTMANUILOGGER_ENTERFN( "CCertManUICertificateHelper::SetLocationInfo" );
       
  1144 
       
  1145     switch ( aLocUid->iUid )
       
  1146         {
       
  1147         case KFileCertStoreUid:
       
  1148         case KTrustedServerCertStoreUid:
       
  1149         case KDeviceCertStoreUid:
       
  1150         case KDeviceKeyStoreUid:
       
  1151         case KTokenTypeFileKeystore:
       
  1152             location = R_TEXT_RESOURCE_DETAILS_VIEW_LOCATION_PHONE_MEMORY;
       
  1153             break;
       
  1154 
       
  1155         case KWIMCertStoreUid:
       
  1156             location = R_TEXT_RESOURCE_DETAILS_VIEW_LOCATION_SMART_CARD;
       
  1157             break;
       
  1158 
       
  1159         default:
       
  1160             if ( aCertificate )
       
  1161                 {
       
  1162                 location = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED;
       
  1163                 }
       
  1164             else
       
  1165                 {
       
  1166                 location = R_TEXT_RESOURCE_DETAILS_VIEW_NO_PRIVATE_KEY;
       
  1167                 }
       
  1168             break;
       
  1169         }
       
  1170 
       
  1171     if ( aCertificate )
       
  1172         {
       
  1173         locationRes = R_TEXT_RESOURCE_DETAILS_VIEW_CERTIFICATE_LOCATION;
       
  1174         }
       
  1175     else
       
  1176         {
       
  1177         locationRes = R_TEXT_RESOURCE_DETAILS_VIEW_PRIVATE_KEY_LOCATION;
       
  1178         }
       
  1179 
       
  1180     DetailsFieldResourceL( aMessage, locationRes, location );
       
  1181 
       
  1182     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::SetLocationInfo" );
       
  1183     }
       
  1184 
       
  1185 // ---------------------------------------------------------
       
  1186 // CCertManUICertificateHelper::CreateMessageBodyTextL()
       
  1187 // ---------------------------------------------------------
       
  1188 //
       
  1189 void CCertManUICertificateHelper::CreateMessageBodyTextL( TInt aIndex, TInt aType,
       
  1190         CEikonEnv* aEikonEnv, HBufC& aMessage )
       
  1191     {
       
  1192     CERTMANUILOGGER_ENTERFN( "CCertManUICertificateHelper::CreateMessageBodyTextL" );
       
  1193 
       
  1194     // Use certificate index from previous view
       
  1195     HBufC8* urlBuf = NULL;
       
  1196     CCTCertInfo* entry = NULL;
       
  1197     CCertificate* details = NULL;
       
  1198     CUnifiedCertStore*& store = iKeeper.CertManager();
       
  1199 
       
  1200     if( aType == KCertTypeAuthority )
       
  1201         {
       
  1202         entry = ( iKeeper.iCALabelEntries )[ aIndex ]->iCAEntry;
       
  1203         }
       
  1204     else if( aType == KCertTypeTrustedSite )
       
  1205         {
       
  1206         entry = ( iKeeper.iPeerLabelEntries )[ aIndex ]->iPeerEntry;
       
  1207         }
       
  1208     else if( aType == KCertTypeDevice )
       
  1209         {
       
  1210         entry = ( iKeeper.iDeviceLabelEntries )[ aIndex ]->iDeviceEntry;
       
  1211         }
       
  1212     else
       
  1213         {
       
  1214         entry = ( iKeeper.iUserLabelEntries )[ aIndex ]->iUserEntry;
       
  1215         }
       
  1216 
       
  1217     TCertificateFormat certiticateFormat = entry->CertificateFormat();
       
  1218 
       
  1219     if( certiticateFormat != EX509CertificateUrl )
       
  1220         {
       
  1221         TInt err = iKeeper.iWrapper->GetCertificateL( store, *entry, details );
       
  1222         CleanupStack::PushL( details );
       
  1223         User::LeaveIfError( err );
       
  1224 
       
  1225         ValidateCertificateL( aIndex, details, *entry, aType );
       
  1226         }
       
  1227     else
       
  1228         {
       
  1229         urlBuf = HBufC8::NewLC( entry->Size() );
       
  1230         TPtr8 urlPtr = urlBuf->Des();
       
  1231         TInt err = iKeeper.iWrapper->GetUrlCertificateL( store, *entry, urlPtr );
       
  1232         User::LeaveIfError( err );
       
  1233         }
       
  1234 
       
  1235     if( aType == KCertTypeTrustedSite )
       
  1236         {
       
  1237         CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL();
       
  1238         CleanupStack::PushL( trustedSitesStore );
       
  1239 
       
  1240         RPointerArray<HBufC> trustedSites;
       
  1241         CleanupResetAndDestroyPushL( trustedSites );
       
  1242         trustedSitesStore->GetTrustedSitesL( details->Encoding(), trustedSites );
       
  1243 
       
  1244         if( trustedSites.Count() > 0 )
       
  1245             {
       
  1246             if( trustedSites.Count() == 1 )
       
  1247                 {
       
  1248                 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_SITE );
       
  1249                 }
       
  1250             else
       
  1251                 {
       
  1252                 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_SITES );
       
  1253                 }
       
  1254 
       
  1255             for( TInt i = 0; i < trustedSites.Count(); i++ )
       
  1256                 {
       
  1257                 aMessage.Des().Append( *trustedSites[ i ] );
       
  1258                 aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
  1259                 }
       
  1260             aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
  1261             }
       
  1262 
       
  1263         CleanupStack::PopAndDestroy( &trustedSites );
       
  1264         CleanupStack::PopAndDestroy( trustedSitesStore );
       
  1265         }
       
  1266     else
       
  1267         {
       
  1268         DetailsFieldDynamicL( aMessage, entry->Label(),
       
  1269                 R_TEXT_RESOURCE_DETAILS_VIEW_LABEL,
       
  1270                 R_TEXT_RESOURCE_VIEW_NO_LABEL_DETAILS );
       
  1271         }
       
  1272 
       
  1273     // certificate issuer and owner
       
  1274     if( certiticateFormat == EX509Certificate )
       
  1275         {
       
  1276         HBufC* owner = NULL;
       
  1277         X509CertNameParser::SubjectFullNameL( *(CX509Certificate*)details, owner );
       
  1278         CleanupStack::PushL( owner );
       
  1279 
       
  1280         HBufC* issuer = NULL;
       
  1281         X509CertNameParser::IssuerFullNameL( *(CX509Certificate*)details, issuer );
       
  1282         CleanupStack::PushL( issuer );
       
  1283 
       
  1284         DetailsFieldDynamicL( aMessage, issuer->Des(),
       
  1285             R_TEXT_RESOURCE_DETAILS_VIEW_ISSUER,
       
  1286             R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED );
       
  1287         CleanupStack::PopAndDestroy( issuer );
       
  1288 
       
  1289         // certificate subject
       
  1290         DetailsFieldDynamicL( aMessage, owner->Des(),
       
  1291             R_TEXT_RESOURCE_DETAILS_VIEW_SUBJECT,
       
  1292             R_TEXT_RESOURCE_VIEW_NO_SUBJECT_DETAILS );
       
  1293         CleanupStack::PopAndDestroy( owner );
       
  1294         }
       
  1295 
       
  1296     // Get key usage and location. This is done only client certificates.
       
  1297     const TInt KLocationUnknown = 0;
       
  1298     TUid keyLocation = { KLocationUnknown };
       
  1299 
       
  1300     if(( aType == KCertTypePersonal ) || ( aType == KCertTypeDevice ))
       
  1301         {
       
  1302         TInt usage;
       
  1303         switch( GetKeyUsageAndLocationL( entry, &keyLocation ) )
       
  1304             {
       
  1305             case EPKCS15UsageSignSignRecover:
       
  1306             case EPKCS15UsageSignDecrypt:
       
  1307             case EPKCS15UsageSign:
       
  1308                 usage = R_TEXT_RESOURCE_DETAILS_VIEW_CLIENT_AUTHENTICATION;
       
  1309                 break;
       
  1310             case EPKCS15UsageNonRepudiation:
       
  1311                 usage = R_TEXT_RESOURCE_DETAILS_VIEW_DIGITAL_SIGNING;
       
  1312                 break;
       
  1313             default:
       
  1314                 usage = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED;
       
  1315                 break;
       
  1316             }
       
  1317         DetailsFieldResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_KEY_USAGE, usage );
       
  1318         }
       
  1319 
       
  1320     if( certiticateFormat == EX509Certificate )
       
  1321         {
       
  1322         // Certificate validity period
       
  1323         // Hometime's offset to UTC
       
  1324         TLocale locale;
       
  1325         TTimeIntervalSeconds offSet = locale.UniversalTimeOffset();
       
  1326 
       
  1327         DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_VALID_FROM );
       
  1328         const CValidityPeriod& validityPeriod = details->ValidityPeriod();
       
  1329         TTime startValue = validityPeriod.Start();
       
  1330         startValue += offSet;
       
  1331 
       
  1332         HBufC* dateFormatString = aEikonEnv->AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
  1333 
       
  1334         TBuf<KMaxLengthTextDateString> startString;
       
  1335         startValue.FormatL( startString, *dateFormatString );
       
  1336         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( startString );
       
  1337         aMessage.Des().Append( startString );
       
  1338         aMessage.Des().Append( KCertManUIDetailsViewEnterEnter );
       
  1339 
       
  1340         DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_VALID_UNTIL );
       
  1341         TTime finishValue = validityPeriod.Finish();
       
  1342         finishValue += offSet;
       
  1343         TBuf<KMaxLengthTextDateString> finishString;
       
  1344 
       
  1345         finishValue.FormatL( finishString, *dateFormatString );
       
  1346         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString );
       
  1347         aMessage.Des().Append( finishString );
       
  1348         aMessage.Des().Append( KCertManUIDetailsViewEnterEnter );
       
  1349 
       
  1350         CleanupStack::PopAndDestroy( dateFormatString );
       
  1351 
       
  1352         TUid certLoc;
       
  1353         certLoc.iUid = entry->Token().TokenType().Type().iUid;
       
  1354         SetLocationInfoL( aMessage, ETrue, &certLoc );
       
  1355         }
       
  1356     else if( certiticateFormat == EX509CertificateUrl )
       
  1357         {
       
  1358         HBufC* urlBuf16 = HBufC::NewLC( urlBuf->Length() );
       
  1359         TPtr urlPtr = urlBuf16->Des();
       
  1360         urlPtr.Copy(*urlBuf);
       
  1361         DetailsFieldDynamicL( aMessage, urlBuf16->Des(),
       
  1362                 R_TEXT_RESOURCE_DETAILS_VIEW_CERTIFICATE_LOCATION,
       
  1363                 R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED );
       
  1364         CleanupStack::PopAndDestroy( urlBuf16 );
       
  1365         }
       
  1366     else
       
  1367         {
       
  1368         // nothing
       
  1369         }
       
  1370 
       
  1371     // certificate format
       
  1372     TInt fieldType = 0;
       
  1373     TInt fieldType2 = 0;
       
  1374     switch( certiticateFormat )
       
  1375         {
       
  1376         case EX509Certificate:
       
  1377         case EX509CertificateUrl:
       
  1378             {
       
  1379             fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_CERT_FORMAT_X509;
       
  1380             break;
       
  1381             }
       
  1382          default:
       
  1383             {
       
  1384             fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED;
       
  1385             break;
       
  1386             }
       
  1387         }
       
  1388     DetailsFieldResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_CERT_FORMAT, fieldType );
       
  1389 
       
  1390     // Private key location, only for user and device certicates
       
  1391     if(( aType == KCertTypePersonal ) || ( aType == KCertTypeDevice ))
       
  1392         {
       
  1393         SetLocationInfoL( aMessage, EFalse, &keyLocation );
       
  1394         }
       
  1395 
       
  1396     if( certiticateFormat == EX509Certificate )
       
  1397         {
       
  1398         __UHEAP_MARK;
       
  1399 
       
  1400         // certificate algorithms
       
  1401 
       
  1402         // digest algorithm
       
  1403         TAlgorithmId algorithmId = details->SigningAlgorithm().DigestAlgorithm().Algorithm();
       
  1404         switch( algorithmId )
       
  1405             {
       
  1406             case EMD2:
       
  1407                 {
       
  1408                 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_MD2;
       
  1409                 break;
       
  1410                 }
       
  1411             case EMD5:
       
  1412                 {
       
  1413                 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_MD5;
       
  1414                 break;
       
  1415                 }
       
  1416             case ESHA1:
       
  1417                 {
       
  1418                 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_SHA1;
       
  1419                 break;
       
  1420                 }
       
  1421             default:
       
  1422                 {
       
  1423                 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN;
       
  1424                 break;
       
  1425                 }
       
  1426             }
       
  1427 
       
  1428         // public-key algorithm
       
  1429         algorithmId = details->SigningAlgorithm().AsymmetricAlgorithm().Algorithm();
       
  1430         switch( algorithmId )
       
  1431             {
       
  1432             case ERSA:
       
  1433                 {
       
  1434                 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_RSA;
       
  1435                 break;
       
  1436                 }
       
  1437             case EDSA:
       
  1438                 {
       
  1439                 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_DSA;
       
  1440                 break;
       
  1441                 }
       
  1442             case EDH:
       
  1443                 {
       
  1444                 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_DH;
       
  1445                 break;
       
  1446                 }
       
  1447             default:
       
  1448                 {
       
  1449                 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN;
       
  1450                 }
       
  1451             }
       
  1452 
       
  1453         // If other algorithm is unknown
       
  1454         if( fieldType == R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN ||
       
  1455                 fieldType2 == R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN )
       
  1456             {
       
  1457             DetailsFieldResourceL( aMessage,
       
  1458                     R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM,
       
  1459                     R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN );
       
  1460             }
       
  1461         else // Both are known.
       
  1462             {
       
  1463             DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM );
       
  1464             HBufC* stringHolder = StringLoader::LoadLC( fieldType );
       
  1465             aMessage.Des().Append( stringHolder->Des() );
       
  1466             CleanupStack::PopAndDestroy( stringHolder );
       
  1467             stringHolder = StringLoader::LoadLC( fieldType2 );
       
  1468             aMessage.Des().Append( stringHolder->Des() );
       
  1469             CleanupStack::PopAndDestroy( stringHolder );
       
  1470             aMessage.Des().Append( KCertManUIDetailsViewEnterEnter );
       
  1471             }
       
  1472 
       
  1473         // certificate serial number
       
  1474         DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_SERIAL_NUMBER );
       
  1475         TPtrC8 serialNumber = details->SerialNumber();
       
  1476         TBuf<KMaxLengthTextSerialNumberFormatting> buf2;
       
  1477 
       
  1478         for( TInt i = 0; i < serialNumber.Length(); i++ )
       
  1479            {
       
  1480            buf2.Format( KCertManUIDetailsViewHexaFormat, serialNumber[i] );
       
  1481            aMessage.Des().Append( buf2 );
       
  1482            }
       
  1483 
       
  1484         aMessage.Des().Append( KCertManUIDetailsViewEnterEnter );
       
  1485 
       
  1486         // certificate fingerprint SHA-1
       
  1487         DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_FINGERPRINT );
       
  1488         TPtrC8 sha1_fingerprint = details->Fingerprint();
       
  1489         DevideToBlocks( sha1_fingerprint, aMessage.Des() );
       
  1490         aMessage.Des().Append( KCertManUIDetailsViewEnterEnter );
       
  1491 
       
  1492         // certificate fingerprint MD5
       
  1493         DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_FINGERPRINT_MD5 );
       
  1494 
       
  1495         CMD5* md5 = CMD5::NewL();
       
  1496         CleanupStack::PushL( md5 );
       
  1497         TBuf8<20> fingerprint = md5->Hash( details->Encoding() );
       
  1498         CleanupStack::PopAndDestroy( md5 );
       
  1499 
       
  1500         DevideToBlocks( fingerprint, aMessage.Des() );
       
  1501         aMessage.Des().Append( KCertManUIDetailsViewEnterEnter );
       
  1502 
       
  1503         // Public key
       
  1504         // qtn_cm_public_key looks like this "Public key (%0U %1N bit):"
       
  1505         // so DetailsResource cannot be used to get it.
       
  1506 
       
  1507         // We already know the public key algorithm, it has been put into fieldType2 above.
       
  1508         HBufC* pubkeyHolder = StringLoader::LoadLC( fieldType2 );  // %0U
       
  1509 
       
  1510         CDesCArrayFlat* strArray = new (ELeave) CDesCArrayFlat( 1 );
       
  1511         CleanupStack::PushL( strArray );
       
  1512 
       
  1513         strArray->InsertL( 0, *pubkeyHolder );
       
  1514 
       
  1515         // Get public key already here to get length of it for string loader.
       
  1516         const CSubjectPublicKeyInfo& publicKey = details->PublicKey();
       
  1517         TPtrC8 keyData = publicKey.KeyData();
       
  1518         TInt size = keyData.Size();  // %1N
       
  1519 
       
  1520         // To get key size decode DER encoded key got from the certificate.
       
  1521         TX509KeyFactory key;
       
  1522 
       
  1523         // There doesn't seem to be definition of MAX_INT anywhere so calculate it.
       
  1524         TReal maxInt;
       
  1525         TReal intBits = sizeof( TInt ) * 8;
       
  1526         Math::Pow( maxInt, 2, intBits );
       
  1527         maxInt = ( maxInt / 2 ) - 1;
       
  1528 
       
  1529         switch( algorithmId )
       
  1530             {
       
  1531             case ERSA:
       
  1532                 {
       
  1533                 const CRSAPublicKey* keyRSA = key.RSAPublicKeyL( keyData );
       
  1534 
       
  1535                 const TInteger& n = keyRSA->N();
       
  1536 
       
  1537                 TUint keySizeN = n.BitCount();
       
  1538 
       
  1539                 // Play it safe.
       
  1540                 if( keySizeN < maxInt )
       
  1541                     {
       
  1542                     size = keySizeN;
       
  1543                     }
       
  1544 
       
  1545                 delete keyRSA;
       
  1546 
       
  1547                 break;
       
  1548                 }
       
  1549             case EDSA:
       
  1550                 {
       
  1551                 TPtrC8 params = publicKey.EncodedParams();
       
  1552                 const CDSAPublicKey* keyDSA = key.DSAPublicKeyL( params, keyData );
       
  1553 
       
  1554                 const TInteger& y = keyDSA->Y();
       
  1555 
       
  1556                 TUint keySizeY = y.BitCount();
       
  1557 
       
  1558                 // Play it safe.
       
  1559                 if( keySizeY < maxInt )
       
  1560                     {
       
  1561                     size = keySizeY;
       
  1562                     }
       
  1563 
       
  1564                 delete keyDSA;
       
  1565 
       
  1566                 break;
       
  1567                 }
       
  1568             // There doesn't seem to be TX509KeyFactory function for DH keys.
       
  1569             // If the key is DH or unknown, just multiply length of the key
       
  1570             // in bytes with 8. It is not correct but at least gives an idea.
       
  1571             // Without setting something to size 'unknown' text should be used
       
  1572             // below for the string which is much more error prone than setting
       
  1573             // at least something.
       
  1574             case EDH:
       
  1575             default:
       
  1576                 {
       
  1577                 size = 8 * keyData.Size();
       
  1578                 }
       
  1579             }
       
  1580 
       
  1581         CArrayFixFlat<TInt>* intArr = new (ELeave) CArrayFixFlat<TInt>( 1 );
       
  1582         CleanupStack::PushL( intArr );
       
  1583         intArr->AppendL( size );
       
  1584 
       
  1585         // Load string and set algorithm and key length strings.
       
  1586         HBufC* stringHolder = StringLoader::LoadLC( R_TEXT_RESOURCE_DETAILS_VIEW_PUBLIC_KEY,
       
  1587                 *strArray, *intArr );
       
  1588         aMessage.Des().Append( stringHolder->Des() );
       
  1589         aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
  1590 
       
  1591         // Finally append the public key.
       
  1592         DevideToBlocks( keyData, aMessage.Des() );
       
  1593 
       
  1594         const TInt KItemsInCleanupStack = 4; // stringHolder, intArr, strArray, pubkeyHolder
       
  1595         CleanupStack::PopAndDestroy( KItemsInCleanupStack, pubkeyHolder );
       
  1596 
       
  1597         __UHEAP_MARKEND;
       
  1598         }
       
  1599     else
       
  1600         {
       
  1601         // SetUrlCertAlgorihm()
       
  1602         }
       
  1603 
       
  1604     if( certiticateFormat != EX509CertificateUrl )
       
  1605         {
       
  1606         CleanupStack::PopAndDestroy( details );
       
  1607         }
       
  1608     else
       
  1609         {
       
  1610         CleanupStack::PopAndDestroy( urlBuf );
       
  1611         }
       
  1612 
       
  1613     aMessage.Des().Append( KCertManUIDetailsViewEnter );
       
  1614 
       
  1615     CERTMANUILOGGER_LEAVEFN( "CCertManUICertificateHelper::CreateMessageBodyTextL" );
       
  1616     }
       
  1617 
       
  1618 
       
  1619 // End of file