pkiutilities/CertSaver/src/CertSaverModel.cpp
branchRCL_3
changeset 22 03674e5abf46
parent 21 09b1ac925e3f
child 23 94da73d93b58
--- a/pkiutilities/CertSaver/src/CertSaverModel.cpp	Tue Aug 31 16:04:40 2010 +0300
+++ b/pkiutilities/CertSaver/src/CertSaverModel.cpp	Wed Sep 01 12:19:59 2010 +0100
@@ -16,6 +16,9 @@
 */
 
 
+// INCLUDE FILES
+#include <aknnotewrappers.h>        // Note dialogs
+#include <aknmessagequerydialog.h>  // For CAknMessageQueryDialog
 #include <StringLoader.h>           // For loading resource strings
 #include <unifiedcertstore.h>       // For saving the certificates
 #include <mctwritablecertstore.h>   // For saving the certificates
@@ -32,8 +35,6 @@
 #include <x509certext.h>
 #include <mctkeystore.h>
 #include <TrustedSitesStore.h>
-#include <eikenv.h>                 // CEikonEnv
-#include <AknUtils.h>               // AknTextUtils
 
 #include <CertSaver.rsg>
 #include "CertSaverModel.h"
@@ -43,14 +44,7 @@
 #include "certsaver.hrh"
 #include "securityuisvariant.hrh"
 
-#include <hbdevicemessageboxsymbian.h>
-#include <hbdevicenotificationdialogsymbian.h>
-#include <hbsymbianvariant.h>
-
-#include "SecQueryUi.h"                   // needed for label dialog
-
 // CONSTANTS
-
 const TInt32 KWTLSTrusterUID( 268479059 );
 const TInt32 KInternetTrusterUID( 268441661 );
 const TInt32 KApplicationControllerTrusterUID( 268452523 );
@@ -62,14 +56,12 @@
 
 const TInt KMaxLengthTextMeassageBody( 5000 );
 const TInt KMaxLengthTextDateString( 11 );    // "dd/mm/yyyy0"
-const TInt KMaxLengthTextCheckBoxData( 255 );    // "dd/mm/yyyy0"
 
 //Issuer and Owner max visible length
 const TInt KMaxLengthTextCertIdentifierVisible( 1000 );
 const TInt KAttempts( 3 );
 
 const TInt KFingerprintLength( 50 );
-const TInt KTokenLength( 32 );
 
 _LIT( KCertSaverListBoxItemPrefix, "1\t" );
 const TInt KItemBufLen = 2 + KMaxName;
@@ -124,7 +116,6 @@
             const TCertificateOwnerType& aOwnerType,
             const TCertificateFormat& aCertFormat )
     {
-
     iCertOwnerType = aOwnerType;
     iCertFormat = aCertFormat;
     iNewCert = &aCertificate;
@@ -148,7 +139,6 @@
 //
 void CCertSaverModel::DoSavePrivateKeyL( const TDesC8& aKey )
     {
-
     CheckFSSpaceL( aKey );
 
     TKeyIdentifier keyIdentifier;
@@ -168,8 +158,7 @@
     CleanupStack::PopAndDestroy( pkcs8Data );
     if (KeyAlreadyExistsL( startDate, endDate, keyIdentifier, keyUsage) )
         {
-        // used to leave with error none
-        return;
+        User::Leave( KErrNone );
         }
 
     TInt accessType( 0 );
@@ -207,7 +196,7 @@
         case KErrKeySize:
         case KErrArgument:
             {
-            ShowInformationNoteL( R_CERTSAVER_KEY_TYPE_NOT_SUPPORTED );
+            ShowErrorNoteL( R_CERTSAVER_KEY_TYPE_NOT_SUPPORTED );
             User::Leave( KErrCancel );
             break;
             }
@@ -218,21 +207,21 @@
             }
         case KErrKeyUsage:
             {
-            ShowInformationNoteL( R_CERTSAVER_PRIVATE_KEY_CORRUPTED );
+            ShowErrorNoteL( R_CERTSAVER_PRIVATE_KEY_CORRUPTED );
             User::Leave( KErrCancel );
             break;
             }
         case KErrCancel:
         case KErrPermissionDenied:
             {
-            ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED );
+            ShowErrorNoteL( R_CERTSAVER_PKCS12_DISCARDED );
             User::Leave( KErrCancel );
             break;
             }
         case KErrCorrupt:
         case KErrEof:
             {
-            ShowInformationNoteL( R_CERTSAVER_KEYSTORE_CORRUPTED );
+            ShowErrorNoteL( R_CERTSAVER_KEYSTORE_CORRUPTED );
             User::Leave( KErrCancel );
             break;
             }
