sl@0: /* sl@0: * Copyright (c) 2002-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: * Declares key helper classes for PKCS#10 that perform the algorithm dependant work. sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __PKCS10KEYHELPER_H__ sl@0: #define __PKCS10KEYHELPER_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include "x509keyencoder.h" sl@0: sl@0: class CASN1EncBase; sl@0: class CASN1EncSequence; sl@0: class CASN1EncBitString; sl@0: sl@0: /** sl@0: * Abstract base class defines the interface for PKCS#10 key helpers. sl@0: * sl@0: * This class is fairly dumb, and provides a generic interface for various sl@0: * keystore functionality. The methods are called from the RunL of sl@0: * CPKCS10Request. sl@0: * sl@0: * The implementation decodes the public key to create a public key object - sl@0: * this is pretty wasteful, as the first thing we're going to do is re-encode it sl@0: * again, mostly in exactly the same format. However it's simpler and less sl@0: * error-prome to do it this way. sl@0: */ sl@0: class CPKCS10KeyHelper : public CBase sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: * Create appropriate subclass of CPKCS10KeyHelper depending on key sl@0: * alogorithm. sl@0: * sl@0: * @param aKeyStore The keystore to use - this object takes ownership. sl@0: * @param aKeyInfo The key to use. sl@0: */ sl@0: static CPKCS10KeyHelper* CreateKeyHelperL(MCTKeyStore& aKeyStore, sl@0: const CCTKeyInfo& aKeyInfo, sl@0: const TDesC8& aExportedKey, sl@0: const TAlgorithmId aDigestId); sl@0: sl@0: virtual ~CPKCS10KeyHelper(); sl@0: sl@0: public: sl@0: sl@0: void FetchPublicKey(TRequestStatus& aStatus); sl@0: void CancelFetchPublicKey(); sl@0: sl@0: virtual void OpenSigner(TRequestStatus& aStatus) = 0; sl@0: virtual void CancelOpenSigner() = 0; sl@0: sl@0: virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus) = 0; sl@0: virtual void CancelSignDigest() = 0; sl@0: sl@0: virtual CASN1EncBase* EncodeKeyLC(); sl@0: virtual CASN1EncSequence* EncodeSignatureAlgorithmLC(); sl@0: virtual CASN1EncBitString* EncodeSignatureLC() = 0; sl@0: sl@0: protected: sl@0: sl@0: CPKCS10KeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo); sl@0: sl@0: virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, sl@0: const TAlgorithmId aDigestId) = 0; sl@0: sl@0: CASN1EncBase* DigestInfoLC(const TDesC8& digest); sl@0: sl@0: protected: sl@0: sl@0: MCTKeyStore& iKeyStore; sl@0: const CCTKeyInfo& iKeyInfo; sl@0: TX509KeyEncoder* iKeyEncoder; sl@0: }; sl@0: sl@0: /** sl@0: * Implementation of PKCS#10 key helper for RSA keys. sl@0: */ sl@0: class CPKCS10RSAKeyHelper : public CPKCS10KeyHelper sl@0: { sl@0: public: sl@0: sl@0: CPKCS10RSAKeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo); sl@0: virtual ~CPKCS10RSAKeyHelper(); sl@0: sl@0: private: sl@0: sl@0: virtual void OpenSigner(TRequestStatus& aStatus); sl@0: virtual void CancelOpenSigner(); sl@0: sl@0: virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus); sl@0: virtual void CancelSignDigest(); sl@0: sl@0: virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, const TAlgorithmId aDigestId); sl@0: virtual CASN1EncBitString* EncodeSignatureLC(); sl@0: sl@0: private: sl@0: sl@0: CRSAPublicKey* iPublicKey; sl@0: MRSASigner* iRSASigner; sl@0: CRSASignature* iRSASignature; sl@0: HBufC8* iDigestBuf; sl@0: }; sl@0: sl@0: /** sl@0: * Implementation of PKCS#10 key helper for DSA keys. sl@0: */ sl@0: class CPKCS10DSAKeyHelper : public CPKCS10KeyHelper sl@0: { sl@0: public: sl@0: sl@0: CPKCS10DSAKeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo); sl@0: virtual ~CPKCS10DSAKeyHelper(); sl@0: sl@0: private: sl@0: sl@0: virtual void OpenSigner(TRequestStatus& aStatus); sl@0: virtual void CancelOpenSigner(); sl@0: sl@0: virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus); sl@0: virtual void CancelSignDigest(); sl@0: sl@0: virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, const TAlgorithmId aDigestId); sl@0: virtual CASN1EncSequence* EncodeSignatureAlgorithmLC(); sl@0: virtual CASN1EncBitString* EncodeSignatureLC(); sl@0: sl@0: private: sl@0: sl@0: CDSAPublicKey* iPublicKey; sl@0: MDSASigner* iDSASigner; sl@0: CDSASignature* iDSASignature; sl@0: }; sl@0: sl@0: #endif