pkiutilities/CertSaver/src/CertSaverModel.cpp
branchRCL_3
changeset 54 94da73d93b58
parent 50 03674e5abf46
child 67 79bd6bd83ec3
equal deleted inserted replaced
50:03674e5abf46 54:94da73d93b58
     1 /*
     1 /*
     2 * Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    73 _LIT( KSpace, " " );
    73 _LIT( KSpace, " " );
    74 _LIT( KDoubleEnter, "\n\n" );
    74 _LIT( KDoubleEnter, "\n\n" );
    75 _LIT( KEnter, "\n" );
    75 _LIT( KEnter, "\n" );
    76 
    76 
    77 const TUid KTrustedServerTokenUid = { 0x101FB66F };
    77 const TUid KTrustedServerTokenUid = { 0x101FB66F };
    78 const TUid KFileTokensUid = { 0x101F501A };
    78 const TUid KFileCertStoreTokenUid = { 0x101F501A };
       
    79 const TUid KDeviceCertStoreTokenUid = { 0x101FB668 };
       
    80 const TUid KFileKeyStoreTokenUid = { KTokenTypeFileKeystore };  // 0x101F7333
       
    81 const TUid KDeviceKeyStoreTokenUid = { 0x101FB66A };
       
    82 
       
    83 const TInt64 KZeroTime = 0;
    79 
    84 
    80 _LIT_SECURITY_POLICY_V1( KSymbianKeyStoreMgmtPolicy,
    85 _LIT_SECURITY_POLICY_V1( KSymbianKeyStoreMgmtPolicy,
    81                          VID_DEFAULT, ECapabilityWriteUserData );
    86                          VID_DEFAULT, ECapabilityWriteUserData );
    82 _LIT_SECURITY_POLICY_C1( KSymbianKeyStoreUsePolicy, ECapabilityReadUserData );
    87 _LIT_SECURITY_POLICY_C1( KSymbianKeyStoreUsePolicy, ECapabilityReadUserData );
    83 
    88 
    92     delete iUnifiedCertStore;
    97     delete iUnifiedCertStore;
    93     iTrusterUids.Close();
    98     iTrusterUids.Close();
    94     }
    99     }
    95 
   100 
    96 // ----------------------------------------------------------
   101 // ----------------------------------------------------------
    97 // CCertSaverModel::CCertSaverModel(
   102 // CCertSaverModel::CCertSaverModel()
    98 //    const CCertSaverDocument* aDocument, CCertSaverAppUi* aAppUi)
   103 // ----------------------------------------------------------
    99 // ----------------------------------------------------------
   104 //
   100 //
   105 CCertSaverModel::CCertSaverModel( CCertSaverAppUi* aAppUi, const CCertParser& aParser ) :
   101 CCertSaverModel::CCertSaverModel(
       
   102     CCertSaverAppUi* aAppUi,
       
   103     const CCertParser& aParser ):
       
   104     iAppUi( aAppUi ), iFs( iAppUi->CoeEnv()->FsSession() ), iParser( aParser ),
   106     iAppUi( aAppUi ), iFs( iAppUi->CoeEnv()->FsSession() ), iParser( aParser ),
   105     iSavedCACertsCount( 0 ), iSavedKeysCount( 0 ),
   107     iSavedCACertsCount( 0 ), iSavedKeysCount( 0 ),
   106     iSavedUserCertsCount( 0 ), iKeyAlreadyExists( EFalse )
   108     iSavedUserCertsCount( 0 ), iKeyAlreadyExists( EFalse ),
       
   109     iSelectedKeyStoreToken( KFileKeyStoreTokenUid ),
       
   110     iSelectedCertStoreToken( KFileCertStoreTokenUid ),
       
   111     iSelectedKeyStoreIndex( KErrNotFound )
   107     {
   112     {
   108     }
   113     }
   109 
   114 
   110 // ----------------------------------------------------------
   115 // ----------------------------------------------------------
   111 // CCertSaverModel::SaveCertificateL()
   116 // CCertSaverModel::SaveCertificateL()
   117             const TCertificateFormat& aCertFormat )
   122             const TCertificateFormat& aCertFormat )
   118     {
   123     {
   119     iCertOwnerType = aOwnerType;
   124     iCertOwnerType = aOwnerType;
   120     iCertFormat = aCertFormat;
   125     iCertFormat = aCertFormat;
   121     iNewCert = &aCertificate;
   126     iNewCert = &aCertificate;
       
   127     iSelectedKeyStoreToken = KFileKeyStoreTokenUid;
       
   128     iSelectedCertStoreToken = KFileCertStoreTokenUid;
   122 
   129 
   123     if ( aOwnerType == EPeerCertificate )
   130     if ( aOwnerType == EPeerCertificate )
   124         {
   131         {
   125         TInt ret = QueryTrustedSiteL();
   132         TInt ret = QueryTrustedSiteL();
   126         if ( ret != KErrNone )
   133         if ( ret != KErrNone )
   145     CDecPKCS8Data* pkcs8Data = TASN1DecPKCS8::DecodeDERL( aKey );
   152     CDecPKCS8Data* pkcs8Data = TASN1DecPKCS8::DecodeDERL( aKey );
   146     CleanupStack::PushL( pkcs8Data );
   153     CleanupStack::PushL( pkcs8Data );
   147     MPKCS8DecodedKeyPairData* keyPairData = pkcs8Data->KeyPairData();
   154     MPKCS8DecodedKeyPairData* keyPairData = pkcs8Data->KeyPairData();
   148     keyPairData->GetKeyIdentifierL( keyIdentifier );
   155     keyPairData->GetKeyIdentifierL( keyIdentifier );
   149 
   156 
   150     TTime startDate;
   157     TTime startDate( KZeroTime );
   151     TTime endDate;
   158     TTime endDate( KZeroTime );
   152     GetKeyValidityPeriodL( startDate, endDate, keyIdentifier );
   159     GetKeyValidityPeriodL( startDate, endDate, keyIdentifier );
   153 
   160 
   154     TInt err = KErrNone;
   161     TInt err = KErrNone;
   155     CCTKeyInfo* keyInfo = NULL;
   162     CCTKeyInfo* keyInfo = NULL;
   156     TBuf<KPrivaKeyLabelLength> keyLabel( KPrivateKeyLabel );
   163     TBuf<KPrivaKeyLabelLength> keyLabel( KPrivateKeyLabel );
   157     TKeyUsagePKCS15 keyUsage = KeyUsageL( keyIdentifier, pkcs8Data->Algorithm() );
   164     TKeyUsagePKCS15 keyUsage = KeyUsageL( keyIdentifier, pkcs8Data->Algorithm() );
   158     CleanupStack::PopAndDestroy( pkcs8Data );
   165     CleanupStack::PopAndDestroy( pkcs8Data );
   159     if (KeyAlreadyExistsL( startDate, endDate, keyIdentifier, keyUsage) )
   166     if ( KeyAlreadyExistsL( startDate, endDate, keyIdentifier, keyUsage) )
   160         {
   167         {
   161         User::Leave( KErrNone );
   168         return;
   162         }
   169         }
   163 
   170 
   164     TInt accessType( 0 );
   171     TInt accessType( 0 );
   165 
   172 
   166     accessType |= CCTKeyInfo::EExtractable;
   173     accessType |= CCTKeyInfo::EExtractable;
   167 
   174 
   168     for ( TInt i = 0; i < KAttempts; i++ )
   175     for ( TInt i = 0; i < KAttempts; i++ )
   169         {
   176         {
   170         CreateKeyLabelL( keyLabel );
   177         CreateKeyLabelL( keyLabel );
   171         // Should not use hardcoded index
   178         err = iWrapper->AddKey( iSelectedKeyStoreIndex, aKey, keyUsage, keyLabel,
   172         err = iWrapper->AddKey( 0, aKey, keyUsage, keyLabel,
       
   173             accessType, startDate, endDate, keyInfo );
   179             accessType, startDate, endDate, keyInfo );
   174         if ( err != KErrAlreadyExists )
   180         if ( err != KErrAlreadyExists )
   175             {
   181             {
   176             i = KAttempts;
   182             i = KAttempts;
   177             }
   183             }
   296 // ----------------------------------------------------------
   302 // ----------------------------------------------------------
   297 // CCertSaverModel::GetKeyValidityPeriodL()
   303 // CCertSaverModel::GetKeyValidityPeriodL()
   298 //
   304 //
   299 // ----------------------------------------------------------
   305 // ----------------------------------------------------------
   300 //
   306 //
   301 void CCertSaverModel::GetKeyValidityPeriodL(
   307 void CCertSaverModel::GetKeyValidityPeriodL( TTime& aStartDate, TTime& aEndDate,
   302     TTime& aStartDate,
   308         const TKeyIdentifier& aKeyIdentifier, const CArrayPtr<CX509Certificate>& aCertArray )
   303     TTime& aEndDate,
   309     {
   304     const TKeyIdentifier& aKeyIdentifier )
   310     const TTime timeNotSet( KZeroTime );
   305     {
   311 
   306 
   312     for( TInt index = 0; index < aCertArray.Count(); index++ )
   307     for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
   313         {
   308         {
   314         const CX509Certificate* cert = aCertArray.At( index );
   309         const CX509Certificate* cert = iParser.UserCertificates().At( i );
   315         if( cert->KeyIdentifierL() == aKeyIdentifier )
   310         if ( cert->KeyIdentifierL() == aKeyIdentifier )
   316             {
   311             {
   317             if ( aStartDate == timeNotSet || aStartDate > cert->ValidityPeriod().Start() )
   312             // Associated certificate found
       
   313             // In the first round aStartDate and aEndDate is initialised.
       
   314             if ( i == 0 || aStartDate > cert->ValidityPeriod().Start() )
       
   315                 {
   318                 {
   316                 aStartDate = cert->ValidityPeriod().Start();
   319                 aStartDate = cert->ValidityPeriod().Start();
   317                 }
   320                 }
   318             if ( i == 0 || aEndDate < cert->ValidityPeriod().Finish() )
   321             if ( aEndDate == timeNotSet || aEndDate < cert->ValidityPeriod().Finish() )
   319                 {
   322                 {
   320                 aEndDate = cert->ValidityPeriod().Finish();
   323                 aEndDate = cert->ValidityPeriod().Finish();
   321                 }
   324                 }
   322             }
   325             }
   323         }
   326         }
       
   327     }
       
   328 
       
   329 // ----------------------------------------------------------
       
   330 // CCertSaverModel::GetKeyValidityPeriodL()
       
   331 //
       
   332 // ----------------------------------------------------------
       
   333 //
       
   334 void CCertSaverModel::GetKeyValidityPeriodL( TTime& aStartDate, TTime& aEndDate,
       
   335         const TKeyIdentifier& aKeyIdentifier )
       
   336     {
       
   337     GetKeyValidityPeriodL( aStartDate, aEndDate, aKeyIdentifier, iParser.UserCertificates() );
       
   338     GetKeyValidityPeriodL( aStartDate, aEndDate, aKeyIdentifier, iParser.CACertificates() );
   324     }
   339     }
   325 
   340 
   326 // ----------------------------------------------------------
   341 // ----------------------------------------------------------
   327 // CCertSaverModel::CreateKeyLabelL()
   342 // CCertSaverModel::CreateKeyLabelL()
   328 //
   343 //
   368         {
   383         {
   369         for ( TInt i = 0; i < keyStoreCount; ++i )
   384         for ( TInt i = 0; i < keyStoreCount; ++i )
   370             {
   385             {
   371             TUid uid =
   386             TUid uid =
   372             iWrapper->UnifiedKeyStore().KeyStoreManager(i).Token().TokenType().Type();
   387             iWrapper->UnifiedKeyStore().KeyStoreManager(i).Token().TokenType().Type();
   373             if ( uid == TUid::Uid( KTokenTypeFileKeystore ) )
   388             if ( uid == iSelectedKeyStoreToken )
   374                 // if this is not found, we use the first one,
   389                 // if this is not found, we use the first one,
   375                 // which is already initialised
   390                 // which is already initialised
   376                 {
   391                 {
   377                 iSelectedKeyStore = i;
   392                 iSelectedKeyStoreIndex = i;
   378                 }
   393                 }
   379             }
   394             }
   380         }
   395         }
   381 
   396 
   382     for ( TInt i = 0; i < iParser.Keys().Count(); i++ )
   397     for ( TInt i = 0; i < iParser.Keys().Count(); i++ )
   512     ConstructMessageL( msgPtr );
   527     ConstructMessageL( msgPtr );
   513     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message );
   528     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message );
   514     CleanupStack::PopAndDestroy( message );
   529     CleanupStack::PopAndDestroy( message );
   515     CleanupStack::PushL( dlg );
   530     CleanupStack::PushL( dlg );
   516 
   531 
   517 
       
   518     dlg->PrepareLC( R_MESSAGE_QUERY_DOSAVE );
   532     dlg->PrepareLC( R_MESSAGE_QUERY_DOSAVE );
   519 
   533 
   520     HBufC* header = StringLoader::LoadLC( R_CERTSAVER_DETAILS_HEADING );
   534     HBufC* header = StringLoader::LoadLC( R_CERTSAVER_DETAILS_HEADING );
   521     dlg->QueryHeading()->SetTextL( header->Des() );
   535     dlg->QueryHeading()->SetTextL( header->Des() );
   522     CleanupStack::PopAndDestroy( header );
   536     CleanupStack::PopAndDestroy( header );
   618         // Compare fingerprint of listed certificates to
   632         // Compare fingerprint of listed certificates to
   619         // fingerprint of new certificate
   633         // fingerprint of new certificate
   620         // If the certificate is already in CACerts.dat,
   634         // If the certificate is already in CACerts.dat,
   621         // then don't save it
   635         // then don't save it
   622         if ( iNewCert->Fingerprint() == certificate->Fingerprint() &&
   636         if ( iNewCert->Fingerprint() == certificate->Fingerprint() &&
   623             (( *iEntries[i]).Handle().iTokenHandle.iTokenTypeUid == KFileTokensUid ) )
   637             (( *iEntries[i]).Handle().iTokenHandle.iTokenTypeUid == iSelectedCertStoreToken ) )
   624             {
   638             {
   625             found = ETrue;
   639             found = ETrue;
   626             }
   640             }
   627         delete certificate;
   641         delete certificate;
   628         certificate = NULL;
   642         certificate = NULL;
   664             HandleSaveErrorL( status );
   678             HandleSaveErrorL( status );
   665             User::Leave( KErrCancel );
   679             User::Leave( KErrCancel );
   666             }
   680             }
   667         }
   681         }
   668 
   682 
       
   683     // Select which store to use
       
   684     TUid certstoreToken;
       
   685     switch( iCertOwnerType )
       
   686         {
       
   687         case ECACertificate:
       
   688             certstoreToken = KFileCertStoreTokenUid;
       
   689             break;
       
   690         case EUserCertificate:
       
   691             certstoreToken = iSelectedCertStoreToken;
       
   692             break;
       
   693         case EPeerCertificate:
       
   694             certstoreToken = KTrustedServerTokenUid;
       
   695             break;
       
   696         default:
       
   697             certstoreToken = KFileCertStoreTokenUid;
       
   698             break;
       
   699         }
       
   700 
   669     // Get interface to writable store.
   701     // Get interface to writable store.
   670     TInt certstoreIndex( -1 );
   702     TInt certstoreIndex = -1;
   671     TInt count = iUnifiedCertStore->WritableCertStoreCount();
   703     TInt count = iUnifiedCertStore->WritableCertStoreCount();
   672     if ( count > 0 )
   704     if ( count > 0 )
   673         {
   705         {
   674         for ( TInt i = 0; i < count; i++ )
   706         for ( TInt i = 0; i < count; i++ )
   675             {
   707             {
   676             MCTWritableCertStore& writableCertStore =
   708             MCTWritableCertStore& writableCertStore =
   677                     iUnifiedCertStore->WritableCertStore( i );
   709                     iUnifiedCertStore->WritableCertStore( i );
   678 
   710 
   679             MCTToken& token = writableCertStore.Token();
   711             MCTToken& token = writableCertStore.Token();
   680             TUid tokenuid = token.Handle().iTokenTypeUid;
   712             TUid tokenuid = token.Handle().iTokenTypeUid;
   681             if ( ( tokenuid == KTrustedServerTokenUid ) && ( iCertOwnerType == EPeerCertificate ) ||
   713             if ( tokenuid == certstoreToken )
   682                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == ECACertificate ) ||
       
   683                  ( tokenuid == KFileTokensUid ) && ( iCertOwnerType == EUserCertificate ) )
       
   684                 {
   714                 {
   685                 certstoreIndex = i;
   715                 certstoreIndex = i;
   686                 break;
   716                 break;
   687                 }
   717                 }
   688             }
   718             }
   756             User::Leave( KErrExitApp );
   786             User::Leave( KErrExitApp );
   757             }
   787             }
   758 
   788 
   759         // takes ownership of trusterUids
   789         // takes ownership of trusterUids
   760         status = iWrapper->SetApplicability(
   790         status = iWrapper->SetApplicability(
   761             iUnifiedCertStore->WritableCertStore( certstoreIndex ), *(iEntries[0]), iTrusterUids );
   791             iUnifiedCertStore->WritableCertStore( certstoreIndex ),
       
   792             *( iEntries[ 0 ] ), iTrusterUids );
   762 
   793 
   763         // If error happened, show error note and give up. Otherwise, continue
   794         // If error happened, show error note and give up. Otherwise, continue
   764         if ( status )
   795         if ( status )
   765             {
   796             {
   766             HandleSaveErrorL( status );
   797             HandleSaveErrorL( status );
   767             User::Leave( KErrExitApp );
   798             User::Leave( KErrExitApp );
   768             }
   799             }
   769 
   800 
   770         // Downloaded certificate is trusted by default
   801         // Downloaded certificate is trusted by default
   771         status = iWrapper->SetTrust(
   802         status = iWrapper->SetTrust(
   772             iUnifiedCertStore->WritableCertStore(certstoreIndex), *(iEntries[0]), ETrue );
   803             iUnifiedCertStore->WritableCertStore( certstoreIndex ),
       
   804             *( iEntries [ 0 ] ), ETrue );
   773         if ( status )
   805         if ( status )
   774             {
   806             {
   775             HandleSaveErrorL( status );
   807             HandleSaveErrorL( status );
   776             }
   808             }
   777 
   809 
  1106     dateFormatString = iAppUi->CoeEnv()->AllocReadResourceLC(
  1138     dateFormatString = iAppUi->CoeEnv()->AllocReadResourceLC(
  1107         R_QTN_DATE_USUAL_WITH_ZERO );
  1139         R_QTN_DATE_USUAL_WITH_ZERO );
  1108     // format the date to user readable format. The format is locale dependent
  1140     // format the date to user readable format. The format is locale dependent
  1109     finishValue.FormatL( finishString, *dateFormatString );
  1141     finishValue.FormatL( finishString, *dateFormatString );
  1110     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString );
  1142     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finishString );
  1111     CleanupStack::PopAndDestroy(); // dateFormatString
  1143     CleanupStack::PopAndDestroy( dateFormatString );
  1112     aMessage.Append( finishString );
  1144     aMessage.Append( finishString );
  1113     AddNewlinesToMessage( aMessage );
  1145     AddNewlinesToMessage( aMessage );
  1114     }
  1146     }
  1115 
  1147 
  1116 // ----------------------------------------------------------
  1148 // ----------------------------------------------------------
  1492 //
  1524 //
  1493 void CCertSaverModel::SavePKCS12L()
  1525 void CCertSaverModel::SavePKCS12L()
  1494     {
  1526     {
  1495     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1527     HBufC* message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1496     TPtr msgPtr = message->Des();
  1528     TPtr msgPtr = message->Des();
  1497     ConstructPKCS12QueryMsgL(msgPtr, iParser.Keys().Count(),
  1529 	TInt keysCount = iParser.Keys().Count();
  1498                             iParser.UserCertificates().Count(),
  1530     TInt userCertificateCount = iParser.UserCertificates().Count();
  1499                             iParser.CACertificates().Count() );
  1531     TInt caCertificateCount = iParser.CACertificates().Count();
  1500     TBool save = DoMessageQueryL(
  1532     ConstructPKCS12QueryMsgL( msgPtr, keysCount, userCertificateCount, caCertificateCount );
  1501         R_MESSAGE_QUERY_DOSAVE, R_CERTSAVER_HEADER_PKCS12_FILE_CONTAINS,
  1533     TBool save = DoMessageQueryL( R_MESSAGE_QUERY_DOSAVE,
  1502         *message );
  1534             R_CERTSAVER_HEADER_PKCS12_FILE_CONTAINS, *message );
  1503     CleanupStack::PopAndDestroy( message );
  1535     CleanupStack::PopAndDestroy( message );
  1504     message = NULL;
  1536     message = NULL;
  1505     if ( !save )
  1537     if ( !save )
  1506         {
  1538         {
  1507         ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED );
  1539         ShowInformationNoteL( R_CERTSAVER_PKCS12_DISCARDED );
  1508         User::Leave( KErrExitApp );
  1540         User::Leave( KErrExitApp );
  1509         }
  1541         }
       
  1542 
       
  1543     if ( keysCount )
       
  1544         {
       
  1545         CAknQueryDialog* protectWithPasswordQuery = CAknQueryDialog::NewL();
       
  1546         TInt buttonId = protectWithPasswordQuery->ExecuteLD( R_CERTSAVER_PROTECT_WITH_PASSWORD );
       
  1547         if ( buttonId == EAknSoftkeyYes )
       
  1548             {
       
  1549             iSelectedKeyStoreToken = KFileKeyStoreTokenUid;
       
  1550             iSelectedCertStoreToken = KFileCertStoreTokenUid;
       
  1551             }
       
  1552         else
       
  1553             {
       
  1554             iSelectedKeyStoreToken = KDeviceKeyStoreTokenUid;
       
  1555             iSelectedCertStoreToken = KDeviceCertStoreTokenUid;
       
  1556             }
       
  1557         }
       
  1558 
  1510     TInt status = KErrNone;
  1559     TInt status = KErrNone;
  1511     // save private keys
  1560     // save private keys
  1512     TRAP( status, SavePrivateKeyL() );
  1561     TRAP( status, SavePrivateKeyL() );
  1513 
  1562 
  1514     // save user certificates if private key was saved.
  1563     // save user certificates if private key was saved.
  1515     if ( ( iSavedKeysCount > 0 || iKeyAlreadyExists ) && iParser.UserCertificates().Count() > 0 )
  1564     if ( ( iSavedKeysCount > 0 || iKeyAlreadyExists ) && userCertificateCount > 0 )
  1516         {
  1565         {
  1517         for ( TInt i = 0; i < iParser.UserCertificates().Count(); i++ )
  1566         for ( TInt i = 0; i < userCertificateCount; i++ )
  1518             {
  1567             {
  1519             const CX509Certificate* cert = iParser.UserCertificates().At(i);
  1568             const CX509Certificate* cert = iParser.UserCertificates().At(i);
  1520             iCertOwnerType = EUserCertificate;
  1569             iCertOwnerType = EUserCertificate;
  1521             iCertFormat = EX509Certificate;
  1570             iCertFormat = EX509Certificate;
  1522             iNewCert = cert;
  1571             iNewCert = cert;
  1525                 {
  1574                 {
  1526                 User::Leave( KErrExitApp );
  1575                 User::Leave( KErrExitApp );
  1527                 }
  1576                 }
  1528             }
  1577             }
  1529         }
  1578         }
       
  1579 
  1530     // save CA certificates
  1580     // save CA certificates
  1531     if ( iParser.CACertificates().Count() > 0 )
  1581     if ( caCertificateCount > 0 )
  1532         {
  1582         {
  1533         for ( TInt i = 0; i < iParser.CACertificates().Count(); i++ )
  1583         for ( TInt i = 0; i < caCertificateCount; i++ )
  1534             {
  1584             {
  1535             const CX509Certificate* cert = iParser.CACertificates().At( i );
  1585             const CX509Certificate* cert = iParser.CACertificates().At( i );
  1536             iCertOwnerType = ECACertificate;
  1586             iCertOwnerType = ECACertificate;
  1537             iCertFormat = EX509Certificate;
  1587             iCertFormat = EX509Certificate;
  1538             iNewCert = cert;
  1588             iNewCert = cert;
  1541                 {
  1591                 {
  1542                 User::Leave( KErrExitApp );
  1592                 User::Leave( KErrExitApp );
  1543                 }
  1593                 }
  1544             }
  1594             }
  1545         }
  1595         }
       
  1596 
  1546     if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0
  1597     if ( iSavedCACertsCount != 0 || iSavedKeysCount != 0
  1547         || iSavedUserCertsCount != 0 )
  1598         || iSavedUserCertsCount != 0 )
  1548         {
  1599         {
  1549         message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1600         message = HBufC::NewLC( KMaxLengthTextMeassageBody );
  1550         TPtr msgPtr2 = message->Des();
  1601         TPtr msgPtr2 = message->Des();
  1551         ConstructPKCS12QueryMsgL(
  1602         ConstructPKCS12QueryMsgL(
  1552             msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount );
  1603             msgPtr2, iSavedKeysCount, iSavedUserCertsCount, iSavedCACertsCount );
  1553         DoMessageQueryL(
  1604         DoMessageQueryL( R_MESSAGE_QUERY_SAVED, R_CERTSAVER_HEADER_SAVED, *message );
  1554             R_MESSAGE_QUERY_SAVED, R_CERTSAVER_HEADER_SAVED, *message );
       
  1555         CleanupStack::PopAndDestroy( message );
  1605         CleanupStack::PopAndDestroy( message );
  1556         }
  1606         }
  1557     else
  1607     else
  1558         {
  1608         {
  1559         ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED );
  1609         ShowInformationNoteL( R_QTN_CM_PKCS12_SAVING_FAILED );