os/security/cryptoservices/certificateandkeymgmt/tcertstore/t_certstoreactions.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tcertstore/t_certstoreactions.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,427 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 +/**
    1.23 + @file 
    1.24 + @internalTechnology
    1.25 +*/
    1.26 + 
    1.27 +#ifndef __T_CERTSTOREACTIONS_H__
    1.28 +#define __T_CERTSTOREACTIONS_H__
    1.29 +
    1.30 +#include "t_testhandler.h"
    1.31 +#include <unifiedcertstore.h>
    1.32 +#include <unifiedkeystore.h>
    1.33 +#include <certificateapps.h>
    1.34 +#include <e32cons.h>
    1.35 +#include <badesca.h>
    1.36 +#include "t_testaction.h"
    1.37 +#include <cctcertinfo.h>
    1.38 +
    1.39 +class Output;
    1.40 +class CSWICertStore;
    1.41 +
    1.42 +enum TCertStoreType
    1.43 +	{
    1.44 +	EUnifiedCertStore,
    1.45 +	ESWICertStore
    1.46 +	};
    1.47 +
    1.48 +class CCertStoreChangeNotifier : public CActive
    1.49 +  	{
    1.50 +  public:
    1.51 +  	static CCertStoreChangeNotifier* NewL(TInt& aNotificationFlag);
    1.52 +  	virtual ~CCertStoreChangeNotifier();
    1.53 +  	void StartNotification();
    1.54 +  	TInt& iNotifiedCounter;
    1.55 +  	void SetCompleteStatus(TRequestStatus* aStatus);
    1.56 +  private:
    1.57 +  	CCertStoreChangeNotifier(TInt& aNotificationFlag);
    1.58 +  	void ConstructL();
    1.59 +  	void DoCancel();
    1.60 +  	void RunL();
    1.61 +  private:	
    1.62 +  	RProperty iCertStoreChangeProperty;	
    1.63 +  	TRequestStatus* iCompleteStatus;
    1.64 +  	};
    1.65 +
    1.66 +/**
    1.67 + * Contains either a unified cert store instance or a SWI cert store instance.
    1.68 + * 
    1.69 + * Either can be accessed through the CertStore() method, but
    1.70 + * AsUnifiedCertStore() and AsSWICertStore() will panic if the store is the
    1.71 + * wrong type.
    1.72 + *
    1.73 + * This class owns the cert store pointer.
    1.74 + */
    1.75 +class COpenCertStore : public CBase
    1.76 +	{
    1.77 + public:
    1.78 +	virtual ~COpenCertStore();
    1.79 +
    1.80 +	TCertStoreType Type();
    1.81 +	MCertStore& CertStore();
    1.82 +
    1.83 +	void SetCertStore(CUnifiedCertStore* aCertStore);
    1.84 +	CUnifiedCertStore& AsUnifiedCertStore();
    1.85 +
    1.86 +	void SetCertStore(CSWICertStore* aCertStore);
    1.87 +	CSWICertStore& AsSWICertStore();
    1.88 +	
    1.89 + private:
    1.90 +
    1.91 + private:
    1.92 +
    1.93 +	TBool iSet;
    1.94 +	TCertStoreType iType;
    1.95 +	union
    1.96 +		{
    1.97 +		TAny* iAny;
    1.98 +		CUnifiedCertStore* iUnifiedCertStore;
    1.99 +		CSWICertStore* iSwiCertStore;
   1.100 +		};
   1.101 +	};
   1.102 +
   1.103 +/**
   1.104 + * Per-thread shared data.
   1.105 + *
   1.106 + * This contains stuff that is shared by more than one test action, eg the cert
   1.107 + * stores we are testing.
   1.108 + */
   1.109 +class CSharedData : public CBase
   1.110 +	{
   1.111 +public:
   1.112 +	~CSharedData();
   1.113 +	void InitCertificateAppInfoManagerL();
   1.114 +	void DeleteCertificateAppInfoManager();
   1.115 +	RPointerArray<COpenCertStore>& CertStores();
   1.116 +public:
   1.117 +	RFs iFs;
   1.118 +	RPointerArray<COpenCertStore> iCertStores;	
   1.119 +	CCertificateAppInfoManager* iCertificateAppInfoManager;
   1.120 +	};
   1.121 +
   1.122 +class CCertStoreTestAction : public CTestAction
   1.123 +	{
   1.124 +public:
   1.125 +	virtual ~CCertStoreTestAction();
   1.126 +
   1.127 +protected:
   1.128 +	CCertStoreTestAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.129 +
   1.130 +	// Methods for accessing the shared app info manager
   1.131 +	void InitTheCertificateAppInfoManagerL();
   1.132 +	void DeleteTheCertificateAppInfoManager();
   1.133 +  	CCertificateAppInfoManager* TheCertificateAppInfoManager();
   1.134 +
   1.135 +	// Methods for accessing the shared cert stores
   1.136 +	TInt CertStoreCount();
   1.137 +	TCertStoreType CertStoreType(TInt aIndex = 0);
   1.138 +	MCertStore& CertStore(TInt aIndex = 0);
   1.139 +	void AddCertStoreL(CUnifiedCertStore* aCertStore);
   1.140 +	CUnifiedCertStore& UnifiedCertStore(TInt aIndex = 0);
   1.141 +	void AddCertStoreL(CSWICertStore* aCertStore);
   1.142 +	CSWICertStore& SWICertStore(TInt aIndex = 0);
   1.143 +	void RemoveCertStore(TInt aIndex);
   1.144 +
   1.145 +protected:
   1.146 +	RFs& iFs;
   1.147 +
   1.148 + private:
   1.149 +	CSharedData& CertStoreSharedData();
   1.150 +	RPointerArray<COpenCertStore>& CertStores();	
   1.151 +	void DoPerformPrerequisite(TRequestStatus& aStatus);
   1.152 +	void DoPerformPostrequisite(TRequestStatus& aStatus);
   1.153 +	};
   1.154 +
   1.155 +class CSubscriberAction: public CCertStoreTestAction
   1.156 +	{
   1.157 +public:
   1.158 + 	virtual ~CSubscriberAction();
   1.159 + 
   1.160 +protected:
   1.161 + 	CSubscriberAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.162 + 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.163 + 	TInt iNotifierFlag;
   1.164 + 	TInt iNotificationSubscribed;		
   1.165 + 	CCertStoreChangeNotifier* iNotifier;		
   1.166 + 	};
   1.167 +
   1.168 +/**
   1.169 + * This action creates and initializes a certificate store manager.
   1.170 + * It should be used before any action requiring a certificate store manager.
   1.171 + * All the actions are likely to require one.
   1.172 + */
   1.173 +class CInitialiseCertStore : public CCertStoreTestAction
   1.174 +	{
   1.175 +public:
   1.176 +	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole,
   1.177 +		Output& aOut, const TTestActionSpec& aTestActionSpec);
   1.178 +	static CTestAction* NewLC(RFs& aFs, CConsoleBase& aConsole,	
   1.179 +		Output& aOut, const TTestActionSpec& aTestActionSpec);
   1.180 +	~CInitialiseCertStore();
   1.181 +
   1.182 +public:
   1.183 +	virtual void PerformAction(TRequestStatus& aStatus);
   1.184 +	virtual void PerformCancel();
   1.185 +	virtual void Reset();
   1.186 +
   1.187 +private:
   1.188 +	CInitialiseCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.189 +	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.190 +	void DoReportAction();
   1.191 +	void DoCheckResult(TInt aError);
   1.192 +
   1.193 +private:
   1.194 +	enum TState
   1.195 +		{
   1.196 +		ENew,
   1.197 +		EAppend,
   1.198 +		ECheckOrder,
   1.199 +		EFinished
   1.200 +		};
   1.201 +
   1.202 +private:
   1.203 +	TState iState;
   1.204 +	TBool iOpenedForWrite;
   1.205 + 	RArray<TInt> iFilterOrdering;
   1.206 + 	RArray<TInt32> iExpectedOrderingResult;
   1.207 +	CUnifiedCertStore* iNewUnifiedCertStore;
   1.208 +	};
   1.209 +
   1.210 +class COnlyCreateCertStore : public CCertStoreTestAction
   1.211 +	{
   1.212 +public:
   1.213 +	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.214 +		const TTestActionSpec& aTestActionSpec);
   1.215 +	~COnlyCreateCertStore() {};
   1.216 +
   1.217 +public:
   1.218 +	virtual void PerformAction(TRequestStatus& aStatus);
   1.219 +	virtual void PerformCancel();
   1.220 +	virtual void Reset();
   1.221 +
   1.222 +private:
   1.223 +	enum TState
   1.224 +		{
   1.225 +		EInit,
   1.226 +		EFinished
   1.227 +		};
   1.228 +
   1.229 +private:
   1.230 +	COnlyCreateCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.231 +	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.232 +	void DoReportAction();
   1.233 +	void DoCheckResult(TInt aError);
   1.234 +
   1.235 +private:
   1.236 +	TState iState;
   1.237 +	TBool iOpenedForWrite;
   1.238 +
   1.239 +	CUnifiedCertStore* iNewUnifiedCertStore;
   1.240 +	};
   1.241 +
   1.242 +class CDeleteCertStore : public CCertStoreTestAction
   1.243 +	{
   1.244 +	public:
   1.245 +		static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
   1.246 +			const TTestActionSpec& aTestActionSpec);
   1.247 +		static CTestAction* NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.248 +			const TTestActionSpec& aTestActionSpec);
   1.249 +		~CDeleteCertStore();
   1.250 +		virtual void PerformAction(TRequestStatus& aStatus);
   1.251 +		virtual void PerformCancel();
   1.252 +		virtual void Reset();
   1.253 +
   1.254 +	private:
   1.255 +		CDeleteCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.256 +		void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.257 +		void DoReportAction();
   1.258 +		void DoCheckResult(TInt aError);
   1.259 +
   1.260 +	private:
   1.261 +		enum TState
   1.262 +			{
   1.263 +			EDelete,
   1.264 +			EFinished
   1.265 +			};
   1.266 +
   1.267 +	private:
   1.268 +		TState iState;
   1.269 +	};
   1.270 +
   1.271 +
   1.272 +class CX509Certificate;
   1.273 +class CWTLSCertificate;
   1.274 +
   1.275 +// This is the base class used by both CSetApplications and CSetTrusters. This
   1.276 +// is required because of the merging of the SetApplicability and SetTrust API
   1.277 +// calls on the certstore
   1.278 +class CSetAppsAndTrust : public CSubscriberAction
   1.279 +
   1.280 +	{
   1.281 +public:
   1.282 +	~CSetAppsAndTrust();
   1.283 +	virtual void PerformAction(TRequestStatus& aStatus);
   1.284 +	virtual void Reset();
   1.285 +	virtual void PerformCancel();
   1.286 +
   1.287 +protected:
   1.288 +	CSetAppsAndTrust(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.289 +	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.290 +	void GetCerts(TRequestStatus& aStatus);
   1.291 +	void SetCertLabel(const TDesC8& aLabel);
   1.292 +
   1.293 +	/** Implemented by derived classes, called from PerformAction. */
   1.294 +	virtual void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus) = 0;
   1.295 +	/** Implemented by derived classes, called from PerformCancel. */
   1.296 +	virtual void DoPerformCancel() = 0;
   1.297 +
   1.298 +protected:
   1.299 +	enum TState
   1.300 +		{
   1.301 +		EGetCAEntries,
   1.302 +		ESetAppTrust,
   1.303 +		ECheckNotification,
   1.304 +		EFinished
   1.305 +		};
   1.306 +
   1.307 +protected:
   1.308 +	/**
   1.309 +	 * The label of the certificate we want to set the trust settings for
   1.310 +	 */ 
   1.311 +	TCertLabel iLabel;
   1.312 +
   1.313 +	// Index into the certinfo list which points to the certificate we
   1.314 +	// are interested in
   1.315 +	TInt iIndex;
   1.316 +	 
   1.317 +	TState iState;
   1.318 +	CCertAttributeFilter *iFilter;
   1.319 +	RMPointerArray<CCTCertInfo> iCertInfos;
   1.320 +	};
   1.321 +
   1.322 +
   1.323 +
   1.324 +/**
   1.325 + * This class is used to test the trust settings of a certificate.
   1.326 + */
   1.327 +class CSetApplications : public CSetAppsAndTrust
   1.328 +	{
   1.329 +public:
   1.330 +	/**
   1.331 +	 * @param aInfo This is what is enclosed in the <actionbody> and </actionbody> tags 
   1.332 +	 * of the test script.
   1.333 +	 */
   1.334 +	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.335 +		const TTestActionSpec& aTestActionSpec);
   1.336 +	~CSetApplications();
   1.337 +
   1.338 +private:
   1.339 +	CSetApplications(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.340 +	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.341 +	void DoReportAction();
   1.342 +	void DoCheckResult(TInt aError);
   1.343 +	void AppendUid(const TDesC8& aUid);
   1.344 +	void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus);
   1.345 +	void DoPerformCancel();
   1.346 +
   1.347 +private:
   1.348 +	/**
   1.349 +	 * The array of applications that trust this certificate.
   1.350 +	 */
   1.351 +	RArray<TUid> iApplications;
   1.352 +	};
   1.353 +
   1.354 +/**
   1.355 + * This class is used to test the trust settings of a certificate.
   1.356 + */
   1.357 +class CSetTrusters : public CSetAppsAndTrust
   1.358 +	{
   1.359 +public:
   1.360 +	/**
   1.361 +	 * @param aInfo This is what is enclosed in the <actionbody> and </actionbody> tags 
   1.362 +	 * of the test script.
   1.363 +	 */
   1.364 +	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.365 +		const TTestActionSpec& aTestActionSpec);
   1.366 +	~CSetTrusters();
   1.367 +
   1.368 +private:
   1.369 +	CSetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.370 +	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.371 +	void DoReportAction();
   1.372 +	void DoCheckResult(TInt aError);
   1.373 +	void SetTrusted(const TDesC8& aTrusted);
   1.374 +	void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus);
   1.375 +	void DoPerformCancel();
   1.376 +
   1.377 +private:
   1.378 +	// The trusted setting to set
   1.379 +	TBool iTrusted;
   1.380 +	};
   1.381 +
   1.382 +/**
   1.383 + * This class is used to test the trust settings of a certificate.
   1.384 + */
   1.385 +class CGetTrusters : public CCertStoreTestAction
   1.386 +	{
   1.387 +public:
   1.388 +	/**
   1.389 +	 * @param aInfo This is what is enclosed in the <actionbody> and </actionbody> tags 
   1.390 +	 * of the test script.
   1.391 +	 */
   1.392 +	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   1.393 +		const TTestActionSpec& aTestActionSpec);
   1.394 +	~CGetTrusters();
   1.395 +	virtual void PerformAction(TRequestStatus& aStatus);
   1.396 +	virtual void PerformCancel();
   1.397 +	virtual void Reset();
   1.398 +
   1.399 +private:
   1.400 +	CGetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   1.401 +	void ConstructL(const TTestActionSpec& aTestActionSpec);
   1.402 +	void GetCerts(TRequestStatus& aStatus);
   1.403 +	void SetCertLabel(const TDesC8& aLabel);
   1.404 +	void SetExpectedTrusters(const TDesC8& aExpectedTrusters);
   1.405 +	void DoReportAction();
   1.406 +	void DoCheckResult(TInt aError);
   1.407 +
   1.408 +private:
   1.409 +	enum TState
   1.410 +		{
   1.411 +		EGetCAEntries,
   1.412 +		EGetTrusters,
   1.413 +		EFinished
   1.414 +		};
   1.415 +
   1.416 +private:
   1.417 +	/**
   1.418 +	 * The label of the certificate we want to get the trust settings of
   1.419 +	 */ 
   1.420 +	TCertLabel iLabel;
   1.421 +	TState iState;
   1.422 +	TBool iTrust;
   1.423 +	TBool iExpectedTrust;
   1.424 +	CCertAttributeFilter *iFilter;
   1.425 +	RMPointerArray<CCTCertInfo> iCertInfos;
   1.426 +	RArray<TUid> iTrusters;
   1.427 +	RArray<TUid> iExpectedTrusters;
   1.428 +	};
   1.429 +
   1.430 +#endif