os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_setapps.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_setapps.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,152 @@
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_commands.h"
1.23 +#include "certtool_controller.h"
1.24 +
1.25 +
1.26 +/*static*/ CCertToolSetApps* CCertToolSetApps::NewLC(CCertToolController* aController)
1.27 + {
1.28 + CCertToolSetApps* self = new (ELeave) CCertToolSetApps(aController);
1.29 + CleanupStack::PushL(self);
1.30 + self->ConstructL();
1.31 + return self;
1.32 + }
1.33 +
1.34 +/*static*/ CCertToolSetApps* CCertToolSetApps::NewL(CCertToolController* aController)
1.35 + {
1.36 + CCertToolSetApps* self = CCertToolSetApps::NewLC(aController);
1.37 + CleanupStack::Pop(self);
1.38 + return self;
1.39 + }
1.40 +
1.41 +CCertToolSetApps::CCertToolSetApps(CCertToolController* aController) : CCertToolList(aController), iCertIndex (-1)
1.42 + {
1.43 + }
1.44 +
1.45 +
1.46 +CCertToolSetApps::~CCertToolSetApps()
1.47 + {
1.48 + Cancel();
1.49 + }
1.50 +
1.51 +void CCertToolSetApps::RunL()
1.52 + {
1.53 + if (iStatus.Int() != KErrNone)
1.54 + {
1.55 + // A problem occured. Handle gracefully.
1.56 + User::Leave(iStatus.Int());
1.57 + }
1.58 +
1.59 + switch (iState)
1.60 + {
1.61 + case EListCerts:
1.62 + {
1.63 + if (iCertInfos.Count()==0)
1.64 + {
1.65 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_EMPTY);
1.66 + CActiveScheduler::Stop();
1.67 + }
1.68 + else
1.69 + {
1.70 + if (iParams->iDefault)
1.71 + {
1.72 + // Look for a specific certificate
1.73 + for (TInt j = 0; j < iCertInfos.Count(); j++)
1.74 + {
1.75 + if (iCertInfos[j]->Label() == *iParams->iDefault)
1.76 + {
1.77 + iCertIndex = j;
1.78 + break;
1.79 + }
1.80 + }
1.81 +
1.82 + if (iCertIndex != -1)
1.83 + {
1.84 + // Certificate found set app uids!
1.85 + if (iParams->iCertstoreIndex == -1)
1.86 + {
1.87 + iParams->iCertstoreIndex = 0;
1.88 + }
1.89 + if (iParams->iCertstoreIndex >= iCertStore->CertStoreCount())
1.90 + {
1.91 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTEXIST);
1.92 + User::Leave(KErrArgument);
1.93 + }
1.94 + if(iCertInfos[iCertIndex]->CertificateOwnerType() == ECACertificate)
1.95 + {
1.96 + iState = ESetTrust;
1.97 + }
1.98 + else
1.99 + {
1.100 + iState = EFinished;
1.101 + }
1.102 + iCertStore->SetApplicability(*iCertInfos[iCertIndex], iParams->iUIDs, iStatus);
1.103 + SetActive();
1.104 + break;
1.105 + }
1.106 + else
1.107 + {
1.108 + User::Leave(KErrNotFound);
1.109 + }
1.110 + }
1.111 + }
1.112 + }
1.113 + case ESetTrust:
1.114 + {
1.115 + iState = EFinished;
1.116 + const TBool caCert = ETrue;
1.117 + iCertStore->SetTrust(*iCertInfos[iCertIndex],caCert,iStatus);
1.118 + SetActive();
1.119 + }
1.120 + break;
1.121 + case EFinished:
1.122 + {
1.123 + iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_SETAPPS_SUCCESS);
1.124 + CActiveScheduler::Stop();
1.125 + }
1.126 + break;
1.127 + default:
1.128 + {
1.129 + User::Panic(_L("SETAPPS action: Illegal state."), 1);
1.130 + }
1.131 + }
1.132 + }
1.133 +
1.134 +
1.135 +TInt CCertToolSetApps::RunError(TInt aError)
1.136 + {
1.137 + CActiveScheduler::Stop();
1.138 +
1.139 + switch (aError)
1.140 + {
1.141 + case KErrNotFound :
1.142 + {
1.143 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTFOUND));
1.144 + TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));
1.145 + }
1.146 + break;
1.147 + default:
1.148 + {
1.149 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_ADDAPPS_FAIL));
1.150 + TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));
1.151 + }
1.152 + }
1.153 +
1.154 + return KErrNone;
1.155 + }