os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_commands.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-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
#ifndef __KEYTOOL_COMMANDS_H_
sl@0
    20
#define __KEYTOOL_COMMANDS_H_
sl@0
    21
sl@0
    22
#include <e32base.h>
sl@0
    23
#include <ct/rmpointerarray.h>
sl@0
    24
#include <mctkeystore.h>
sl@0
    25
#include <unifiedkeystore.h>
sl@0
    26
#include <badesca.h>
sl@0
    27
sl@0
    28
#ifdef KEYTOOL
sl@0
    29
#include <authserver/authtypes.h>
sl@0
    30
#include <authserver/identity.h>
sl@0
    31
#include <authserver/authclient.h>
sl@0
    32
#endif // KEYTOOL
sl@0
    33
sl@0
    34
class CController;
sl@0
    35
class CKeyToolController;
sl@0
    36
#ifdef KEYTOOL
sl@0
    37
class CKeyInfo;
sl@0
    38
class CFileKeyData;
sl@0
    39
class CPermanentFileStore;
sl@0
    40
class CKeyStoreCenrep;
sl@0
    41
class CPassphrase;
sl@0
    42
#endif // KEYTOOL
sl@0
    43
sl@0
    44
/** 
sl@0
    45
 * This class wraps up the command line parameters
sl@0
    46
 * which affect the keystore command to be executed.
sl@0
    47
 * E.g. the key label we refer to, the key store to use, etc.
sl@0
    48
 */
sl@0
    49
class CKeyToolParameters : public CBase
sl@0
    50
	{
sl@0
    51
	public:
sl@0
    52
		static CKeyToolParameters* NewLC();
sl@0
    53
		~CKeyToolParameters();
sl@0
    54
#ifdef KEYTOOL
sl@0
    55
		enum TErrors
sl@0
    56
			{
sl@0
    57
			EMandatoryArgumentMissing=1,
sl@0
    58
			};
sl@0
    59
#endif // KEYTOOL
sl@0
    60
	enum TSetPolicy
sl@0
    61
		{
sl@0
    62
		ENone =0,
sl@0
    63
		ESetUserPolicy,
sl@0
    64
		ESetManagerPolicy,
sl@0
    65
		ERemoveUserPolicy,
sl@0
    66
		ESetAllUsersPolicy,
sl@0
    67
		};	
sl@0
    68
	protected:
sl@0
    69
		void ConstructL();
sl@0
    70
sl@0
    71
	private:
sl@0
    72
		CKeyToolParameters();
sl@0
    73
sl@0
    74
	public:
sl@0
    75
		TBool						iIsDetailed;
sl@0
    76
		HBufC* 						iPrivate;
sl@0
    77
		HBufC* 						iLabel;
sl@0
    78
		HBufC* 						iDefault;
sl@0
    79
		TInt 						iKeystoreIndex;
sl@0
    80
		TInt 						iCertstoreIndex;
sl@0
    81
		TKeyUsagePKCS15	 			iUsage;
sl@0
    82
		CKeyInfoBase::EKeyAccess	iAccess;
sl@0
    83
		TTime						iEndDate;
sl@0
    84
		RArray<TUid>				iUIDs;
sl@0
    85
		HBufC* 						iOwnerType;
sl@0
    86
		TBool 						iPageWise;
sl@0
    87
		TBool						iRemoveKey;
sl@0
    88
		TSetPolicy					iPolicy;
sl@0
    89
		HBufC*                      iIsDeletable;
sl@0
    90
#ifdef KEYTOOL
sl@0
    91
		HBufC*						iOldKeyFile;
sl@0
    92
		HBufC*						iNewKeyFile;
sl@0
    93
		HBufC* 						iAuthExpression;
sl@0
    94
		TInt						iFreshness;
sl@0
    95
		HBufC*						iPassphrase;
sl@0
    96
#endif // KEYTOOL
sl@0
    97
	};
sl@0
    98
