pkiutilities/DeviceToken/Inc/DevCertOpenedKeysSrv.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2006 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 "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:   The header file of DevCertOpenedKeysSrv
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __DEVCERTOPENEDKEYSSRV_H__
       
    21 #define __DEVCERTOPENEDKEYSSRV_H__
       
    22 
       
    23 #include "DevCertKeyDataManager.h"
       
    24 #include "DevTokenDataTypes.h"
       
    25 
       
    26 class CRSAPrivateKey;
       
    27 class CRSASignature;
       
    28 class CDSAPrivateKey;
       
    29 class CDSASignature;
       
    30 class CDevTokenDHParams;
       
    31 class CDHPublicKey;
       
    32 class CDevCertKeyStoreServer;
       
    33 
       
    34 /**
       
    35  * DevToken Server side
       
    36  * Abstract base class for performing crypto operations on keys.
       
    37  * 
       
    38  *  @lib
       
    39  *  @since S60 v3.2
       
    40  */
       
    41 class CDevCertOpenedKeySrv : public CActive
       
    42     {
       
    43     public:
       
    44     
       
    45         /**
       
    46          * Factory function for creating CDevCertOpenedKeySrv-derived classes.
       
    47          * 
       
    48          * @param aKeyData representing the key
       
    49          * @param aType Type of opened key
       
    50          * @param aMessage IPC message
       
    51          * @param aKeyDataMan Key data manager
       
    52          * @return new object of CDevCertOpenedKeySrv
       
    53          */
       
    54         static CDevCertOpenedKeySrv* NewL(const CDevCertKeyData& aKeyData, TUid aType, const RMessage2& aMessage,
       
    55                                           CDevCertKeyDataManager& aKeyDataMan );
       
    56         
       
    57         virtual ~CDevCertOpenedKeySrv();
       
    58 
       
    59          /**
       
    60          * Returns the object's human-readable label.
       
    61          * 
       
    62          * @param 
       
    63          * @return the object's human-readable label
       
    64          */
       
    65         const TDesC& Label() const;
       
    66         
       
    67         /**
       
    68          * Returns the key's handle so we can identifiy it.
       
    69          * 
       
    70          * @param 
       
    71          * @return the hadnle of key
       
    72          */
       
    73         TInt Handle() const;
       
    74 
       
    75         /**
       
    76          * The type of opened key.
       
    77          * 
       
    78          * @param 
       
    79          * @return the uid of opened key
       
    80          */
       
    81         virtual TUid Type() const = 0;
       
    82 
       
    83     protected:
       
    84         
       
    85         CDevCertOpenedKeySrv(const CDevCertKeyData& aKeyData, CDevCertKeyDataManager& aKeyDataMan );
       
    86         
       
    87         void DoOperation(TRequestStatus& aStatus);
       
    88         
       
    89         // Methods supplied by derived classes
       
    90         
       
    91     protected:
       
    92     
       
    93         /**
       
    94          * The key algorithm this operation applies to
       
    95          * 
       
    96          * @param
       
    97          * @return
       
    98          */
       
    99         virtual CDevTokenKeyInfo::EKeyAlgorithm Algorithm() const = 0;
       
   100 
       
   101         /**
       
   102          * The key usage required to perform this operation
       
   103          * 
       
   104          * @param
       
   105          * @return
       
   106          */
       
   107         virtual TKeyUsagePKCS15 RequiredUsage() const = 0;
       
   108         
       
   109         /**
       
   110          * Load the private key data
       
   111          * 
       
   112          * @param aStream used to read data
       
   113          * @return
       
   114          */
       
   115         virtual void ReadPrivateKeyL(RReadStream& aStream) = 0;
       
   116         
       
   117         /**
       
   118          * Perform the operation, called from RunL
       
   119          * 
       
   120          * @param 
       
   121          * @return
       
   122          */
       
   123         virtual void PerformOperationL() = 0;
       
   124         
       
   125         /**
       
   126          * Clean up, called after normal end error completion
       
   127          * 
       
   128          * @param 
       
   129          * @return
       
   130          */
       
   131         virtual void Cleanup() = 0;
       
   132 
       
   133     private:
       
   134         enum TState
       
   135             {
       
   136             EIdle,
       
   137             EOperation
       
   138             };
       
   139             
       
   140         // from CActive
       
   141         
       
   142         virtual void RunL();
       
   143         
       
   144         virtual TInt RunError(TInt aError);
       
   145         
       
   146         virtual void DoCancel();
       
   147 
       
   148     private:
       
   149         
       
   150         void ConstructL(const RMessage2& aMessage);
       
   151         
       
   152         void CheckKeyL(const CDevTokenKeyInfo& aKeyInfo, const RMessage2& aMessage);
       
   153         
       
   154         void Complete(TInt aError);
       
   155 
       
   156     private:
       
   157         
       
   158         const CDevCertKeyData&  iKeyData;
       
   159         
       
   160         CDevCertKeyDataManager& iKeyDataMan;
       
   161         
       
   162         HBufC*         iLabel;
       
   163         
       
   164         TState         iState;
       
   165         
       
   166         TRequestStatus*    iClientStatus;
       
   167 
       
   168     protected:
       
   169         
       
   170         TBool        iKeyRead;
       
   171     };
       
   172 
       
   173 
       
   174 /**
       
   175  * DevToken Server side
       
   176  * class for performing crypto operations on RSA keys.
       
   177  *
       
   178  *  @lib
       
   179  *  @since S60 v3.2
       
   180  */
       
   181 class CDevCertRSARepudiableSignerSrv : public CDevCertOpenedKeySrv
       
   182     {
       
   183     public:
       
   184         
       
   185         CDevCertRSARepudiableSignerSrv(const CDevCertKeyData& aKeyData, CDevCertKeyDataManager& aKeyDataMan );
       
   186         
       
   187         ~CDevCertRSARepudiableSignerSrv();
       
   188         
       
   189         void Sign(const TDesC8& aPlaintext, CRSASignature*& aSignature, TRequestStatus& aStatus);
       
   190 
       
   191     private:
       
   192         
       
   193         virtual TUid Type() const;
       
   194         
       
   195         virtual CDevTokenKeyInfo::EKeyAlgorithm Algorithm() const;
       
   196         
       
   197         virtual TKeyUsagePKCS15 RequiredUsage() const;
       
   198         
       
   199         virtual void ReadPrivateKeyL(RReadStream& aStream);
       
   200         
       
   201         virtual void PerformOperationL();
       
   202         
       
   203         virtual void Cleanup();
       
   204 
       
   205     private:
       
   206         
       
   207         CRSAPrivateKey* iPrivateKey;
       
   208         
       
   209         TPtrC8      iPlaintext;
       
   210         
       
   211         CRSASignature** iSignaturePtr;  
       
   212     };
       
   213 
       
   214 
       
   215 /**
       
   216  * DevToken Server side
       
   217  * class for performing crypto operations on DSA keys.
       
   218  *
       
   219  *  @lib
       
   220  *  @since S60 v3.2
       
   221  */
       
   222 class CDevCertDSARepudiableSignerSrv : public CDevCertOpenedKeySrv
       
   223     {
       
   224     public:
       
   225         
       
   226         CDevCertDSARepudiableSignerSrv(const CDevCertKeyData& aKeyData, CDevCertKeyDataManager& aKeyDataMan );
       
   227         
       
   228         ~CDevCertDSARepudiableSignerSrv();
       
   229         
       
   230         void Sign(const TDesC8& aPlaintext, CDSASignature*& aSignature, TRequestStatus& aStatus);
       
   231 
       
   232     private: 
       
   233         
       
   234         virtual TUid Type() const;
       
   235         
       
   236         virtual CDevTokenKeyInfo::EKeyAlgorithm Algorithm() const;
       
   237         
       
   238         virtual TKeyUsagePKCS15 RequiredUsage() const;
       
   239         
       
   240         virtual void ReadPrivateKeyL(RReadStream& aStream);
       
   241         
       
   242         virtual void PerformOperationL();
       
   243         
       
   244         virtual void Cleanup();
       
   245 
       
   246     private:
       
   247         
       
   248         CDSAPrivateKey* iPrivateKey;
       
   249         
       
   250         TPtrC8      iPlaintext;
       
   251         
       
   252         CDSASignature** iSignaturePtr;  
       
   253     };
       
   254 
       
   255 
       
   256 /**
       
   257  * DevToken Server side
       
   258  * class for performing decrypt operations on RSA keys.
       
   259  *
       
   260  *  @lib
       
   261  *  @since S60 v3.2
       
   262  */
       
   263 class CDevCertRSADecryptorSrv : public CDevCertOpenedKeySrv
       
   264     {
       
   265     public:
       
   266         
       
   267         CDevCertRSADecryptorSrv(const CDevCertKeyData& aKeyData, CDevCertKeyDataManager& aKeyDataMan );
       
   268         
       
   269         ~CDevCertRSADecryptorSrv();
       
   270         
       
   271         void Decrypt(const TDesC8& aCiphertext, HBufC8*&, TRequestStatus& aStatus);
       
   272 
       
   273     private:
       
   274         
       
   275         virtual TUid Type() const;
       
   276         
       
   277         virtual CDevTokenKeyInfo::EKeyAlgorithm Algorithm() const;
       
   278         
       
   279         virtual TKeyUsagePKCS15 RequiredUsage() const;
       
   280         
       
   281         virtual void ReadPrivateKeyL(RReadStream& aStream);
       
   282         
       
   283         virtual void PerformOperationL();
       
   284         
       
   285         virtual void Cleanup();
       
   286 
       
   287     private:
       
   288         
       
   289         CRSAPrivateKey* iPrivateKey;
       
   290         
       
   291         TPtrC8      iCiphertext;
       
   292         
       
   293         HBufC8**    iPlaintextPtr;
       
   294     };
       
   295 
       
   296 
       
   297 /**
       
   298  * DevToken Server side
       
   299  * class for performing crypto operations on DH keys.
       
   300  *
       
   301  *  @lib
       
   302  *  @since S60 v3.2
       
   303  */
       
   304 class CDevCertDHAgreementSrv : public CDevCertOpenedKeySrv
       
   305     {
       
   306     public:
       
   307     
       
   308         CDevCertDHAgreementSrv(const CDevCertKeyData& aKeyData, CDevCertKeyDataManager& aKeyDataMan );
       
   309         
       
   310         ~CDevCertDHAgreementSrv();
       
   311         
       
   312         void PublicKey(CDevTokenDHParams& aParameters, RInteger& aPublicKey, TRequestStatus& aStatus);
       
   313         
       
   314         void Agree(CDHPublicKey& aY, HBufC8*& aAgreedKey, TRequestStatus& aStatus);
       
   315 
       
   316     private:
       
   317         
       
   318         virtual TUid Type() const;
       
   319         
       
   320         virtual CDevTokenKeyInfo::EKeyAlgorithm Algorithm() const;
       
   321         
       
   322         virtual TKeyUsagePKCS15 RequiredUsage() const;
       
   323         
       
   324         virtual void ReadPrivateKeyL(RReadStream& aStream);
       
   325         
       
   326         virtual void PerformOperationL();
       
   327         
       
   328         virtual void Cleanup();
       
   329 
       
   330     private:
       
   331         
       
   332         void DoPublicKeyL();
       
   333         
       
   334         void DoAgreeL();
       
   335 
       
   336     enum TDHState
       
   337         {
       
   338         EIdle,
       
   339         EPublicKey,
       
   340         EAgree
       
   341         };
       
   342 
       
   343     private:
       
   344         
       
   345         RInteger    iKey;
       
   346         
       
   347         TDHState    iDHState;
       
   348         
       
   349         // For public key operation
       
   350         CDevTokenDHParams*    iPKParams;
       
   351         
       
   352         RInteger*     iPKPublicKeyPtr;
       
   353         
       
   354         // For agree key operation
       
   355         CDHPublicKey* iAKPublicKey;
       
   356         
       
   357         HBufC8**    iAKAgreedKeyPtr;
       
   358     };
       
   359 
       
   360 #endif  //__DEVCERTOPENEDKEYSSRV_H__
       
   361 
       
   362 //EOF
       
   363