os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Server/OpenedKeys.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.
     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 * COpenedKey, abstract base class for performing crypto operations on keys
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @internalTechnology
    23 */
    24  
    25 #ifndef __OpenedKeys_h__
    26 #define __OpenedKeys_h__
    27 
    28 #include "CKeyDataManager.h"
    29 #include "keystorepassphrase.h"
    30 #include "fsdatatypes.h"
    31 
    32 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
    33 #include <authserver/authclient.h>
    34 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
    35 
    36 class CRSAPrivateKey;
    37 class CRSASignature;
    38 class CDSAPrivateKey;
    39 class CDSASignature;
    40 class CDHParams;
    41 class CDHPublicKey;
    42 class CFSKeyStoreServer;
    43 
    44 class COpenedKey : public CActive
    45 	{
    46 	
    47 protected:
    48 	enum TState
    49 		{
    50 		EIdle,
    51 		EGetPassphrase,
    52 		#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
    53 		EDoAuthenticate,
    54 		EAuthenticate,
    55 		#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
    56 		};
    57 	
    58 public:
    59 	/** Factory function for creating COpenedKey-derived classes. */
    60 	static COpenedKey* NewL(const CFileKeyData& aKeyData, TUid aType, const RMessage2& aMessage,
    61 							CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
    62 	
    63 	virtual ~COpenedKey();
    64 
    65 	/** Returns the object's human-readable label */
    66 	const TDesC& Label() const;
    67 
    68 	/** Returns the key's handle so we can identifiy it. */
    69 	TInt Handle() const;
    70 
    71 	/// The type of opened key
    72 	virtual TUid Type() const = 0;
    73 
    74 protected:
    75 	COpenedKey(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
    76 	void GetPassphrase(TRequestStatus& aStatus);
    77 
    78 	// Methods supplied by derived classes
    79 
    80 	/// The key algorithm this operation applies to
    81 	virtual CKeyInfo::EKeyAlgorithm Algorithm() const = 0;
    82 	/// The key usage required to perform this operation
    83 	virtual TKeyUsagePKCS15 RequiredUsage() const = 0;
    84 	/// Load the private key data
    85 	virtual void ReadPrivateKeyL(RReadStream& aStream) = 0;
    86 	/// Perform the operation, called from RunL
    87 	virtual void PerformOperationL() = 0;
    88 	/// Clean up, called after normal end error completion
    89 	virtual void Cleanup() = 0;
    90 
    91 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
    92 protected:
    93 	void AuthenticateL();
    94 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
    95 	
    96 private:
    97 	virtual void RunL();
    98 	virtual TInt RunError(TInt aError);
    99 	virtual void DoCancel();
   100 
   101 private:
   102 	void ConstructL(const RMessage2& aMessage);
   103 	void CheckKeyL(const RMessage2& aMessage);
   104 	void Complete(TInt aError);
   105 
   106 private:
   107 	const CFileKeyData&  iKeyData;
   108 	CFileKeyDataManager& iKeyDataMan;
   109 	CPassphraseManager&  iPassMan;
   110 	HBufC*				 iLabel;
   111 	
   112 	CPassphrase*		 iPassphrase;
   113 	CKeyInfo* 			iKeyInfo;
   114 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   115 	AuthServer::CIdentity* iUserIdentity;
   116 	AuthServer::RAuthClient iAuthClient;
   117 	AuthServer::CAuthExpression* iExpression;
   118 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   119 protected:
   120 	TState				 iState;
   121 	TRequestStatus*		 iClientStatus;
   122 	TBool				 iKeyRead;
   123 	};
   124 
   125 class CRSARepudiableSigner : public COpenedKey
   126 	{
   127  public:
   128 	CRSARepudiableSigner(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
   129 	~CRSARepudiableSigner();
   130 	void Sign(const TDesC8& aPlaintext, CRSASignature*& aSignature, TRequestStatus& aStatus);
   131 
   132  private:
   133 	virtual TUid Type() const;
   134 	virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
   135 	virtual TKeyUsagePKCS15 RequiredUsage() const;
   136 	virtual void ReadPrivateKeyL(RReadStream& aStream);
   137 	virtual void PerformOperationL();
   138 	virtual void Cleanup();
   139 
   140  private:
   141 	CRSAPrivateKey* iPrivateKey;
   142 	TPtrC8 			iPlaintext;
   143 	CRSASignature** iSignaturePtr;	
   144 	};
   145 
   146 class CDSARepudiableSigner : public COpenedKey
   147 	{
   148  public:
   149 	CDSARepudiableSigner(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
   150 	~CDSARepudiableSigner();
   151 	void Sign(const TDesC8& aPlaintext, CDSASignature*& aSignature, TRequestStatus& aStatus);
   152 
   153  private:	
   154 	virtual TUid Type() const;
   155 	virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
   156 	virtual TKeyUsagePKCS15 RequiredUsage() const;
   157 	virtual void ReadPrivateKeyL(RReadStream& aStream);
   158 	virtual void PerformOperationL();
   159 	virtual void Cleanup();
   160 
   161  private:
   162 	CDSAPrivateKey* iPrivateKey;
   163 	TPtrC8 			iPlaintext;
   164 	CDSASignature** iSignaturePtr;	
   165 	};
   166 
   167 class CFSRSADecryptor : public COpenedKey
   168 	{
   169  public:
   170 	CFSRSADecryptor(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
   171 	~CFSRSADecryptor();
   172 	void Decrypt(const TDesC8& aCiphertext, HBufC8*&, TRequestStatus& aStatus);
   173 
   174  private:
   175 	virtual TUid Type() const;
   176 	virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
   177 	virtual TKeyUsagePKCS15 RequiredUsage() const;
   178  	virtual void ReadPrivateKeyL(RReadStream& aStream);
   179 	virtual void PerformOperationL();
   180 	virtual void Cleanup();
   181 	
   182  private:
   183 	CRSAPrivateKey* iPrivateKey;
   184 	TPtrC8 			iCiphertext;
   185 	HBufC8**		iPlaintextPtr;
   186 	};
   187 
   188 class CDHAgreement : public COpenedKey
   189 	{
   190  public:
   191 	CDHAgreement(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
   192 	~CDHAgreement();
   193 	void PublicKey(CDHParams& aParameters, RInteger& aPublicKey, TRequestStatus& aStatus);
   194 	void Agree(CDHPublicKey& aY, HBufC8*& aAgreedKey, TRequestStatus& aStatus);
   195 
   196  private:
   197 	virtual TUid Type() const;
   198 	virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
   199 	virtual TKeyUsagePKCS15 RequiredUsage() const;
   200 	virtual void ReadPrivateKeyL(RReadStream& aStream);
   201 	virtual void PerformOperationL();
   202 	virtual void Cleanup();
   203 
   204  private:
   205 	void DoPublicKeyL();
   206 	void DoAgreeL();
   207 	
   208 	enum TDHState
   209 		{
   210 		EIdle,
   211 		EPublicKey,
   212 		EAgree
   213 		};
   214 
   215  private:
   216 	RInteger 	  iKey;
   217 	TDHState	  iDHState;
   218 	// For public key operation
   219 	CDHParams* 	  iPKParams;
   220 	RInteger* 	  iPKPublicKeyPtr;
   221 	// For agree key operation
   222 	CDHPublicKey* iAKPublicKey;
   223 	HBufC8** 	  iAKAgreedKeyPtr;
   224 	};
   225 
   226 #endif