sl@0
    99
sl@0
   100
/**
sl@0
   101
 * Interface that every keytool command class must implement.
sl@0
   102
 */
sl@0
   103
class CKeyToolCommand : public CActive
sl@0
   104
	{
sl@0
   105
	public:
sl@0
   106
		virtual void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam) = 0;
sl@0
   107
		
sl@0
   108
	protected:
sl@0
   109
		CKeyToolCommand(CController* aController);
sl@0
   110
sl@0
   111
	protected:
sl@0
   112
		CController* iController;
sl@0
   113
		CKeyToolParameters* iParams; // we do not own this!		
sl@0
   114
	};
sl@0
   115
	
sl@0
   116
	
sl@0
   117
/**
sl@0
   118
 * Implements the keytool list action. This is an active object as listing is asynchronous.
sl@0
   119
 */
sl@0
   120
class CKeytoolUsage : public CKeyToolCommand
sl@0
   121
	{
sl@0
   122
public:
sl@0
   123
	static CKeytoolUsage* NewLC(CKeyToolController* aController);
sl@0
   124
	static CKeytoolUsage* NewL(CKeyToolController* aController);
sl@0
   125
	~CKeytoolUsage();
sl@0
   126
	void ConstructL();
sl@0
   127
sl@0
   128
public: // From CKeyToolCommand
sl@0
   129
	void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
sl@0
   130
	
sl@0
   131
public: // From CActive
sl@0
   132
	void RunL();
sl@0
   133
	void DoCancel();
sl@0
   134
	
sl@0
   135
protected:
sl@0
   136
	CKeytoolUsage(CKeyToolController* aController);			
sl@0
   137
	};
sl@0
   138
	
sl@0
   139
sl@0
   140
/**
sl@0
   141
 * Implements the keytool list action. This is an active object as listing is asynchronous.
sl@0
   142
 */
sl@0
   143
class CKeytoolList : public CKeyToolCommand
sl@0
   144
	{
sl@0
   145
public:
sl@0
   146
	static CKeytoolList* NewLC(CKeyToolController* aController);
sl@0
   147
	static CKeytoolList* NewL(CKeyToolController* aController);
sl@0
   148
	~CKeytoolList();
sl@0
   149
	void ConstructL();
sl@0
   150
sl@0
   151
public: // From CKeyToolCommand
sl@0
   152
	void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
sl@0
   153
	
sl@0
   154
public: // From CActive
sl@0
   155
	void RunL();
sl@0
   156
	void DoCancel();
sl@0
   157
	TInt RunError(TInt aError);	
sl@0
   158
	
sl@0
   159
protected:
sl@0
   160
	CKeytoolList(CKeyToolController* aController);
sl@0
   161
sl@0
   162
protected:
sl@0
   163
	RMPointerArray<CCTKeyInfo> iKeys;
sl@0
   164
	CUnifiedKeyStore* iKeyStore;
sl@0
   165
	TCTKeyAttributeFilter iFilter;
sl@0
   166
	MKeyStore* iKeyStoreImp;
sl@0
   167
	
sl@0
   168
	enum TState
sl@0
   169
		{
sl@0
   170
		EListKeys,
sl@0
   171
		EFinished,
sl@0
   172
		EIntermediate
sl@0
   173
		} iState;			
sl@0
   174
	};
sl@0
   175
	
sl@0
   176
sl@0
   177
sl@0
   178
sl@0
   179
/**
sl@0
   180
 * Implements the keytool import action.
sl@0
   181
 */
sl@0
   182
