os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_setpolicy.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_setpolicy.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,175 @@
1.4 +/*
1.5 +* Copyright (c) 2007-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 <mctkeystore.h>
1.23 +
1.24 +#include "keytool_utils.h"
1.25 +#include "keytool_commands.h"
1.26 +#include "keytool_controller.h"
1.27 +
1.28 +#include <keytool.rsg>
1.29 +
1.30 +
1.31 +/*static*/ CKeytoolSetPolicy* CKeytoolSetPolicy::NewLC(CKeyToolController* aController)
1.32 + {
1.33 + CKeytoolSetPolicy* self = new (ELeave) CKeytoolSetPolicy(aController);
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL();
1.36 + return self;
1.37 + }
1.38 +
1.39 +/*static*/ CKeytoolSetPolicy* CKeytoolSetPolicy::NewL(CKeyToolController* aController)
1.40 + {
1.41 + CKeytoolSetPolicy* self = CKeytoolSetPolicy::NewLC(aController);
1.42 + CleanupStack::Pop(self);
1.43 + return self;
1.44 + }
1.45 +
1.46 +CKeytoolSetPolicy::CKeytoolSetPolicy(CKeyToolController* aController) : CKeytoolList(aController)
1.47 + {
1.48 + }
1.49 +
1.50 +CKeytoolSetPolicy::~CKeytoolSetPolicy()
1.51 + {
1.52 + Cancel();
1.53 + }
1.54 +
1.55 +void CKeytoolSetPolicy::RunL()
1.56 + {
1.57 + if (iStatus.Int() != KErrNone)
1.58 + {
1.59 + // A problem occured. Handle gracefully.
1.60 + User::Leave(iStatus.Int());
1.61 + }
1.62 +
1.63 + switch (iState)
1.64 + {
1.65 + case EListKeys:
1.66 + {
1.67 + iKey = KeyToolUtils::findKey(iKeys, *iParams->iDefault);
1.68 + if (iKey)
1.69 + {
1.70 + TSecureId secureId; // Application secure ID
1.71 + TSecurityPolicy securePolicy;
1.72 + idx = 0;
1.73 + if (iParams->iPolicy == CKeyToolParameters::ESetManagerPolicy)
1.74 + {
1.75 + securePolicy = ECapabilityWriteDeviceData;
1.76 + iKeyStore->SetManagementPolicy(iKey->Handle(), securePolicy, iStatus);
1.77 + }
1.78 + else
1.79 + {
1.80 + if (iParams->iPolicy == CKeyToolParameters::ESetUserPolicy)
1.81 + {
1.82 + secureId = iParams->iUIDs[idx];
1.83 + securePolicy = secureId;
1.84 + }
1.85 + else if (iParams->iPolicy == CKeyToolParameters::ESetAllUsersPolicy)
1.86 + {
1.87 + securePolicy = TSecurityPolicy::EAlwaysPass;
1.88 + }
1.89 + else if (iParams->iPolicy == CKeyToolParameters::ERemoveUserPolicy)
1.90 + {
1.91 + iParams->iUIDs.Close();
1.92 + iParams->iUIDs.Append(TUid::Uid(KUidSecurityKeytool));
1.93 + secureId = iParams->iUIDs[idx];
1.94 + securePolicy = secureId;
1.95 + }
1.96 + else
1.97 + {
1.98 + User::Leave(KErrNotFound); //should not come here
1.99 + }
1.100 + iKeyStore->SetUsePolicy(iKey->Handle(), securePolicy, iStatus);
1.101 + }
1.102 + iState = EFinished;
1.103 + SetActive();
1.104 + }
1.105 + else
1.106 + {
1.107 + User::Leave(KErrNotFound);
1.108 + }
1.109 + }
1.110 + break;
1.111 + case EFinished:
1.112 + {
1.113 + if (iParams->iPolicy == CKeyToolParameters::ESetManagerPolicy)
1.114 + {
1.115 + iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SMANAGERSUCCESS);
1.116 + }
1.117 + else if (iParams->iPolicy == CKeyToolParameters::ESetUserPolicy)
1.118 + {
1.119 + iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SUSERSUCCESS);
1.120 + }
1.121 + else if (iParams->iPolicy == CKeyToolParameters::ESetAllUsersPolicy)
1.122 + {
1.123 + iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SALLUSERSSUCCESS);
1.124 + }
1.125 + else
1.126 + {
1.127 + iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_RUSERSUCCESS);
1.128 + }
1.129 + CActiveScheduler::Stop();
1.130 + }
1.131 + break;
1.132 + default:
1.133 + {
1.134 + User::Panic(_L("SETUSERS action: Illegal state."), 1);
1.135 + }
1.136 + }
1.137 + }
1.138 +
1.139 +TInt CKeytoolSetPolicy::RunError(TInt aError)
1.140 + {
1.141 + CActiveScheduler::Stop();
1.142 +
1.143 + switch (aError)
1.144 + {
1.145 + case KErrNotFound :
1.146 + {
1.147 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_NOTFOUND));
1.148 + }
1.149 + break;
1.150 + case KErrAccessDenied :
1.151 + {
1.152 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_ACCESS));
1.153 + }
1.154 + break;
1.155 + default:
1.156 + {
1.157 + if (iParams->iPolicy == CKeyToolParameters::ESetManagerPolicy)
1.158 + {
1.159 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SMANAGERFAIL, aError));
1.160 + }
1.161 + else if (iParams->iPolicy == CKeyToolParameters::ESetUserPolicy)
1.162 + {
1.163 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SUSERFAIL, aError));
1.164 + }
1.165 + else if (iParams->iPolicy == CKeyToolParameters::ESetAllUsersPolicy)
1.166 + {
1.167 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_SALLUSERSFAIL, aError));
1.168 + }
1.169 + else
1.170 + {
1.171 + TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_RUSERFAIL, aError));
1.172 + }
1.173 + }
1.174 + }
1.175 +
1.176 + return KErrNone;
1.177 + }
1.178 +