networksecurity/tls/protocol/handshakereceiveevents.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 /**
       
     2 * Copyright (c) 2003-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 "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 * Header file containing classes for received Handshake protocol messages.
       
    16 * Note that the Hello Request message, though a Handshake protocol message,
       
    17 * is handled separately. 
       
    18 * 
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @file HandshakeReceiveEvents.h
       
    26 */
       
    27 #include "tlsevent.h"
       
    28 #include "tlshandshakeitem.h"
       
    29 #include "tlsconnection.h"
       
    30 #include <tlstypedef.h>
       
    31 
       
    32 #ifndef _HANDSHAKERECEIVEEVENTS_H_
       
    33 #define _HANDSHAKERECEIVEEVENTS_H_
       
    34 
       
    35 class CHandshakeHeader;
       
    36 class CRecordParser;
       
    37 class CHandshake;
       
    38 class CStateMachine;
       
    39 class CTLSProvider;
       
    40 class CTLSSession;
       
    41 class CHandshakeReceive : public CTlsEvent
       
    42 /**
       
    43  * @class This abstract class describes received SSL3.0 and TLS1.0 Handshake protocol
       
    44  * messages (event classes). It owns the received message.
       
    45  */
       
    46 {
       
    47 public:
       
    48    CHandshakeReceive( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser );
       
    49    ~CHandshakeReceive();
       
    50 
       
    51    CHandshake& Handshake(); //MUST NOT be called from CHelloRequest since that 
       
    52                            //is processed from CRecvAppData state machine
       
    53    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const = 0; // Determines object to accept a Handshake message.
       
    54    static TInt RxOffset();
       
    55 
       
    56 protected:
       
    57    CHandshakeHeader* iHandshakeMessage; // Currently processed incoming message
       
    58    CRecordParser& iRecordParser;
       
    59    TSglQueLink iRxlink;			// Link object (singly linked list of received messages)
       
    60 };
       
    61 
       
    62 
       
    63 inline CHandshakeReceive::CHandshakeReceive( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
    64    CTlsEvent( &aTlsProvider, &aStateMachine ),
       
    65    iRecordParser( aRecordParser )
       
    66 {
       
    67 }
       
    68 
       
    69 inline CHandshake& CHandshakeReceive::Handshake()
       
    70 {
       
    71 	return (CHandshake&) *iStateMachine;
       
    72 }
       
    73 
       
    74 inline TInt CHandshakeReceive::RxOffset()
       
    75 {
       
    76 	return _FOFF(CHandshakeReceive, iRxlink);
       
    77 }
       
    78 /////////////////////////////////////////////////////////////////////////////////////////////////
       
    79 //
       
    80 class CHandshakeParser : public CTlsEvent
       
    81 /**
       
    82  * @class This class collects a full handshake message and picks the next event  
       
    83  * class (from its list of allowed ones) to process the message.
       
    84  */
       
    85 {
       
    86 public:
       
    87    CHandshakeParser( CStateMachine& aStateMachine, CRecordParser& aRecordParser );
       
    88    ~CHandshakeParser();
       
    89 
       
    90    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
    91    virtual TBool AcceptRecord( TInt aRecordType ) const;
       
    92    
       
    93    TPtr8 Message();
       
    94    void SetMessageAsUserDataL( TInt aWaitingFor );
       
    95    void DestroyRxList();
       
    96    void AddToList( CHandshakeReceive& aRxMsgItem);
       
    97 
       
    98    CHandshake& Handshake();
       
    99 
       
   100 protected:
       
   101    TInt ParseHeaderL();		//	Sets iNextEvent to a proper message parser
       
   102    CTlsEvent* LookUpEventL( const TUint8 aHandshakeType );
       
   103    CAsynchEvent* ProcessNextL( TRequestStatus& aStatus );
       
   104 
       
   105 protected:
       
   106    TSglQue<CHandshakeReceive> iMessageList;		// List of expected Handshake protocol messages to receive
       
   107    TSglQueIter<CHandshakeReceive> iRxListIter;	// List iterator
       
   108    CRecordParser& iRecordParser;
       
   109    HBufC8* iMessage;							// Received handshake message 
       
   110    TPtr8 iMessagePtr;							// Pointer to the buffer returned by the Handshake Parser.
       
   111    TInt iWaitingFor;							// Number of bytes to read
       
   112    TUint8   iMessageType;     //received message type
       
   113 };
       
   114 
       
   115 
       
   116 /////////////////////////////////////////////////////////////////////////////////////////////////
       
   117 /** SSL3.0/TLS1.0 RECEIVED MESSAGES **/
       
   118 
       
   119 class CServerHello : public CHandshakeReceive
       
   120 /**
       
   121  * @class This class represents a Server Hello message (received by the protocol).
       
   122  */
       
   123 {
       
   124 public:
       
   125    CServerHello( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser );
       
   126    ~CServerHello();
       
   127 
       
   128    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const;
       
   129    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
   130 
       
   131 protected:
       
   132    TBool iCipherListRead; //for re-negotiation only due to a very bad TLS provider
       
   133    RArray<TTLSCipherSuite> iCipherList; //---------""------------------------
       
   134 };
       
   135 
       
   136 
       
   137 class CCertificateReq : public CHandshakeReceive
       
   138 /**
       
   139  * @class This class represents a Certificate Request message (received by the protocol).
       
   140  */
       
   141 {
       
   142 public:
       
   143    CCertificateReq( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& iRecordParser );
       
   144 
       
   145    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const;
       
   146    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
   147 };
       
   148 
       
   149 
       
   150 class CServerCertificate : public CHandshakeReceive
       
   151 /**
       
   152  * @class This class represents a Server Certificate message (received by the protocol).
       
   153  */
       
   154 {
       
   155 public:
       
   156    CServerCertificate( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& iRecordParser );
       
   157 
       
   158    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const;
       
   159    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
   160 };
       
   161 
       
   162 class CServerKeyExch : public CHandshakeReceive
       
   163 /**
       
   164  * @class This class represents a Server Key exchange message (received by the protocol).
       
   165  */
       
   166 {
       
   167 public:
       
   168    CServerKeyExch( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser );
       
   169 
       
   170    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const;
       
   171    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
   172 
       
   173 protected:
       
   174    void CreateMessageL( TTLSKeyExchangeAlgorithm aKeyExchange, TAlgorithmId aSignAlgorithm );
       
   175 };
       
   176 
       
   177 
       
   178 class CServerHelloDone : public CHandshakeReceive
       
   179 /**
       
   180  * @class This class represents a Server Hello Done message (received by the protocol).
       
   181  */
       
   182 {
       
   183 public:
       
   184    CServerHelloDone( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser );
       
   185 
       
   186    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const;
       
   187    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
   188 
       
   189 };
       
   190 
       
   191 class CRecvFinished : public CHandshakeReceive
       
   192 /**
       
   193  * @class This class represents a Finished message from the server (received by the protocol).
       
   194  */
       
   195 {
       
   196 public:
       
   197    CRecvFinished( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser );
       
   198    ~CRecvFinished();
       
   199 
       
   200    virtual TBool AcceptMessage( const TUint8 aHandshakeType ) const;
       
   201    virtual CAsynchEvent* ProcessL( TRequestStatus& aStatus );
       
   202 
       
   203 private:
       
   204 	CSHA1* iShaPtr;					// Copy of SHA1 hash object, used to hash the handshake messages
       
   205 	CMD5*  iMd5Ptr;					// Copy of MD5 hash object, used to hash the handshake messages
       
   206 };
       
   207 
       
   208 
       
   209 // Inline methods - CHandshakeParser
       
   210 inline CHandshakeParser::CHandshakeParser( CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   211    CTlsEvent( NULL, &aStateMachine ),	
       
   212    iMessageList( CHandshakeReceive::RxOffset() ),
       
   213    iRxListIter( iMessageList ),
       
   214    iRecordParser( aRecordParser ),
       
   215    iMessagePtr(NULL, 0),
       
   216    iWaitingFor( KTlsHandshakeHeaderSize )
       
   217 {
       
   218 	LOG(Log::Printf(_L("CHandshakeParser::CHandshakeParser()\n"));)
       
   219 }
       
   220 
       
   221 inline CHandshake& CHandshakeParser::Handshake()
       
   222 /**
       
   223  * This method returns a reference to a Handshake negotiation state machine.
       
   224  */
       
   225 {
       
   226 	LOG(Log::Printf(_L("CHandshakeParser::CHandshakeParser()\n"));)
       
   227 	return (CHandshake&) *iStateMachine;
       
   228 }
       
   229 
       
   230 // Inline method - CServerHello
       
   231 inline CServerHello::CServerHello( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   232    CHandshakeReceive( aTlsProvider, aStateMachine, aRecordParser )
       
   233 {
       
   234 }
       
   235 
       
   236 // Inline method - CCertificateReq
       
   237 inline CCertificateReq::CCertificateReq( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   238    CHandshakeReceive( aTlsProvider, aStateMachine, aRecordParser )
       
   239 {
       
   240 }
       
   241 
       
   242 // Inline method - CServerCertificate
       
   243 inline CServerCertificate::CServerCertificate( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   244    CHandshakeReceive( aTlsProvider, aStateMachine, aRecordParser )
       
   245 {
       
   246 }
       
   247 
       
   248 // Inline method - CServerKeyExch
       
   249 inline CServerKeyExch::CServerKeyExch( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   250    CHandshakeReceive( aTlsProvider, aStateMachine, aRecordParser )
       
   251 {
       
   252 }
       
   253 
       
   254 // Inline method - CServerHelloDone
       
   255 inline CServerHelloDone::CServerHelloDone( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   256    CHandshakeReceive( aTlsProvider, aStateMachine, aRecordParser )
       
   257 {
       
   258 }
       
   259 
       
   260 // Inline method - CRecvFinished
       
   261 inline CRecvFinished::CRecvFinished( CTLSProvider& aTlsProvider, CStateMachine& aStateMachine, CRecordParser& aRecordParser ) :
       
   262    CHandshakeReceive( aTlsProvider, aStateMachine, aRecordParser ),
       
   263    iShaPtr( NULL ),
       
   264    iMd5Ptr( NULL )
       
   265 {
       
   266 }
       
   267 
       
   268 #endif