class CKeytoolImport : public CKeyToolCommand
sl@0
   183
	{
sl@0
   184
public:
sl@0
   185
	static CKeytoolImport* NewLC(CController* aController);
sl@0
   186
	static CKeytoolImport* NewL(CController* aController);
sl@0
   187
	~CKeytoolImport();
sl@0
   188
	void ConstructL();
sl@0
   189
sl@0
   190
public: // From CKeyToolCommand
sl@0
   191
	void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
sl@0
   192
	
sl@0
   193
public: // From CActive
sl@0
   194
	void RunL();
sl@0
   195
	void DoCancel();
sl@0
   196
	TInt RunError(TInt aError);
sl@0
   197
	
sl@0
   198
protected:	
sl@0
   199
	/**
sl@0
   200
	 * Given some (supposed) pkcs8 data, tells you whether we are dealing with 
sl@0
   201
	 * a PrivateKeyInfo or EncryptedPrivateKeyInfo ASN1 type.
sl@0
   202
	 */
sl@0
   203
	TBool IsPkcs8EncryptedL(TDesC8& aBinaryData);
sl@0
   204
	
sl@0
   205
private:
sl@0
   206
	CKeytoolImport(CController* aController);
sl@0
   207
	void Pkcs8PreprocessorL();
sl@0
   208
	
sl@0
   209
private:
sl@0
   210
	HBufC8* iKeyData;
sl@0
   211
	CCTKeyInfo* iKeyInfo;	
sl@0
   212
	};
sl@0
   213
sl@0
   214
sl@0
   215
sl@0
   216
sl@0
   217
/**
sl@0
   218
 * Implements the keytool remove action. 
sl@0
   219
 */
sl@0
   220
class CKeytoolRemove : public CKeytoolList
sl@0
   221
	{
sl@0
   222
public:
sl@0
   223
	static CKeytoolRemove* NewLC(CKeyToolController* aController);
sl@0
   224
	static CKeytoolRemove* NewL(CKeyToolController* aController);
sl@0
   225
	~CKeytoolRemove();
sl@0
   226
	
sl@0
   227
public: // From CActive
sl@0
   228
	void RunL();
sl@0
   229
	
sl@0
   230
protected:
sl@0
   231
sl@0
   232
private:
sl@0
   233
	CKeytoolRemove(CKeyToolController* aController);
sl@0
   234
sl@0
   235
private:
sl@0
   236
	RArray<CCTKeyInfo*> iKeyList;
sl@0
   237
	TInt idx;
sl@0
   238
	};
sl@0
   239
sl@0
   240
sl@0
   241
sl@0
   242
/**
sl@0
   243
 */
sl@0
   244
class CKeyToolListStores : public CKeyToolCommand
sl@0
   245
	{
sl@0
   246
public:
sl@0
   247
	static CKeyToolListStores* NewLC(CKeyToolController* aController);
sl@0
   248
	static CKeyToolListStores* NewL(CKeyToolController* aController);
sl@0
   249
	~CKeyToolListStores();
sl@0
   250
	void ConstructL();
sl@0
   251
sl@0
   252
public: // From CCertToolCommand
sl@0
   253
	void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
sl@0
   254
	
sl@0
   255
public: // From CActive
sl@0
   256
	void RunL();
sl@0
   257
	void DoCancel();	
sl@0
   258
	
sl@0
   259
protected:
sl@0
   260
	CKeyToolListStores(CKeyToolController* aController);			
sl@0
   261
	
sl@0
   262
private:
sl@0
   263
	RArray<MCTKeyStore> iCertStoreList; 
sl@0
   264
	};
sl@0
   265
sl@0
   266
sl@0
   267
/**
sl@0
   268
 * Implements the keytool set policy action. 
sl@0
   269
 */
sl@0
   270
class CKeytoolSetPolicy : public CKeytoolList
sl@0
   271
	{
sl@0
   272
public:
sl@0
   273
	static CKeytoolSetPolicy* NewLC(CKeyToolController* aController);
sl@0
   274
	static CKeytoolSetPolicy* NewL(CKeyToolController* aController);
sl@0
   275
	~CKeytoolSetPolicy();
sl@0
   276
	
sl@0
   277
public: // From CActive
sl@0
   278
	void RunL();
sl@0
   279
	TInt RunError(TInt aError);
sl@0
   280
protected:
sl@0
   281
sl@0
   282
private:
sl@0
   283
	CKeytoolSetPolicy(CKeyToolController* aController);
sl@0
   284
sl@0
   285
private:
sl@0
   286
	CCTKeyInfo* iKey;
sl@0
   287
	TInt idx;
sl@0
   288
	};
