realtimenetprots/sipfw/SIP/SIPSec/IpSecPlugin/src/CStatePendingKey.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2004-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 // Name          : CStatePendingKey.cpp
       
    15 // Part of       : SIPSec, IpSec Plugin
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "sipsecurityheaderbase.h"
       
    22 #include "sipresponse.h"
       
    23 #include "CSipSecAgreeRecord.h"
       
    24 #include "SipSecIpsecParams.h"
       
    25 #include "MIpSecAgreeContextParams.h"
       
    26 #include "CIpSecSadbHandler.h"
       
    27 #include "SipSecUtils.h"
       
    28 #include "CStatePendingKey.h"	
       
    29 
       
    30 // ----------------------------------------------------------------------------
       
    31 // CPendingKey::CPendingKey
       
    32 // ----------------------------------------------------------------------------
       
    33 //
       
    34 CPendingKey::CPendingKey() 
       
    35     {
       
    36     }
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // CPendingKey::State
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 CState::TSecAgreeRecordState CPendingKey::State()
       
    43 	{
       
    44 	return EPendingKey;
       
    45 	}
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // CPendingKey::TimerExpiredL
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 void CPendingKey::TimerExpiredL(  
       
    52 	CSipSecAgreeRecord& aRec,
       
    53 	TTimerId /* aTimerId */, 
       
    54 	TAny* /* aTimerParam */ )
       
    55 	{
       
    56 	aRec.iParams.SaDeleted( &aRec );
       
    57 	}
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // CPendingKey::Resp4xxL
       
    61 // ----------------------------------------------------------------------------
       
    62 //					  	  	
       
    63 void CPendingKey::Resp4xxL(  
       
    64 	CSipSecAgreeRecord& aRec,
       
    65 	CSIPResponse& aResponse,
       
    66 	CSIPRequest& /* aRequest */ )
       
    67 	{
       
    68 	aRec.iSecVerifyHeaders.ResetAndDestroy();
       
    69 	aRec.CopyHeadersFromMessageL( aResponse, EFalse );
       
    70 	// Wait 4 minutes for Digest plugin to generate a new key
       
    71 	aRec.StartTimerL( KTempTime );
       
    72 	}
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CPendingKey::AuthKeyL
       
    76 // ----------------------------------------------------------------------------
       
    77 //		
       
    78 TBool CPendingKey::AuthKeyL(  
       
    79 	CSipSecAgreeRecord& aRec,
       
    80 	const TDesC8& aAuthKey )
       
    81 	{	
       
    82 	// 1. Find all security-verify headers with KIpSec3gpp mechanism
       
    83 	// 2. Find which one has highest q
       
    84 	// 3. Find security-client header that has the same algorithm
       
    85 	
       
    86 	CSIPSecurityHeaderBase* 
       
    87 		vh = SipSecUtils::HeaderWithHighestVaL( aRec.iSecVerifyHeaders,
       
    88 											     KIpSec3gpp,
       
    89 											     KPreference );
       
    90 											     
       
    91 	__ASSERT_ALWAYS( vh, User::Leave( KErrNotFound ) );
       
    92 											     
       
    93 	const RStringF alg = SipSecUtils::ValueFL( *vh, KAlgorithm );
       
    94 	
       
    95 	CSIPSecurityHeaderBase* 
       
    96 		ch = SipSecUtils::HeaderWithParamVaL( 
       
    97 								 aRec.iSecClientHeaders,
       
    98 								 KIpSec3gpp,
       
    99 								 KAlgorithm,
       
   100 								 alg.DesC() );
       
   101 	aRec.SetSaParamsL( *ch, *vh, aAuthKey );
       
   102 	aRec.AddSasL();
       
   103 			 	  
       
   104 	aRec.NextState( EPendingSa );
       
   105 	return ETrue;
       
   106 	}
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CPendingKey::AuthKeyFailedL
       
   110 // ----------------------------------------------------------------------------
       
   111 //	
       
   112 void CPendingKey::AuthKeyFailedL( CSipSecAgreeRecord& aRec )
       
   113     {
       
   114     // aRec will be deleted because of incorrect MAC or SQN in received 401
       
   115     ClearSaL( aRec );
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CPendingKey::ClearSaL
       
   120 // ----------------------------------------------------------------------------
       
   121 //	
       
   122 void CPendingKey::ClearSaL(	CSipSecAgreeRecord& aRec )
       
   123 	{
       
   124 	aRec.StopTimer();
       
   125 	aRec.iParams.SaCleared( &aRec );	
       
   126 	}
       
   127 	
       
   128 // End of File