sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #ifndef __KEYTOOL_COMMANDS_H_ sl@0: #define __KEYTOOL_COMMANDS_H_ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef KEYTOOL sl@0: #include sl@0: #include sl@0: #include sl@0: #endif // KEYTOOL sl@0: sl@0: class CController; sl@0: class CKeyToolController; sl@0: #ifdef KEYTOOL sl@0: class CKeyInfo; sl@0: class CFileKeyData; sl@0: class CPermanentFileStore; sl@0: class CKeyStoreCenrep; sl@0: class CPassphrase; sl@0: #endif // KEYTOOL sl@0: sl@0: /** sl@0: * This class wraps up the command line parameters sl@0: * which affect the keystore command to be executed. sl@0: * E.g. the key label we refer to, the key store to use, etc. sl@0: */ sl@0: class CKeyToolParameters : public CBase sl@0: { sl@0: public: sl@0: static CKeyToolParameters* NewLC(); sl@0: ~CKeyToolParameters(); sl@0: #ifdef KEYTOOL sl@0: enum TErrors sl@0: { sl@0: EMandatoryArgumentMissing=1, sl@0: }; sl@0: #endif // KEYTOOL sl@0: enum TSetPolicy sl@0: { sl@0: ENone =0, sl@0: ESetUserPolicy, sl@0: ESetManagerPolicy, sl@0: ERemoveUserPolicy, sl@0: ESetAllUsersPolicy, sl@0: }; sl@0: protected: sl@0: void ConstructL(); sl@0: sl@0: private: sl@0: CKeyToolParameters(); sl@0: sl@0: public: sl@0: TBool iIsDetailed; sl@0: HBufC* iPrivate; sl@0: HBufC* iLabel; sl@0: HBufC* iDefault; sl@0: TInt iKeystoreIndex; sl@0: TInt iCertstoreIndex; sl@0: TKeyUsagePKCS15 iUsage; sl@0: CKeyInfoBase::EKeyAccess iAccess; sl@0: TTime iEndDate; sl@0: RArray iUIDs; sl@0: HBufC* iOwnerType; sl@0: TBool iPageWise; sl@0: TBool iRemoveKey; sl@0: TSetPolicy iPolicy; sl@0: HBufC* iIsDeletable; sl@0: #ifdef KEYTOOL sl@0: HBufC* iOldKeyFile; sl@0: HBufC* iNewKeyFile; sl@0: HBufC* iAuthExpression; sl@0: TInt iFreshness; sl@0: HBufC* iPassphrase; sl@0: #endif // KEYTOOL sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Interface that every keytool command class must implement. sl@0: */ sl@0: class CKeyToolCommand : public CActive sl@0: { sl@0: public: sl@0: virtual void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam) = 0; sl@0: sl@0: protected: sl@0: CKeyToolCommand(CController* aController); sl@0: sl@0: protected: sl@0: CController* iController; sl@0: CKeyToolParameters* iParams; // we do not own this! sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Implements the keytool list action. This is an active object as listing is asynchronous. sl@0: */ sl@0: class CKeytoolUsage : public CKeyToolCommand sl@0: { sl@0: public: sl@0: static CKeytoolUsage* NewLC(CKeyToolController* aController); sl@0: static CKeytoolUsage* NewL(CKeyToolController* aController); sl@0: ~CKeytoolUsage(); sl@0: void ConstructL(); sl@0: sl@0: public: // From CKeyToolCommand sl@0: void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: protected: sl@0: CKeytoolUsage(CKeyToolController* aController); sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Implements the keytool list action. This is an active object as listing is asynchronous. sl@0: */ sl@0: class CKeytoolList : public CKeyToolCommand sl@0: { sl@0: public: sl@0: static CKeytoolList* NewLC(CKeyToolController* aController); sl@0: static CKeytoolList* NewL(CKeyToolController* aController); sl@0: ~CKeytoolList(); sl@0: void ConstructL(); sl@0: sl@0: public: // From CKeyToolCommand sl@0: void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: protected: sl@0: CKeytoolList(CKeyToolController* aController); sl@0: sl@0: protected: sl@0: RMPointerArray iKeys; sl@0: CUnifiedKeyStore* iKeyStore; sl@0: TCTKeyAttributeFilter iFilter; sl@0: MKeyStore* iKeyStoreImp; sl@0: sl@0: enum TState sl@0: { sl@0: EListKeys, sl@0: EFinished, sl@0: EIntermediate sl@0: } iState; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Implements the keytool import action. sl@0: */ sl@0: class CKeytoolImport : public CKeyToolCommand sl@0: { sl@0: public: sl@0: static CKeytoolImport* NewLC(CController* aController); sl@0: static CKeytoolImport* NewL(CController* aController); sl@0: ~CKeytoolImport(); sl@0: void ConstructL(); sl@0: sl@0: public: // From CKeyToolCommand sl@0: void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: protected: sl@0: /** sl@0: * Given some (supposed) pkcs8 data, tells you whether we are dealing with sl@0: * a PrivateKeyInfo or EncryptedPrivateKeyInfo ASN1 type. sl@0: */ sl@0: TBool IsPkcs8EncryptedL(TDesC8& aBinaryData); sl@0: sl@0: private: sl@0: CKeytoolImport(CController* aController); sl@0: void Pkcs8PreprocessorL(); sl@0: sl@0: private: sl@0: HBufC8* iKeyData; sl@0: CCTKeyInfo* iKeyInfo; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: * Implements the keytool remove action. sl@0: */ sl@0: class CKeytoolRemove : public CKeytoolList sl@0: { sl@0: public: sl@0: static CKeytoolRemove* NewLC(CKeyToolController* aController); sl@0: static CKeytoolRemove* NewL(CKeyToolController* aController); sl@0: ~CKeytoolRemove(); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: sl@0: protected: sl@0: sl@0: private: sl@0: CKeytoolRemove(CKeyToolController* aController); sl@0: sl@0: private: sl@0: RArray iKeyList; sl@0: TInt idx; sl@0: }; sl@0: sl@0: sl@0: sl@0: /** sl@0: */ sl@0: class CKeyToolListStores : public CKeyToolCommand sl@0: { sl@0: public: sl@0: static CKeyToolListStores* NewLC(CKeyToolController* aController); sl@0: static CKeyToolListStores* NewL(CKeyToolController* aController); sl@0: ~CKeyToolListStores(); sl@0: void ConstructL(); sl@0: sl@0: public: // From CCertToolCommand sl@0: void DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: protected: sl@0: CKeyToolListStores(CKeyToolController* aController); sl@0: sl@0: private: sl@0: RArray iCertStoreList; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Implements the keytool set policy action. sl@0: */ sl@0: class CKeytoolSetPolicy : public CKeytoolList sl@0: { sl@0: public: sl@0: static CKeytoolSetPolicy* NewLC(CKeyToolController* aController); sl@0: static CKeytoolSetPolicy* NewL(CKeyToolController* aController); sl@0: ~CKeytoolSetPolicy(); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: TInt RunError(TInt aError); sl@0: protected: sl@0: sl@0: private: sl@0: CKeytoolSetPolicy(CKeyToolController* aController); sl@0: sl@0: private: sl@0: CCTKeyInfo* iKey; sl@0: TInt idx; sl@0: }; sl@0: sl@0: sl@0: #ifdef KEYTOOL sl@0: sl@0: /** sl@0: * Implements the migration of old keystore to the new keystore format sl@0: * which uses the authentication server. sl@0: */ sl@0: class CKeytoolMigrateStore : public CActive sl@0: { sl@0: sl@0: private: sl@0: enum TMigrateStoreState sl@0: { sl@0: EAfterAuthentication, sl@0: sl@0: }; sl@0: public: sl@0: static CKeytoolMigrateStore* NewLC(CKeyToolParameters* aParams); sl@0: static CKeytoolMigrateStore* NewL(CKeyToolParameters* aParams); sl@0: ~CKeytoolMigrateStore(); sl@0: void ConstructL(CKeyToolParameters* aParams); sl@0: sl@0: public: // From CKeyToolCommand sl@0: void DoCommandL(); sl@0: sl@0: public: // From CActive sl@0: void RunL(); sl@0: void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: sl@0: private: sl@0: CKeytoolMigrateStore(); sl@0: void WriteKeyL( const CKeyInfo& aKeyInfo, sl@0: RStoreWriteStream& aWriteInfoStream ); sl@0: sl@0: void WriteAuthDetailsL( RStoreWriteStream& aWriteInfoStream ); sl@0: void RevertStore(TAny* aStore); sl@0: void InitializeDefaultParams(); sl@0: void WriteKeyInformationL(); sl@0: template inline void EncryptAndStoreL(const T& aKey, RStoreWriteStream& aStream ); sl@0: void StoreKeyL(const TDesC8& aKeyData, RStoreWriteStream& aStream); sl@0: template void RetrieveAndStorePublicKeyL( CFileKeyData* aKeyData, T* aPublicKey ); sl@0: template void RetrieveAndStorePrivateKeyL( CFileKeyData* aKeyData, T* aPrivateKey ); sl@0: static void CleanKeyInfo(TAny* aKeyInfo); sl@0: sl@0: private: sl@0: AuthServer::TIdentityId iIdentityId; sl@0: AuthServer::RAuthClient iAuthClient; sl@0: CPermanentFileStore* iWriteFileStore; sl@0: CPermanentFileStore* iReadFileStore; sl@0: TStreamId iWriteLookupStreamId; sl@0: CKeyToolParameters* iParams; sl@0: RFs iFs; sl@0: CKeyStoreCenrep* iKeyStoreCenrep; sl@0: CPassphrase* iPassphrase; sl@0: AuthServer::CIdentity* iUserIdentity; sl@0: TMigrateStoreState iState; sl@0: sl@0: RPointerArray iKeyList; sl@0: }; sl@0: sl@0: #endif // KEYTOOL sl@0: #endif sl@0: