realtimenetprots/sipfw/SIP/SIPSec/TlsPlugin/src/csipsectlsplugin.cpp
changeset 0 307788aac0a8
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        : csipsectlsplugin.cpp
       
    15 // Part of     : SIPSec TLS Plugin
       
    16 // Version     : %version: 2.1.1 %
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "TSIPTransportParams.h"
       
    22 #include "MSIPTransportMgr.h"
       
    23 #include "csipsectlsplugin.h"
       
    24 #include "tsipsecmechanisminitparams.h"
       
    25 #include "sipsecurityclientheader.h"
       
    26 #include "sipsecurityserverheader.h"
       
    27 #include "sipsecurityverifyheader.h"
       
    28 #include "ctlscache.h"
       
    29 #include "ctlsentry.h"
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CSIPSecTlsPlugin::NewL
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CSIPSecTlsPlugin* CSIPSecTlsPlugin::NewL( TAny* aInitParams )
       
    36 	{
       
    37 	__ASSERT_ALWAYS( aInitParams, User::Leave( KErrArgument ) );
       
    38 
       
    39 	CSIPSecTlsPlugin* self = new ( ELeave ) CSIPSecTlsPlugin(
       
    40 		static_cast< TSIPSecMechanismInitParams* >
       
    41 			( aInitParams )->iTransportMgr );
       
    42 	CleanupStack::PushL( self );
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop( self );
       
    45 	return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CSIPSecTlsPlugin::CSIPSecTlsPlugin
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CSIPSecTlsPlugin::CSIPSecTlsPlugin( MSIPTransportMgr& aTransportMgr ) :
       
    53   	iTransportMgr( aTransportMgr )
       
    54     {
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CSIPSecTlsPlugin::ConstructL
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CSIPSecTlsPlugin::ConstructL()
       
    62     {
       
    63 	iCache = CTLSCache::NewL();
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSIPSecTlsPlugin::~CSIPSecTlsPlugin
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CSIPSecTlsPlugin::~CSIPSecTlsPlugin()
       
    71     {
       
    72     delete iCache;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CSIPSecTlsPlugin::Name
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 const TDesC8& CSIPSecTlsPlugin::Name() const
       
    80 	{
       
    81 	_LIT8( KSIPSecTLSName, "tls");
       
    82 	return KSIPSecTLSName;
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CSIPSecTlsPlugin::InitializeSecurityClientL
       
    87 // Making the offer.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CSIPSecTlsPlugin::InitializeSecurityClientL(
       
    91 	CSIPSecurityClientHeader& aSecurityClient )
       
    92 	{
       
    93     aSecurityClient.SetMechanismNameL( Name() );
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSIPSecTlsPlugin::ProcessSecurityVerifyL
       
    98 // After the framework has chosen security mechanism. it calls this function of
       
    99 // the selected mechanism for all outgoing requests using the security
       
   100 // agreement.
       
   101 // Check that both Security-Server and Security-Verify header exist for this
       
   102 // mechanism.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CSIPSecTlsPlugin::ProcessSecurityVerifyL(
       
   106 	TSIPTransportParams& aTransportParams,
       
   107 	CSIPRequest& /*aRequest*/,
       
   108 	TInetAddr& aNextHop,
       
   109 	const CUri8& /*aRemoteTarget*/,
       
   110 	const TDesC8& /*aOutboundProxy*/,
       
   111 	MSIPSecUser* aUser,
       
   112 	TRegistrationId /*aRegistrationId*/,
       
   113 	RPointerArray<CSIPSecurityServerHeader>& aSecurityServer,
       
   114 	RPointerArray<CSIPSecurityVerifyHeader>& aSecurityVerify )
       
   115 	{
       
   116 	__ASSERT_ALWAYS( aUser, User::Leave( KErrArgument ) );
       
   117 
       
   118 	TInt i = 0;
       
   119 	CSIPSecurityServerHeader* secServer = NULL;
       
   120 	for ( i = 0; i < aSecurityServer.Count() && !secServer; ++i )
       
   121 		{
       
   122 		if ( aSecurityServer[i]->MechanismName().CompareF( Name() ) == 0 )
       
   123             {
       
   124             secServer = aSecurityServer[i];
       
   125             }
       
   126 		}
       
   127 	__ASSERT_ALWAYS( secServer, User::Leave( KErrArgument ) );
       
   128 
       
   129 	CSIPSecurityVerifyHeader* secVerify = NULL;
       
   130 	for ( i = 0; i < aSecurityVerify.Count() && !secVerify; ++i )
       
   131 		{
       
   132 		if ( aSecurityVerify[i]->MechanismName().CompareF( Name() ) == 0 )
       
   133             {
       
   134             secVerify = aSecurityVerify[i];
       
   135             }
       
   136 		}
       
   137 	__ASSERT_ALWAYS( secVerify, User::Leave( KErrArgument ) );
       
   138 
       
   139 	ProcessRequestL( aTransportParams, aNextHop, *aUser );
       
   140 	}
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CSIPSecTlsPlugin::ProcessRequestL
       
   144 // If no TLS connection to the next hop, create it.
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CSIPSecTlsPlugin::ProcessRequestL( TSIPTransportParams& aTransportParams,
       
   148 										const TInetAddr& aNextHop,	
       
   149 										const MSIPSecUser& aSIPSecUser )
       
   150 	{
       
   151 	CTLSEntry* entry = iCache->SearchByNextHop( aNextHop );
       
   152 	if ( !entry )
       
   153 		{
       
   154 		iTransportMgr.CreateTLSTransportL( aTransportParams );
       
   155 
       
   156 		iCache->AddEntryL( aNextHop,
       
   157 						   aTransportParams.TransportId(),
       
   158 						   aSIPSecUser );
       
   159 		}
       
   160 	}
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CSIPSecTlsPlugin::AddSecurityParamsL
       
   164 // Framework calls this function for all SIPSec plugins.
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void
       
   168 CSIPSecTlsPlugin::AddSecurityParamsL( TSIPTransportParams& aTransportParams,
       
   169 								      CSIPRequest& /*aRequest*/,
       
   170 								      TRegistrationId /*aRegistrationId*/,
       
   171 								      TTransactionId /*aTransactionId*/,
       
   172 					                  TInetAddr& aNextHop,
       
   173 					                  const CUri8& /*aRemoteTarget*/,
       
   174 					                  const TDesC8& /*aOutboundProxy*/,
       
   175 									  MSIPSecUser* aUser )
       
   176 	{
       
   177 	__ASSERT_ALWAYS( aUser, User::Leave( KErrArgument ) );
       
   178 
       
   179 	CTLSEntry* entry = iCache->SearchByNextHop( aNextHop );
       
   180 	if ( entry )
       
   181 		{
       
   182 		aTransportParams.SetTransportId( entry->TransportId() );
       
   183 		}	
       
   184 	}
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CSIPSecTlsPlugin::ResponseReceivedL
       
   188 // Framework calls this function for all SIPSec plugins.
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 TBool CSIPSecTlsPlugin::ResponseReceivedL(
       
   192 	TSIPTransportParams& /*aTransportParams*/,
       
   193 	CSIPResponse& /*aResponse*/,
       
   194 	CSIPRequest& /*aRequest*/,
       
   195 	TRegistrationId /*aRegistrationId*/,
       
   196 	TTransactionId /*aTransactionId*/,
       
   197 	TInetAddr& /*aNextHop*/,
       
   198 	const CUri8& /*aRemoteTarget*/,
       
   199 	const TDesC8& /*aOutboundProxy*/,
       
   200 	MSIPSecUser* /*aUser*/,
       
   201 	MSIPSecSecurityMechanismObserver& /*aObserver*/ )
       
   202 	{
       
   203 	return EFalse;
       
   204 	}
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CSIPSecTlsPlugin::IsServerInitiatedSecAgreeAllowed
       
   208 // Framework calls this function if it has selected TLS as the security
       
   209 // mechanism to use.
       
   210 // Server initiated TLS must not be supported.
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 TBool CSIPSecTlsPlugin::IsServerInitiatedSecAgreeAllowed() const
       
   214 	{
       
   215 	return EFalse;
       
   216 	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CSIPSecTlsPlugin::ParametersUpdatedL
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TBool CSIPSecTlsPlugin::ParametersUpdatedL( MSIPSecUser* /*aUser*/ )
       
   223 	{
       
   224 	return EFalse;
       
   225 	}
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CSIPSecTlsPlugin::CancelPendingOperations
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CSIPSecTlsPlugin::CancelPendingOperations(
       
   232 	MSIPSecSecurityMechanismObserver* /*aObserver*/ )
       
   233 	{
       
   234 	}
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CSIPSecTlsPlugin::ClearCache
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CSIPSecTlsPlugin::ClearCache( MSIPSecUser* aUser )
       
   241 	{
       
   242 	if ( aUser )
       
   243 		{
       
   244 		iCache->RemoveSIPSecUser( iTransportMgr, *aUser );
       
   245 		}
       
   246 	}
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CSIPSecTlsPlugin::SetCredentialsL
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CSIPSecTlsPlugin::SetCredentialsL( TTransactionId /*aTransactionId*/,
       
   253                                         const TDesC8& /*aRealm*/,
       
   254 						                const TDesC8& /*aOutboundProxy*/, 
       
   255 									    const TDesC8& /*aUserName*/,
       
   256 									    const TDesC8& /*aPassword*/)
       
   257 	{
       
   258 	}
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CSIPSecTlsPlugin::SetCredentialsL
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 void CSIPSecTlsPlugin::SetCredentialsL( const MSIPSecUser& /*aUser*/,
       
   265                                         const TDesC8& /*aRealm*/,
       
   266 						                const TDesC8& /*aOutboundProxy*/, 
       
   267 									    const TDesC8& /*aUserName*/,
       
   268 									    const TDesC8& /*aPassword*/)
       
   269 	{
       
   270 	}
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CSIPSecTlsPlugin::IgnoreChallenge
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TInt CSIPSecTlsPlugin::IgnoreChallenge( TTransactionId /*aTransactionId*/, 
       
   277                                         const TDesC8& /*aRealm*/,
       
   278                                         const MSIPSecUser* /*aTrustedUser*/ )
       
   279 	{
       
   280 	return KErrNotFound;
       
   281 	}
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CSIPSecTlsPlugin::RemoveCredentials
       
   285 // -----------------------------------------------------------------------------
       
   286 //	
       
   287 TInt CSIPSecTlsPlugin::RemoveCredentials( const TDesC8& /*aRealm*/ )
       
   288 	{
       
   289 	return KErrNotFound;
       
   290  	}