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