os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_engine.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_engine.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,326 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "certtool_engine.h"
1.23 +#include "certtool_controller.h"
1.24 +#include "keytool_controller.h"
1.25 +
1.26 +
1.27 +/*static*/ CCertToolEngine* CCertToolEngine::NewLC(CCertToolController* aController)
1.28 + {
1.29 + CCertToolEngine* self = new (ELeave) CCertToolEngine(aController);
1.30 + CleanupStack::PushL(self);
1.31 + self->ConstructL();
1.32 + return self;
1.33 + }
1.34 +
1.35 +/*static*/ CCertToolEngine* CCertToolEngine::NewL(CCertToolController* aController)
1.36 + {
1.37 + CCertToolEngine* self = CCertToolEngine::NewLC(aController);
1.38 + CleanupStack::Pop(self);
1.39 + return self;
1.40 + }
1.41 +
1.42 +CCertToolEngine::CCertToolEngine(CCertToolController* aController) : CActive(EPriorityNormal)
1.43 + {
1.44 + iCurrentAction = EIdle;
1.45 + iController = aController;
1.46 + }
1.47 +
1.48 +CCertToolEngine::~CCertToolEngine()
1.49 + {
1.50 + Cancel();
1.51 + delete iHandler;
1.52 + delete iKeyHandler;
1.53 + delete iKeyController;
1.54 +
1.55 + delete iKeyStore;
1.56 + iFsKeyStore.Close();
1.57 + delete iCertStore;
1.58 + iFs.Close();
1.59 + delete iScheduler;
1.60 + }
1.61 +
1.62 +void CCertToolEngine::ConstructL()
1.63 + {
1.64 + iScheduler = new(ELeave) CActiveScheduler;
1.65 + CActiveScheduler::Install(iScheduler);
1.66 +
1.67 + User::LeaveIfError(iFs.Connect());
1.68 +
1.69 + iCertStore = CUnifiedCertStore::NewL(iFs, ETrue);
1.70 +
1.71 + User::LeaveIfError(iFsKeyStore.Connect());
1.72 +
1.73 + iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
1.74 +
1.75 + CActiveScheduler::Add(this);
1.76 + }
1.77 +
1.78 +void CCertToolEngine::RunL()
1.79 + {
1.80 + if (iStatus.Int() != KErrNone)
1.81 + {
1.82 + User::Leave(iStatus.Int());
1.83 + }
1.84 +
1.85 + switch (iState)
1.86 + {
1.87 + case EInitialiseKeyStore:
1.88 + {
1.89 + iKeyHandler->DoCommandL(*iKeyStore, iParam);
1.90 + iState = EDone;
1.91 + }
1.92 + break;
1.93 + case EInitialise:
1.94 + {
1.95 + iHandler->DoCommandL(*iCertStore, iParam);
1.96 + iState = EDone;
1.97 + }
1.98 + break;
1.99 + case EDone:
1.100 + {
1.101 + }
1.102 + break;
1.103 + default:
1.104 + {
1.105 + User::Panic(_L("Certtool Engine - Illegal state"), 0);
1.106 + }
1.107 + }
1.108 + }
1.109 +
1.110 +TInt CCertToolEngine::RunError(TInt aError)
1.111 + {
1.112 + CActiveScheduler::Stop();
1.113 +
1.114 + switch (iCurrentAction)
1.115 + {
1.116 + case EList:
1.117 + {
1.118 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_LIST, aError));
1.119 + }
1.120 + break;
1.121 + case EImport:
1.122 + {
1.123 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_IMPORT, aError));
1.124 + }
1.125 + break;
1.126 + default:
1.127 + {
1.128 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_UNKNOWN, aError));
1.129 + }
1.130 + }
1.131 + return KErrNone;
1.132 + }
1.133 +
1.134 +
1.135 +void CCertToolEngine::DoCancel()
1.136 + {
1.137 + //CActiveScheduler::Stop();
1.138 + }
1.139 +
1.140 +
1.141 +//\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
1.142 +//\\//\\//\\//\\// Business methods //\\//\\//\\//\\//
1.143 +//\\//\\//\\//\\////\\//\\//\\//\\////\\//\\//\\//\\//
1.144 +
1.145 +void CCertToolEngine::ListL(CKeyToolParameters* aParam)
1.146 + {
1.147 + Cancel();
1.148 + iParam = aParam;
1.149 + iCurrentAction = EList;
1.150 + delete iHandler;
1.151 + iHandler = NULL;
1.152 + iHandler = CCertToolList::NewL(iController);
1.153 + iState = EInitialise;
1.154 + iCertStore->Initialize(iStatus);
1.155 + SetActive();
1.156 + }
1.157 +
1.158 +void CCertToolEngine::ListStoresL(CKeyToolParameters* aParam)
1.159 + {
1.160 + Cancel();
1.161 + iParam = aParam;
1.162 + iCurrentAction = EList;
1.163 + iHandler = CCertToolListStores::NewL(iController);
1.164 + iState = EInitialise;
1.165 + iCertStore->Initialize(iStatus);
1.166 + SetActive();
1.167 + }
1.168 +
1.169 +void CCertToolEngine::ImportPrivateL(CKeyToolParameters* aParam)
1.170 + {
1.171 + Cancel();
1.172 +
1.173 + iKeyController = CKeyToolController::NewL(iController->GetView());
1.174 + if (!aParam->iDefault)
1.175 + {
1.176 + iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_KEYFILE);
1.177 + User::Leave(KErrArgument);
1.178 + }
1.179 +
1.180 + iParam = aParam;
1.181 + iCurrentAction = EImport;
1.182 + iKeyHandler = CKeytoolImport::NewL(iKeyController);
1.183 + iState = EInitialiseKeyStore;
1.184 + iKeyStore->Initialize(iStatus);
1.185 + SetActive();
1.186 + }
1.187 +
1.188 +void CCertToolEngine::SetManagerPolicyL(CKeyToolParameters* aParam)
1.189 + {
1.190 + Cancel();
1.191 + delete iKeyController;
1.192 + iKeyController = NULL;
1.193 + iKeyController = CKeyToolController::NewL(iController->GetView());
1.194 + if (!aParam->iDefault)
1.195 + {
1.196 + iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);
1.197 + User::Leave(KErrArgument);
1.198 + }
1.199 +
1.200 + iParam = aParam;
1.201 + iCurrentAction = ESetPolicy;
1.202 + delete iKeyHandler;
1.203 + iKeyHandler = NULL;
1.204 + iKeyHandler = CKeytoolSetPolicy::NewL(iKeyController);
1.205 + iState = EInitialiseKeyStore;
1.206 + delete iKeyStore;
1.207 + iKeyStore = NULL;
1.208 + iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
1.209 + iKeyStore->Initialize(iStatus);
1.210 + SetActive();
1.211 + }
1.212 +
1.213 +void CCertToolEngine::RemovePrivateL(CKeyToolParameters* aParam)
1.214 + {
1.215 + Cancel();
1.216 +
1.217 + iKeyController = CKeyToolController::NewL(iController->GetView());
1.218 + if (!aParam->iDefault)
1.219 + {
1.220 + iKeyController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_REMOVE);
1.221 + User::Leave(KErrArgument);
1.222 + }
1.223 +
1.224 + iParam = aParam;
1.225 + iCurrentAction = ERemove;
1.226 + iKeyHandler = CKeytoolRemove::NewL(iKeyController);
1.227 + iState = EInitialiseKeyStore;
1.228 + User::LeaveIfError(iFsKeyStore.Connect());
1.229 + delete iKeyStore;
1.230 + iKeyStore = NULL;
1.231 + iKeyStore = CUnifiedKeyStore::NewL(iFsKeyStore);
1.232 + iKeyStore->Initialize(iStatus);
1.233 + SetActive();
1.234 + }
1.235 +
1.236 +void CCertToolEngine::ImportL(CKeyToolParameters* aParam)
1.237 + {
1.238 + Cancel();
1.239 + delete iKeyHandler;
1.240 + iKeyHandler = NULL;
1.241 + delete iKeyController;
1.242 + iKeyController = NULL;
1.243 +
1.244 + if (!aParam->iDefault)
1.245 + {
1.246 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_CERTFILE);
1.247 + User::Leave(KErrArgument);
1.248 + }
1.249 +
1.250 + iParam = aParam;
1.251 + iCurrentAction = EImport;
1.252 + iHandler = CCertToolAdd::NewL(iController);
1.253 + iState = EInitialise;
1.254 + iCertStore->Initialize(iStatus);
1.255 + SetActive();
1.256 + }
1.257 +
1.258 +void CCertToolEngine::RemoveL(CKeyToolParameters* aParam)
1.259 + {
1.260 + Cancel();
1.261 + delete iKeyHandler;
1.262 + iKeyHandler = NULL;
1.263 + delete iKeyController;
1.264 + iKeyController = NULL;
1.265 +
1.266 + if (!aParam->iDefault)
1.267 + {
1.268 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVE);
1.269 + User::Leave(KErrArgument);
1.270 + }
1.271 +
1.272 + iParam = aParam;
1.273 + iCurrentAction = ERemove;
1.274 + iHandler = CCertToolRemove::NewL(iController);
1.275 + iState = EInitialise;
1.276 + iCertStore->Initialize(iStatus);
1.277 + SetActive();
1.278 + }
1.279 +
1.280 +void CCertToolEngine::SetupUidCommandL(CKeyToolParameters* aParam)
1.281 + {
1.282 + Cancel();
1.283 + if (!aParam->iDefault && !aParam->iLabel)
1.284 + {
1.285 + iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOCERT);
1.286 + User::Leave(KErrArgument);
1.287 + }
1.288 +
1.289 + if (aParam->iUIDs.Count()==0)
1.290 + {
1.291 + iController->DisplayLocalisedMsgL(R_CERTTOOL_USAGE_NOAPPS);
1.292 + User::Leave(KErrArgument);
1.293 + }
1.294 +
1.295 + iParam = aParam;
1.296 + iCurrentAction = EAddApps;
1.297 + iState = EInitialise;
1.298 + iCertStore->Initialize(iStatus);
1.299 + SetActive();
1.300 + }
1.301 +
1.302 +void CCertToolEngine::SetAppsL(CKeyToolParameters* aParam)
1.303 + {
1.304 + iCurrentAction = ESetApps;
1.305 + iHandler = CCertToolSetApps::NewL(iController);
1.306 + SetupUidCommandL(aParam);
1.307 + }
1.308 +
1.309 +
1.310 +void CCertToolEngine::RemoveAppsL(CKeyToolParameters* aParam)
1.311 + {
1.312 + iHandler = CCertToolRemoveApps::NewL(iController);
1.313 + SetupUidCommandL(aParam);
1.314 + }
1.315 +
1.316 +
1.317 +void CCertToolEngine::AddAppsL(CKeyToolParameters* aParam)
1.318 + {
1.319 + iHandler = CCertToolAddApps::NewL(iController);
1.320 + SetupUidCommandL(aParam);
1.321 + }
1.322 +
1.323 +
1.324 +
1.325 +void CCertToolEngine::DisplayUsageL(CKeyToolParameters* aParam)
1.326 + {
1.327 + iHandler = CCertToolUsage::NewL(iController);
1.328 + iHandler->DoCommandL(*iCertStore, aParam);
1.329 + }