os/security/cryptoservices/certificateandkeymgmt/tcertstore/t_certstoreactions.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file 
    21  @internalTechnology
    22 */
    23  
    24 #ifndef __T_CERTSTOREACTIONS_H__
    25 #define __T_CERTSTOREACTIONS_H__
    26 
    27 #include "t_testhandler.h"
    28 #include <unifiedcertstore.h>
    29 #include <unifiedkeystore.h>
    30 #include <certificateapps.h>
    31 #include <e32cons.h>
    32 #include <badesca.h>
    33 #include "t_testaction.h"
    34 #include <cctcertinfo.h>
    35 
    36 class Output;
    37 class CSWICertStore;
    38 
    39 enum TCertStoreType
    40 	{
    41 	EUnifiedCertStore,
    42 	ESWICertStore
    43 	};
    44 
    45 class CCertStoreChangeNotifier : public CActive
    46   	{
    47   public:
    48   	static CCertStoreChangeNotifier* NewL(TInt& aNotificationFlag);
    49   	virtual ~CCertStoreChangeNotifier();
    50   	void StartNotification();
    51   	TInt& iNotifiedCounter;
    52   	void SetCompleteStatus(TRequestStatus* aStatus);
    53   private:
    54   	CCertStoreChangeNotifier(TInt& aNotificationFlag);
    55   	void ConstructL();
    56   	void DoCancel();
    57   	void RunL();
    58   private:	
    59   	RProperty iCertStoreChangeProperty;	
    60   	TRequestStatus* iCompleteStatus;
    61   	};
    62 
    63 /**
    64  * Contains either a unified cert store instance or a SWI cert store instance.
    65  * 
    66  * Either can be accessed through the CertStore() method, but
    67  * AsUnifiedCertStore() and AsSWICertStore() will panic if the store is the
    68  * wrong type.
    69  *
    70  * This class owns the cert store pointer.
    71  */
    72 class COpenCertStore : public CBase
    73 	{
    74  public:
    75 	virtual ~COpenCertStore();
    76 
    77 	TCertStoreType Type();
    78 	MCertStore& CertStore();
    79 
    80 	void SetCertStore(CUnifiedCertStore* aCertStore);
    81 	CUnifiedCertStore& AsUnifiedCertStore();
    82 
    83 	void SetCertStore(CSWICertStore* aCertStore);
    84 	CSWICertStore& AsSWICertStore();
    85 	
    86  private:
    87 
    88  private:
    89 
    90 	TBool iSet;
    91 	TCertStoreType iType;
    92 	union
    93 		{
    94 		TAny* iAny;
    95 		CUnifiedCertStore* iUnifiedCertStore;
    96 		CSWICertStore* iSwiCertStore;
    97 		};
    98 	};
    99 
   100 /**
   101  * Per-thread shared data.
   102  *
   103  * This contains stuff that is shared by more than one test action, eg the cert
   104  * stores we are testing.
   105  */
   106 class CSharedData : public CBase
   107 	{
   108 public:
   109 	~CSharedData();
   110 	void InitCertificateAppInfoManagerL();
   111 	void DeleteCertificateAppInfoManager();
   112 	RPointerArray<COpenCertStore>& CertStores();
   113 public:
   114 	RFs iFs;
   115 	RPointerArray<COpenCertStore> iCertStores;	
   116 	CCertificateAppInfoManager* iCertificateAppInfoManager;
   117 	};
   118 
   119 class CCertStoreTestAction : public CTestAction
   120 	{
   121 public:
   122 	virtual ~CCertStoreTestAction();
   123 
   124 protected:
   125 	CCertStoreTestAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   126 
   127 	// Methods for accessing the shared app info manager
   128 	void InitTheCertificateAppInfoManagerL();
   129 	void DeleteTheCertificateAppInfoManager();
   130   	CCertificateAppInfoManager* TheCertificateAppInfoManager();
   131 
   132 	// Methods for accessing the shared cert stores
   133 	TInt CertStoreCount();
   134 	TCertStoreType CertStoreType(TInt aIndex = 0);
   135 	MCertStore& CertStore(TInt aIndex = 0);
   136 	void AddCertStoreL(CUnifiedCertStore* aCertStore);
   137 	CUnifiedCertStore& UnifiedCertStore(TInt aIndex = 0);
   138 	void AddCertStoreL(CSWICertStore* aCertStore);
   139 	CSWICertStore& SWICertStore(TInt aIndex = 0);
   140 	void RemoveCertStore(TInt aIndex);
   141 
   142 protected:
   143 	RFs& iFs;
   144 
   145  private:
   146 	CSharedData& CertStoreSharedData();
   147 	RPointerArray<COpenCertStore>& CertStores();	
   148 	void DoPerformPrerequisite(TRequestStatus& aStatus);
   149 	void DoPerformPostrequisite(TRequestStatus& aStatus);
   150 	};
   151 
   152 class CSubscriberAction: public CCertStoreTestAction
   153 	{
   154 public:
   155  	virtual ~CSubscriberAction();
   156  
   157 protected:
   158  	CSubscriberAction(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   159  	void ConstructL(const TTestActionSpec& aTestActionSpec);
   160  	TInt iNotifierFlag;
   161  	TInt iNotificationSubscribed;		
   162  	CCertStoreChangeNotifier* iNotifier;		
   163  	};
   164 
   165 /**
   166  * This action creates and initializes a certificate store manager.
   167  * It should be used before any action requiring a certificate store manager.
   168  * All the actions are likely to require one.
   169  */
   170 class CInitialiseCertStore : public CCertStoreTestAction
   171 	{
   172 public:
   173 	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole,
   174 		Output& aOut, const TTestActionSpec& aTestActionSpec);
   175 	static CTestAction* NewLC(RFs& aFs, CConsoleBase& aConsole,	
   176 		Output& aOut, const TTestActionSpec& aTestActionSpec);
   177 	~CInitialiseCertStore();
   178 
   179 public:
   180 	virtual void PerformAction(TRequestStatus& aStatus);
   181 	virtual void PerformCancel();
   182 	virtual void Reset();
   183 
   184 private:
   185 	CInitialiseCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   186 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   187 	void DoReportAction();
   188 	void DoCheckResult(TInt aError);
   189 
   190 private:
   191 	enum TState
   192 		{
   193 		ENew,
   194 		EAppend,
   195 		ECheckOrder,
   196 		EFinished
   197 		};
   198 
   199 private:
   200 	TState iState;
   201 	TBool iOpenedForWrite;
   202  	RArray<TInt> iFilterOrdering;
   203  	RArray<TInt32> iExpectedOrderingResult;
   204 	CUnifiedCertStore* iNewUnifiedCertStore;
   205 	};
   206 
   207 class COnlyCreateCertStore : public CCertStoreTestAction
   208 	{
   209 public:
   210 	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   211 		const TTestActionSpec& aTestActionSpec);
   212 	~COnlyCreateCertStore() {};
   213 
   214 public:
   215 	virtual void PerformAction(TRequestStatus& aStatus);
   216 	virtual void PerformCancel();
   217 	virtual void Reset();
   218 
   219 private:
   220 	enum TState
   221 		{
   222 		EInit,
   223 		EFinished
   224 		};
   225 
   226 private:
   227 	COnlyCreateCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   228 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   229 	void DoReportAction();
   230 	void DoCheckResult(TInt aError);
   231 
   232 private:
   233 	TState iState;
   234 	TBool iOpenedForWrite;
   235 
   236 	CUnifiedCertStore* iNewUnifiedCertStore;
   237 	};
   238 
   239 class CDeleteCertStore : public CCertStoreTestAction
   240 	{
   241 	public:
   242 		static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut,
   243 			const TTestActionSpec& aTestActionSpec);
   244 		static CTestAction* NewLC(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   245 			const TTestActionSpec& aTestActionSpec);
   246 		~CDeleteCertStore();
   247 		virtual void PerformAction(TRequestStatus& aStatus);
   248 		virtual void PerformCancel();
   249 		virtual void Reset();
   250 
   251 	private:
   252 		CDeleteCertStore(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   253 		void ConstructL(const TTestActionSpec& aTestActionSpec);
   254 		void DoReportAction();
   255 		void DoCheckResult(TInt aError);
   256 
   257 	private:
   258 		enum TState
   259 			{
   260 			EDelete,
   261 			EFinished
   262 			};
   263 
   264 	private:
   265 		TState iState;
   266 	};
   267 
   268 
   269 class CX509Certificate;
   270 class CWTLSCertificate;
   271 
   272 // This is the base class used by both CSetApplications and CSetTrusters. This
   273 // is required because of the merging of the SetApplicability and SetTrust API
   274 // calls on the certstore
   275 class CSetAppsAndTrust : public CSubscriberAction
   276 
   277 	{
   278 public:
   279 	~CSetAppsAndTrust();
   280 	virtual void PerformAction(TRequestStatus& aStatus);
   281 	virtual void Reset();
   282 	virtual void PerformCancel();
   283 
   284 protected:
   285 	CSetAppsAndTrust(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   286 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   287 	void GetCerts(TRequestStatus& aStatus);
   288 	void SetCertLabel(const TDesC8& aLabel);
   289 
   290 	/** Implemented by derived classes, called from PerformAction. */
   291 	virtual void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus) = 0;
   292 	/** Implemented by derived classes, called from PerformCancel. */
   293 	virtual void DoPerformCancel() = 0;
   294 
   295 protected:
   296 	enum TState
   297 		{
   298 		EGetCAEntries,
   299 		ESetAppTrust,
   300 		ECheckNotification,
   301 		EFinished
   302 		};
   303 
   304 protected:
   305 	/**
   306 	 * The label of the certificate we want to set the trust settings for
   307 	 */ 
   308 	TCertLabel iLabel;
   309 
   310 	// Index into the certinfo list which points to the certificate we
   311 	// are interested in
   312 	TInt iIndex;
   313 	 
   314 	TState iState;
   315 	CCertAttributeFilter *iFilter;
   316 	RMPointerArray<CCTCertInfo> iCertInfos;
   317 	};
   318 
   319 
   320 
   321 /**
   322  * This class is used to test the trust settings of a certificate.
   323  */
   324 class CSetApplications : public CSetAppsAndTrust
   325 	{
   326 public:
   327 	/**
   328 	 * @param aInfo This is what is enclosed in the <actionbody> and </actionbody> tags 
   329 	 * of the test script.
   330 	 */
   331 	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   332 		const TTestActionSpec& aTestActionSpec);
   333 	~CSetApplications();
   334 
   335 private:
   336 	CSetApplications(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   337 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   338 	void DoReportAction();
   339 	void DoCheckResult(TInt aError);
   340 	void AppendUid(const TDesC8& aUid);
   341 	void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus);
   342 	void DoPerformCancel();
   343 
   344 private:
   345 	/**
   346 	 * The array of applications that trust this certificate.
   347 	 */
   348 	RArray<TUid> iApplications;
   349 	};
   350 
   351 /**
   352  * This class is used to test the trust settings of a certificate.
   353  */
   354 class CSetTrusters : public CSetAppsAndTrust
   355 	{
   356 public:
   357 	/**
   358 	 * @param aInfo This is what is enclosed in the <actionbody> and </actionbody> tags 
   359 	 * of the test script.
   360 	 */
   361 	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   362 		const TTestActionSpec& aTestActionSpec);
   363 	~CSetTrusters();
   364 
   365 private:
   366 	CSetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   367 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   368 	void DoReportAction();
   369 	void DoCheckResult(TInt aError);
   370 	void SetTrusted(const TDesC8& aTrusted);
   371 	void DoSetAppTrust(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus);
   372 	void DoPerformCancel();
   373 
   374 private:
   375 	// The trusted setting to set
   376 	TBool iTrusted;
   377 	};
   378 
   379 /**
   380  * This class is used to test the trust settings of a certificate.
   381  */
   382 class CGetTrusters : public CCertStoreTestAction
   383 	{
   384 public:
   385 	/**
   386 	 * @param aInfo This is what is enclosed in the <actionbody> and </actionbody> tags 
   387 	 * of the test script.
   388 	 */
   389 	static CTestAction* NewL(RFs& aFs, CConsoleBase& aConsole, Output& aOut, 
   390 		const TTestActionSpec& aTestActionSpec);
   391 	~CGetTrusters();
   392 	virtual void PerformAction(TRequestStatus& aStatus);
   393 	virtual void PerformCancel();
   394 	virtual void Reset();
   395 
   396 private:
   397 	CGetTrusters(RFs& aFs, CConsoleBase& aConsole, Output& aOut);
   398 	void ConstructL(const TTestActionSpec& aTestActionSpec);
   399 	void GetCerts(TRequestStatus& aStatus);
   400 	void SetCertLabel(const TDesC8& aLabel);
   401 	void SetExpectedTrusters(const TDesC8& aExpectedTrusters);
   402 	void DoReportAction();
   403 	void DoCheckResult(TInt aError);
   404 
   405 private:
   406 	enum TState
   407 		{
   408 		EGetCAEntries,
   409 		EGetTrusters,
   410 		EFinished
   411 		};
   412 
   413 private:
   414 	/**
   415 	 * The label of the certificate we want to get the trust settings of
   416 	 */ 
   417 	TCertLabel iLabel;
   418 	TState iState;
   419 	TBool iTrust;
   420 	TBool iExpectedTrust;
   421 	CCertAttributeFilter *iFilter;
   422 	RMPointerArray<CCTCertInfo> iCertInfos;
   423 	RArray<TUid> iTrusters;
   424 	RArray<TUid> iExpectedTrusters;
   425 	};
   426 
   427 #endif