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