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