networksecurity/tls/protocol/changecipherevents.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Change Cipher Spec protocol messages implementation file.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21   
       
    22 #include "changecipherevents.h"
       
    23 #include "tlshandshake.h"
       
    24 #include "recordprotocolevents.h"
       
    25 #include "handshakereceiveevents.h"
       
    26 
       
    27 
       
    28 CAsynchEvent* CSendChangeCipherSpec::ProcessL( TRequestStatus& aStatus )
       
    29 /** 
       
    30  * This message consists of a single byte of value 1, which is compressed and encrypted 
       
    31  * under the current connection state. Typically this message activates security services
       
    32  * (i.e. encryption + MAC).
       
    33  *
       
    34  * @param aStatus Request status object
       
    35  * @return CAsynchEvent* Pointer to the next asynchronous event to be processed.
       
    36  */
       
    37 {
       
    38 	LOG(Log::Printf(_L("CSendChangeCipherSpec::ProcessL()\n"));)
       
    39 		
       
    40 	// Set the message content and its record type.
       
    41 	iCipherSpecMsg.Copy( iMsgPtr, KChangeCipherSpecMsgLength );
       
    42 	CRecordComposer& RecordComposer = iRecordComposer;
       
    43 	RecordComposer.SetUserData( &iCipherSpecMsg );
       
    44 	RecordComposer.SetRecordType( ETlsChangeCipherContentType );
       
    45 	
       
    46 	// Update the History and set the next event to be processed. The next message to be 
       
    47 	// transmitted is the Finished message and this will be last in the current list.
       
    48 	iStateMachine->UpdateHistory( ETlsChangeCipherSent );
       
    49 
       
    50    //RecordComposer.ChangeCipher(); happens from CRecordComposer itslf after thei record's been sent
       
    51    RecordComposer.SetNext( Handshake().NextTxEvent() );
       
    52 	return RecordComposer.ProcessL( aStatus );
       
    53 }
       
    54 
       
    55 TBool CRecvChangeCipherSpec::AcceptRecord( TInt aRecordType ) const
       
    56 /** 
       
    57  * This method determines whether the first byte of a Record protocol header 
       
    58  * (content type) can be accepted by an event.
       
    59  *
       
    60  * @param aRecordType Integer specifying the Record protocol content type
       
    61  * @return TBool Boolean indicating whether or not the record should be accepted by  
       
    62  * this event.
       
    63  */
       
    64 {
       
    65 	LOG(Log::Printf(_L("CRecvChangeCipherSpec::AcceptRecord()\n"));)
       
    66 	TInt nHistory = iStateMachine->History();
       
    67 	
       
    68 	return aRecordType == ETlsChangeCipherContentType && 
       
    69 		(nHistory & ETlsFullHandshake|ETlsFinishedSent == ETlsFullHandshake|ETlsFinishedSent ||
       
    70 		nHistory & ETlsAbbreviatedHandshake|ETlsServerHelloRecv == ETlsAbbreviatedHandshake|ETlsServerHelloRecv);
       
    71 }
       
    72 
       
    73 CAsynchEvent* CRecvChangeCipherSpec::ProcessL( TRequestStatus& aStatus )
       
    74 /**
       
    75  * This method processes a received Change Cipher Spec message. This message should consist 
       
    76  * of a single byte of value 1. It is impossible for any other message to follow a CCS msg 
       
    77  * in a TLS record.
       
    78  */
       
    79 {
       
    80 	LOG(Log::Printf(_L("CRecvChangeCipherSpec::ProcessL()\n"));)
       
    81 
       
    82 	iStateMachine->UpdateHistory( ETlsChangeCipherRecv ); // Update the Handshake history	
       
    83 	TPtr8 ccsMsg ( iRecordParser.PtrHBuf() );
       
    84    User::LeaveIfError( ccsMsg.Length() != KChangeCipherSpecMsgLength ? KErrSSLAlertUnexpectedMessage : KErrNone );
       
    85 	TUint8 msgValue = ccsMsg[0];
       
    86 
       
    87 	if ( msgValue != KChangeCipherSpecMsg )
       
    88 	{
       
    89 		LOG(Log::Printf(_L("CRecvChangeCipherSpec::ProcessL - Value of CCS message is NOT equal to 1\n"));)
       
    90 		User::Leave(KErrArgument);
       
    91 	}
       
    92 	LOG(Log::Printf(_L("ChangeCipherSpec message of value %d received"), msgValue );)
       
    93 
       
    94 	// Reset the length of CRecordParser::iUserData for the next message.
       
    95 	iRecordParser.UserData()->SetLength(0);
       
    96    iRecordParser.ChangeCipher();
       
    97 
       
    98 	return iRecordParser.ProcessL( aStatus );	// Call the Record Parser to read again from the socket.
       
    99 }