os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_engine.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "certtool_engine.h"
sl@0
    20
#include "certtool_controller.h"
sl@0
    21
#include "keytool_controller.h"
sl@0
    22
sl@0
    23
sl@0
    24
/*static*/ CCertToolEngine* CCertToolEngine::NewLC(CCertToolController* aController)
sl@0
    25
	{
sl@0
    26
	CCertToolEngine* self = new (ELeave) CCertToolEngine(aController);
sl@0
    27
	CleanupStack::PushL(self);
sl@0
    28
	self->ConstructL();
sl@0
    29
	return self;
sl@0
    30
	}
sl@0
    31
	
sl@0
    32
/*static*/ CCertToolEngine* CCertToolEngine::NewL(CCertToolController* aController)
sl@0
    33
	{
sl@0
    34
	CCertToolEngine* self = CCertToolEngine::NewLC(aController);
sl@0
    35
	CleanupStack::Pop(self);
sl@0
    36
	return self;
sl@0
    37
	}
sl@0
    38
	
sl@0
    39
CCertToolEngine::CCertToolEngine(CCertToolController* aController) : CActive(EPriorityNormal)
sl@0
    40
	{
sl@0
    41
	iCurrentAction = EIdle;
sl@0
    42
	iController = aController;
sl@0
    43
	}
sl@0
    44
	
sl@0
    45
CCertToolEngine::~CCertToolEngine()
sl@0
    46
	{
sl@0
    47
	Cancel();	
sl@0
    48
	delete iHandler;		
sl@0
    49
	delete iKeyHandler;
sl@0
    50
	delete iKeyController;
sl@0
    51
sl@0
    52
	delete iKeyStore;
sl@0
    53
	iFsKeyStore.Close();	
sl@0
    54
	delete iCertStore;		
sl@0
    55
	iFs.Close();			
sl@0
    56
	delete iScheduler;
sl@0
    57
	}
sl@0
    58
	
sl@0
    59
void CCertToolEngine::ConstructL()
sl@0
    60
	{
sl@0
    61
	iScheduler = new(ELeave) CActiveScheduler;
sl@0
    62
	CActiveScheduler::Install(iScheduler);
sl@0
    63
	
sl@0
    64
	User::LeaveIfError(iFs.Connect());
sl@0
    65
	
sl@0
    66
	iCertStore = CUnifiedCertStore::NewL(iFs, ETrue);
sl@0
    67
sl@0
    68
	User::LeaveIfError(iFsKeyStore.Connect());
sl@0
    69
sl@0
    70
	iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
sl@0
    71
	
sl@0
    72
	CActiveScheduler::Add(this);	
sl@0
    73
	}
sl@0
    74
sl@0
    75
void CCertToolEngine::RunL()
sl@0
    76
	{
sl@0
    77
	if (iStatus.Int() != KErrNone)
sl@0
    78
		{
sl@0
    79
		User::Leave(iStatus.Int());
sl@0
    80
		}
sl@0
    81
		
sl@0
    82
	switch (iState)
sl@0
    83
		{
sl@0
    84
		case EInitialiseKeyStore:
sl@0
    85
			{
sl@0
    86
			iKeyHandler->DoCommandL(*iKeyStore, iParam);		
sl@0
    87
			iState = EDone;
sl@0
    88
			}
sl@0
    89
			break;		
sl@0
    90
		case EInitialise:
sl@0
    91
			{
sl@0
    92
			iHandler->DoCommandL(*iCertStore, iParam);		
sl@0
    93
			iState = EDone;
sl@0
    94
			}
sl@0
    95
			break;
sl@0
    96
		case EDone:
sl@0
    97
			{
sl@0
    98
			}
sl@0
    99
			break;
sl@0
   100
		default:
sl@0
   101
			{
sl@0
   102
			User::Panic(_L("Certtool Engine - Illegal state"), 0);
sl@0
   103
			}
sl@0
   104
		}
sl@0
   105
	}
sl@0
   106
	
sl@0
   107
TInt CCertToolEngine::RunError(TInt aError)
sl@0
   108
	{	
sl@0
   109
	CActiveScheduler::Stop();	
sl@0
   110
	
sl@0
   111
	switch (iCurrentAction)
sl@0
   112
		{
sl@0
   113
		case EList:
sl@0
   114
			{
sl@0
   115
			TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_LIST, aError));			
sl@0
   116
			}
sl@0
   117
			break;
sl@0
   118
		case EImport:
sl@0
   119
			{
sl@0
   120
			TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_IMPORT, aError));						
sl@0
   121
			}
sl@0
   122
			break;
sl@0
   123
		default:
sl@0
   124
			{
sl@0
   125
			TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_UNKNOWN, aError));			
sl@0
   126
			}
sl@0
   127
		}	
