pkiutilities/CertSaver/src/CertSaverModel.cpp
changeset 30 cc1cea6aabaf
parent 0 164170e6151a
child 33 3aa774c655ac
equal deleted inserted replaced
26:aad866c37519 30:cc1cea6aabaf
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <aknnotewrappers.h>        // Note dialogs
    20 #include <aknnotewrappers.h>        // Note dialogs
    21 #include <aknmessagequerydialog.h>  // For CAknMessageQueryDialog
    21 
       
    22 
       
    23 
    22 #include <StringLoader.h>           // For loading resource strings
    24 #include <StringLoader.h>           // For loading resource strings
    23 #include <unifiedcertstore.h>       // For saving the certificates
    25 #include <unifiedcertstore.h>       // For saving the certificates
    24 #include <mctwritablecertstore.h>   // For saving the certificates
    26 #include <mctwritablecertstore.h>   // For saving the certificates
    25 #include <sysutil.h>                // For FFSSpaceBelowCriticalLevelL(..)
    27 #include <sysutil.h>                // For FFSSpaceBelowCriticalLevelL(..)
    26 #include <X509CertNameParser.h>     // For default label
    28 #include <X509CertNameParser.h>     // For default label
    42 #include "CertSaverAppUi.h"
    44 #include "CertSaverAppUi.h"
    43 #include "CertSaverSyncWrapper.h"
    45 #include "CertSaverSyncWrapper.h"
    44 #include "certsaver.hrh"
    46 #include "certsaver.hrh"
    45 #include "securityuisvariant.hrh"
    47 #include "securityuisvariant.hrh"
    46 
    48 
       
    49 #include <hbdevicemessageboxsymbian.h>
       
    50 #include <hbdevicenotificationdialogsymbian.h>
       
    51 #include <hbsymbianvariant.h>
       
    52 
       
    53 #include "SecQueryUi.h"                   // needed for label dialog
       
    54 
    47 // CONSTANTS
    55 // CONSTANTS
       
    56 
    48 const TInt32 KWTLSTrusterUID( 268479059 );
    57 const TInt32 KWTLSTrusterUID( 268479059 );
    49 const TInt32 KInternetTrusterUID( 268441661 );
    58 const TInt32 KInternetTrusterUID( 268441661 );
    50 const TInt32 KApplicationControllerTrusterUID( 268452523 );
    59 const TInt32 KApplicationControllerTrusterUID( 268452523 );
    51 const TInt32 KJavaInstallTrusterUID( 270506792 );
    60 const TInt32 KJavaInstallTrusterUID( 270506792 );
    52 const TInt32 KOCSPTrusterUID( 268478646 );
    61 const TInt32 KOCSPTrusterUID( 268478646 );
    54 
    63 
    55 const TInt KTrusterArrayInitSize( 2 );
    64 const TInt KTrusterArrayInitSize( 2 );
    56 
    65 
    57 const TInt KMaxLengthTextMeassageBody( 5000 );
    66 const TInt KMaxLengthTextMeassageBody( 5000 );
    58 const TInt KMaxLengthTextDateString( 11 );    // "dd/mm/yyyy0"
    67 const TInt KMaxLengthTextDateString( 11 );    // "dd/mm/yyyy0"
       
    68 const TInt KMaxLengthTextCheckBoxData( 255 );    // "dd/mm/yyyy0"
    59 
    69 
    60 //Issuer and Owner max visible length
    70 //Issuer and Owner max visible length
    61 const TInt KMaxLengthTextCertIdentifierVisible( 1000 );
    71 const TInt KMaxLengthTextCertIdentifierVisible( 1000 );
    62 const TInt KAttempts( 3 );
    72 const TInt KAttempts( 3 );
    63 
    73 
    64 const TInt KFingerprintLength( 50 );
    74 const TInt KFingerprintLength( 50 );
       
    75 const TInt KTokenLength( 32 );
    65 
    76 
    66 _LIT( KCertSaverListBoxItemPrefix, "1\t" );
    77 _LIT( KCertSaverListBoxItemPrefix, "1\t" );
    67 const TInt KItemBufLen = 2 + KMaxName;
    78 const TInt KItemBufLen = 2 + KMaxName;
    68 
    79 
    69 _LIT( KPrivateKeyLabel, "PrivateKey " );
    80 _LIT( KPrivateKeyLabel, "PrivateKey " );
   114 void CCertSaverModel::SaveCertificateL(
   125 void CCertSaverModel::SaveCertificateL(
   115             const CX509Certificate& aCertificate,
   126             const CX509Certificate& aCertificate,
   116             const TCertificateOwnerType& aOwnerType,
   127             const TCertificateOwnerType& aOwnerType,
   117             const TCertificateFormat& aCertFormat )
   128             const TCertificateFormat& aCertFormat )
   118     {
   129     {
       
   130 
   119     iCertOwnerType = aOwnerType;
   131     iCertOwnerType = aOwnerType;
   120     iCertFormat = aCertFormat;
   132     iCertFormat = aCertFormat;
   121     iNewCert = &aCertificate;
   133     iNewCert = &aCertificate;
   122 
   134 
   123     if ( aOwnerType == EPeerCertificate )
   135     if ( aOwnerType == EPeerCertificate )
   137 //
   149 //
   138 // ----------------------------------------------------------
   150 // ----------------------------------------------------------
   139 //
   151 //
   140 void CCertSaverModel::DoSavePrivateKeyL( const TDesC8& aKey )
   152 void CCertSaverModel::DoSavePrivateKeyL( const TDesC8& aKey )
   141     {
   153     {
       
   154 
   142     CheckFSSpaceL( aKey );
   155     CheckFSSpaceL( aKey );
   143 
   156 
   144     TKeyIdentifier keyIdentifier;
   157     TKeyIdentifier keyIdentifier;
   145     CDecPKCS8Data* pkcs8Data = TASN1DecPKCS8::DecodeDERL( aKey );
   158     CDecPKCS8Data* pkcs8Data = TASN1DecPKCS8::DecodeDERL( aKey );
   146     CleanupStack::PushL( pkcs8Data );
   159     CleanupStack::PushL( pkcs8Data );
   156     TBuf<KPrivaKeyLabelLength> keyLabel( KPrivateKeyLabel );
   169     TBuf<KPrivaKeyLabelLength> keyLabel( KPrivateKeyLabel );
   157     TKeyUsagePKCS15 keyUsage = KeyUsageL( keyIdentifier, pkcs8Data->Algorithm() );
   170     TKeyUsagePKCS15 keyUsage = KeyUsageL( keyIdentifier, pkcs8Data->Algorithm() );
   158     CleanupStack::PopAndDestroy( pkcs8Data );
   171     CleanupStack::PopAndDestroy( pkcs8Data );
   159     if (KeyAlreadyExistsL( startDate, endDate, keyIdentifier, keyUsage) )
   172     if (KeyAlreadyExistsL( startDate, endDate, keyIdentifier, keyUsage) )
   160         {
   173         {
   161         User::Leave( KErrNone );
   174         // used to leave with error none
       
   175         return;
   162         }
   176         }
   163 
   177 
   164     TInt accessType( 0 );
   178     TInt accessType( 0 );
   165 
   179 
   166     accessType |= CCTKeyInfo::EExtractable;
   180     accessType |= CCTKeyInfo::EExtractable;
   252     TTime& aStartDate,
   266     TTime& aStartDate,
   253     TTime& aEndDate,
   267     TTime& aEndDate,
   254     const TKeyIdentifier& aKeyIdentifier,
   268     const TKeyIdentifier& aKeyIdentifier,
   255     TKeyUsagePKCS15& aKeyUsage )
   269     TKeyUsagePKCS15& aKeyUsage )
   256     {
   270     {
       
   271 
   257     TBool ret = EFalse;
   272     TBool ret = EFalse;
   258     TCTKeyAttributeFilter keyFilter;
   273     TCTKeyAttributeFilter keyFilter;
   259     keyFilter.iKeyAlgorithm = CKeyInfoBase::EInvalidAlgorithm;
   274     keyFilter.iKeyAlgorithm = CKeyInfoBase::EInvalidAlgorithm;
   260     keyFilter.iKeyId = aKeyIdentifier;
   275     keyFilter.iKeyId = aKeyIdentifier;
   261     keyFilter.iPolicyFilter = TCTKeyAttributeFilter::EManageableKeys;
   276     keyFilter.iPolicyFilter = TCTKeyAttributeFilter::EManageableKeys;
   302     TTime& aStartDate,
   317     TTime& aStartDate,
   303     TTime& aEndDate,
   318     TTime& aEndDate,
   304     const TKeyIdentifier& aKeyIdentifier )
   319     const TKeyIdentifier& aKeyIdentifier )
   305     {
   320     {
   306 
   321 
       
   322 
   307     for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
   323     for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
   308         {
   324         {
   309         const CX509Certificate* cert = iParser.UserCertificates().At( i );
   325         const CX509Certificate* cert = iParser.UserCertificates().At( i );
   310         if ( cert->KeyIdentifierL() == aKeyIdentifier )
   326         if ( cert->KeyIdentifierL() == aKeyIdentifier )
   311             {
   327             {
   328 //
   344 //
   329 // ----------------------------------------------------------
   345 // ----------------------------------------------------------
   330 //
   346 //
   331 void CCertSaverModel::CreateKeyLabelL( TDes& aLabel )
   347 void CCertSaverModel::CreateKeyLabelL( TDes& aLabel )
   332     {
   348     {
       
   349 
   333     TTime time;
   350     TTime time;
   334     time.UniversalTime();
   351     time.UniversalTime();
   335     TBuf<KPrivaKeyLabelLength> dateBuf;
   352     TBuf<KPrivaKeyLabelLength> dateBuf;
   336     time.FormatL( dateBuf, KDateString );
   353     time.FormatL( dateBuf, KDateString );
   337     aLabel.Append( dateBuf );
   354     aLabel.Append( dateBuf );
   347 //
   364 //
   348 // ----------------------------------------------------------
   365 // ----------------------------------------------------------
   349 //
   366 //
   350 void CCertSaverModel::SavePrivateKeyL()
   367 void CCertSaverModel::SavePrivateKeyL()
   351     {
   368     {
       
   369 
   352     if ( iParser.Keys().Count() <= 0 )
   370     if ( iParser.Keys().Count() <= 0 )
   353         {
   371         {
   354         return;
   372         return;
   355         }
   373         }
   356     if ( NULL == iWrapper )
   374     if ( NULL == iWrapper )
   394 //
   412 //
   395 TKeyUsagePKCS15 CCertSaverModel::KeyUsageL(
   413 TKeyUsagePKCS15 CCertSaverModel::KeyUsageL(
   396     const TKeyIdentifier& aKeyIdentifier,
   414     const TKeyIdentifier& aKeyIdentifier,
   397     TAlgorithmId aAlgorithm )
   415     TAlgorithmId aAlgorithm )
   398     {
   416     {
       
   417 
   399 
   418 
   400     TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone;
   419     TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone;
   401     TKeyUsageX509 x509Usage = EX509UsageNone;
   420     TKeyUsageX509 x509Usage = EX509UsageNone;
   402 
   421 
   403     for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
   422     for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
   483 //    const TDesC8& aDataToSave)
   502 //    const TDesC8& aDataToSave)
   484 // ----------------------------------------------------------
   503 // ----------------------------------------------------------
   485 //
   504 //
   486 void CCertSaverModel::CheckFSSpaceL( const TDesC8& aDataToSave )
   505 void CCertSaverModel::CheckFSSpaceL( const TDesC8& aDataToSave )
   487     {
   506     {
       
   507 
   488     if (SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aDataToSave.Size() ))
   508     if (SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, aDataToSave.Size() ))
   489         {
   509         {
   490         HBufC* p = StringLoader::LoadLC( R_CERTSAVER_MEMORY );
   510         HBufC* p = StringLoader::LoadLC( R_CERTSAVER_MEMORY );
   491         CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue );
   511         CHbDeviceMessageBoxSymbian::WarningL(p->Des()); 
   492         note->ExecuteLD( p->Des() );
       
   493         CleanupStack::PopAndDestroy( p );
   512         CleanupStack::PopAndDestroy( p );
   494         User::Leave( KErrExitApp );
   513         User::Leave( KErrExitApp );
   495         }
   514         }
   496     }
   515     }
   497 
       
   498 // ----------------------------------------------------------
   516 // ----------------------------------------------------------
   499 // CCertSaverModel::SaveCertL()
   517 // CCertSaverModel::SaveCertL()
   500 // Saves certificate
   518 // Saves certificate
   501 // ----------------------------------------------------------
   519 // ----------------------------------------------------------
   502 //
   520 //
   503 void CCertSaverModel::SaveCertL()
   521 void CCertSaverModel::SaveCertL()
   504   {
   522   {
       
   523 
   505     if ( !CertificateOkL() )
   524     if ( !CertificateOkL() )
   506         {
   525         {
   507         User::Leave( KErrCancel );
   526         User::Leave( KErrCancel );
   508         }
   527         }
   509 
   528  
   510     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
   529     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
   511     TPtr msgPtr = message->Des();
   530     TPtr msgPtr = message->Des();
   512     ConstructMessageL( msgPtr );
   531     ConstructMessageL( msgPtr );
   513     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message );
   532     CHbDeviceMessageBoxSymbian::TButtonId selection = 
   514     CleanupStack::PopAndDestroy( message );
   533         CHbDeviceMessageBoxSymbian::QuestionL(msgPtr, KNullDesC, KNullDesC);
   515     CleanupStack::PushL( dlg );
   534     TBool doSave= (selection == CHbDeviceMessageBoxSymbian::EAcceptButton);
   516 
   535     CleanupStack::PopAndDestroy(message);
   517 
       
   518     dlg->PrepareLC( R_MESSAGE_QUERY_DOSAVE );
       
   519 
       
   520     HBufC* header = StringLoader::LoadLC( R_CERTSAVER_DETAILS_HEADING );
       
   521     dlg->QueryHeading()->SetTextL( header->Des() );
       
   522     CleanupStack::PopAndDestroy( header );
       
   523     CleanupStack::Pop( dlg );
       
   524     TBool doSave = dlg->RunLD();
       
   525 
   536 
   526     if ( doSave && iCertOwnerType == ECACertificate )
   537     if ( doSave && iCertOwnerType == ECACertificate )
   527         {
   538         {
   528         // warn user about security risk
   539         // warn user about security risk
   529         CAknQueryDialog* warningDialog = CAknQueryDialog::NewL();
   540         HBufC* stringHolder = StringLoader::LoadLC( R_CERTSAVER_WARNING_NOTE );
   530         doSave = warningDialog->ExecuteLD( R_CERTSAVER_WARNING_NOTE );
   541         CHbDeviceMessageBoxSymbian::TButtonId selection = 
       
   542             CHbDeviceMessageBoxSymbian::QuestionL(stringHolder->Des(),KNullDesC, KNullDesC);
       
   543         CleanupStack::PopAndDestroy(stringHolder);
       
   544 	    doSave=(selection == CHbDeviceMessageBoxSymbian::EAcceptButton);
   531         }
   545         }
   532 
   546 
   533     if ( doSave )
   547     if ( doSave )
   534         {
   548         {
   535         //Check that there still is enough space to store the
   549         //Check that there still is enough space to store the certificate.
   536         //certificate.
       
   537         CheckFSSpaceL( iNewCert->Encoding() );
   550         CheckFSSpaceL( iNewCert->Encoding() );
   538         DoSaveCertL();
   551         DoSaveCertL();
   539         }
   552         }
   540     else
   553     else
   541         {
   554         {
   542         ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
   555         ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
   543         User::Leave( KErrCancel );
   556         User::Leave( KErrCancel );
   544         }
   557         }
   545   }
   558   }
   546 
   559 
       
   560 
   547 // ----------------------------------------------------------
   561 // ----------------------------------------------------------
   548 // CCertSaverModel::InitCertStoreL()
   562 // CCertSaverModel::InitCertStoreL()
   549 //
   563 //
   550 // ----------------------------------------------------------
   564 // ----------------------------------------------------------
   551 //
   565 //
   552 void CCertSaverModel::InitCertStoreL()
   566 void CCertSaverModel::InitCertStoreL()
   553     {
   567     {
       
   568 
   554     if ( !iUnifiedCertStore )
   569     if ( !iUnifiedCertStore )
   555         {
   570         {
   556         TRAPD( status, iUnifiedCertStore = CUnifiedCertStore::NewL( iFs, ETrue ) );
   571         TRAPD( status, iUnifiedCertStore = CUnifiedCertStore::NewL( iFs, ETrue ) );
   557         if ( status != KErrNone )
   572         if ( status != KErrNone )
   558             {
   573             {
   574 // Tries to save the certificate to phone memory.
   589 // Tries to save the certificate to phone memory.
   575 // ----------------------------------------------------------
   590 // ----------------------------------------------------------
   576 //
   591 //
   577 void CCertSaverModel::DoSaveCertL()
   592 void CCertSaverModel::DoSaveCertL()
   578     {
   593     {
       
   594 
   579     TInt status = KErrNone;
   595     TInt status = KErrNone;
   580     CCertAttributeFilter* filter = NULL;
   596     CCertAttributeFilter* filter = NULL;
   581     TCertificateFormat certFormat = EX509Certificate;
   597     TCertificateFormat certFormat = EX509Certificate;
   582     HBufC* secondaryName = NULL;
   598     HBufC* secondaryName = NULL;
   583     TCertLabel labelBuf;
   599     TCertLabel labelBuf;
   676             MCTWritableCertStore& writableCertStore =
   692             MCTWritableCertStore& writableCertStore =
   677                     iUnifiedCertStore->WritableCertStore( i );
   693                     iUnifiedCertStore->WritableCertStore( i );
   678 
   694 
   679             MCTToken& token = writableCertStore.Token();
   695             MCTToken& token = writableCertStore.Token();
   680             TUid tokenuid = token.Handle().iTokenTypeUid;
   696             TUid tokenuid = token.Handle().iTokenTypeUid;
   681             if ( ( tokenuid == KTrustedServerTokenUid ) && ( iCertOwnerType == EPeerCertificate ) ||
   697             if ( ( tokenuid == KTrustedServerTokenUid ) && 
       
   698                  ( iCertOwnerType == EPeerCertificate ) ||
   682                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == ECACertificate ) ||
   699                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == ECACertificate ) ||
   683                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == EUserCertificate ) )
   700                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == EUserCertificate ) )
   684                 {
   701                 {
   685                 certstoreIndex = i;
   702                 certstoreIndex = i;
   686                 break;
   703                 break;
   784 // already exist.
   801 // already exist.
   785 // ----------------------------------------------------------
   802 // ----------------------------------------------------------
   786 //
   803 //
   787 TInt CCertSaverModel::QueryLabelL( TCertLabel& aLabel, CUnifiedCertStore& aStore )
   804 TInt CCertSaverModel::QueryLabelL( TCertLabel& aLabel, CUnifiedCertStore& aStore )
   788     {
   805     {
       
   806 
   789     CCertAttributeFilter* filter = NULL;
   807     CCertAttributeFilter* filter = NULL;
   790     TInt status = KErrNone;
   808     TInt status = KErrNone;
   791     RMPointerArray<CCTCertInfo> entries;
   809     RMPointerArray<CCTCertInfo> entries;
   792     TBool loop = ETrue;
   810     TBool loop = ETrue;
   793 
   811 
   794     while ( loop )
   812     while ( loop )
   795         {
   813         {
   796         CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL( aLabel );
   814     HBufC* labelprompt =  CEikonEnv::Static()->AllocReadResourceLC( R_CERTSAVER_ENTER_LABEL );
   797       if ( !dialog->ExecuteLD( R_CERTSAVER_LABEL_QUERY ) )
   815     CSecQueryUi* SecQueryUi = CSecQueryUi::NewL();                                       
       
   816     TInt queryAccepted = SecQueryUi->SecQueryDialog(labelprompt->Des(), aLabel,
       
   817                                                 1,KMaxCertLabelLength,          
       
   818                                                 ESecUiAlphaSupported |          
       
   819                                                 ESecUiCancelSupported |         
       
   820                                                 ESecUiEmergencyNotSupported);   
       
   821     CleanupStack::PopAndDestroy( labelprompt );
       
   822     delete SecQueryUi;  
       
   823     SecQueryUi=NULL;
       
   824 
       
   825       if ( queryAccepted!=KErrNone )
   798             {
   826             {
   799             // cancel
   827             // cancel
   800             ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
   828             ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
   801             return KErrCancel;
   829             return KErrCancel;
   802             }
   830             }
   838 // of the save operation.
   866 // of the save operation.
   839 // ----------------------------------------------------------
   867 // ----------------------------------------------------------
   840 //
   868 //
   841 void CCertSaverModel::HandleSaveErrorL( TInt aStatus ) const
   869 void CCertSaverModel::HandleSaveErrorL( TInt aStatus ) const
   842     {
   870     {
       
   871 
   843     switch ( aStatus )
   872     switch ( aStatus )
   844         {
   873         {
   845         case KErrNone:
   874         case KErrNone:
   846             {
   875             {
   847             ShowConfirmationNoteL( R_CERTSAVER_ERROR_SAVEOK );
   876             ShowConfirmationNoteL( R_CERTSAVER_ERROR_SAVEOK );
   882 // ----------------------------------------------------------
   911 // ----------------------------------------------------------
   883 //
   912 //
   884 void CCertSaverModel::AddToMessageWithStringL(
   913 void CCertSaverModel::AddToMessageWithStringL(
   885     TDes& aMessage, TInt aStringResID, const TDesC& aString ) const
   914     TDes& aMessage, TInt aStringResID, const TDesC& aString ) const
   886     {
   915     {
       
   916 
   887     HBufC* promptPtr = NULL;
   917     HBufC* promptPtr = NULL;
   888     promptPtr = StringLoader::LoadL( aStringResID, aString );
   918     promptPtr = StringLoader::LoadL( aStringResID, aString );
   889     CleanupStack::PushL( promptPtr );
   919     CleanupStack::PushL( promptPtr );
   890     TPtrC prompt( promptPtr->Des() );
   920     TPtrC prompt( promptPtr->Des() );
   891 
   921 
   902 void CCertSaverModel::AddToMessageWithIntL(
   932 void CCertSaverModel::AddToMessageWithIntL(
   903     TDes& aMessage,
   933     TDes& aMessage,
   904     TInt aStringResID,
   934     TInt aStringResID,
   905     TInt aInt ) const
   935     TInt aInt ) const
   906     {
   936     {
       
   937 
   907     HBufC* promptPtr = NULL;
   938     HBufC* promptPtr = NULL;
   908     promptPtr = StringLoader::LoadL( aStringResID, aInt );
   939     promptPtr = StringLoader::LoadL( aStringResID, aInt );
   909     CleanupStack::PushL( promptPtr );
   940     CleanupStack::PushL( promptPtr );
   910     TPtrC prompt( promptPtr->Des() );
   941     TPtrC prompt( promptPtr->Des() );
   911 
   942 
   920 // String loaded from resources with StringLoader.
   951 // String loaded from resources with StringLoader.
   921 // ----------------------------------------------------------
   952 // ----------------------------------------------------------
   922 //
   953 //
   923 void CCertSaverModel::AddToMessageL( TDes& aMessage, TInt aStringResID ) const
   954 void CCertSaverModel::AddToMessageL( TDes& aMessage, TInt aStringResID ) const
   924     {
   955     {
       
   956 
   925     HBufC* promptPtr = NULL;
   957     HBufC* promptPtr = NULL;
   926     promptPtr = StringLoader::LoadL( aStringResID );
   958     promptPtr = StringLoader::LoadL( aStringResID );
   927     CleanupStack::PushL( promptPtr );
   959     CleanupStack::PushL( promptPtr );
   928     TPtrC prompt( promptPtr->Des() );
   960     TPtrC prompt( promptPtr->Des() );
   929 
   961 
   938 // Creates the certificate details message shown to the user.
   970 // Creates the certificate details message shown to the user.
   939 // ----------------------------------------------------------
   971 // ----------------------------------------------------------
   940 //
   972 //
   941 void CCertSaverModel::ConstructMessageL( TDes& aMessage ) const
   973 void CCertSaverModel::ConstructMessageL( TDes& aMessage ) const
   942     {
   974     {
       
   975 
   943     HBufC16* issuerName = NULL;
   976     HBufC16* issuerName = NULL;
   944     HBufC16* subjectName = NULL;
   977     HBufC16* subjectName = NULL;
   945 
   978 
   946 
   979 
   947     X509CertNameParser::SubjectFullNameL( *((CX509Certificate*)iNewCert),
   980     X509CertNameParser::SubjectFullNameL( *((CX509Certificate*)iNewCert),
   994 // CCTSecurityDialogsAO::AddKeyUsageL(...)
  1027 // CCTSecurityDialogsAO::AddKeyUsageL(...)
   995 // -----------------------------------------------------------------------------
  1028 // -----------------------------------------------------------------------------
   996 //
  1029 //
   997 void CCertSaverModel::AddKeyUsageL( TDes& aMessage, const CX509Certificate& aCert ) const
  1030 void CCertSaverModel::AddKeyUsageL( TDes& aMessage, const CX509Certificate& aCert ) const
   998     {
  1031     {
       
  1032 
   999     TKeyUsageX509 x509Usage = EX509UsageNone;
  1033     TKeyUsageX509 x509Usage = EX509UsageNone;
  1000     TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone;
  1034     TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone;
  1001     const CX509CertExtension* ext = aCert.Extension( KKeyUsage );
  1035     const CX509CertExtension* ext = aCert.Extension( KKeyUsage );
  1002     if (ext)
  1036     if (ext)
  1003         {
  1037         {
  1077 // -----------------------------------------------------------------------------
  1111 // -----------------------------------------------------------------------------
  1078 //
  1112 //
  1079 void CCertSaverModel::AddValidityPeriodL(
  1113 void CCertSaverModel::AddValidityPeriodL(
  1080     TDes& aMessage, const CX509Certificate& aCert ) const
  1114     TDes& aMessage, const CX509Certificate& aCert ) const
  1081     {
  1115     {
       
  1116 
  1082     // Hometime's offset to UTC
  1117     // Hometime's offset to UTC
  1083     TLocale locale;
  1118     TLocale locale;
  1084     TTimeIntervalSeconds offSet = locale.UniversalTimeOffset();
  1119     TTimeIntervalSeconds offSet = locale.UniversalTimeOffset();
  1085     AddToMessageL( aMessage, R_CERTSAVER_QTN_CM_VALID_FROM );
  1120     AddToMessageL( aMessage, R_CERTSAVER_QTN_CM_VALID_FROM );
  1086 
  1121 
  1106     dateFormatString = iAppUi->CoeEnv()->AllocReadResourceLC(
  1141     dateFormatString = iAppUi->CoeEnv()->AllocReadResourceLC(
  1107         R_QTN_DATE_USUAL_WITH_ZERO );
  1142         R_QTN_DATE_USUAL_WITH_ZERO );
  1108     // format the date to user readable format. The format is locale dependent
  1143     // format the date to user readable format. The format is locale dependent
  1109     finishValue.FormatL( finishString, *dateFormatString );
  1144     finishValue.FormatL( finishString, *dateFormatString );
  1110     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString );
  1145     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString );
  1111     CleanupStack::PopAndDestroy(); // dateFormatString
  1146     CleanupStack::PopAndDestroy(dateFormatString); // dateFormatString
  1112     aMessage.Append( finishString );
  1147     aMessage.Append( finishString );
  1113     AddNewlinesToMessage( aMessage );
  1148     AddNewlinesToMessage( aMessage );
  1114     }
  1149     }
  1115 
  1150 
  1116 // ----------------------------------------------------------
  1151 // ----------------------------------------------------------
  1118 // Adds two new lines to message.
  1153 // Adds two new lines to message.
  1119 // ----------------------------------------------------------
  1154 // ----------------------------------------------------------
  1120 //
  1155 //
  1121 void CCertSaverModel::AddNewlinesToMessage( TDes& aMessage ) const
  1156 void CCertSaverModel::AddNewlinesToMessage( TDes& aMessage ) const
  1122     {
  1157     {
       
  1158 
  1123     aMessage.Append( KDoubleEnter );
  1159     aMessage.Append( KDoubleEnter );
  1124     }
  1160     }
  1125 
  1161 
  1126 // ----------------------------------------------------------
  1162 // ----------------------------------------------------------
  1127 // CCertSaverModel::CertificateSupported() const
  1163 // CCertSaverModel::CertificateSupported() const
  1128 // Checks that cert is of supported type.
  1164 // Checks that cert is of supported type.
  1129 // ----------------------------------------------------------
  1165 // ----------------------------------------------------------
  1130 //
  1166 //
  1131 TBool CCertSaverModel::CertificateSupported() const
  1167 TBool CCertSaverModel::CertificateSupported() const
  1132     {
  1168     {
       
  1169 
  1133     if ( iCertFormat == EX509Certificate &&
  1170     if ( iCertFormat == EX509Certificate &&
  1134        ( iCertOwnerType == ECACertificate ||
  1171        ( iCertOwnerType == ECACertificate ||
  1135          iCertOwnerType == EPeerCertificate ||
  1172          iCertOwnerType == EPeerCertificate ||
  1136          iCertOwnerType == EUserCertificate))
  1173          iCertOwnerType == EUserCertificate))
  1137         {
  1174         {
  1149 // certificate.
  1186 // certificate.
  1150 // ----------------------------------------------------------
  1187 // ----------------------------------------------------------
  1151 //
  1188 //
  1152 TBool CCertSaverModel::CertificateOkL() const
  1189 TBool CCertSaverModel::CertificateOkL() const
  1153     {
  1190     {
  1154     if ( !CertificateSupported() )
  1191 
  1155         {
  1192     if ( !CertificateSupported() ) 
  1156         ShowErrorNoteL( R_CERTSAVER_ERROR_UNSUPPORTED_CERT );
  1193         {
       
  1194         ShowErrorNoteL( R_CERTSAVER_ERROR_UNSUPPORTED_CERT   ); 
  1157         return EFalse;
  1195         return EFalse;
  1158         }
  1196         }
  1159     if ( CertNotValidAnymore() )
  1197     if ( CertNotValidAnymore() )
  1160         {
  1198         {
  1161         ShowErrorNoteL( R_CERTSAVER_ERROR_CERT_NOT_VALID );
  1199         ShowErrorNoteL(R_CERTSAVER_ERROR_CERT_NOT_VALID);
  1162         return ETrue;
  1200         return ETrue;
  1163         }
  1201         }
  1164     else if ( CertNotValidYet() )
  1202     else if ( CertNotValidYet() )
  1165         {
  1203         {
  1166         ShowErrorNoteL( R_CERTSAVER_ERROR_CERT_NOT_VALID_YET );
  1204         ShowErrorNoteL( R_CERTSAVER_ERROR_CERT_NOT_VALID_YET );
  1173 // Checks if cert isn't valid anymore.
  1211 // Checks if cert isn't valid anymore.
  1174 // ----------------------------------------------------------
  1212 // ----------------------------------------------------------
  1175 //
  1213 //
  1176 TBool CCertSaverModel::CertNotValidAnymore() const
  1214 TBool CCertSaverModel::CertNotValidAnymore() const
  1177     {
  1215     {
       
  1216 
  1178     TTime homeTime;
  1217     TTime homeTime;
  1179     homeTime.HomeTime();
  1218     homeTime.HomeTime();
  1180     if ( iNewCert->ValidityPeriod().Finish() < homeTime )
  1219     if ( iNewCert->ValidityPeriod().Finish() < homeTime )
  1181         {
  1220         {
  1182         return ETrue;
  1221         return ETrue;
  1189 // Checks if cert isn't valid yet.
  1228 // Checks if cert isn't valid yet.
  1190 // ----------------------------------------------------------
  1229 // ----------------------------------------------------------
  1191 //
  1230 //
  1192 TBool CCertSaverModel::CertNotValidYet() const
  1231 TBool CCertSaverModel::CertNotValidYet() const
  1193     {
  1232     {
       
  1233 
  1194     TTime homeTime;
  1234     TTime homeTime;
  1195     homeTime.HomeTime();
  1235     homeTime.HomeTime();
  1196     if ( iNewCert->ValidityPeriod().Start() > homeTime )
  1236     if ( iNewCert->ValidityPeriod().Start() > homeTime )
  1197         {
  1237         {
  1198         return ETrue;
  1238         return ETrue;
  1205 // Creates and shows a confirmation note.
  1245 // Creates and shows a confirmation note.
  1206 // ----------------------------------------------------------
  1246 // ----------------------------------------------------------
  1207 //
  1247 //
  1208 void CCertSaverModel::ShowInformationNoteL( TInt aResourceID ) const
  1248 void CCertSaverModel::ShowInformationNoteL( TInt aResourceID ) const
  1209     {
  1249     {
       
  1250 
  1210     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
  1251     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
  1211     CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
  1252     CHbDeviceMessageBoxSymbian::InformationL(buffer->Des()); 
  1212     note->ExecuteLD( buffer->Des() );
       
  1213     CleanupStack::PopAndDestroy( buffer );
  1253     CleanupStack::PopAndDestroy( buffer );
  1214     }
  1254     }
  1215 // ----------------------------------------------------------
  1255 // ----------------------------------------------------------
  1216 // CCertSaverModel::ShowConfirmationNoteL() const
  1256 // CCertSaverModel::ShowConfirmationNoteL() const
  1217 // Creates and shows a confirmation note.
  1257 // Creates and shows a confirmation note.
  1218 // ----------------------------------------------------------
  1258 // ----------------------------------------------------------
  1219 //
  1259 //
  1220 void CCertSaverModel::ShowConfirmationNoteL( TInt aResourceID ) const
  1260 void CCertSaverModel::ShowConfirmationNoteL( TInt aResourceID ) const
  1221     {
  1261     {
       
  1262 
  1222     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
  1263     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
  1223     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue );
  1264     CHbDeviceMessageBoxSymbian::WarningL(buffer->Des()); 
  1224     note->ExecuteLD( buffer->Des() );
       
  1225     CleanupStack::PopAndDestroy( buffer );
  1265     CleanupStack::PopAndDestroy( buffer );
  1226     }
  1266     }
  1227 
  1267 
  1228 // ----------------------------------------------------------
  1268 // ----------------------------------------------------------
  1229 // CCertSaverModel::ShowErrorNoteL() const
  1269 // CCertSaverModel::ShowErrorNoteL() const
  1230 // Creates and shows an error note.
  1270 // Creates and shows an error note.
  1231 // ----------------------------------------------------------
  1271 // ----------------------------------------------------------
  1232 //
  1272 //
  1233 void CCertSaverModel::ShowErrorNoteL( TInt aResourceID ) const
  1273 void CCertSaverModel::ShowErrorNoteL( TInt aResourceID ) const
  1234     {
  1274     {
       
  1275 
  1235     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
  1276     HBufC* buffer = iAppUi->CoeEnv()->AllocReadResourceLC( aResourceID );
  1236     CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue );
  1277     //TODO: can be changed when hb supports ErrorL
  1237     note->ExecuteLD(buffer->Des());
  1278     CHbDeviceMessageBoxSymbian::WarningL(buffer->Des()); 
  1238     CleanupStack::PopAndDestroy( buffer );
  1279     CleanupStack::PopAndDestroy( buffer );
  1239     }
  1280     }
  1240 
  1281 
  1241 // ----------------------------------------------------------
  1282 // ----------------------------------------------------------
  1242 // CCertSaverModel::TrimCertificateFields() const
  1283 // CCertSaverModel::TrimCertificateFields() const
  1245 // Returns the trimmed certificate field.
  1286 // Returns the trimmed certificate field.
  1246 // ----------------------------------------------------------
  1287 // ----------------------------------------------------------
  1247 //
  1288 //
  1248 TPtrC CCertSaverModel::TrimCertificateFields( TPtrC aField ) const
  1289 TPtrC CCertSaverModel::TrimCertificateFields( TPtrC aField ) const
  1249     {
  1290     {
       
  1291 
  1250     TPtrC cutField = CutCertificateField( aField );
  1292     TPtrC cutField = CutCertificateField( aField );
  1251     // Find one semicolon at a time and crop the
  1293     // Find one semicolon at a time and crop the
  1252     // helpField from the left to search for the next semicolon
  1294     // helpField from the left to search for the next semicolon
  1253     TInt position = cutField.Locate( ';' ); // 1st semicolon
  1295     TInt position = cutField.Locate( ';' ); // 1st semicolon
  1254     TInt fieldLength = cutField.Length();
  1296     TInt fieldLength = cutField.Length();
  1296 // this function cuts it.
  1338 // this function cuts it.
  1297 // ----------------------------------------------------------
  1339 // ----------------------------------------------------------
  1298 //
  1340 //
  1299 TPtrC CCertSaverModel::CutCertificateField( TPtrC aField ) const
  1341 TPtrC CCertSaverModel::CutCertificateField( TPtrC aField ) const
  1300     {
  1342     {
       
  1343 
  1301     TInt fieldLength = aField.Length();
  1344     TInt fieldLength = aField.Length();
  1302     if ( fieldLength >= KMaxLengthTextCertIdentifierVisible )
  1345     if ( fieldLength >= KMaxLengthTextCertIdentifierVisible )
  1303         {
  1346         {
  1304         TPtrC cutCertLabel = aField.Mid( 0, KMaxLengthTextCertIdentifierVisible );
  1347         TPtrC cutCertLabel = aField.Mid( 0, KMaxLengthTextCertIdentifierVisible );
  1305         return cutCertLabel;
  1348         return cutCertLabel;
  1312 // Does needed tasks to exit.
  1355 // Does needed tasks to exit.
  1313 // ----------------------------------------------------------
  1356 // ----------------------------------------------------------
  1314 //
  1357 //
  1315 TInt CCertSaverModel::QueryTrusterUidsL( RArray<TUid>& aUids )
  1358 TInt CCertSaverModel::QueryTrusterUidsL( RArray<TUid>& aUids )
  1316     {
  1359     {
       
  1360 
  1317     TInt ret = KErrCancel;
  1361     TInt ret = KErrCancel;
  1318     CArrayFixFlat<TInt>* selectionArray =
       
  1319         new (ELeave)  CArrayFixFlat<TInt>( KTrusterArrayInitSize );
       
  1320     CleanupStack::PushL( selectionArray );
       
  1321     CDesCArray* itemsArray = new (ELeave) CDesCArrayFlat( KTrusterArrayInitSize );
  1362     CDesCArray* itemsArray = new (ELeave) CDesCArrayFlat( KTrusterArrayInitSize );
  1322     CleanupStack::PushL( itemsArray );
  1363     CleanupStack::PushL( itemsArray );
  1323 
  1364 
  1324     CCertificateAppInfoManager* appInfoManager =
  1365     CCertificateAppInfoManager* appInfoManager =
  1325         CCertificateAppInfoManager::NewL( iFs, EFalse );
  1366         CCertificateAppInfoManager::NewL( iFs, EFalse );
  1328     const RArray<TCertificateAppInfo>& apps = appInfoManager->Applications();
  1369     const RArray<TCertificateAppInfo>& apps = appInfoManager->Applications();
  1329     RArray<TCertificateAppInfo> appsInItemArray( KTrusterArrayInitSize );
  1370     RArray<TCertificateAppInfo> appsInItemArray( KTrusterArrayInitSize );
  1330     CleanupClosePushL( appsInItemArray );
  1371     CleanupClosePushL( appsInItemArray );
  1331     UpdateTrustListboxItemL( apps, appsInItemArray, *itemsArray );
  1372     UpdateTrustListboxItemL( apps, appsInItemArray, *itemsArray );
  1332 
  1373 
  1333     CAknListQueryDialog* dlg = new (ELeave) CAknListQueryDialog( selectionArray );
  1374     HBufC* title = CEikonEnv::Static()->AllocReadResourceLC( R_CERTSAVER_SELECT_TRUSTED_APPS);
  1334     CleanupStack::PushL( dlg );
  1375 
  1335     dlg->PrepareLC( R_CERTSAVER_TRUST_SETTINGS_QUERY );
  1376     RBuf rBuf;     // buffer for items with big enough space
  1336     dlg->SetItemTextArray( itemsArray );
  1377     rBuf.CreateL(KMaxLengthTextMeassageBody);
  1337     dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
  1378     CleanupClosePushL(rBuf);
  1338     if ( dlg->RunLD() )
  1379     for(TInt i = 0; i<itemsArray->Count(); i++) 
  1339         {
  1380         rBuf.Append( (*itemsArray)[i] ); 
  1340         for ( TInt i = 0; i < selectionArray->Count(); ++i )
  1381 
  1341             {
  1382     CSecQueryUi* SecQueryUi = CSecQueryUi::NewL();     
  1342             TInt ii = (*selectionArray)[ i ];
  1383     TInt saved = SecQueryUi->SecQueryDialog(*title, rBuf,1,KTokenLength,              
  1343             aUids.Append( appsInItemArray[ ii ].Id() );
  1384                                              ESecUiAlphaSupported | ESecUiCancelSupported |
  1344             }
  1385                                              ESecUiBasicTypeMultiCheck |
       
  1386                                              ESecUiEmergencyNotSupported);   
       
  1387     delete SecQueryUi;
       
  1388     SecQueryUi=NULL;
       
  1389 
       
  1390     if (saved==KErrNone)
       
  1391         {
       
  1392         TLex16 lex(rBuf);
       
  1393         TChar ch;                                        
       
  1394         TBuf16<KTokenLength> token;          
       
  1395         TInt  val;
       
  1396         while((ch = lex.Get()) != 0 ){                   
       
  1397            while ((ch = lex.Peek()) != '|' && ch!=0) lex.Inc();
       
  1398            token.Copy(lex.MarkedToken());                
       
  1399            TLex lexc(token);
       
  1400            if(lexc.Val(val)!=KErrNone) val=0;
       
  1401            if(val<=appsInItemArray.Count()-1)
       
  1402                aUids.Append( appsInItemArray[ val ].Id() );
       
  1403            lex.Inc();                                    
       
  1404            lex.Mark();                                   
       
  1405          }  
  1345         ret = KErrNone;
  1406         ret = KErrNone;
  1346         }
  1407         }
  1347     else
  1408     else
  1348         {
  1409         {
  1349         ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
  1410         ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
  1350         ret = KErrCancel;
  1411         ret = KErrCancel;
  1351         }
  1412         }
  1352     CleanupStack::Pop( dlg );
  1413 
  1353     CleanupStack::PopAndDestroy( 4, selectionArray );
  1414     rBuf.Close();
       
  1415     CleanupStack::PopAndDestroy(&rBuf);
       
  1416     CleanupStack::PopAndDestroy(title);
       
  1417     CleanupStack::PopAndDestroy(&appsInItemArray);
       
  1418     CleanupStack::PopAndDestroy(appInfoManager);
       
  1419     CleanupStack::PopAndDestroy(itemsArray);
  1354     return ret;
  1420     return ret;
  1355     }
  1421     }
  1356 
  1422 
  1357 // ----------------------------------------------------------
  1423 // ----------------------------------------------------------
  1358 // CCertSaverModel::QueryTrustedSiteL()
  1424 // CCertSaverModel::QueryTrustedSiteL()
  1359 // Shows query for trusted site certificate
  1425 // Shows query for trusted site certificate
  1360 // ----------------------------------------------------------
  1426 // ----------------------------------------------------------
  1361 //
  1427 //
  1362 TInt CCertSaverModel::QueryTrustedSiteL()
  1428 TInt CCertSaverModel::QueryTrustedSiteL()
  1363     {
  1429     {
       
  1430 
  1364     TInt ret = KErrCancel;
  1431     TInt ret = KErrCancel;
  1365     HBufC* label = NULL;
  1432     HBufC* label = NULL;
  1366     HBufC* secondaryName = NULL;
  1433     HBufC* secondaryName = NULL;
  1367     TCertLabel labelBuf;
  1434     TCertLabel labelBuf;
  1368 
  1435 
  1370         (*(CX509Certificate*)iNewCert), label, secondaryName );
  1437         (*(CX509Certificate*)iNewCert), label, secondaryName );
  1371     CleanupStack::PushL( label );
  1438     CleanupStack::PushL( label );
  1372     delete secondaryName;
  1439     delete secondaryName;
  1373     secondaryName = NULL;
  1440     secondaryName = NULL;
  1374     labelBuf = label->Des().Left( CERTSAVER_MAX_LABEL_LEN );
  1441     labelBuf = label->Des().Left( CERTSAVER_MAX_LABEL_LEN );
  1375 
       
  1376 
       
  1377     HBufC* prompt = StringLoader::LoadLC( R_CERTSAVER_TRUSTEDSITE_WARNING, labelBuf );
  1442     HBufC* prompt = StringLoader::LoadLC( R_CERTSAVER_TRUSTEDSITE_WARNING, labelBuf );
  1378 
  1443     CHbDeviceMessageBoxSymbian::TButtonId selection =
  1379     CAknMessageQueryDialog* note = CAknMessageQueryDialog::NewL( *prompt );
  1444         CHbDeviceMessageBoxSymbian::QuestionL(prompt->Des(), KNullDesC, KNullDesC);
  1380 
  1445     if ( selection == CHbDeviceMessageBoxSymbian::EAcceptButton)
  1381     note->PrepareLC( R_CERTSAVER_TRUSTED_SITE_QUERY );
       
  1382     note->SetPromptL( *prompt );
       
  1383 
       
  1384     if ( note->RunLD() )
       
  1385         {
  1446         {
  1386         ret = KErrNone;
  1447         ret = KErrNone;
  1387         }
  1448         }
  1388     else
  1449     else
  1389         {
  1450         {
  1390         ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
  1451         ShowConfirmationNoteL( R_CERTSAVER_CERT_DISCARDED );
  1391         ret = KErrCancel;
  1452         ret = KErrCancel;
  1392         }
  1453         }
  1393 
       
  1394     CleanupStack::PopAndDestroy( prompt );
  1454     CleanupStack::PopAndDestroy( prompt );
  1395 
       
  1396     CleanupStack::PopAndDestroy( label );
  1455     CleanupStack::PopAndDestroy( label );
  1397     return ret;
  1456     return ret;
  1398     }
  1457     }
  1399 
  1458 
  1400 // ----------------------------------------------------------
  1459 // ----------------------------------------------------------
  1405 void CCertSaverModel::UpdateTrustListboxItemL(
  1464 void CCertSaverModel::UpdateTrustListboxItemL(
  1406     const RArray<TCertificateAppInfo>& aApps,
  1465     const RArray<TCertificateAppInfo>& aApps,
  1407     RArray<TCertificateAppInfo>& aAppsInItemArray,
  1466     RArray<TCertificateAppInfo>& aAppsInItemArray,
  1408     CDesCArray& aItemsArray ) const
  1467     CDesCArray& aItemsArray ) const
  1409   {
  1468   {
       
  1469 
  1410     for ( TInt i = 0; i < aApps.Count(); i++ )
  1470     for ( TInt i = 0; i < aApps.Count(); i++ )
  1411         {
  1471         {
  1412         TCertificateAppInfo appInfo = aApps[ i ];
  1472         TCertificateAppInfo appInfo = aApps[ i ];
  1413         TBuf<KItemBufLen> item;
  1473         TBuf<KItemBufLen> item;
  1414         item.Append( KCertSaverListBoxItemPrefix );
  1474         item.Append( KCertSaverListBoxItemPrefix );
  1467 // CCertManUIViewAuthority::DevideToBlocks
  1527 // CCertManUIViewAuthority::DevideToBlocks
  1468 // ---------------------------------------------------------
  1528 // ---------------------------------------------------------
  1469 //
  1529 //
  1470 void CCertSaverModel::DivideToBlocks( const TDesC8& aInput, TDes& aOutput ) const
  1530 void CCertSaverModel::DivideToBlocks( const TDesC8& aInput, TDes& aOutput ) const
  1471     {
  1531     {
       
  1532 
  1472     _LIT( KBlockSeparator, " " );
  1533     _LIT( KBlockSeparator, " " );
  1473     const TInt KBlockLength = 2;
  1534     const TInt KBlockLength = 2;
  1474     TInt blockIndex = 0;
  1535     TInt blockIndex = 0;
  1475     for ( TInt j = 0 ; j < aInput.Length() ; j++ )
  1536     for ( TInt j = 0 ; j < aInput.Length() ; j++ )
  1476         {
  1537         {
  1489 // Saves content of the PKCS#12 file
  1550 // Saves content of the PKCS#12 file
  1490 // ----------------------------------------------------
  1551 // ----------------------------------------------------
  1491 //
  1552 //
  1492 void CCertSaverModel::SavePKCS12L()
  1553 void CCertSaverModel::SavePKCS12L()
  1493     {
  1554     {
       
  1555 
  1494     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1556     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1495     TPtr msgPtr = message->Des();
  1557     TPtr msgPtr = message->Des();
  1496     ConstructPKCS12QueryMsgL(msgPtr, iParser.Keys().Count(),
  1558     ConstructPKCS12QueryMsgL(msgPtr, iParser.Keys().Count(),
  1497                             iParser.UserCertificates().Count(),
  1559                             iParser.UserCertificates().Count(),
  1498                             iParser.CACertificates().Count() );
  1560                             iParser.CACertificates().Count() );
  1499     TBool save = DoMessageQueryL(
  1561 
  1500         R_MESSAGE_QUERY_DOSAVE, R_CERTSAVER_HEADER_PKCS12_FILE_CONTAINS,
  1562     //TODO: Should be in loc file but hardcoded now
  1501         *message );
  1563     _LIT(KCheckBoxCaption,"Protect with Password|1");
  1502     CleanupStack::PopAndDestroy( message );
  1564     TBuf<KMaxLengthTextCheckBoxData> CheckeBoxData(KCheckBoxCaption);
       
  1565 
       
  1566     CSecQueryUi* SecQueryUi = CSecQueryUi::NewL();    
       
  1567     TInt save = SecQueryUi->SecQueryDialog(*message, CheckeBoxData,1,1,
       
  1568                                             ESecUiAlphaSupported | ESecUiCancelSupported |
       
  1569                                             ESecUiBasicTypeCheck | ESecUiEmergencyNotSupported);
       
  1570     CleanupStack::Pop(message);
  1503     message = NULL;
  1571     message = NULL;
  1504     if ( !save )
  1572     delete SecQueryUi;
       
  1573     SecQueryUi=NULL;
       
  1574 
       
  1575     if ( save!=KErrNone )
  1505         {
  1576         {
  1506         ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED );
  1577         ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED );
  1507         User::Leave( KErrExitApp );
  1578         User::Leave( KErrExitApp );
  1508         }
  1579         }
  1509     TInt status = KErrNone;
  1580     TInt status = KErrNone;
  1543             }
  1614             }
  1544         }
  1615         }
  1545     if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0
  1616     if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0
  1546         || iSavedUserCertsCount != 0 )
  1617         || iSavedUserCertsCount != 0 )
  1547         {
  1618         {
       
  1619         HBufC* p = StringLoader::LoadLC( R_CERTSAVER_HEADER_SAVED );
  1548         message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1620         message = HBufC::NewLC( KMaxLengthTextMeassageBody );
       
  1621         message->Des().Append(p->Des());   
  1549         TPtr msgPtr2 = message->Des();
  1622         TPtr msgPtr2 = message->Des();
  1550         ConstructPKCS12QueryMsgL(
  1623         ConstructPKCS12QueryMsgL(
  1551             msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount );
  1624             msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount );
  1552         DoMessageQueryL(
  1625         CHbDeviceMessageBoxSymbian::InformationL(message->Des()); 
  1553             R_MESSAGE_QUERY_SAVED, R_CERTSAVER_HEADER_SAVED, *message );
       
  1554         CleanupStack::PopAndDestroy( message );
  1626         CleanupStack::PopAndDestroy( message );
       
  1627         CleanupStack::PopAndDestroy( p );       
  1555         }
  1628         }
  1556     else
  1629     else
  1557         {
  1630         {
  1558         ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED );
  1631         ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED );
  1559         }
  1632         CleanupStack::PopAndDestroy( message );
  1560     }
  1633         }
  1561 
       
  1562 // ----------------------------------------------------------
       
  1563 // CCertSaverModel::DoMessageQuery()
       
  1564 // Displays message query dialog for user.
       
  1565 // ----------------------------------------------------------
       
  1566 //
       
  1567 TBool CCertSaverModel::DoMessageQueryL(
       
  1568     TInt aDialogResId,
       
  1569     TInt aHeadingResId,
       
  1570     TDesC& aMessage )
       
  1571     {
       
  1572     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( aMessage );
       
  1573     CleanupStack::PushL( dlg );
       
  1574     dlg->PrepareLC( aDialogResId );
       
  1575 
       
  1576     HBufC* header = StringLoader::LoadLC( aHeadingResId );
       
  1577     dlg->QueryHeading()->SetTextL( header->Des() );
       
  1578     CleanupStack::PopAndDestroy( header );
       
  1579     CleanupStack::Pop( dlg );
       
  1580     return dlg->RunLD();
       
  1581     }
  1634     }
  1582 
  1635 
  1583 // ----------------------------------------------------------
  1636 // ----------------------------------------------------------
  1584 // CCertSaverModel::ConstructPKCS12QueryMsgL() const
  1637 // CCertSaverModel::ConstructPKCS12QueryMsgL() const
  1585 // Creates the certificate details message shown to the user.
  1638 // Creates the certificate details message shown to the user.
  1589     TDes& aMessage,
  1642     TDes& aMessage,
  1590     TInt aPrivateKeys,
  1643     TInt aPrivateKeys,
  1591     TInt aUserCerts,
  1644     TInt aUserCerts,
  1592     TInt aCACerts ) const
  1645     TInt aCACerts ) const
  1593     {
  1646     {
       
  1647 
  1594     if ( aPrivateKeys > 0 )
  1648     if ( aPrivateKeys > 0 )
  1595         {
  1649         {
  1596         if ( aPrivateKeys == 1 )
  1650         if ( aPrivateKeys == 1 )
  1597             {
  1651             {
  1598             AddToMessageL( aMessage, R_CERTSAVER_ONE_PRIVATE_KEY );
  1652             AddToMessageL( aMessage, R_CERTSAVER_ONE_PRIVATE_KEY );