os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_commands.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-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 #ifndef __CERTTOOL_COMMANDS_H_
    20 #define __CERTTOOL_COMMANDS_H_
    21 
    22 #include <e32base.h>
    23 #include <ct/rmpointerarray.h>
    24 #include <unifiedcertstore.h>
    25 #include <badesca.h>
    26 //#include <e32cmn.h>
    27 
    28 #include <keytool.rsg>
    29 
    30 #include "keytool_commands.h"
    31 
    32 class CCertToolController;
    33 
    34 /**
    35  * Interface that every keytool command class must implement.
    36  */
    37 class CCertToolCommand : public CActive
    38 	{
    39 	public:
    40 		virtual void DoCommandL(CUnifiedCertStore& aCertStore, CKeyToolParameters* aParam) = 0;
    41 		
    42 	protected:
    43 		CCertToolCommand(CCertToolController* aController);
    44 
    45 	protected:
    46 		CCertToolController* iController;
    47 		CKeyToolParameters* iParams; // we do not own this!		
    48 	};
    49 	
    50 	
    51 /**
    52  * Implements the certtool display usage action.
    53  */
    54 class CCertToolUsage : public CCertToolCommand
    55 	{
    56 public:
    57 	static CCertToolUsage* NewLC(CCertToolController* aController);
    58 	static CCertToolUsage* NewL(CCertToolController* aController);
    59 	~CCertToolUsage();
    60 	void ConstructL();
    61 
    62 public: // From CCertToolCommand
    63 	void DoCommandL(CUnifiedCertStore& aCertStore, CKeyToolParameters* aParam);
    64 	
    65 public: // From CActive
    66 	void RunL();
    67 	void DoCancel();
    68 	
    69 protected:
    70 	CCertToolUsage(CCertToolController* aController);			
    71 	};
    72 	
    73 
    74 /**
    75  * Implements the certtool display usage action.
    76  */
    77 class CCertToolListStores : public CCertToolCommand
    78 	{
    79 public:
    80 	static CCertToolListStores* NewLC(CCertToolController* aController);
    81 	static CCertToolListStores* NewL(CCertToolController* aController);
    82 	~CCertToolListStores();
    83 	void ConstructL();
    84 
    85 public: // From CCertToolCommand
    86 	void DoCommandL(CUnifiedCertStore& aCertStore, CKeyToolParameters* aParam);
    87 	
    88 public: // From CActive
    89 	void RunL();
    90 	void DoCancel();
    91 	
    92 protected:
    93 	CCertToolListStores(CCertToolController* aController);			
    94 	
    95 private:
    96 	RArray<MCTCertStore> iCertStoreList; 
    97 	};
    98 	
    99 
   100 typedef RArray<TUid> RUidArray;
   101 
   102 /**
   103  * Implements the keytool list action. This is an active object as listing is asynchronous.
   104  */
   105 class CCertToolList : public CCertToolCommand
   106 	{
   107 public:
   108 	static CCertToolList* NewLC(CCertToolController* aController);
   109 	static CCertToolList* NewL(CCertToolController* aController);
   110 	~CCertToolList();
   111 	void ConstructL();
   112 	void InitializeIterations();	
   113 
   114 public: // From CCertToolCommand
   115 	void DoCommandL(CUnifiedCertStore& aCertStore, CKeyToolParameters* aParam);
   116 		
   117 public: // From CActive
   118 	void RunL();
   119 	void DoCancel();
   120 	TInt RunError(TInt aError);	
   121 	
   122 protected:
   123 	CCertToolList(CCertToolController* aController);
   124 
   125 protected:
   126 	CUnifiedCertStore* iCertStore;
   127 	MCertStore* iCertStoreImp;
   128 	
   129 	TInt iIndex;
   130 	CCertificate* iCertificate;
   131 
   132 	RUidArray iApps;
   133 	TBool iTrust;
   134 	RArray<RUidArray> iCertApps;
   135 	RArray<TBool> iCertTrust;
   136 	RPointerArray<CCertificate> iParsedCerts;
   137 	RMPointerArray<CCTCertInfo> iCertInfos;	
   138 	CCertAttributeFilter* iFilter;
   139 
   140 	enum TState
   141 		{
   142 		EListCerts,
   143 		ERetrieve,
   144 		EGetApps,
   145 		ESetTrust,
   146 		EFinished,
   147 		EIntermediate,
   148 		EGetTrust,
   149 		} iState;			
   150 
   151 	// Number of certificates that have to be listed up to the current iteration.
   152 	TInt iCurrentListCount;	
   153 	// Keeps track of the number of iterations left.
   154 	TInt iNumberOfIterationsLeft;
   155 	// List offset for the last iteration if total number of certificates is not an exact
   156 	// multiple of default LIST_COUNT.
   157 	TInt iLastIterationOffset;
   158 	// Default list offset for each iteration.
   159 	TInt iCurrentListOffset;
   160 	};
   161 	
   162 
   163 
   164 
   165 /**
   166  * Implements the keytool import action.
   167  */
   168 class CCertToolAdd : public CCertToolCommand
   169 	{
   170 public:
   171 	static CCertToolAdd* NewLC(CCertToolController* aController);
   172 	static CCertToolAdd* NewL(CCertToolController* aController);
   173 	~CCertToolAdd();
   174 	void ConstructL();
   175 
   176 public: // From CKeyToolCommand
   177 	void DoCommandL(CUnifiedCertStore& aCertStore, CKeyToolParameters* aParam);
   178 	
   179 public: // From CActive
   180 	void RunL();
   181 	void DoCancel();
   182 	TInt RunError(TInt aError);
   183 	
   184 private:
   185 	CCertToolAdd(CCertToolController* aController);
   186 
   187 	TCertificateFormat DoRecognizeL(const TDesC8& iData);
   188 
   189 protected:
   190 	enum TState
   191 		{
   192 		EIntermediate,
   193 		EFinish
   194 		} iState;
   195 	
   196 private:
   197 	HBufC8*	iCertData;
   198 	CUnifiedCertStore* iCertStore;	
   199 	TBool iIsDeletable;
   200 	};
   201 
   202 
   203 
   204 /**
   205  * Implements the certtool remove action. 
   206  */
   207 class CCertToolRemove : public CCertToolList
   208 	{
   209 public:
   210 	static CCertToolRemove* NewLC(CCertToolController* aController);
   211 	static CCertToolRemove* NewL(CCertToolController* aController);
   212 	~CCertToolRemove();
   213 	
   214 public: // From CActive
   215 	void RunL();
   216 	TInt RunError(TInt aError);    
   217 protected:
   218 
   219 private:
   220 	CCertToolRemove(CCertToolController* aController);
   221 
   222 private:
   223 
   224 	};
   225 
   226 
   227 /**
   228 *
   229 */
   230 class CCertToolSetApps : public CCertToolList
   231 	{
   232 public:
   233 	static CCertToolSetApps* NewLC(CCertToolController* aController);
   234 	static CCertToolSetApps* NewL(CCertToolController* aController);
   235 	~CCertToolSetApps();
   236 
   237 public: // From CActive
   238 	void RunL();
   239 	TInt RunError(TInt aError);	
   240 protected:
   241 
   242 private:
   243 	CCertToolSetApps(CCertToolController* aController);
   244 	TInt iCertIndex;
   245 	};
   246 	
   247 	
   248 /**
   249 *
   250 */
   251 class CCertToolAddApps : public CCertToolList
   252 	{
   253 public:
   254 	static CCertToolAddApps* NewLC(CCertToolController* aController);
   255 	static CCertToolAddApps* NewL(CCertToolController* aController);
   256 	~CCertToolAddApps();
   257 
   258 public: // From CActive
   259 	void RunL();
   260 	TInt RunError(TInt aError);	
   261 
   262 protected:
   263 	enum TState
   264 		{
   265 		EListCerts,
   266 		ERetrieve,
   267 		EGetApps,
   268 		ESetApps,
   269 		ESetTrust,
   270 		EFinished,
   271 		EIntermediate
   272 		} iState;
   273 
   274 private:
   275 	CCertToolAddApps(CCertToolController* aController);
   276 	TInt iCertIndex;
   277 	};
   278 	
   279 /**
   280 *
   281 */
   282 class CCertToolRemoveApps : public CCertToolList
   283 	{
   284 public:
   285 	static CCertToolRemoveApps* NewLC(CCertToolController* aController);
   286 	static CCertToolRemoveApps* NewL(CCertToolController* aController);
   287 	~CCertToolRemoveApps();
   288 
   289 public: // From CActive
   290 	void RunL();
   291 	TInt RunError(TInt aError);	
   292 
   293 protected:
   294 	enum TState
   295 		{
   296 		EListCerts,
   297 		ERetrieve,
   298 		EGetApps,
   299 		ERemoveApps,
   300 		EFinished,
   301 		EIntermediate
   302 		} iState;
   303 
   304 private:
   305 	CCertToolRemoveApps(CCertToolController* aController);
   306 	
   307 	};
   308 
   309 #endif
   310