sl@0
   128
	return KErrNone;
sl@0
   129
	}
sl@0
   130
sl@0
   131
	
sl@0
   132
void CCertToolEngine::DoCancel()
sl@0
   133
	{
sl@0
   134
	//CActiveScheduler::Stop();
sl@0
   135
	}
sl@0
   136
sl@0
   137
sl@0
   138
//\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
sl@0
   139
//\\//\\//\\//\\// Business methods //\\//\\//\\//\\//
sl@0
   140
//\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
sl@0
   141
	
sl@0
   142
void CCertToolEngine::ListL(CKeyToolParameters* aParam)
sl@0
   143
	{ 
sl@0
   144
	Cancel();
sl@0
   145
	iParam = aParam;
sl@0
   146
	iCurrentAction = EList;
sl@0
   147
	delete iHandler;
sl@0
   148
	iHandler = NULL;
sl@0
   149
	iHandler = CCertToolList::NewL(iController);	
sl@0
   150
	iState = EInitialise;
sl@0
   151
	iCertStore->Initialize(iStatus);	
sl@0
   152
	SetActive();
sl@0
   153
	}
sl@0
   154
	
sl@0
   155
void CCertToolEngine::ListStoresL(CKeyToolParameters* aParam)
sl@0
   156
	{ 
sl@0
   157
	Cancel();
sl@0
   158
	iParam = aParam;
sl@0
   159
	iCurrentAction = EList;
sl@0
   160
	iHandler = CCertToolListStores::NewL(iController);	
sl@0
   161
	iState = EInitialise;
sl@0
   162
	iCertStore->Initialize(iStatus);	
sl@0
   163
	SetActive();
sl@0
   164
	}
sl@0
   165
	
sl@0
   166
void CCertToolEngine::ImportPrivateL(CKeyToolParameters* aParam)
sl@0
   167
	{ 
sl@0
   168
	Cancel();
sl@0
   169
	
sl@0
   170
	iKeyController = CKeyToolController::NewL(iController->GetView());
sl@0
   171
	if (!aParam->iDefault)
sl@0
   172
		{
sl@0
   173
		iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE);	
sl@0
   174
		User::Leave(KErrArgument);
sl@0
   175
		}
sl@0
   176
sl@0
   177
	iParam = aParam;
sl@0
   178
	iCurrentAction = EImport;
sl@0
   179
	iKeyHandler = CKeytoolImport::NewL(iKeyController);	
sl@0
   180
	iState = EInitialiseKeyStore;
sl@0
   181
	iKeyStore->Initialize(iStatus);	
sl@0
   182
	SetActive();
sl@0
   183
	}
sl@0
   184
sl@0
   185
void CCertToolEngine::SetManagerPolicyL(CKeyToolParameters* aParam)
sl@0
   186
	{
sl@0
   187
	Cancel();
sl@0
   188
	delete iKeyController;
sl@0
   189
	iKeyController = NULL;
sl@0
   190
	iKeyController = CKeyToolController::NewL(iController->GetView());
sl@0
   191
	if (!aParam->iDefault)
sl@0
   192
		{
sl@0
   193
		iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);	
sl@0
   194
		User::Leave(KErrArgument);
sl@0
   195
		}
sl@0
   196
sl@0
   197
	iParam = aParam;
sl@0
   198
	iCurrentAction = ESetPolicy;
sl@0
   199
	delete iKeyHandler;
sl@0
   200
	iKeyHandler = NULL;
sl@0
   201
	iKeyHandler = CKeytoolSetPolicy::NewL(iKeyController);	
sl@0
   202
	iState = EInitialiseKeyStore;
sl@0
   203
	delete iKeyStore;
sl@0
   204
	iKeyStore = NULL;
sl@0
   205
	iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
sl@0
   206
	iKeyStore->Initialize(iStatus);	
sl@0
   207
	SetActive();
sl@0
   208
	}
sl@0
   209
	
sl@0
   210
void CCertToolEngine::RemovePrivateL(CKeyToolParameters* aParam)
sl@0
   211
	{
sl@0
   212
	Cancel();
sl@0
   213
	
sl@0
   214
	iKeyController = CKeyToolController::NewL(iController->GetView());
sl@0
   215
	if (!aParam->iDefault)
sl@0
   216
		{
sl@0
   217
		iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);	
sl@0
   218
		User::Leave(KErrArgument);
sl@0
   219
		}
sl@0
   220
sl@0
   221
	iParam = aParam;
sl@0
   222
	iCurrentAction = ERemove;
sl@0
   223
	iKeyHandler = CKeytoolRemove::NewL(iKeyController);	
sl@0
   224
	iState = EInitialiseKeyStore;
sl@0
   225
	User::LeaveIfError(iFsKeyStore.Connect());
