realtimenetprots/sipfw/SIP/SIPSec/IpSecPlugin/inc/CSipSecIpsecMechanism.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:
       
    15 * Name          : CSipSecIpsecMechanism.h
       
    16 * Part of       : SIPSec
       
    17 * Version       : SIP/6.0 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 
       
    29 #ifndef CSIPSECIPSECMECHANISM_H
       
    30 #define CSIPSECIPSECMECHANISM_H
       
    31 
       
    32 #include <lib_pfkey.h>
       
    33 #include <ipsecpolapi.h>
       
    34 
       
    35 #ifdef CPPUNIT_TEST
       
    36 #include "tsipsecmechanisminitparams.h"
       
    37 #include "msipsecsecuritymechanism.h"
       
    38 #else
       
    39 #include "sipsecsecuritymechanism.h"
       
    40 #endif
       
    41 
       
    42 #include "SipSecIpsecParams.h"
       
    43 #include "MSipSecSaDbSendReceiveObserver.h"
       
    44 #include "MIpSecMechanismParams.h"
       
    45 #include "MSIPTransportRemovalObserver.h"
       
    46 
       
    47 class CSipSecSaDbMsgReceiver;
       
    48 class CSipSecSaDbMsgSender;
       
    49 class CSipSecAgreeContext;
       
    50 class MTimerManager;
       
    51 class MSIPTransportMgr;
       
    52 class TSIPSecMechanismInitParams;
       
    53 class CState;
       
    54 class TSIPTransportParams;
       
    55 
       
    56 #ifdef CPPUNIT_TEST
       
    57 class CActiveObjController1;
       
    58 #endif
       
    59 
       
    60 /**
       
    61  * @brief IPSEC Mechanism implementation
       
    62  * 
       
    63  * 
       
    64  */
       
    65 #ifdef CPPUNIT_TEST
       
    66 class CSipSecIpsecMechanism : public CBase, public MSIPSecSecurityMechanism,
       
    67 #else
       
    68 class CSipSecIpsecMechanism : public CSIPSecSecurityMechanism,
       
    69 #endif
       
    70 	public MSipSecSaDbSendReceiveObserver,
       
    71 	public MIpSecMechanismParams,
       
    72 	public MSIPTransportRemovalObserver
       
    73 	{
       
    74 	
       
    75 public: // Constructors and destructor
       
    76 
       
    77     /**
       
    78     * Constructs the object. Leaves on Failure
       
    79     *
       
    80     * @return Return the CSIPSecAgreeRecordContainer object
       
    81     * 
       
    82     */
       
    83 	static CSipSecIpsecMechanism* NewL( TAny* aInitParam );
       
    84 
       
    85     /**
       
    86     * Constructs the object and adds pointer to cleanup stack.
       
    87     *
       
    88     * @return Return the CSIPSecAgreeRecordContainer object
       
    89     */
       
    90 	static CSipSecIpsecMechanism* NewLC( TAny* aInitParam );
       
    91     
       
    92     /**
       
    93     * Destructor
       
    94     */
       
    95     ~CSipSecIpsecMechanism();
       
    96     
       
    97 public: // Functions from MSIPSecSecurityMechanism
       
    98 
       
    99 	const TDesC8& Name() const;
       
   100 	
       
   101 	void InitializeSecurityClientL( CSIPSecurityClientHeader& aSecurityClient );
       
   102 
       
   103   	void ProcessSecurityVerifyL(
       
   104   						TSIPTransportParams& aTransportParams,
       
   105                   	    CSIPRequest& aRequest,
       
   106                         TInetAddr& aNextHop,
       
   107                         const CUri8& aRemoteTarget,
       
   108                         const TDesC8& aOutboundProxy,
       
   109                         MSIPSecUser* aUser,
       
   110                         TRegistrationId aRegistrationId,
       
   111                         RPointerArray<CSIPSecurityServerHeader>& aSecurityServer,
       
   112                 		RPointerArray<CSIPSecurityVerifyHeader>& aSecurityVerify );
       
   113 
       
   114 	void AddSecurityParamsL( TSIPTransportParams& aTransportParams,
       
   115 	                         CSIPRequest& aRequest,
       
   116 	                         TRegistrationId aRegistrationId,
       
   117 	                         TTransactionId aTransactionId,
       
   118 			                 TInetAddr& aNextHop,
       
   119 			                 const CUri8& aRemoteTarget,
       
   120 			                 const TDesC8& aOutboundProxy,
       
   121 							 MSIPSecUser* aUser );
       
   122 						    
       
   123 	TBool ResponseReceivedL( TSIPTransportParams& aTransportParams,
       
   124 	                         CSIPResponse& aResponse,
       
   125 	                         CSIPRequest& aRequest,
       
   126 	                         TRegistrationId aRegistrationId,
       
   127 	                         TTransactionId aTransactionId,
       
   128 			                 TInetAddr& aNextHop,
       
   129 			                 const CUri8& aRemoteTarget,
       
   130 			                 const TDesC8& aOutboundProxy,
       
   131 							 MSIPSecUser* aUser,
       
   132 							 MSIPSecSecurityMechanismObserver& aObserver );
       
   133 	
       
   134 	TBool IsServerInitiatedSecAgreeAllowed() const;
       
   135 	
       
   136 	TBool ParametersUpdatedL( MSIPSecUser* aUser );
       
   137 	    
       
   138 	void CancelPendingOperations( MSIPSecSecurityMechanismObserver* aObserver );
       
   139 
       
   140 	void ClearCache( MSIPSecUser* aUser );
       
   141 
       
   142 	void SetCredentialsL( TTransactionId aTransactionId,
       
   143 	                      const TDesC8& aRealm,
       
   144 			              const TDesC8& aOutboundProxy, 
       
   145 						  const TDesC8& aUserName,
       
   146 						  const TDesC8& aPassword );
       
   147 
       
   148 	void SetCredentialsL( const MSIPSecUser& aUser,
       
   149 	                      const TDesC8& aRealm,
       
   150 			              const TDesC8& aOutboundProxy, 
       
   151 						  const TDesC8& aUserName,
       
   152 						  const TDesC8& aPassword );
       
   153 	
       
   154 	TInt IgnoreChallenge( TTransactionId aTransactionId,
       
   155 	                      const TDesC8& aRealm,
       
   156 	                      const MSIPSecUser* aTrustedUser );
       
   157 
       
   158 	TInt RemoveCredentials( const TDesC8& aRealm );
       
   159 	
       
   160 	
       
   161 public: // Functions from MSipSecSaDbSendReceiveObserver
       
   162 
       
   163 	void MessageSentL( TInt aStatus, 
       
   164 					   TInt aMsgType );
       
   165 
       
   166 	void MessageReceived( TInt aStatus );
       
   167 
       
   168 public: // Functions from MIpSecMechanismParams
       
   169 
       
   170 	TUint T1();
       
   171 	RSADB& Sadb();
       
   172 	RIpsecPolicyServ& PolicyServer();
       
   173 	TUint SeqNumber();
       
   174 	MTimerManager& TimerMan();
       
   175 	MSIPTransportMgr& TransportMan();
       
   176 	void UpdateSecCliL( RPointerArray<CSIPSecurityHeaderBase>& aSecCliHeaders );
       
   177 	void ContextCleared( CSipSecAgreeContext* aContext );
       
   178 	MSIPTransportRemovalObserver* TransportRemovalObserver();
       
   179 	void ProcessInitialReqisterL( TSIPTransportParams& aTransportParams,
       
   180                                   CSIPRequest& aRequest );
       
   181 
       
   182 public: // Function from MSIPTransportRemovalObserver
       
   183 
       
   184     void RemovalCompleted( TUint32 aTransportId );
       
   185     
       
   186 
       
   187 private: // Functions
       
   188 					
       
   189 	TBool Capable();
       
   190 								  
       
   191 	void ConsumeSadbMessage();
       
   192 	
       
   193 	void SadbRegister();
       
   194 	
       
   195 	void SadbAdd();
       
   196 	
       
   197 	void InitSecCliHeaderL( CSIPSecurityClientHeader* aCliHeader );
       
   198 	
       
   199 	void CreateNewContextL( TSIPTransportParams& aTransportParams,
       
   200 	                        CSIPResponse& aResponse, 
       
   201 	                        CSIPRequest& aRequest,
       
   202 	                        TInetAddr& aNextHop, 
       
   203 	                        MSIPSecUser* aUser,
       
   204 	                        MSIPSecSecurityMechanismObserver& aObserver );
       
   205 	                        
       
   206 	CSipSecAgreeContext* FindContext( const MSIPSecUser* aSipUser );
       
   207 	
       
   208 	CSipSecAgreeContext* FindContext( const TInetAddr& aNextHop );
       
   209 
       
   210 	void DeleteContext( CSipSecAgreeContext* aContext );
       
   211 	
       
   212 	void InitializeStatesL();
       
   213 							  
       
   214 private: // Private constructor
       
   215 
       
   216     void ConstructL();
       
   217 
       
   218     /*
       
   219      * Constructor
       
   220      */
       
   221 	CSipSecIpsecMechanism( TSIPSecMechanismInitParams* aInitParams );
       
   222         
       
   223 private: // Data
       
   224 
       
   225 	// Seed used for generating ports and spi's randomly    
       
   226     TInt64 iSeed;
       
   227     
       
   228     // Handle to socket server
       
   229     RSocketServ iSockServ;
       
   230     
       
   231     // Handle to IPSEC SADB
       
   232     RSADB iSaDb;
       
   233     
       
   234     // Handle to IPSEC policy server
       
   235     RIpsecPolicyServ iPolicyServ;
       
   236     
       
   237     // Sequence number for SADB messages
       
   238     TUint iSeqNum;
       
   239     
       
   240     // Buffer for received messages
       
   241     TPfkeyRecvMsg iReceiveBuffer;
       
   242         
       
   243     // Contains protocol, mode, algorithm capabilities
       
   244     TSipSecIpsecCaps iCaps;
       
   245     
       
   246     // IPSEC Sec Agree contexts for each negotiated SAs
       
   247     RPointerArray<CSipSecAgreeContext> iSecAgreeContexts;
       
   248     
       
   249     // Timer services
       
   250     MTimerManager& iTimerMgr;
       
   251     
       
   252     // Plugin context (Framework)
       
   253     MSIPSecEngineContext& iEngineContext;
       
   254     
       
   255     // Transport management (ConnectionMgr)
       
   256     MSIPTransportMgr& iTransportMgr;
       
   257     
       
   258    	// SIP T1 timer
       
   259 	TUint iT1;
       
   260     
       
   261     // All states of the record
       
   262 	RPointerArray<CState> iStates;
       
   263 	
       
   264 	// Receiver for SADB messages
       
   265 	CSipSecSaDbMsgReceiver* iSaDbMsgReceiver;
       
   266 	
       
   267 	// Sender for sending initial SADB_REGISTER message
       
   268 	CSipSecSaDbMsgSender* iSaDbMsgSender;
       
   269 
       
   270 
       
   271 #ifdef CPPUNIT_TEST
       
   272 	friend class CActiveObjController1;
       
   273 	friend class CSipIpSecTest;
       
   274 public:
       
   275 	CActiveObjController1* iObjCtr;   
       
   276 #endif
       
   277 	};
       
   278 
       
   279 #endif // CSIPSECIPSECMECHANISM_H
       
   280 
       
   281 
       
   282 // End of File