realtimenetprots/sipfw/SIP/SIPSec/DigestPlugin/src/CSIPSecChallengeAKA.cpp
changeset 0 307788aac0a8
child 16 43c4dec3cb1f
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2008-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          : CSIPSecChallengeAKA.cpp
       
    15 // Part of       : SIPSec/DigestPlugin
       
    16 // Version       : SIP/6.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "SipLogs.h"
       
    22 #include "CSIPSecChallengeAKA.h"
       
    23 #include "CSIPSecDigest.h"
       
    24 #include "CSIPSecSIMRecord.h"
       
    25 #include "CSIPSecDigestPlugin.h"
       
    26 #include "sipsecdigestcontext.h"
       
    27 #include "sipstrings.h"
       
    28 #include "sipstrconsts.h"
       
    29 #include <imcvcodc.h>
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CSIPSecChallengeAKA::CSIPSecAlgAKA
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CSIPSecChallengeAKA::CSIPSecChallengeAKA( CSIPSecDigest::TChallengeType aType,
       
    39 										  CSIPSecRequestData::TQop aQop ) :
       
    40     CSIPSecChallengeMD5( aType, aQop )
       
    41     {
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CSIPSecChallengeAKA::NewLC
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CSIPSecChallengeAKA*
       
    49 CSIPSecChallengeAKA::NewLC( CSIPSecDigest::TChallengeType aType,
       
    50                             CSIPAuthenticateHeaderBase& aAuthenticateHeader,
       
    51                             CSIPSecRequestData::TQop aQop )
       
    52     {
       
    53 	CSIPSecChallengeAKA* self = new ( ELeave ) CSIPSecChallengeAKA( aType,
       
    54 																	aQop );
       
    55 	CleanupStack::PushL( self );
       
    56 	self->ConstructL( aAuthenticateHeader );
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CSIPSecChallengeAKA::~CSIPSecChallengeAKA
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CSIPSecChallengeAKA::~CSIPSecChallengeAKA()
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSIPSecChallengeAKA::VerifyTypeL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CSIPSecChallengeAKA::VerifyTypeL( CSIPSecUserRecord::TType aType ) const
       
    73 	{
       
    74 	__ASSERT_ALWAYS( aType == CSIPSecUserRecord::EIMS,
       
    75         			 User::Leave( KErrPermissionDenied ) );
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSIPSecChallengeAKA::CreateUserRecordL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CSIPSecUserRecord*
       
    83 CSIPSecChallengeAKA::CreateUserRecordL( const TDesC8& aRealm,
       
    84 										const MSIPSecUser& aUser,
       
    85 										TRegistrationId aRegistrationId,
       
    86 									    TTransactionId aTransactionId,
       
    87 									    TUint aResponseCode ) const
       
    88 	{
       
    89 	CSIPSecSIMRecord* record = CSIPSecSIMRecord::NewL( aRealm,
       
    90 													   aUser,
       
    91 													   aRegistrationId,
       
    92 													   aTransactionId );
       
    93 	record->UpdateMessageCounter( aResponseCode );
       
    94 	return record;
       
    95 	}
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CSIPSecChallengeAKA::SupportedAlgorithm
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 RStringF CSIPSecChallengeAKA::SupportedAlgorithm()
       
   102     {
       
   103     return SIPStrings::StringF( SipStrConsts::EAKAv1MD5 );
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CSIPSecChallengeAKA::AlgorithmName
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 RStringF CSIPSecChallengeAKA::AlgorithmName() const
       
   111     {
       
   112     return CSIPSecChallengeAKA::SupportedAlgorithm();
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CSIPSecChallengeAKA::ProcessResponseL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TBool CSIPSecChallengeAKA::ProcessResponseL( TSIPSecDigestCtxSetup& aContext,
       
   120 									   	     TBool& aAskCredentials ) const
       
   121     {
       
   122     // AKA gets credentials from SIM card, not from MSIPSecUser
       
   123     aAskCredentials = EFalse;
       
   124 
       
   125 	CSIPSecSIMRecord& userData =
       
   126 		static_cast< CSIPSecSIMRecord& >( aContext.UserData() );
       
   127     if ( userData.IsValid() )
       
   128     	{
       
   129     	if ( userData.Failure() == CSIPSecSIMRecord::ESQN )
       
   130             {
       
   131             const TInt KBase64EncodedAutsLength = 20;
       
   132 			HBufC8* auts = HBufC8::NewLC( KBase64EncodedAutsLength );
       
   133 			TPtr8 autsPtr( auts->Des() );
       
   134 
       
   135 		    TImCodecB64 encoder;
       
   136 		    User::LeaveIfError( encoder.Encode( userData.AUTS(), autsPtr ) );
       
   137             aContext.SetParamValueL( SipStrConsts::EAuts, *auts );
       
   138 
       
   139             CleanupStack::PopAndDestroy( auts );
       
   140             }
       
   141         if ( userData.SecretData().Length() == 0 )
       
   142             {
       
   143             CalculateSecretDataA1L( aContext );
       
   144             }
       
   145         return EFalse;
       
   146     	}
       
   147 
       
   148     aContext.RequestUserCredentialsL();
       
   149     return ETrue;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CSIPSecChallengeAKA::ProcessRequestL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void
       
   157 CSIPSecChallengeAKA::ProcessRequestL( TSIPSecDigestCtxProcess& aContext ) const
       
   158     {
       
   159     __SIP_LOG( "SIPSecChallAKA:ProcessRequestL" )
       
   160 
       
   161     CSIPSecSIMRecord& userData =
       
   162     	static_cast< CSIPSecSIMRecord& >( aContext.UserData() );
       
   163     __ASSERT_ALWAYS ( userData.Failure() != CSIPSecSIMRecord::EPrivateIdentity,
       
   164     				  User::Leave( KErrGeneral ) );
       
   165 
       
   166     if ( userData.Failure() == CSIPSecSIMRecord::EMAC )
       
   167         {
       
   168         __SIP_LOG( "MAC failure, set empty nonce&response" )
       
   169 
       
   170 		aContext.SetParamWithEmptyValueL( SipStrConsts::ENonce );
       
   171         aContext.SetParamWithEmptyValueL( SipStrConsts::EResponse );
       
   172         }
       
   173     else
       
   174     	{
       
   175     	if ( userData.Failure() == CSIPSecSIMRecord::ESQN &&
       
   176     		 aContext.Parent().Plugin().EmptyResponseAfterSqnFailure() )
       
   177     		{
       
   178     		__SIP_LOG( "set empty response parameter after SQN" )
       
   179     		aContext.SetParamWithEmptyValueL( SipStrConsts::EResponse );
       
   180     		}
       
   181     	else
       
   182     		{
       
   183     		CSIPSecChallengeMD5::ProcessRequestL( aContext );
       
   184     		}
       
   185         }
       
   186     }