cpsecplugins/cpadvancedsecplugin/src/advsecsettingscertmover_symbian.cpp
changeset 63 989397f9511c
equal deleted inserted replaced
62:3255e7d5bd67 63:989397f9511c
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Helper class to move certificates
       
    15 *
       
    16 */
       
    17 
       
    18 #include "advsecsettingscertmover_symbian.h"
       
    19 #include "advsecsettingsstoreuids.h"
       
    20 #include <unifiedcertstore.h>           // CUnifiedCertStore
       
    21 #include <unifiedkeystore.h>            // CUnifiedKeyStore
       
    22 #include <cctcertinfo.h>                // CCTCertInfo
       
    23 #include <mctwritablecertstore.h>       // MCTWritableCertStore
       
    24 #include <mctkeystoremanager.h>         // MCTKeyStoreManager
       
    25 
       
    26 const TInt KMaxBufferLength = 0x3000;   // 12kB, for keys and certificates
       
    27 _LIT_SECURITY_POLICY_C1( KKeyStoreUsePolicy, ECapabilityReadUserData );
       
    28 
       
    29 // TODO: replace with proper logging
       
    30 #ifdef _DEBUG
       
    31 #define TRACE(x)        RDebug::Printf(x)
       
    32 #define TRACE1(x, y)    RDebug::Printf((x), (y))
       
    33 #define TRACE2(x, y, z) RDebug::Printf((x), (y), (z))
       
    34 #else
       
    35 #define TRACE(x)
       
    36 #define TRACE1(x, y)
       
    37 #define TRACE2(x, y, z)
       
    38 #endif
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CAdvSecSettingsCertMover::NewL()
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CAdvSecSettingsCertMover *CAdvSecSettingsCertMover::NewL(RFs &aFs)
       
    48 {
       
    49     TRACE("CAdvSecSettingsCertMover::NewL()");
       
    50     CAdvSecSettingsCertMover* self = new( ELeave ) CAdvSecSettingsCertMover(aFs);
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop(self);
       
    54     return self;
       
    55 }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CAdvSecSettingsCertMover::~CAdvSecSettingsCertMover()
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CAdvSecSettingsCertMover::~CAdvSecSettingsCertMover()
       
    62 {
       
    63     TRACE("CAdvSecSettingsCertMover::~CAdvSecSettingsCertMover()");
       
    64     Cancel();
       
    65     delete iCertStore;
       
    66     iTargetCertStore = NULL;
       
    67     delete iCertFilter;
       
    68     iCerts.Close();
       
    69 
       
    70     delete iKeyStore;
       
    71     iSourceKeyStore = NULL;
       
    72     iTargetKeyStore = NULL;
       
    73     delete iKeyFilter;
       
    74     iKeys.Close();
       
    75     if (iSavedKeyInfo) {
       
    76         iSavedKeyInfo->Release();
       
    77     }
       
    78 
       
    79     delete iDataBuffer;
       
    80     iClientStatus = NULL;
       
    81     iCertInfo = NULL;
       
    82 }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CAdvSecSettingsCertMover::Move()
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CAdvSecSettingsCertMover::Move(const CCTCertInfo &aCert,
       
    89     TInt aSourceCertStoreTokenId, TInt aTargetCertStoreTokenId,
       
    90     TRequestStatus &aStatus)
       
    91 {
       
    92     TRACE("CAdvSecSettingsCertMover::Move()");
       
    93     aStatus = KRequestPending;
       
    94     if (!iClientStatus) {
       
    95         iClientStatus = &aStatus;
       
    96 
       
    97         iCertInfo = &aCert;
       
    98         iSourceCertStoreTokenId = aSourceCertStoreTokenId;
       
    99         iTargetCertStoreTokenId = aTargetCertStoreTokenId;
       
   100 
       
   101         if (iState <= EIdle) {
       
   102             // Start move operation if initializations are complete.
       
   103             if (iState == EIdle) {
       
   104                 TRAPD(err, StartMoveOperationL());
       
   105                 if (err) {
       
   106                     TRACE1("CAdvSecSettingsCertMover::Move(), error %d", err);
       
   107                     User::RequestComplete(iClientStatus, err);
       
   108                     iClientStatus = NULL;
       
   109                 }
       
   110             }
       
   111             // If initializations are not complete yet, then moving
       
   112             // starts in RunL() after initializations are completed.
       
   113         } else {
       
   114             // Possibly initializations have failed.
       
   115             TRACE("CAdvSecSettingsCertMover::Move(), RequestComplete KErrGeneral");
       
   116             User::RequestComplete(iClientStatus, KErrGeneral);
       
   117             iClientStatus = NULL;
       
   118         }
       
   119     } else {
       
   120         TRACE("CAdvSecSettingsCertMover::Move(), RequestComplete KErrInUse");
       
   121         TRequestStatus* status = &aStatus;
       
   122         User::RequestComplete(status, KErrInUse);
       
   123     }
       
   124 }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CAdvSecSettingsCertMover::DoCancel()
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CAdvSecSettingsCertMover::DoCancel()
       
   131 {
       
   132     TRACE("CAdvSecSettingsCertMover::DoCancel()");
       
   133     switch (iState) {
       
   134     case EInitializingCertStore:
       
   135         iCertStore->CancelInitialize();
       
   136         iState = ENotInitialized;
       
   137         break;
       
   138     case EInitializingKeyStore:
       
   139         iKeyStore->CancelInitialize();
       
   140         iState = ENotInitialized;
       
   141         break;
       
   142     case EMovingKeyListingKeys:
       
   143         iKeyStore->CancelList();
       
   144         iState = EIdle;
       
   145         break;
       
   146     case EMovingKeyExportingKeys:
       
   147         iSourceKeyStore->CancelExportKey();
       
   148         iState = EIdle;
       
   149         break;
       
   150     case EMovingKeyImportingKeys:
       
   151         iTargetKeyStore->CancelImportKey();
       
   152         iState = EIdle;
       
   153         break;
       
   154     case EMovingKeyDeletingOriginal:
       
   155         iSourceKeyStore->CancelDeleteKey();
       
   156         iState = EIdle;
       
   157         break;
       
   158     case EMovingCertListingCerts:
       
   159         iCertStore->CancelList();
       
   160         iState = EIdle;
       
   161         break;
       
   162     case EMovingCertRetrievingCerts:
       
   163         iSourceCertStore->CancelRetrieve();
       
   164         iState = EIdle;
       
   165         break;
       
   166     case EMovingCertAddingCerts:
       
   167         iTargetCertStore->CancelAdd();
       
   168         iState = EIdle;
       
   169         break;
       
   170     case EMovingCertDeletingOriginal:
       
   171         iSourceCertStore->CancelRemove();
       
   172         iState = EIdle;
       
   173         break;
       
   174     default:
       
   175         break;
       
   176     }
       
   177 
       
   178     if (iClientStatus) {
       
   179         TRACE("CAdvSecSettingsCertMover::DoCancel(), RequestComplete KErrCancel");
       
   180         User::RequestComplete(iClientStatus, KErrCancel);
       
   181         iClientStatus = NULL;
       
   182     }
       
   183 }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CAdvSecSettingsCertMover::RunL()
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CAdvSecSettingsCertMover::RunL()
       
   190 {
       
   191     TRACE2("CAdvSecSettingsCertMover::RunL(), iState=%d, iStatus.Int()=%d", iState, iStatus.Int());
       
   192     User::LeaveIfError(iStatus.Int());
       
   193 
       
   194     switch (iState) {
       
   195     case EInitializingCertStore:
       
   196         iKeyStore->Initialize(iStatus);
       
   197         iState = EInitializingKeyStore;
       
   198         SetActive();
       
   199         break;
       
   200     case EInitializingKeyStore:
       
   201         iState = EIdle;
       
   202         if (iClientStatus) {
       
   203             StartMoveOperationL();
       
   204         }
       
   205         break;
       
   206     case EMovingKeyListingKeys:
       
   207         ExportFirstKeyL();
       
   208         break;
       
   209     case EMovingKeyExportingKeys:
       
   210         SaveExportedKeyL();
       
   211         break;
       
   212     case EMovingKeyImportingKeys:
       
   213         DeleteOriginalKeyL();
       
   214         break;
       
   215     case EMovingKeyDeletingOriginal:
       
   216         ExportNextKeyL();
       
   217         break;
       
   218     case EMovingCertListingCerts:
       
   219         RetrieveFirstCertL();
       
   220         break;
       
   221     case EMovingCertRetrievingCerts:
       
   222         SaveRetrievedCertL();
       
   223         break;
       
   224     case EMovingCertAddingCerts:
       
   225         DeleteOriginalCertL();
       
   226         break;
       
   227     case EMovingCertDeletingOriginal:
       
   228         RetrieveNextCertL();
       
   229         break;
       
   230     default:
       
   231         ASSERT(EFalse);
       
   232         break;
       
   233     }
       
   234 }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CAdvSecSettingsCertMover::RunError()
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 TInt CAdvSecSettingsCertMover::RunError(TInt aError)
       
   241 {
       
   242     TRACE1("CAdvSecSettingsCertMover::RunError(), aError=%d", aError);
       
   243     if (iClientStatus) {
       
   244         TRACE1("CAdvSecSettingsCertMover::RunError(), RequestComplete %d", aError);
       
   245         User::RequestComplete(iClientStatus, aError);
       
   246         iClientStatus = NULL;
       
   247     }
       
   248     if (iState < EIdle) {
       
   249         iState = EFailed;
       
   250     } else {
       
   251         iState = EIdle;
       
   252     }
       
   253     return KErrNone;
       
   254 }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CAdvSecSettingsCertMover::CAdvSecSettingsCertMover()
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 CAdvSecSettingsCertMover::CAdvSecSettingsCertMover(RFs &aFs) :
       
   261     CActive(CActive::EPriorityLow), iFs(aFs), iDataPtr(0,0)
       
   262 {
       
   263     CActiveScheduler::Add(this);
       
   264 }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CAdvSecSettingsCertMover::ConstructL()
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CAdvSecSettingsCertMover::ConstructL()
       
   271 {
       
   272     TRACE("CAdvSecSettingsCertMover::ConstructL()");
       
   273     const TBool KWriteMode = ETrue;
       
   274     iCertStore = CUnifiedCertStore::NewL(iFs, KWriteMode);
       
   275     iKeyStore = CUnifiedKeyStore::NewL(iFs);
       
   276 
       
   277     iDataBuffer = HBufC8::New(KMaxBufferLength);
       
   278     iDataPtr.Set(iDataBuffer->Des());
       
   279 
       
   280     iCertStore->Initialize(iStatus);
       
   281     iState = EInitializingCertStore;
       
   282     SetActive();
       
   283 }
       
   284 
       
   285 // ---------------------------------------------------------------------------
       
   286 // CAdvSecSettingsCertMover::StartMoveOperationL()
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 void CAdvSecSettingsCertMover::StartMoveOperationL()
       
   290 {
       
   291     TRACE("CAdvSecSettingsCertMover::StartMoveOperationL()");
       
   292     FindSourceAndTargetKeyStoresL();
       
   293     FindSourceAndTargetCertStoreL();
       
   294     StartMovingKeysL();
       
   295 }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CAdvSecSettingsCertMover::FindSourceAndTargetKeyStoresL()
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CAdvSecSettingsCertMover::FindSourceAndTargetKeyStoresL()
       
   302 {
       
   303     TRACE("CAdvSecSettingsCertMover::FindSourceAndTargetKeyStoresL()");
       
   304     TInt keyStoreSourceTokenId = CorrespondingKeyStoreTokenId(iSourceCertStoreTokenId);
       
   305     TInt keyStoreTargetTokenId = CorrespondingKeyStoreTokenId(iTargetCertStoreTokenId);
       
   306     TInt keyStoreSourceIndex = KErrNotFound;
       
   307     TInt keyStoreTargetIndex = KErrNotFound;
       
   308 
       
   309     TInt count = iKeyStore->KeyStoreManagerCount();
       
   310     for (TInt index = 0; index < count; index++) {
       
   311         MCTKeyStoreManager& keystoremanager = iKeyStore->KeyStoreManager(index);
       
   312         MCTToken& token = keystoremanager.Token();
       
   313         TUid tokenTypeUid = token.Handle().iTokenTypeUid;
       
   314         if (tokenTypeUid.iUid == keyStoreSourceTokenId) {
       
   315             keyStoreSourceIndex = index;
       
   316         }
       
   317         if (tokenTypeUid.iUid == keyStoreTargetTokenId) {
       
   318             keyStoreTargetIndex = index;
       
   319         }
       
   320     }
       
   321 
       
   322     if (keyStoreSourceIndex == KErrNotFound || keyStoreTargetIndex == KErrNotFound) {
       
   323         User::Leave(KErrNotFound);
       
   324     }
       
   325 
       
   326     iSourceKeyStore = &( iKeyStore->KeyStoreManager(keyStoreSourceIndex) );
       
   327     iTargetKeyStore = &( iKeyStore->KeyStoreManager(keyStoreTargetIndex) );
       
   328 }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CAdvSecSettingsCertMover::FindSourceAndTargetCertStoreL()
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CAdvSecSettingsCertMover::FindSourceAndTargetCertStoreL()
       
   335 {
       
   336     TRACE("CAdvSecSettingsCertMover::FindSourceAndTargetCertStoreL()");
       
   337     TInt certStoreSourceIndex = KErrNotFound;
       
   338     TInt certStoreTargetIndex = KErrNotFound;
       
   339 
       
   340     TInt count = iCertStore->WritableCertStoreCount();
       
   341     for (TInt index = 0; index < count; index++) {
       
   342         MCTWritableCertStore& writablestore = iCertStore->WritableCertStore(index);
       
   343         MCTToken& token = writablestore.Token();
       
   344         TUid tokenTypeUid = token.Handle().iTokenTypeUid;
       
   345         if (tokenTypeUid.iUid == iSourceCertStoreTokenId) {
       
   346             certStoreSourceIndex = index;
       
   347         }
       
   348         if (tokenTypeUid.iUid == iTargetCertStoreTokenId) {
       
   349             certStoreTargetIndex = index;
       
   350         }
       
   351     }
       
   352 
       
   353     if (certStoreSourceIndex == KErrNotFound || certStoreTargetIndex == KErrNotFound) {
       
   354         User::Leave(KErrNotFound);
       
   355     }
       
   356 
       
   357     iSourceCertStore = &( iCertStore->WritableCertStore(certStoreSourceIndex) );
       
   358     iTargetCertStore = &( iCertStore->WritableCertStore(certStoreTargetIndex) );
       
   359 }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CAdvSecSettingsCertMover::CorrespondingKeyStoreTokenId()
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 TInt CAdvSecSettingsCertMover::CorrespondingKeyStoreTokenId(TInt aCertStoreTokenId)
       
   366 {
       
   367     TInt keyStoreTokenId = KErrNotFound;
       
   368     switch (aCertStoreTokenId) {
       
   369     case KAdvSecSettingsFileCertStore:
       
   370         keyStoreTokenId = KAdvSecSettingsFileKeyStore;
       
   371         break;
       
   372     case KAdvSecSettingsDeviceCertStore:
       
   373         keyStoreTokenId = KAdvSecSettingsDeviceKeyStore;
       
   374         break;
       
   375     default:
       
   376         ASSERT(EFalse);     // Unsupported cert store token id used
       
   377         break;
       
   378     }
       
   379     return keyStoreTokenId;
       
   380 }
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // CAdvSecSettingsCertMover::StartMovingKeysL()
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CAdvSecSettingsCertMover::StartMovingKeysL()
       
   387 {
       
   388     TRACE("CAdvSecSettingsCertMover::StartMovingKeysL()");
       
   389     if (iKeyFilter) {
       
   390         delete iKeyFilter;
       
   391         iKeyFilter = NULL;
       
   392     }
       
   393     iKeyFilter = new( ELeave ) TCTKeyAttributeFilter;
       
   394     iKeyFilter->iKeyId = iCertInfo->SubjectKeyId();
       
   395     iKeyFilter->iPolicyFilter =  TCTKeyAttributeFilter::EAllKeys;
       
   396     iKeyStore->List(iKeys, *iKeyFilter, iStatus);
       
   397     iState = EMovingKeyListingKeys;
       
   398     SetActive();
       
   399 }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CAdvSecSettingsCertMover::ExportFirstKeyL()
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CAdvSecSettingsCertMover::ExportFirstKeyL()
       
   406 {
       
   407     TRACE1("CAdvSecSettingsCertMover::ExportFirstKeyL(), iKeys.Count()=%d", iKeys.Count());
       
   408     iKeyIndex = 0;
       
   409     ExportOneKeyL();
       
   410 }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CAdvSecSettingsCertMover::ExportOneKeyL()
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void CAdvSecSettingsCertMover::ExportOneKeyL()
       
   417 {
       
   418     TRACE("CAdvSecSettingsCertMover::ExportOneKeyL()");
       
   419     if (iKeyIndex < iKeys.Count()) {
       
   420         const CCTKeyInfo& keyInfo = *(iKeys[iKeyIndex]);
       
   421         iSourceKeyStore->ExportKey(keyInfo.Handle(), iDataBuffer, iStatus);
       
   422         iState = EMovingKeyExportingKeys;
       
   423         SetActive();
       
   424     } else {
       
   425         TRACE("CAdvSecSettingsCertMover::ExportOneKeyL(), all done");
       
   426         StartMovingCertificatesL();
       
   427     }
       
   428 }
       
   429 
       
   430 // ---------------------------------------------------------------------------
       
   431 // CAdvSecSettingsCertMover::ExportNextKeyL()
       
   432 // ---------------------------------------------------------------------------
       
   433 //
       
   434 void CAdvSecSettingsCertMover::ExportNextKeyL()
       
   435 {
       
   436     TRACE("CAdvSecSettingsCertMover::ExportNextKeyL()");
       
   437     ++iKeyIndex;
       
   438     ExportOneKeyL();
       
   439 }
       
   440 
       
   441 // ---------------------------------------------------------------------------
       
   442 // CAdvSecSettingsCertMover::SaveExportedKeyL()
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 void CAdvSecSettingsCertMover::SaveExportedKeyL()
       
   446 {
       
   447     TRACE("CAdvSecSettingsCertMover::SaveExportedKeyL()");
       
   448     const CCTKeyInfo& keyInfo = *(iKeys[iKeyIndex]);
       
   449     iSourceKeyHandle = keyInfo.Handle();
       
   450 
       
   451     // TODO: is this needed? should iSavedKeyInfo be always used?
       
   452     // Keys having CCTKeyInfo::ELocal access type cannot be imported.
       
   453     // Workaround is to create almost identical copy of CCTKeyInfo without
       
   454     // ELocal access type flag. UsePolicy is also updated.
       
   455     TInt accessType = keyInfo.AccessType();
       
   456     if (accessType & CCTKeyInfo::ELocal) {
       
   457         accessType ^= CCTKeyInfo::ELocal;
       
   458 
       
   459         HBufC* label = keyInfo.Label().AllocLC();
       
   460         if (iSavedKeyInfo) {
       
   461             iSavedKeyInfo->Release();
       
   462             iSavedKeyInfo = NULL;
       
   463         }
       
   464         iSavedKeyInfo = CCTKeyInfo::NewL( keyInfo.ID(), keyInfo.Usage(),
       
   465             keyInfo.Size(), NULL, label, keyInfo.Token(), keyInfo.HandleID(),
       
   466             KKeyStoreUsePolicy, keyInfo.ManagementPolicy(),keyInfo.Algorithm(),
       
   467             keyInfo.AccessType(), keyInfo.Native(), keyInfo.StartDate(),
       
   468             keyInfo.EndDate() );
       
   469         CleanupStack::Pop(label);
       
   470 
       
   471         iTargetKeyStore->ImportKey(*iDataBuffer, iSavedKeyInfo, iStatus);
       
   472     } else {
       
   473         iTargetKeyStore->ImportKey(*iDataBuffer, iKeys[iKeyIndex], iStatus);
       
   474     }
       
   475     iState = EMovingKeyImportingKeys;
       
   476     SetActive();
       
   477 }
       
   478 
       
   479 // ---------------------------------------------------------------------------
       
   480 // CAdvSecSettingsCertMover::DeleteOriginalKeyL()
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 void CAdvSecSettingsCertMover::DeleteOriginalKeyL()
       
   484 {
       
   485     TRACE("CAdvSecSettingsCertMover::DeleteOriginalKeyL()");
       
   486     iSourceKeyStore->DeleteKey(iSourceKeyHandle, iStatus);
       
   487     iState = EMovingKeyDeletingOriginal;
       
   488     SetActive();
       
   489 }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CAdvSecSettingsCertMover::StartMovingCertificatesL()
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 void CAdvSecSettingsCertMover::StartMovingCertificatesL()
       
   496 {
       
   497     TRACE("CAdvSecSettingsCertMover::StartMovingCertificatesL()");
       
   498     if (iCertFilter) {
       
   499         delete iCertFilter;
       
   500         iCertFilter = NULL;
       
   501     }
       
   502     iCertFilter = CCertAttributeFilter::NewL();
       
   503     iCertFilter->SetOwnerType(EUserCertificate);
       
   504     iCertFilter->SetSubjectKeyId(iCertInfo->SubjectKeyId());
       
   505     iCertStore->List(iCerts, *iCertFilter, iStatus);
       
   506     iState = EMovingCertListingCerts;
       
   507     SetActive();
       
   508 }
       
   509 
       
   510 // ---------------------------------------------------------------------------
       
   511 // CAdvSecSettingsCertMover::RetrieveFirstCertL()
       
   512 // ---------------------------------------------------------------------------
       
   513 //
       
   514 void CAdvSecSettingsCertMover::RetrieveFirstCertL()
       
   515 {
       
   516     TRACE1("CAdvSecSettingsCertMover::RetrieveFirstCertL(), iCerts.Count()=%d", iCerts.Count());
       
   517     iCertIndex = 0;
       
   518     RetrieveOneCertL();
       
   519 }
       
   520 
       
   521 // ---------------------------------------------------------------------------
       
   522 // CAdvSecSettingsCertMover::RetrieveOneCertL()
       
   523 // ---------------------------------------------------------------------------
       
   524 //
       
   525 void CAdvSecSettingsCertMover::RetrieveOneCertL()
       
   526 {
       
   527     TRACE("CAdvSecSettingsCertMover::RetrieveOneCertL()");
       
   528     if (iCertIndex < iCerts.Count()) {
       
   529         const CCTCertInfo& certInfo = *(iCerts[iCertIndex]);
       
   530         iSourceCertStore->Retrieve(certInfo, iDataPtr, iStatus);
       
   531         iState = EMovingCertRetrievingCerts;
       
   532         SetActive();
       
   533     } else {
       
   534         TRACE("CAdvSecSettingsCertMover::RetrieveOneCertL(), all done");
       
   535         iState = EIdle;
       
   536         User::RequestComplete(iClientStatus, KErrNone);
       
   537         iClientStatus = NULL;
       
   538     }
       
   539 }
       
   540 
       
   541 // ---------------------------------------------------------------------------
       
   542 // CAdvSecSettingsCertMover::RetrieveNextCertL()
       
   543 // ---------------------------------------------------------------------------
       
   544 //
       
   545 void CAdvSecSettingsCertMover::RetrieveNextCertL()
       
   546 {
       
   547     TRACE("CAdvSecSettingsCertMover::RetrieveNextCertL()");
       
   548     ++iCertIndex;
       
   549     RetrieveOneCertL();
       
   550 }
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 // CAdvSecSettingsCertMover::SaveRetrievedCertL()
       
   554 // ---------------------------------------------------------------------------
       
   555 //
       
   556 void CAdvSecSettingsCertMover::SaveRetrievedCertL()
       
   557 {
       
   558     TRACE("CAdvSecSettingsCertMover::SaveRetrievedCertL()");
       
   559     const CCTCertInfo& certInfo = *(iCerts[iCertIndex]);
       
   560     iTargetCertStore->Add(certInfo.Label(), EX509Certificate, EUserCertificate,
       
   561         &(certInfo.SubjectKeyId()), &(certInfo.IssuerKeyId()), *iDataBuffer, iStatus);
       
   562     iState = EMovingCertAddingCerts;
       
   563     SetActive();
       
   564 }
       
   565 
       
   566 // ---------------------------------------------------------------------------
       
   567 // CAdvSecSettingsCertMover::DeleteOriginalCertL()
       
   568 // ---------------------------------------------------------------------------
       
   569 //
       
   570 void CAdvSecSettingsCertMover::DeleteOriginalCertL()
       
   571 {
       
   572     TRACE("CAdvSecSettingsCertMover::DeleteOriginalCertL()");
       
   573     const CCTCertInfo& certInfo = *(iCerts[iCertIndex]);
       
   574     iSourceCertStore->Remove(certInfo, iStatus);
       
   575     iState = EMovingCertDeletingOriginal;
       
   576     SetActive();
       
   577 }
       
   578