1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs10/keyhelper.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,156 @@
1.4 +/*
1.5 +* Copyright (c) 2002-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 +* Declares key helper classes for PKCS#10 that perform the algorithm dependant work.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 + @internalComponent
1.26 + @released
1.27 +*/
1.28 +
1.29 +#ifndef __PKCS10KEYHELPER_H__
1.30 +#define __PKCS10KEYHELPER_H__
1.31 +
1.32 +#include <mctkeystore.h>
1.33 +#include <x509keys.h>
1.34 +#include "x509keyencoder.h"
1.35 +
1.36 +class CASN1EncBase;
1.37 +class CASN1EncSequence;
1.38 +class CASN1EncBitString;
1.39 +
1.40 +/**
1.41 + * Abstract base class defines the interface for PKCS#10 key helpers.
1.42 + *
1.43 + * This class is fairly dumb, and provides a generic interface for various
1.44 + * keystore functionality. The methods are called from the RunL of
1.45 + * CPKCS10Request.
1.46 + *
1.47 + * The implementation decodes the public key to create a public key object -
1.48 + * this is pretty wasteful, as the first thing we're going to do is re-encode it
1.49 + * again, mostly in exactly the same format. However it's simpler and less
1.50 + * error-prome to do it this way.
1.51 + */
1.52 +class CPKCS10KeyHelper : public CBase
1.53 + {
1.54 + public:
1.55 +
1.56 + /**
1.57 + * Create appropriate subclass of CPKCS10KeyHelper depending on key
1.58 + * alogorithm.
1.59 + *
1.60 + * @param aKeyStore The keystore to use - this object takes ownership.
1.61 + * @param aKeyInfo The key to use.
1.62 + */
1.63 + static CPKCS10KeyHelper* CreateKeyHelperL(MCTKeyStore& aKeyStore,
1.64 + const CCTKeyInfo& aKeyInfo,
1.65 + const TDesC8& aExportedKey,
1.66 + const TAlgorithmId aDigestId);
1.67 +
1.68 + virtual ~CPKCS10KeyHelper();
1.69 +
1.70 + public:
1.71 +
1.72 + void FetchPublicKey(TRequestStatus& aStatus);
1.73 + void CancelFetchPublicKey();
1.74 +
1.75 + virtual void OpenSigner(TRequestStatus& aStatus) = 0;
1.76 + virtual void CancelOpenSigner() = 0;
1.77 +
1.78 + virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus) = 0;
1.79 + virtual void CancelSignDigest() = 0;
1.80 +
1.81 + virtual CASN1EncBase* EncodeKeyLC();
1.82 + virtual CASN1EncSequence* EncodeSignatureAlgorithmLC();
1.83 + virtual CASN1EncBitString* EncodeSignatureLC() = 0;
1.84 +
1.85 + protected:
1.86 +
1.87 + CPKCS10KeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo);
1.88 +
1.89 + virtual void CreateKeyEncoderL(const TDesC8& aExportedKey,
1.90 + const TAlgorithmId aDigestId) = 0;
1.91 +
1.92 + CASN1EncBase* DigestInfoLC(const TDesC8& digest);
1.93 +
1.94 + protected:
1.95 +
1.96 + MCTKeyStore& iKeyStore;
1.97 + const CCTKeyInfo& iKeyInfo;
1.98 + TX509KeyEncoder* iKeyEncoder;
1.99 + };
1.100 +
1.101 +/**
1.102 + * Implementation of PKCS#10 key helper for RSA keys.
1.103 + */
1.104 +class CPKCS10RSAKeyHelper : public CPKCS10KeyHelper
1.105 + {
1.106 + public:
1.107 +
1.108 + CPKCS10RSAKeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo);
1.109 + virtual ~CPKCS10RSAKeyHelper();
1.110 +
1.111 + private:
1.112 +
1.113 + virtual void OpenSigner(TRequestStatus& aStatus);
1.114 + virtual void CancelOpenSigner();
1.115 +
1.116 + virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus);
1.117 + virtual void CancelSignDigest();
1.118 +
1.119 + virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, const TAlgorithmId aDigestId);
1.120 + virtual CASN1EncBitString* EncodeSignatureLC();
1.121 +
1.122 +private:
1.123 +
1.124 + CRSAPublicKey* iPublicKey;
1.125 + MRSASigner* iRSASigner;
1.126 + CRSASignature* iRSASignature;
1.127 + HBufC8* iDigestBuf;
1.128 + };
1.129 +
1.130 +/**
1.131 + * Implementation of PKCS#10 key helper for DSA keys.
1.132 + */
1.133 +class CPKCS10DSAKeyHelper : public CPKCS10KeyHelper
1.134 + {
1.135 + public:
1.136 +
1.137 + CPKCS10DSAKeyHelper(MCTKeyStore& aKeyStore, const CCTKeyInfo& aKeyInfo);
1.138 + virtual ~CPKCS10DSAKeyHelper();
1.139 +
1.140 + private:
1.141 +
1.142 + virtual void OpenSigner(TRequestStatus& aStatus);
1.143 + virtual void CancelOpenSigner();
1.144 +
1.145 + virtual void SignDigestL(const TDesC8& aDigest, TRequestStatus& aStatus);
1.146 + virtual void CancelSignDigest();
1.147 +
1.148 + virtual void CreateKeyEncoderL(const TDesC8& aExportedKey, const TAlgorithmId aDigestId);
1.149 + virtual CASN1EncSequence* EncodeSignatureAlgorithmLC();
1.150 + virtual CASN1EncBitString* EncodeSignatureLC();
1.151 +
1.152 + private:
1.153 +
1.154 + CDSAPublicKey* iPublicKey;
1.155 + MDSASigner* iDSASigner;
1.156 + CDSASignature* iDSASignature;
1.157 + };
1.158 +
1.159 +#endif