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