os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_removeapps.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_removeapps.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,184 @@
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 <mctwritablecertstore.h>
1.23 +
1.24 +#include "certtool_commands.h"
1.25 +#include "certtool_controller.h"
1.26 +
1.27 +#include "keytool_utils.h"
1.28 +
1.29 +/*static*/ CCertToolRemoveApps* CCertToolRemoveApps::NewLC(CCertToolController* aController)
1.30 + {
1.31 + CCertToolRemoveApps* self = new (ELeave) CCertToolRemoveApps(aController);
1.32 + CleanupStack::PushL(self);
1.33 + self->ConstructL();
1.34 + return self;
1.35 + }
1.36 +
1.37 +/*static*/ CCertToolRemoveApps* CCertToolRemoveApps::NewL(CCertToolController* aController)
1.38 + {
1.39 + CCertToolRemoveApps* self = CCertToolRemoveApps::NewLC(aController);
1.40 + CleanupStack::Pop(self);
1.41 + return self;
1.42 + }
1.43 +
1.44 +CCertToolRemoveApps::CCertToolRemoveApps(CCertToolController* aController) : CCertToolList(aController)
1.45 + {
1.46 + }
1.47 +
1.48 +
1.49 +CCertToolRemoveApps::~CCertToolRemoveApps()
1.50 + {
1.51 + Cancel();
1.52 + }
1.53 +
1.54 +void CCertToolRemoveApps::RunL()
1.55 + {
1.56 + if (iStatus.Int() != KErrNone)
1.57 + {
1.58 + // A problem occured. Handle gracefully.
1.59 + User::Leave(iStatus.Int());
1.60 + }
1.61 + switch (iState)
1.62 + {
1.63 + case EListCerts:
1.64 + {
1.65 + if (iCertInfos.Count()==0)
1.66 + {
1.67 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_EMPTY);
1.68 + CActiveScheduler::Stop();
1.69 + }
1.70 + else
1.71 + {
1.72 + if (iParams->iDefault)
1.73 + {
1.74 + // Look for a specific certificate
1.75 + TInt certIndex = -1;
1.76 + for (TInt j = 0; j < iCertInfos.Count(); j++)
1.77 + {
1.78 + if (iCertInfos[j]->Label() == *iParams->iDefault)
1.79 + {
1.80 + certIndex = j;
1.81 + break;
1.82 + }
1.83 + }
1.84 +
1.85 + if (certIndex != -1)
1.86 + {
1.87 + iIndex = certIndex;
1.88 + // Certificate found set app uids!
1.89 + if (iParams->iCertstoreIndex == -1)
1.90 + {
1.91 + iParams->iCertstoreIndex = 0;
1.92 + }
1.93 + if (iParams->iCertstoreIndex >= iCertStore->CertStoreCount())
1.94 + {
1.95 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTEXIST);
1.96 + User::Leave(KErrArgument);
1.97 + }
1.98 + iCertStore->Applications(*iCertInfos[iIndex], iApps, iStatus);
1.99 + iState = ERemoveApps;
1.100 + SetActive();
1.101 + }
1.102 + else
1.103 + {
1.104 + User::Leave(KErrNotFound);
1.105 + }
1.106 + }
1.107 + }
1.108 +
1.109 + }
1.110 + break;
1.111 + case ERemoveApps:
1.112 + {
1.113 + if (iParams->iCertstoreIndex == -1)
1.114 + {
1.115 + iParams->iCertstoreIndex = 0;
1.116 + }
1.117 + if (iParams->iCertstoreIndex >= iCertStore->CertStoreCount())
1.118 + {
1.119 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTEXIST);
1.120 + User::Leave(KErrArgument);
1.121 + }
1.122 + TInt failCount = 0;
1.123 + // Check for duplicates
1.124 + for (TInt k = 0; k < iParams->iUIDs.Count(); k++)
1.125 + {
1.126 + TInt idx = iApps.Find(iParams->iUIDs[k]);
1.127 + if ( idx == KErrNotFound)
1.128 + {
1.129 + failCount++;
1.130 + TBuf<128> msg;
1.131 + const TDesC& tmp = KeyToolUtils::Uid2Des(iParams->iUIDs[k]);
1.132 + msg.Format(_L("The certificate wan not trusted for application %S."), &tmp);
1.133 + iController->DisplayErrorL(msg, iParams->iPageWise);
1.134 + }
1.135 + else
1.136 + {
1.137 + iApps.Remove(idx);
1.138 + }
1.139 + }
1.140 +
1.141 + if (failCount == iParams->iUIDs.Count())
1.142 + {
1.143 + CActiveScheduler::Stop();
1.144 + }
1.145 + else
1.146 + {
1.147 + iState = EFinished;
1.148 + iCertStore->SetApplicability(*iCertInfos[iIndex], iApps, iStatus);
1.149 + SetActive();
1.150 + }
1.151 + }
1.152 + break;
1.153 + case EFinished:
1.154 + {
1.155 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_REMOVEAPPS_SUCCESS);
1.156 + CActiveScheduler::Stop();
1.157 + }
1.158 + break;
1.159 + default:
1.160 + {
1.161 + User::Panic(_L("REMOVEAPPS action: Illegal state."), 1);
1.162 + }
1.163 + }
1.164 +
1.165 + }
1.166 +
1.167 +TInt CCertToolRemoveApps::RunError(TInt aError)
1.168 + {
1.169 + CActiveScheduler::Stop();
1.170 +
1.171 + switch (aError)
1.172 + {
1.173 + case KErrNotFound :
1.174 + {
1.175 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTFOUND));
1.176 + TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));
1.177 + }
1.178 + break;
1.179 + default:
1.180 + {
1.181 + TRAP_IGNORE(iController->DisplayErrorL(_L("RemoveApps: Unknown error. "), aError));
1.182 + TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));
1.183 + }
1.184 + }
1.185 +
1.186 + return KErrNone;
1.187 + }