cryptoservices/certificateandkeymgmt/pkcs10/keyhelper.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2002-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 * Declares key helper classes for PKCS#10 that perform the algorithm dependant work.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 /**
       
    23  @file
       
    24  @internalComponent
       
    25  @released 
       
    26 */
       
    27 
       
    28 #ifndef __PKCS10KEYHELPER_H__
       
    29 #define __PKCS10KEYHELPER_H__
       
    30 
       
    31 #include <mctkeystore.h>
       
    32 #include <x509keys.h>
       
    33 
       
    34 class CASN1EncBase;
       
    35 class CASN1EncSequence;
       
    36 class CASN1EncBitString;
       
    37 
       
    38 /**
       
    39  * Abstract base class defines the interface for PKCS#10 key helpers.
       
    40  *
       
    41  * This class is fairly dumb, and provides a generic interface for various
       
    42  * keystore functionality.  The methods are called from the RunL of
       
    43  * CPKCS10Request.
       
    44  *
       
    45  * The implementation decodes the public key to create a public key object -
       
    46  * this is pretty wasteful, as the first thing we're going to do is re-encode it
       
    47  * again, mostly in exactly the same format.  However it's simpler and less
       
    48  * error-prome to do it this way.
       
    49  */
       
    50 class CPKCS10KeyHelper : public CBase
       
    51 	{
       
    52  public:
       
    53 
       
    54 	/**
       
    55 	 * Create appropriate subclass of CPKCS10KeyHelper depending on key
       
    56 	 * alogorithm.
       
    57 	 *
       
    58 	 * @param aKeyStore The keystore to use - this object takes ownership.
       
    59 	 * @param aKeyInfo The key to use.
       
    60 	 */	
       
    61 	static CPKCS10KeyHelper* CreateKeyHelperL(MCTKeyStore& aKeyStore,
       
    62 											  const CCTKeyInfo& aKeyInfo,
       
    63 											  const TDesC8& aExportedKey,
       
    64 											  const TAlgorithmId aDigestId);
       
    65 
       
    66 	virtual ~CPKCS10KeyHelper();
       
    67 
       
    68  public:
       
    69 
       
    70 	void FetchPublicKey(TRequestStatus& aStatus);
       
    71 	void CancelFetchPublicKey();
       
    72 
       
    73 	virtual void OpenSigner(TRequestStatus& aStatus) = 0;
       
    74 	virtual void CancelOpenSigner() = 0;
       
    75 
       
    76 	virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus) = 0;
       
    77 	virtual void CancelSignDigest() = 0;
       
    78 
       
    79 	virtual CASN1EncBase* EncodeKeyLC();
       
    80 	virtual CASN1EncSequence* EncodeSignatureAlgorithmLC();
       
    81 	virtual CASN1EncBitString* EncodeSignatureLC() = 0;
       
    82 	
       
    83  protected:
       
    84 
       
    85 	CPKCS10KeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo);
       
    86 
       
    87 	virtual void CreateKeyEncoderL(const TDesC8& aExportedKey,
       
    88 								   const TAlgorithmId aDigestId) = 0;
       
    89 	
       
    90 	CASN1EncBase* DigestInfoLC(const TDesC8& digest);
       
    91 
       
    92  protected:
       
    93 
       
    94 	MCTKeyStore&		iKeyStore;
       
    95 	const CCTKeyInfo&	iKeyInfo;
       
    96 	TX509KeyEncoder*	iKeyEncoder;
       
    97 	};
       
    98 
       
    99 /**
       
   100  * Implementation of PKCS#10 key helper for RSA keys.
       
   101  */
       
   102 class CPKCS10RSAKeyHelper : public CPKCS10KeyHelper
       
   103 	{
       
   104  public:
       
   105 
       
   106 	CPKCS10RSAKeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo);
       
   107 	virtual ~CPKCS10RSAKeyHelper();
       
   108 
       
   109  private:
       
   110 
       
   111 	virtual void OpenSigner(TRequestStatus& aStatus);
       
   112 	virtual void CancelOpenSigner();
       
   113 
       
   114 	virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus);
       
   115 	virtual void CancelSignDigest();	
       
   116 
       
   117 	virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, const TAlgorithmId aDigestId);
       
   118 	virtual CASN1EncBitString* EncodeSignatureLC();
       
   119 
       
   120 private:
       
   121 
       
   122 	CRSAPublicKey*		iPublicKey;
       
   123 	MRSASigner*			iRSASigner;
       
   124 	CRSASignature*		iRSASignature;
       
   125 	HBufC8* 			iDigestBuf;
       
   126 	};
       
   127 
       
   128 /**
       
   129  * Implementation of PKCS#10 key helper for DSA keys.
       
   130  */
       
   131 class CPKCS10DSAKeyHelper : public CPKCS10KeyHelper
       
   132 	{
       
   133  public:
       
   134 
       
   135 	CPKCS10DSAKeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo);
       
   136 	virtual ~CPKCS10DSAKeyHelper();
       
   137 
       
   138  private:
       
   139 	
       
   140 	virtual void OpenSigner(TRequestStatus& aStatus);
       
   141 	virtual void CancelOpenSigner();
       
   142 
       
   143 	virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus);
       
   144 	virtual void CancelSignDigest();	
       
   145 
       
   146 	virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, const TAlgorithmId aDigestId);
       
   147 	virtual CASN1EncSequence* EncodeSignatureAlgorithmLC();
       
   148 	virtual CASN1EncBitString* EncodeSignatureLC();
       
   149 
       
   150  private:
       
   151 
       
   152  	CDSAPublicKey* 		iPublicKey;
       
   153 	MDSASigner*			iDSASigner;
       
   154 	CDSASignature*		iDSASignature;
       
   155 	};
       
   156 
       
   157 #endif