os/security/cryptoservices/filebasedcertificateandkeystores/test/keytool/keytool_commands.h
First public contribution.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifndef __KEYTOOL_COMMANDS_H_
20 #define __KEYTOOL_COMMANDS_H_
23 #include <ct/rmpointerarray.h>
24 #include <mctkeystore.h>
25 #include <unifiedkeystore.h>
29 #include <authserver/authtypes.h>
30 #include <authserver/identity.h>
31 #include <authserver/authclient.h>
35 class CKeyToolController;
39 class CPermanentFileStore;
40 class CKeyStoreCenrep;
45 * This class wraps up the command line parameters
46 * which affect the keystore command to be executed.
47 * E.g. the key label we refer to, the key store to use, etc.
49 class CKeyToolParameters : public CBase
52 static CKeyToolParameters* NewLC();
53 ~CKeyToolParameters();
57 EMandatoryArgumentMissing=1,
81 TKeyUsagePKCS15 iUsage;
82 CKeyInfoBase::EKeyAccess iAccess;
93 HBufC* iAuthExpression;
101 * Interface that every keytool command class must implement.
103 class CKeyToolCommand : public CActive
106 virtual void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam) = 0;
109 CKeyToolCommand(CController* aController);
112 CController* iController;
113 CKeyToolParameters* iParams; // we do not own this!
118 * Implements the keytool list action. This is an active object as listing is asynchronous.
120 class CKeytoolUsage : public CKeyToolCommand
123 static CKeytoolUsage* NewLC(CKeyToolController* aController);
124 static CKeytoolUsage* NewL(CKeyToolController* aController);
128 public: // From CKeyToolCommand
129 void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
131 public: // From CActive
136 CKeytoolUsage(CKeyToolController* aController);
141 * Implements the keytool list action. This is an active object as listing is asynchronous.
143 class CKeytoolList : public CKeyToolCommand
146 static CKeytoolList* NewLC(CKeyToolController* aController);
147 static CKeytoolList* NewL(CKeyToolController* aController);
151 public: // From CKeyToolCommand
152 void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
154 public: // From CActive
157 TInt RunError(TInt aError);
160 CKeytoolList(CKeyToolController* aController);
163 RMPointerArray<CCTKeyInfo> iKeys;
164 CUnifiedKeyStore* iKeyStore;
165 TCTKeyAttributeFilter iFilter;
166 MKeyStore* iKeyStoreImp;
180 * Implements the keytool import action.
182 class CKeytoolImport : public CKeyToolCommand
185 static CKeytoolImport* NewLC(CController* aController);
186 static CKeytoolImport* NewL(CController* aController);
190 public: // From CKeyToolCommand
191 void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
193 public: // From CActive
196 TInt RunError(TInt aError);
200 * Given some (supposed) pkcs8 data, tells you whether we are dealing with
201 * a PrivateKeyInfo or EncryptedPrivateKeyInfo ASN1 type.
203 TBool IsPkcs8EncryptedL(TDesC8& aBinaryData);
206 CKeytoolImport(CController* aController);
207 void Pkcs8PreprocessorL();
211 CCTKeyInfo* iKeyInfo;
218 * Implements the keytool remove action.
220 class CKeytoolRemove : public CKeytoolList
223 static CKeytoolRemove* NewLC(CKeyToolController* aController);
224 static CKeytoolRemove* NewL(CKeyToolController* aController);
227 public: // From CActive
233 CKeytoolRemove(CKeyToolController* aController);
236 RArray<CCTKeyInfo*> iKeyList;
244 class CKeyToolListStores : public CKeyToolCommand
247 static CKeyToolListStores* NewLC(CKeyToolController* aController);
248 static CKeyToolListStores* NewL(CKeyToolController* aController);
249 ~CKeyToolListStores();
252 public: // From CCertToolCommand
253 void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam);
255 public: // From CActive
260 CKeyToolListStores(CKeyToolController* aController);
263 RArray<MCTKeyStore> iCertStoreList;
268 * Implements the keytool set policy action.
270 class CKeytoolSetPolicy : public CKeytoolList
273 static CKeytoolSetPolicy* NewLC(CKeyToolController* aController);
274 static CKeytoolSetPolicy* NewL(CKeyToolController* aController);
275 ~CKeytoolSetPolicy();
277 public: // From CActive
279 TInt RunError(TInt aError);
283 CKeytoolSetPolicy(CKeyToolController* aController);
294 * Implements the migration of old keystore to the new keystore format
295 * which uses the authentication server.
297 class CKeytoolMigrateStore : public CActive
301 enum TMigrateStoreState
303 EAfterAuthentication,
307 static CKeytoolMigrateStore* NewLC(CKeyToolParameters* aParams);
308 static CKeytoolMigrateStore* NewL(CKeyToolParameters* aParams);
309 ~CKeytoolMigrateStore();
310 void ConstructL(CKeyToolParameters* aParams);
312 public: // From CKeyToolCommand
315 public: // From CActive
318 TInt RunError(TInt aError);
321 CKeytoolMigrateStore();
322 void WriteKeyL( const CKeyInfo& aKeyInfo,
323 RStoreWriteStream& aWriteInfoStream );
325 void WriteAuthDetailsL( RStoreWriteStream& aWriteInfoStream );
326 void RevertStore(TAny* aStore);
327 void InitializeDefaultParams();
328 void WriteKeyInformationL();
329 template <class T> inline void EncryptAndStoreL(const T& aKey, RStoreWriteStream& aStream );
330 void StoreKeyL(const TDesC8& aKeyData, RStoreWriteStream& aStream);
331 template <class T> void RetrieveAndStorePublicKeyL( CFileKeyData* aKeyData, T* aPublicKey );
332 template <class T> void RetrieveAndStorePrivateKeyL( CFileKeyData* aKeyData, T* aPrivateKey );
333 static void CleanKeyInfo(TAny* aKeyInfo);
336 AuthServer::TIdentityId iIdentityId;
337 AuthServer::RAuthClient iAuthClient;
338 CPermanentFileStore* iWriteFileStore;
339 CPermanentFileStore* iReadFileStore;
340 TStreamId iWriteLookupStreamId;
341 CKeyToolParameters* iParams;
343 CKeyStoreCenrep* iKeyStoreCenrep;
344 CPassphrase* iPassphrase;
345 AuthServer::CIdentity* iUserIdentity;
346 TMigrateStoreState iState;
348 RPointerArray<CFileKeyData> iKeyList;