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