os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Server/OpenedKeys.h
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/source/keystore/Server/OpenedKeys.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,226 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* COpenedKey, abstract base class for performing crypto operations on keys
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalTechnology
1.26 +*/
1.27 +
1.28 +#ifndef __OpenedKeys_h__
1.29 +#define __OpenedKeys_h__
1.30 +
1.31 +#include "CKeyDataManager.h"
1.32 +#include "keystorepassphrase.h"
1.33 +#include "fsdatatypes.h"
1.34 +
1.35 +#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.36 +#include <authserver/authclient.h>
1.37 +#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.38 +
1.39 +class CRSAPrivateKey;
1.40 +class CRSASignature;
1.41 +class CDSAPrivateKey;
1.42 +class CDSASignature;
1.43 +class CDHParams;
1.44 +class CDHPublicKey;
1.45 +class CFSKeyStoreServer;
1.46 +
1.47 +class COpenedKey : public CActive
1.48 + {
1.49 +
1.50 +protected:
1.51 + enum TState
1.52 + {
1.53 + EIdle,
1.54 + EGetPassphrase,
1.55 + #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.56 + EDoAuthenticate,
1.57 + EAuthenticate,
1.58 + #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.59 + };
1.60 +
1.61 +public:
1.62 + /** Factory function for creating COpenedKey-derived classes. */
1.63 + static COpenedKey* NewL(const CFileKeyData& aKeyData, TUid aType, const RMessage2& aMessage,
1.64 + CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
1.65 +
1.66 + virtual ~COpenedKey();
1.67 +
1.68 + /** Returns the object's human-readable label */
1.69 + const TDesC& Label() const;
1.70 +
1.71 + /** Returns the key's handle so we can identifiy it. */
1.72 + TInt Handle() const;
1.73 +
1.74 + /// The type of opened key
1.75 + virtual TUid Type() const = 0;
1.76 +
1.77 +protected:
1.78 + COpenedKey(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
1.79 + void GetPassphrase(TRequestStatus& aStatus);
1.80 +
1.81 + // Methods supplied by derived classes
1.82 +
1.83 + /// The key algorithm this operation applies to
1.84 + virtual CKeyInfo::EKeyAlgorithm Algorithm() const = 0;
1.85 + /// The key usage required to perform this operation
1.86 + virtual TKeyUsagePKCS15 RequiredUsage() const = 0;
1.87 + /// Load the private key data
1.88 + virtual void ReadPrivateKeyL(RReadStream& aStream) = 0;
1.89 + /// Perform the operation, called from RunL
1.90 + virtual void PerformOperationL() = 0;
1.91 + /// Clean up, called after normal end error completion
1.92 + virtual void Cleanup() = 0;
1.93 +
1.94 +#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.95 +protected:
1.96 + void AuthenticateL();
1.97 +#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.98 +
1.99 +private:
1.100 + virtual void RunL();
1.101 + virtual TInt RunError(TInt aError);
1.102 + virtual void DoCancel();
1.103 +
1.104 +private:
1.105 + void ConstructL(const RMessage2& aMessage);
1.106 + void CheckKeyL(const RMessage2& aMessage);
1.107 + void Complete(TInt aError);
1.108 +
1.109 +private:
1.110 + const CFileKeyData& iKeyData;
1.111 + CFileKeyDataManager& iKeyDataMan;
1.112 + CPassphraseManager& iPassMan;
1.113 + HBufC* iLabel;
1.114 +
1.115 + CPassphrase* iPassphrase;
1.116 + CKeyInfo* iKeyInfo;
1.117 +#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.118 + AuthServer::CIdentity* iUserIdentity;
1.119 + AuthServer::RAuthClient iAuthClient;
1.120 + AuthServer::CAuthExpression* iExpression;
1.121 +#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
1.122 +protected:
1.123 + TState iState;
1.124 + TRequestStatus* iClientStatus;
1.125 + TBool iKeyRead;
1.126 + };
1.127 +
1.128 +class CRSARepudiableSigner : public COpenedKey
1.129 + {
1.130 + public:
1.131 + CRSARepudiableSigner(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
1.132 + ~CRSARepudiableSigner();
1.133 + void Sign(const TDesC8& aPlaintext, CRSASignature*& aSignature, TRequestStatus& aStatus);
1.134 +
1.135 + private:
1.136 + virtual TUid Type() const;
1.137 + virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
1.138 + virtual TKeyUsagePKCS15 RequiredUsage() const;
1.139 + virtual void ReadPrivateKeyL(RReadStream& aStream);
1.140 + virtual void PerformOperationL();
1.141 + virtual void Cleanup();
1.142 +
1.143 + private:
1.144 + CRSAPrivateKey* iPrivateKey;
1.145 + TPtrC8 iPlaintext;
1.146 + CRSASignature** iSignaturePtr;
1.147 + };
1.148 +
1.149 +class CDSARepudiableSigner : public COpenedKey
1.150 + {
1.151 + public:
1.152 + CDSARepudiableSigner(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
1.153 + ~CDSARepudiableSigner();
1.154 + void Sign(const TDesC8& aPlaintext, CDSASignature*& aSignature, TRequestStatus& aStatus);
1.155 +
1.156 + private:
1.157 + virtual TUid Type() const;
1.158 + virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
1.159 + virtual TKeyUsagePKCS15 RequiredUsage() const;
1.160 + virtual void ReadPrivateKeyL(RReadStream& aStream);
1.161 + virtual void PerformOperationL();
1.162 + virtual void Cleanup();
1.163 +
1.164 + private:
1.165 + CDSAPrivateKey* iPrivateKey;
1.166 + TPtrC8 iPlaintext;
1.167 + CDSASignature** iSignaturePtr;
1.168 + };
1.169 +
1.170 +class CFSRSADecryptor : public COpenedKey
1.171 + {
1.172 + public:
1.173 + CFSRSADecryptor(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
1.174 + ~CFSRSADecryptor();
1.175 + void Decrypt(const TDesC8& aCiphertext, HBufC8*&, TRequestStatus& aStatus);
1.176 +
1.177 + private:
1.178 + virtual TUid Type() const;
1.179 + virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
1.180 + virtual TKeyUsagePKCS15 RequiredUsage() const;
1.181 + virtual void ReadPrivateKeyL(RReadStream& aStream);
1.182 + virtual void PerformOperationL();
1.183 + virtual void Cleanup();
1.184 +
1.185 + private:
1.186 + CRSAPrivateKey* iPrivateKey;
1.187 + TPtrC8 iCiphertext;
1.188 + HBufC8** iPlaintextPtr;
1.189 + };
1.190 +
1.191 +class CDHAgreement : public COpenedKey
1.192 + {
1.193 + public:
1.194 + CDHAgreement(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan);
1.195 + ~CDHAgreement();
1.196 + void PublicKey(CDHParams& aParameters, RInteger& aPublicKey, TRequestStatus& aStatus);
1.197 + void Agree(CDHPublicKey& aY, HBufC8*& aAgreedKey, TRequestStatus& aStatus);
1.198 +
1.199 + private:
1.200 + virtual TUid Type() const;
1.201 + virtual CKeyInfo::EKeyAlgorithm Algorithm() const;
1.202 + virtual TKeyUsagePKCS15 RequiredUsage() const;
1.203 + virtual void ReadPrivateKeyL(RReadStream& aStream);
1.204 + virtual void PerformOperationL();
1.205 + virtual void Cleanup();
1.206 +
1.207 + private:
1.208 + void DoPublicKeyL();
1.209 + void DoAgreeL();
1.210 +
1.211 + enum TDHState
1.212 + {
1.213 + EIdle,
1.214 + EPublicKey,
1.215 + EAgree
1.216 + };
1.217 +
1.218 + private:
1.219 + RInteger iKey;
1.220 + TDHState iDHState;
1.221 + // For public key operation
1.222 + CDHParams* iPKParams;
1.223 + RInteger* iPKPublicKeyPtr;
1.224 + // For agree key operation
1.225 + CDHPublicKey* iAKPublicKey;
1.226 + HBufC8** iAKAgreedKeyPtr;
1.227 + };
1.228 +
1.229 +#endif