rtp/srtpstack/src/tsrtpstreaminstatelatebind.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2005 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:    implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "tsrtpstreaminstatelatebind.h"
       
    21 #include "msrtpstreamincontext.h"
       
    22 #include "msrtpcryptohandlercontext.h"
       
    23 #include "msrtpcryptohandlercontextrtp.h"
       
    24 #include "msrtpcryptohandlercontextrtcp.h"
       
    25 #include "srtputils.h"
       
    26 
       
    27 // ----------------------------------------------------------------------------
       
    28 // TSRTPStreamInStateLateBind::TSRTPStreamInStateLateBind
       
    29 // ----------------------------------------------------------------------------
       
    30 //
       
    31 TSRTPStreamInStateLateBind::TSRTPStreamInStateLateBind(
       
    32     MSRTPStreamInContext& aStreamContext,
       
    33     MSRTPCryptoHandlerContextRTP& aCryptoHandlerRTPContext,
       
    34     MSRTPCryptoHandlerContextRTCP& aCryptoHandlerRTCPContext)
       
    35     : TSRTPStreamInStateBase(aStreamContext,
       
    36                             aCryptoHandlerRTPContext, 
       
    37                             aCryptoHandlerRTCPContext)
       
    38     {
       
    39     }
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // TSRTPStreamInStateLateBind::DoUnprotectSrtpL
       
    43 // ----------------------------------------------------------------------------
       
    44 //		
       
    45 HBufC8* TSRTPStreamInStateLateBind::DoUnprotectSrtpL(const TDesC8& aPacket)
       
    46     {
       
    47     SRTP_DEBUG_DETAIL( "TSRTPStreamInStateLateBind::DoUnprotectSrtpL ENTRY");
       
    48    	SRTP_DEBUG_TINT_VALUE( "Encrypted PacketLength is", aPacket.Length() );                 
       
    49              
       
    50     // first initialize current encrypted RTP packet..
       
    51     iCryptoHandlerRTPContext.InitializeEncryptedPacketL(aPacket);    
       
    52     
       
    53     
       
    54     // for the first RTP packet, we need to set 
       
    55     // receiver s_l value to current sequence number, see RFC
       
    56     iCryptoHandlerRTPContext.SetReceiver_s_l();
       
    57        
       
    58     // Step 2 (in RFC 3711, section 3.3):
       
    59     // count the packet index i
       
    60     iCryptoHandlerRTPContext.CountReceiverPacketIndexL();
       
    61     
       
    62   	SRTP_DEBUG_DETAIL( "CheckMasterKeyIdentifier" );
       
    63     
       
    64     // check MKI if it is used
       
    65     iCryptoHandlerRTPContext.CheckMasterKeyIdentifierL();
       
    66    	
       
    67    	SRTP_DEBUG_DETAIL( "DeriveSessionKeysL" );
       
    68                   
       
    69     // derive session keys..
       
    70     iCryptoHandlerRTPContext.DeriveSessionKeysL();
       
    71 
       
    72     // do the replay protection, based on sender packetIndex 
       
    73     //note that in RCC mode, it set packet index as sender one
       
    74     iCryptoHandlerRTPContext.ReplayProtectionL();
       
    75     
       
    76     SRTP_DEBUG_DETAIL( "AuthenticateL" );
       
    77       
       
    78     // do the authentication (integrity check)
       
    79     iCryptoHandlerRTPContext.AuthenticateL();
       
    80                
       
    81     /*
       
    82     if "error in authentication"
       
    83         "clear Crypto Handler"
       
    84         go to the uninitialized state
       
    85     iStreamContext.ChangeRTPState(MSRTPStreamInContext::ESRTPStreamInUninitialized);    
       
    86     */
       
    87   	SRTP_DEBUG_DETAIL( "DecryptL" );
       
    88                     
       
    89      // step 6 decrypt..
       
    90     HBufC8* decryptedPacket = iCryptoHandlerRTPContext.DecryptL();
       
    91      
       
    92     // Step 7, conditional update s_l and ROC values..
       
    93     // (in RFC 3711, section 3.3):         
       
    94     iCryptoHandlerRTPContext.Update_s_l_and_RocL();
       
    95     iCryptoHandlerRTPContext.AddReplayIndex(); 
       
    96  
       
    97 
       
    98     // first RTP packet successfully decrypted..
       
    99     // session keys derived etc..
       
   100     // we can go to normal state
       
   101     SRTP_DEBUG_DETAIL( "ChangeStreamIn State to Normal" );
       
   102            
       
   103     
       
   104     iStreamContext.ChangeRTPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   105     
       
   106     SRTP_DEBUG_TINT_VALUE( "the decrypted packet Length is", decryptedPacket->Length());            
       
   107         
       
   108     SRTP_DEBUG_DETAIL( "TSRTPStreamInStateLateBind::DoUnprotectSrtpL EXIT");
       
   109    	
       
   110     // return decrypted RTP packet
       
   111     return decryptedPacket;    
       
   112     
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------------------------------
       
   116 // TSRTPStreamInStateLateBind::DoUnprotectSrtcpL
       
   117 // ----------------------------------------------------------------------------
       
   118 //		
       
   119 HBufC8* TSRTPStreamInStateLateBind::DoUnprotectSrtcpL(const TDesC8& aPacket)
       
   120     {
       
   121      // first initialize current encrypted RTP packet..
       
   122     iCryptoHandlerRTCPContext.InitializeEncryptedPacketL(aPacket);    
       
   123     
       
   124     
       
   125     //(in RFC 3711, section 3.4):
       
   126     // count the packet index i
       
   127     iCryptoHandlerRTCPContext.ReceiverPacketIndexL();
       
   128      
       
   129     // check MKI if it is used
       
   130     iCryptoHandlerRTCPContext.CheckMasterKeyIdentifierL();
       
   131      
       
   132     // derive session keys..
       
   133     iCryptoHandlerRTCPContext.DeriveSessionKeysL();
       
   134 
       
   135     // do the replay protection 
       
   136     iCryptoHandlerRTCPContext.ReplayProtectionL();
       
   137 
       
   138     // do the authentication (integrity check)
       
   139     iCryptoHandlerRTCPContext.AuthenticateL();
       
   140                
       
   141      // decrypt..
       
   142     HBufC8* decryptedPacket = iCryptoHandlerRTCPContext.DecryptL();
       
   143      
       
   144     iCryptoHandlerRTCPContext.AddReplayIndex(); 
       
   145     // first RTP packet successfully decrypted..
       
   146     // session keys derived etc..
       
   147     // we can go to normal state
       
   148     iStreamContext.ChangeRTCPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   149     
       
   150     
       
   151     // return decrypted RTP packet
       
   152     return decryptedPacket;    
       
   153     }