@@ -265,7 +254,6 @@
     const TKeyIdentifier& aKeyIdentifier,
     TKeyUsagePKCS15& aKeyUsage )
     {
-
     TBool ret = EFalse;
     TCTKeyAttributeFilter keyFilter;
     keyFilter.iKeyAlgorithm = CKeyInfoBase::EInvalidAlgorithm;
@@ -284,7 +272,7 @@
         case KErrCorrupt:
         case KErrEof:
             {
-            ShowInformationNoteL( R_CERTSAVER_KEYSTORE_CORRUPTED );
+            ShowErrorNoteL( R_CERTSAVER_KEYSTORE_CORRUPTED );
             User::Leave( KErrCancel );
             }
         default:
@@ -316,7 +304,6 @@
     const TKeyIdentifier& aKeyIdentifier )
     {
 
-
     for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
         {
         const CX509Certificate* cert = iParser.UserCertificates().At( i );
@@ -343,7 +330,6 @@
 //
 void CCertSaverModel::CreateKeyLabelL( TDes& aLabel )
     {
-
     TTime time;
     time.UniversalTime();
     TBuf<KPrivaKeyLabelLength> dateBuf;
@@ -363,7 +349,6 @@
 //
 void CCertSaverModel::SavePrivateKeyL()
     {
-
     if ( iParser.Keys().Count() <= 0 )
         {
         return;
@@ -412,7 +397,6 @@
     TAlgorithmId aAlgorithm )
     {
 
-
     TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone;
     TKeyUsageX509 x509Usage = EX509UsageNone;
 
@@ -501,13 +485,16 @@
 //
 void CCertSaverModel::CheckFSSpaceL( const TDesC8& aDataToSave )
     {
-
     if (SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aDataToSave.Size() ))
         {
-        ShowInformationNoteL(R_CERTSAVER_MEMORY);
+        HBufC* p = StringLoader::LoadLC( R_CERTSAVER_MEMORY );
+        CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue );
+        note->ExecuteLD( p->Des() );
+        CleanupStack::PopAndDestroy( p );
         User::Leave( KErrExitApp );
         }
     }
+
 // ----------------------------------------------------------
 // CCertSaverModel::SaveCertL()
 // Saves certificate
@@ -515,44 +502,48 @@
 //
 void CCertSaverModel::SaveCertL()
   {
-
     if ( !CertificateOkL() )
         {
         User::Leave( KErrCancel );
         }
- 
+
     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
     TPtr msgPtr = message->Des();
     ConstructMessageL( msgPtr );
-    CHbDeviceMessageBoxSymbian::TButtonId selection = 
-        CHbDeviceMessageBoxSymbian::QuestionL(msgPtr, KNullDesC, KNullDesC);
-    TBool doSave= (selection == CHbDeviceMessageBoxSymbian::EAcceptButton);
-    CleanupStack::PopAndDestroy(message);
-/*
+    CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message );
+    CleanupStack::PopAndDestroy( message );
+    CleanupStack::PushL( dlg );
+
+
+    dlg->PrepareLC( R_MESSAGE_QUERY_DOSAVE );
+
+    HBufC* header = StringLoader::LoadLC( R_CERTSAVER_DETAILS_HEADING );
+    dlg->QueryHeading()->SetTextL( header->Des() );
+    CleanupStack::PopAndDestroy( header );
+    CleanupStack::Pop( dlg );
+    TBool doSave = dlg->RunLD();
+
     if ( doSave && iCertOwnerType == ECACertificate )
         {
         // warn user about security risk
-        HBufC* stringHolder = StringLoader::LoadLC( R_CERTSAVER_WARNING_NOTE );
-        CHbDeviceMessageBoxSymbian::TButtonId selection = 
-            CHbDeviceMessageBoxSymbian::QuestionL(stringHolder->Des(),KNullDesC, KNullDesC);
-        CleanupStack::PopAndDestroy(stringHolder);
-	    doSave=(selection == CHbDeviceMessageBoxSymbian::EAcceptButton);
+        CAknQueryDialog* warningDialog = CAknQueryDialog::NewL();
+        doSave = warningDialog->ExecuteLD( R_CERTSAVER_WARNING_NOTE );
         }
-*/
+
     if ( doSave )
         {
-        //Check that there still is enough space to store the certificate.
+        //Check that there still is enough space to store the
+        //certificate.
         CheckFSSpaceL( iNewCert->Encoding() );
         DoSaveCertL();
         }
     else
         {
-        ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED);
+        ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
         User::Leave( KErrCancel );
         }
   }
 
-
 // ----------------------------------------------------------
 // CCertSaverModel::InitCertStoreL()
 //
@@ -560,13 +551,12 @@
 //
 void CCertSaverModel::InitCertStoreL()
     {
-
     if ( !iUnifiedCertStore )
         {
         TRAPD( status, iUnifiedCertStore = CUnifiedCertStore::NewL( iFs, ETrue ) );
         if ( status != KErrNone )
             {
-            ShowInformationNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
+            ShowErrorNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
             User::Leave( KErrExitApp );
             }
         // initialize unified cert store
@@ -586,7 +576,6 @@
 //
 void CCertSaverModel::DoSaveCertL()
     {
-
     TInt status = KErrNone;
     CCertAttributeFilter* filter = NULL;
     TCertificateFormat certFormat = EX509Certificate;
@@ -689,8 +678,7 @@
 
             MCTToken& token = writableCertStore.Token();
             TUid tokenuid = token.Handle().iTokenTypeUid;
-            if ( ( tokenuid == KTrustedServerTokenUid ) && 
-                 ( iCertOwnerType == EPeerCertificate ) ||
+            if ( ( tokenuid == KTrustedServerTokenUid ) && ( iCertOwnerType == EPeerCertificate ) ||
                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == ECACertificate ) ||
                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == EUserCertificate ) )
                 {
@@ -702,7 +690,7 @@
         if ( certstoreIndex < 0 )
             {
             // Couldn't find certificate storage
-            ShowInformationNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
+            ShowErrorNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
             User::Leave( KErrExitApp );
             }
 
@@ -741,7 +729,7 @@
         {
         // If there is none WritableCertStore,
         // then at least cacerts.dat is corrupted.
-        ShowInformationNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
+        ShowErrorNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
         User::Leave( KErrExitApp );
         }
 
@@ -798,7 +786,6 @@
 //
 TInt CCertSaverModel::QueryLabelL( TCertLabel& aLabel, CUnifiedCertStore& aStore )
     {
-
     CCertAttributeFilter* filter = NULL;
     TInt status = KErrNone;
     RMPointerArray<CCTCertInfo> entries;
@@ -806,21 +793,11 @@
 
     while ( loop )
         {
-    HBufC* labelprompt =  CEikonEnv::Static()->AllocReadResourceLC( R_CERTSAVER_ENTER_LABEL );
-    CSecQueryUi* SecQueryUi = CSecQueryUi::NewL();                                       
-    TInt queryAccepted = SecQueryUi->SecQueryDialog(labelprompt->Des(), aLabel,
-                                                1,KMaxCertLabelLength,          
-                                                ESecUiAlphaSupported |          
-                                                ESecUiCancelSupported |         
-                                                ESecUiEmergencyNotSupported);   
-    CleanupStack::PopAndDestroy( labelprompt );
-    delete SecQueryUi;  
-    SecQueryUi=NULL;
-
-      if ( queryAccepted!=KErrNone )
+        CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL( aLabel );
+      if ( !dialog->ExecuteLD( R_CERTSAVER_LABEL_QUERY ) )
             {
             // cancel
-            ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED);
+            ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
             return KErrCancel;
             }
         // Create filter to confirm that label doesn't already exist.
@@ -863,32 +840,31 @@
 //
 void CCertSaverModel::HandleSaveErrorL( TInt aStatus ) const
     {
-
     switch ( aStatus )
         {
         case KErrNone:
             {
-            ShowInformationNoteL(R_CERTSAVER_ERROR_SAVEOK);
+            ShowConfirmationNoteL( R_CERTSAVER_ERROR_SAVEOK );
             break;
             }
         case KErrNotSupported:
             {
-            ShowInformationNoteL(R_CERTSAVER_ERROR_UNSUPPORTED_CERT);
+            ShowErrorNoteL( R_CERTSAVER_ERROR_UNSUPPORTED_CERT );
             break;
             }
         case KErrBadName:
             {
-            ShowInformationNoteL(R_CERTSAVER_ERROR_LABEL_ALREADY_EXISTS);
+            ShowErrorNoteL( R_CERTSAVER_ERROR_LABEL_ALREADY_EXISTS );
             break;
             }
         case KErrAlreadyExists:
             {
-            ShowInformationNoteL(R_CERTSAVER_ERROR_ALREADY_EXISTS);
+            ShowErrorNoteL( R_CERTSAVER_ERROR_ALREADY_EXISTS );
             break;
             }
         case KErrArgument:
             {
-            ShowInformationNoteL(R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED);
+            ShowErrorNoteL( R_CERTSAVER_ERROR_CACERTS_DB_CORRUPTED );
             break;
             }
         default:
@@ -908,7 +884,6 @@
 void CCertSaverModel::AddToMessageWithStringL(
     TDes& aMessage, TInt aStringResID, const TDesC& aString ) const
     {
-
     HBufC* promptPtr = NULL;
     promptPtr = StringLoader::LoadL( aStringResID, aString );
     CleanupStack::PushL( promptPtr );
@@ -929,7 +904,6 @@
     TInt aStringResID,
     TInt aInt ) const
     {
-
     HBufC* promptPtr = NULL;
     promptPtr = StringLoader::LoadL( aStringResID, aInt );
     CleanupStack::PushL( promptPtr );
@@ -948,7 +922,6 @@
 //
 void CCertSaverModel::AddToMessageL( TDes& aMessage, TInt aStringResID ) const
     {
-
     HBufC* promptPtr = NULL;
     promptPtr = StringLoader::LoadL( aStringResID );
     CleanupStack::PushL( promptPtr );
@@ -967,7 +940,6 @@
 //
 void CCertSaverModel::ConstructMessageL( TDes& aMessage ) const
     {
-
     HBufC16* issuerName = NULL;
     HBufC16* subjectName = NULL;
 
@@ -1024,7 +996,6 @@
 //
 void CCertSaverModel::AddKeyUsageL( TDes& aMessage, const CX509Certificate& aCert ) const
     {
-
     TKeyUsageX509 x509Usage = EX509UsageNone;
     TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone;
     const CX509CertExtension* ext = aCert.Extension( KKeyUsage );
@@ -1108,7 +1079,6 @@
 void CCertSaverModel::AddValidityPeriodL(
     TDes& aMessage, const CX509Certificate& aCert ) const
     {
-
     // Hometime's offset to UTC
     TLocale locale;
     TTimeIntervalSeconds offSet = locale.UniversalTimeOffset();
@@ -1138,7 +1108,7 @@
     // format the date to user readable format. The format is locale dependent
     finishValue.FormatL( finishString, *dateFormatString );
     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString );
-    CleanupStack::PopAndDestroy(dateFormatString); // dateFormatString
+    CleanupStack::PopAndDestroy(); // dateFormatString
     aMessage.Append( finishString );
     AddNewlinesToMessage( aMessage );
     }
@@ -1150,7 +1120,6 @@
 //
 void CCertSaverModel::AddNewlinesToMessage( TDes& aMessage ) const
     {
-
     aMessage.Append( KDoubleEnter );
     }
 
@@ -1161,7 +1130,6 @@
 //
 TBool CCertSaverModel::CertificateSupported() const
     {
-
     if ( iCertFormat == EX509Certificate &&
        ( iCertOwnerType == ECACertificate ||
          iCertOwnerType == EPeerCertificate ||
@@ -1183,20 +1151,19 @@
 //
 TBool CCertSaverModel::CertificateOkL() const
     {
-
-    if ( !CertificateSupported() ) 
+    if ( !CertificateSupported() )
         {
-        ShowInformationNoteL(R_CERTSAVER_ERROR_UNSUPPORTED_CERT);
+        ShowErrorNoteL( R_CERTSAVER_ERROR_UNSUPPORTED_CERT );
         return EFalse;
         }
     if ( CertNotValidAnymore() )
         {
-        ShowInformationNoteL(R_CERTSAVER_ERROR_CERT_NOT_VALID);
+        ShowErrorNoteL( R_CERTSAVER_ERROR_CERT_NOT_VALID );
         return ETrue;
         }
     else if ( CertNotValidYet() )
         {
-        ShowInformationNoteL(R_CERTSAVER_ERROR_CERT_NOT_VALID_YET);
+        ShowErrorNoteL( R_CERTSAVER_ERROR_CERT_NOT_VALID_YET );
         }
     return ETrue;
     }
@@ -1208,7 +1175,6 @@
 //
 TBool CCertSaverModel::CertNotValidAnymore() const
     {
-
     TTime homeTime;
     homeTime.HomeTime();
     if ( iNewCert->ValidityPeriod().Finish() < homeTime )
@@ -1225,7 +1191,6 @@
 //
 TBool CCertSaverModel::CertNotValidYet() const
     {
-
     TTime homeTime;
     homeTime.HomeTime();
     if ( iNewCert->ValidityPeriod().Start() > homeTime )
@@ -1242,15 +1207,35 @@
 //
 void CCertSaverModel::ShowInformationNoteL( TInt aResourceID ) const
     {
-
+    HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
+    CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
+    note->ExecuteLD( buffer->Des() );
+    CleanupStack::PopAndDestroy( buffer );
+    }
+// ----------------------------------------------------------
+// CCertSaverModel::ShowConfirmationNoteL() const
+// Creates and shows a confirmation note.
+// ----------------------------------------------------------
+//
+void CCertSaverModel::ShowConfirmationNoteL( TInt aResourceID ) const
+    {
     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
-    CHbDeviceMessageBoxSymbian* iMessageBox = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EInformation);
-    CleanupStack::PushL(iMessageBox);                                                                                    
-    iMessageBox->SetTextL(buffer->Des());                                                                                
-    iMessageBox->SetTimeout(6000);                                                                                      
-    iMessageBox->ExecL();                                                                                                
-    CleanupStack::PopAndDestroy(iMessageBox);                                                                            
-    CleanupStack::PopAndDestroy( buffer );      
+    CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue );
+    note->ExecuteLD( buffer->Des() );
+    CleanupStack::PopAndDestroy( buffer );
+    }
+
+// ----------------------------------------------------------
+// CCertSaverModel::ShowErrorNoteL() const
+// Creates and shows an error note.
+// ----------------------------------------------------------
+//
+void CCertSaverModel::ShowErrorNoteL( TInt aResourceID ) const
+    {
+    HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
+    CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue );
+    note->ExecuteLD(buffer->Des());
+    CleanupStack::PopAndDestroy( buffer );
     }
 
 // ----------------------------------------------------------
@@ -1262,7 +1247,6 @@
 //
 TPtrC CCertSaverModel::TrimCertificateFields( TPtrC aField ) const
     {
-
     TPtrC cutField = CutCertificateField( aField );
     // Find one semicolon at a time and crop the
     // helpField from the left to search for the next semicolon
@@ -1314,7 +1298,6 @@
 //
 TPtrC CCertSaverModel::CutCertificateField( TPtrC aField ) const
     {
-
     TInt fieldLength = aField.Length();
     if ( fieldLength >= KMaxLengthTextCertIdentifierVisible )
         {
@@ -1331,8 +1314,10 @@
 //
 TInt CCertSaverModel::QueryTrusterUidsL( RArray<TUid>& aUids )
     {
-
     TInt ret = KErrCancel;
+    CArrayFixFlat<TInt>* selectionArray =
+        new (ELeave)  CArrayFixFlat<TInt>( KTrusterArrayInitSize );
+    CleanupStack::PushL( selectionArray );
     CDesCArray* itemsArray = new (ELeave) CDesCArrayFlat( KTrusterArrayInitSize );
     CleanupStack::PushL( itemsArray );
 
@@ -1345,52 +1330,28 @@
     CleanupClosePushL( appsInItemArray );
     UpdateTrustListboxItemL( apps, appsInItemArray, *itemsArray );
 
-    HBufC* title = CEikonEnv::Static()->AllocReadResourceLC( R_CERTSAVER_SELECT_TRUSTED_APPS);
-
-    RBuf rBuf;     // buffer for items with big enough space
-    rBuf.CreateL(KMaxLengthTextMeassageBody);
-    CleanupClosePushL(rBuf);
-    for(TInt i = 0; i<itemsArray->Count(); i++) 
-        rBuf.Append( (*itemsArray)[i] ); 
-
-    CSecQueryUi* SecQueryUi = CSecQueryUi::NewL();     
-    TInt saved = SecQueryUi->SecQueryDialog(*title, rBuf,1,KTokenLength,              
-                                             ESecUiAlphaSupported | ESecUiCancelSupported |
-                                             ESecUiBasicTypeMultiCheck |
-                                             ESecUiEmergencyNotSupported);   
-    delete SecQueryUi;
-    SecQueryUi=NULL;
-
-    if (saved==KErrNone)
+    CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( selectionArray );
+    CleanupStack::PushL( dlg );
+    dlg->PrepareLC( R_CERTSAVER_TRUST_SETTINGS_QUERY );
+    dlg->SetItemTextArray( itemsArray );
+    dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
+    if ( dlg->RunLD() )
         {
-        TLex16 lex(rBuf);
-        TChar ch;                                        
-        TBuf16<KTokenLength> token;          
-        TInt  val;
-        while((ch = lex.Get()) != 0 ){                   
-           while ((ch = lex.Peek()) != '|' && ch!=0) lex.Inc();
-           token.Copy(lex.MarkedToken());                
-           TLex lexc(token);
-           if(lexc.Val(val)!=KErrNone) val=0;
-           if(val<=appsInItemArray.Count()-1)
-               aUids.Append( appsInItemArray[ val ].Id() );
-           lex.Inc();                                    
-           lex.Mark();                                   
-         }  
+        aUids.Reset();
+        for ( TInt i = 0; i < selectionArray->Count(); ++i )
+            {
+            TInt ii = (*selectionArray)[ i ];
+            aUids.Append( appsInItemArray[ ii ].Id() );
+            }
         ret = KErrNone;
         }
     else
         {
-        ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED);
+        ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
         ret = KErrCancel;
         }
-
-    rBuf.Close();
-    CleanupStack::PopAndDestroy(&rBuf);
-    CleanupStack::PopAndDestroy(title);
-    CleanupStack::PopAndDestroy(&appsInItemArray);
-    CleanupStack::PopAndDestroy(appInfoManager);
-    CleanupStack::PopAndDestroy(itemsArray);
+    CleanupStack::Pop( dlg );
+    CleanupStack::PopAndDestroy( 4, selectionArray );
     return ret;
     }
 
@@ -1401,7 +1362,6 @@
 //
 TInt CCertSaverModel::QueryTrustedSiteL()
     {
-
     TInt ret = KErrCancel;
     HBufC* label = NULL;
     HBufC* secondaryName = NULL;
@@ -1413,19 +1373,27 @@
     delete secondaryName;
     secondaryName = NULL;
     labelBuf = label->Des().Left( CERTSAVER_MAX_LABEL_LEN );
+
+
     HBufC* prompt = StringLoader::LoadLC( R_CERTSAVER_TRUSTEDSITE_WARNING, labelBuf );
-    CHbDeviceMessageBoxSymbian::TButtonId selection =
-        CHbDeviceMessageBoxSymbian::QuestionL(prompt->Des(), KNullDesC, KNullDesC);
-    if ( selection == CHbDeviceMessageBoxSymbian::EAcceptButton)
+
+    CAknMessageQueryDialog* note = CAknMessageQueryDialog::NewL( *prompt );
+
+    note->PrepareLC( R_CERTSAVER_TRUSTED_SITE_QUERY );
+    note->SetPromptL( *prompt );
+
+    if ( note->RunLD() )
         {
         ret = KErrNone;
         }
     else
         {
-        ShowInformationNoteL(R_CERTSAVER_CERT_DISCARDED);
+        ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
         ret = KErrCancel;
         }
+
     CleanupStack::PopAndDestroy( prompt );
+
     CleanupStack::PopAndDestroy( label );
     return ret;
     }
@@ -1440,7 +1408,6 @@
     RArray<TCertificateAppInfo>& aAppsInItemArray,
     CDesCArray& aItemsArray ) const
   {
-
     for ( TInt i = 0; i < aApps.Count(); i++ )
         {
         TCertificateAppInfo appInfo = aApps[ i ];
@@ -1503,7 +1470,6 @@
 //
 void CCertSaverModel::DivideToBlocks( const TDesC8& aInput, TDes& aOutput ) const
     {
-
     _LIT( KBlockSeparator, " " );
     const TInt KBlockLength = 2;
     TInt blockIndex = 0;
@@ -1526,37 +1492,25 @@
 //
 void CCertSaverModel::SavePKCS12L()
     {
-
     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
     TPtr msgPtr = message->Des();
     ConstructPKCS12QueryMsgL(msgPtr, iParser.Keys().Count(),
                             iParser.UserCertificates().Count(),
                             iParser.CACertificates().Count() );
-
-    //TODO: Should be in loc file but hardcoded now
-    _LIT(KCheckBoxCaption,"Protect with Password|1");
-    TBuf<KMaxLengthTextCheckBoxData> CheckeBoxData(KCheckBoxCaption);
-
-    CSecQueryUi* SecQueryUi = CSecQueryUi::NewL();    
-    TInt save = SecQueryUi->SecQueryDialog(*message, CheckeBoxData,1,1,
-                                            ESecUiAlphaSupported | ESecUiCancelSupported |
-                                            ESecUiBasicTypeCheck | ESecUiEmergencyNotSupported);
-    CleanupStack::Pop(message);
+    TBool save = DoMessageQueryL(
+        R_MESSAGE_QUERY_DOSAVE, R_CERTSAVER_HEADER_PKCS12_FILE_CONTAINS,
+        *message );
+    CleanupStack::PopAndDestroy( message );
     message = NULL;
-    delete SecQueryUi;
-    SecQueryUi=NULL;
-
-    if ( save!=KErrNone )
+    if ( !save )
         {
         ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED );
         User::Leave( KErrExitApp );
         }
     TInt status = KErrNone;
     // save private keys
-   if(CheckeBoxData.Compare(_L("1"))==0)
-   {
-       TRAP( status, SavePrivateKeyL() );
-   }
+    TRAP( status, SavePrivateKeyL() );
+
     // save user certificates if private key was saved.
     if ( ( iSavedKeysCount > 0 || iKeyAlreadyExists ) && iParser.UserCertificates().Count() > 0 )
         {
@@ -1589,28 +1543,42 @@
                 }
             }
         }
-/*
     if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0
         || iSavedUserCertsCount != 0 )
         {
-// show how many have been saved
-        HBufC* p = StringLoader::LoadLC( R_CERTSAVER_HEADER_SAVED );             
-        message = HBufC::NewLC( KMaxLengthTextMeassageBody );                    
-        message->Des().Append(p->Des());                                         
-        TPtr msgPtr2 = message->Des();                                           
-        ConstructPKCS12QueryMsgL(                                                
+        message = HBufC::NewLC( KMaxLengthTextMeassageBody );
+        TPtr msgPtr2 = message->Des();
+        ConstructPKCS12QueryMsgL(
             msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount );
-        CHbDeviceMessageBoxSymbian::InformationL(message->Des());                
-        CleanupStack::PopAndDestroy( message );                                  
-        CleanupStack::PopAndDestroy( p );                                        
+        DoMessageQueryL(
+            R_MESSAGE_QUERY_SAVED, R_CERTSAVER_HEADER_SAVED, *message );
+        CleanupStack::PopAndDestroy( message );
         }
     else
         {
-        // the contents could not be saved is dropped
         ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED );
-        CleanupStack::PopAndDestroy( message );
         }
-*/
+    }
+
+// ----------------------------------------------------------
+// CCertSaverModel::DoMessageQuery()
+// Displays message query dialog for user.
+// ----------------------------------------------------------
+//
+TBool CCertSaverModel::DoMessageQueryL(
+    TInt aDialogResId,
+    TInt aHeadingResId,
+    TDesC& aMessage )
+    {
+    CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( aMessage );
+    CleanupStack::PushL( dlg );
+    dlg->PrepareLC( aDialogResId );
+
+    HBufC* header = StringLoader::LoadLC( aHeadingResId );
+    dlg->QueryHeading()->SetTextL( header->Des() );
+    CleanupStack::PopAndDestroy( header );
+    CleanupStack::Pop( dlg );
+    return dlg->RunLD();
     }
 
 // ----------------------------------------------------------
@@ -1624,7 +1592,6 @@
     TInt aUserCerts,
     TInt aCACerts ) const
     {
-
     if ( aPrivateKeys > 0 )
         {
         if ( aPrivateKeys == 1 )