sl@0
   226
	delete iKeyStore;
sl@0
   227
	iKeyStore = NULL;
sl@0
   228
	iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
sl@0
   229
	iKeyStore->Initialize(iStatus);	
sl@0
   230
	SetActive();
sl@0
   231
	}
sl@0
   232
sl@0
   233
void CCertToolEngine::ImportL(CKeyToolParameters* aParam)
sl@0
   234
	{ 
sl@0
   235
	Cancel();
sl@0
   236
	delete iKeyHandler;
sl@0
   237
	iKeyHandler = NULL;
sl@0
   238
	delete iKeyController;
sl@0
   239
	iKeyController = NULL;
sl@0
   240
	
sl@0
   241
	if (!aParam->iDefault)
sl@0
   242
		{
sl@0
   243
		iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_CERTFILE);	
sl@0
   244
		User::Leave(KErrArgument);
sl@0
   245
		}	
sl@0
   246
sl@0
   247
	iParam = aParam;
sl@0
   248
	iCurrentAction = EImport;
sl@0
   249
	iHandler = CCertToolAdd::NewL(iController);	
sl@0
   250
	iState = EInitialise;
sl@0
   251
	iCertStore->Initialize(iStatus);	
sl@0
   252
	SetActive();
sl@0
   253
	}
sl@0
   254
sl@0
   255
void CCertToolEngine::RemoveL(CKeyToolParameters* aParam)
sl@0
   256
	{ 
sl@0
   257
	Cancel();
sl@0
   258
	delete iKeyHandler;
sl@0
   259
	iKeyHandler = NULL;
sl@0
   260
	delete iKeyController;
sl@0
   261
	iKeyController = NULL;	
sl@0
   262
	
sl@0
   263
	if (!aParam->iDefault)
sl@0
   264
		{
sl@0
   265
		iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE);			
sl@0
   266
		User::Leave(KErrArgument);
sl@0
   267
		}
sl@0
   268
sl@0
   269
	iParam = aParam;
sl@0
   270
	iCurrentAction = ERemove;
sl@0
   271
	iHandler = CCertToolRemove::NewL(iController);	
sl@0
   272
	iState = EInitialise;
sl@0
   273
	iCertStore->Initialize(iStatus);	
sl@0
   274
	SetActive();
sl@0
   275
	}
sl@0
   276
	
sl@0
   277
void CCertToolEngine::SetupUidCommandL(CKeyToolParameters* aParam)
sl@0
   278
	{
sl@0
   279
	Cancel();
sl@0
   280
	if (!aParam->iDefault && !aParam->iLabel)
sl@0
   281
		{
sl@0
   282
		iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOCERT);			
sl@0
   283
		User::Leave(KErrArgument);
sl@0
   284
		}	
sl@0
   285
sl@0
   286
	if (aParam->iUIDs.Count()==0)
sl@0
   287
		{
sl@0
   288
		iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOAPPS);
sl@0
   289
		User::Leave(KErrArgument);
sl@0
   290
		}
sl@0
   291
sl@0
   292
	iParam = aParam;
sl@0
   293
	iCurrentAction = EAddApps;
sl@0
   294
	iState = EInitialise;
sl@0
   295
	iCertStore->Initialize(iStatus);	
sl@0
   296
	SetActive();		
sl@0
   297
	}
sl@0
   298
	
sl@0
   299
void CCertToolEngine::SetAppsL(CKeyToolParameters* aParam)
sl@0
   300
	{
sl@0
   301
	iCurrentAction = ESetApps;	
sl@0
   302
	iHandler = CCertToolSetApps::NewL(iController);	
sl@0
   303
	SetupUidCommandL(aParam);
sl@0
   304
	}
sl@0
   305
	
sl@0
   306
	
sl@0
   307
void CCertToolEngine::RemoveAppsL(CKeyToolParameters* aParam)
sl@0
   308
	{
sl@0
   309
	iHandler = CCertToolRemoveApps::NewL(iController);	
sl@0
   310
	SetupUidCommandL(aParam);	
sl@0
   311
	}
sl@0
   312
	
sl@0
   313
sl@0
   314
void CCertToolEngine::AddAppsL(CKeyToolParameters* aParam)
sl@0
   315
	{
sl@0
   316
	iHandler = CCertToolAddApps::NewL(iController);	
sl@0
   317
	SetupUidCommandL(aParam);
sl@0
   318
	}
sl@0
   319
	
sl@0
   320
sl@0
   321
	
sl@0
   322
void CCertToolEngine::DisplayUsageL(CKeyToolParameters* aParam)
sl@0
   323
	{
sl@0
   324
	iHandler = CCertToolUsage::NewL(iController);	
sl@0
   325
	iHandler->DoCommandL(*iCertStore, aParam);
sl@0
   326
	}