sl@0
   289
sl@0
   290
sl@0
   291
#ifdef KEYTOOL
sl@0
   292
sl@0
   293
/**
sl@0
   294
 * Implements the migration of old keystore to the new keystore format 
sl@0
   295
 * which uses the authentication server. 
sl@0
   296
 */
sl@0
   297
class CKeytoolMigrateStore : public CActive
sl@0
   298
	{
sl@0
   299
	
sl@0
   300
private:
sl@0
   301
	enum TMigrateStoreState
sl@0
   302
		{
sl@0
   303
		EAfterAuthentication,
sl@0
   304
		
sl@0
   305
		};
sl@0
   306
public:
sl@0
   307
	static CKeytoolMigrateStore* NewLC(CKeyToolParameters* aParams);
sl@0
   308
	static CKeytoolMigrateStore* NewL(CKeyToolParameters* aParams);
sl@0
   309
	~CKeytoolMigrateStore();
sl@0
   310
	void ConstructL(CKeyToolParameters* aParams);
sl@0
   311
sl@0
   312
public: // From CKeyToolCommand
sl@0
   313
	void DoCommandL();
sl@0
   314
sl@0
   315
public: // From CActive
sl@0
   316
	void RunL();
sl@0
   317
	void DoCancel();
sl@0
   318
	TInt RunError(TInt aError);	
sl@0
   319
	
sl@0
   320
private:
sl@0
   321
	CKeytoolMigrateStore();
sl@0
   322
	void WriteKeyL(	const CKeyInfo& aKeyInfo, 
sl@0
   323
					RStoreWriteStream& aWriteInfoStream );
sl@0
   324
sl@0
   325
	void WriteAuthDetailsL( RStoreWriteStream& aWriteInfoStream );
sl@0
   326
	void RevertStore(TAny* aStore);
sl@0
   327
	void InitializeDefaultParams();
sl@0
   328
	void WriteKeyInformationL();
sl@0
   329
	template <class T> inline void EncryptAndStoreL(const T& aKey, RStoreWriteStream& aStream );
sl@0
   330
	void StoreKeyL(const TDesC8& aKeyData, RStoreWriteStream& aStream);
sl@0
   331
	template <class T> void RetrieveAndStorePublicKeyL( CFileKeyData* aKeyData, T* aPublicKey );
sl@0
   332
	template <class T> void RetrieveAndStorePrivateKeyL( CFileKeyData* aKeyData, T* aPrivateKey );
sl@0
   333
	static void CleanKeyInfo(TAny* aKeyInfo);
sl@0
   334
	
sl@0
   335
private:
sl@0
   336
	AuthServer::TIdentityId iIdentityId;
sl@0
   337
	AuthServer::RAuthClient iAuthClient; 
sl@0
   338
	CPermanentFileStore* iWriteFileStore;
sl@0
   339
	CPermanentFileStore* iReadFileStore;
sl@0
   340
	TStreamId iWriteLookupStreamId;
sl@0
   341
	CKeyToolParameters* iParams;
sl@0
   342
	RFs iFs;
sl@0
   343
	CKeyStoreCenrep* iKeyStoreCenrep;
sl@0
   344
	CPassphrase* iPassphrase;
sl@0
   345
	AuthServer::CIdentity* iUserIdentity;
sl@0
   346
	TMigrateStoreState iState;
sl@0
   347
	
sl@0
   348
	RPointerArray<CFileKeyData> iKeyList;
sl@0
   349
	};
sl@0
   350
sl@0
   351
#endif // KEYTOOL
sl@0
   352
#endif
sl@0
   353