rtp/srtpstack/src/tsrtpstreaminstateuninit.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 "tsrtpstreaminstateuninit.h"
       
    21 #include "msrtpstreamincontext.h"
       
    22 #include "msrtpcryptohandlercontext.h"
       
    23 #include "msrtpcryptohandlercontextrtp.h"
       
    24 #include "msrtpcryptohandlercontextrtcp.h"
       
    25 #include "srtputils.h"
       
    26 
       
    27 // ----------------------------------------------------------------------------
       
    28 // TSRTPStreamInStateUninit::TSRTPStreamInStateUninit
       
    29 // ----------------------------------------------------------------------------
       
    30 //
       
    31 TSRTPStreamInStateUninit::TSRTPStreamInStateUninit(
       
    32     MSRTPStreamInContext& aStreamContext,
       
    33     MSRTPCryptoHandlerContextRTP& aCryptoHandlerRTPContext,
       
    34     MSRTPCryptoHandlerContextRTCP& aCryptoHandlerRTCPContext)
       
    35     : TSRTPStreamInStateBase(aStreamContext,
       
    36                             aCryptoHandlerRTPContext, 
       
    37                             aCryptoHandlerRTCPContext)
       
    38     {
       
    39     }
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // TSRTPStreamInStateUninit::DoUnprotectSrtpL
       
    43 // ----------------------------------------------------------------------------
       
    44 //		
       
    45 HBufC8* TSRTPStreamInStateUninit::DoUnprotectSrtpL(const TDesC8& aPacket)
       
    46     {    
       
    47     SRTP_DEBUG_DETAIL( "TSRTPStreamInStateUninit::DoUnprotectSrtpL entry" );
       
    48     // first initialize current encrypted RTP packet..
       
    49     iCryptoHandlerRTPContext.InitializeEncryptedPacketL(aPacket);    
       
    50    
       
    51     SRTP_DEBUG_TINT_VALUE("Encrypted PacketLength is", aPacket.Length() );                
       
    52              
       
    53     // for the first RTP packet, we need to set 
       
    54     // receiver s_l value to current sequence number, see RFC
       
    55     iCryptoHandlerRTPContext.SetReceiver_s_l();
       
    56        
       
    57     // Step 2 (in RFC 3711, section 3.3):
       
    58     // count the packet index i
       
    59     iCryptoHandlerRTPContext.CountReceiverPacketIndexL();
       
    60      
       
    61     // check MKI if it is used
       
    62     iCryptoHandlerRTPContext.CheckMasterKeyIdentifierL();
       
    63     SRTP_DEBUG_DETAIL( "DeriveSessionKeysL" );
       
    64                
       
    65     // derive session keys..
       
    66     iCryptoHandlerRTPContext.DeriveSessionKeysL();
       
    67 
       
    68     // do the replay protection 
       
    69     iCryptoHandlerRTPContext.ReplayProtectionL();	
       
    70     
       
    71 	SRTP_DEBUG_DETAIL("DeriveSessionKeysL" );
       
    72     
       
    73     // do the authentication (integrity check)
       
    74     iCryptoHandlerRTPContext.AuthenticateL();
       
    75    	SRTP_DEBUG_DETAIL("Authenticated");
       
    76                
       
    77      // decrypt..
       
    78     HBufC8* decryptedPacket = iCryptoHandlerRTPContext.DecryptL();
       
    79    	SRTP_DEBUG_DETAIL( "StreamInStateUninit,Decrypted" );
       
    80      
       
    81     // Step 6, conditional update s_l and ROC values..
       
    82     // (in RFC 3711, section 3.3):         
       
    83     iCryptoHandlerRTPContext.Update_s_l_and_RocL();
       
    84     iCryptoHandlerRTPContext.AddReplayIndex(); 
       
    85     // first RTP packet successfully decrypted..
       
    86     // session keys derived etc..
       
    87     // we can go to normal state
       
    88     iStreamContext.ChangeRTPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
    89     
       
    90     
       
    91     SRTP_DEBUG_DETAIL( "StreamInStateUninit, UnprotectRTP Out" );
       
    92     
       
    93     // return decrypted RTP packet
       
    94     SRTP_DEBUG_DETAIL( "TSRTPStreamInStateUninit::DoUnprotectSrtpL exit" );
       
    95     
       
    96     return decryptedPacket;    
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // TSRTPStreamInStateUninit::DoUnprotectSrtcpL
       
   101 // ----------------------------------------------------------------------------
       
   102 //		
       
   103 HBufC8* TSRTPStreamInStateUninit::DoUnprotectSrtcpL(const TDesC8& aPacket)
       
   104     {
       
   105      // first initialize current encrypted RTP packet..
       
   106     iCryptoHandlerRTCPContext.InitializeEncryptedPacketL(aPacket);    
       
   107     
       
   108     
       
   109     //(in RFC 3711, section 3.4):
       
   110     // count the packet index i
       
   111     iCryptoHandlerRTCPContext.ReceiverPacketIndexL();
       
   112      
       
   113     // check MKI if it is used
       
   114     iCryptoHandlerRTCPContext.CheckMasterKeyIdentifierL();
       
   115      
       
   116     // derive session keys..
       
   117     iCryptoHandlerRTCPContext.DeriveSessionKeysL();
       
   118 
       
   119     // do the replay protection 
       
   120     iCryptoHandlerRTCPContext.ReplayProtectionL();
       
   121 
       
   122     // do the authentication (integrity check)
       
   123     iCryptoHandlerRTCPContext.AuthenticateL();
       
   124                
       
   125      // decrypt..
       
   126     HBufC8* decryptedPacket = iCryptoHandlerRTCPContext.DecryptL();
       
   127      
       
   128    	iCryptoHandlerRTCPContext.AddReplayIndex(); 
       
   129     // first RTP packet successfully decrypted..
       
   130     // session keys derived etc..
       
   131     // we can go to normal state
       
   132     iStreamContext.ChangeRTCPState(MSRTPStreamInContext::ESRTPStreamInNormal);
       
   133     
       
   134     
       
   135     // return decrypted RTP packet
       
   136     return decryptedPacket;    
       
   137     }