realtimenetprots/sipfw/SIP/SIPSec/DigestPlugin/inc/CSIPSecCredentials.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          : CSIPSecCredentials.h
       
    16 * Part of       : SIPSec/DigestPlugin
       
    17 * Version       : SIP/6.0
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 #ifndef __CSIPSEC_CREDENTIALS_H__
       
    29 #define __CSIPSEC_CREDENTIALS_H__
       
    30 
       
    31 // INCLUDES
       
    32 #include "CSIPSecDigestCacheEntry.h"
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CSIPAuthorizationHeaderBase;
       
    36 class CSIPSecChallenge;
       
    37 class CSIPSecDigest;
       
    38 class TSIPSecDigestCtxSetup;
       
    39 class TSIPSecPluginCtxResponse;
       
    40 class TSIPSecDigestCtxProcess;
       
    41 
       
    42 // CLASS DECLARATION
       
    43 /**
       
    44  * @brief Class representing credentials created based on challenge received in
       
    45  * a 401/407 response
       
    46  * 
       
    47  * @class CSIPSecCredentials CSIPSecCredentials.h "CSIPSecCredentials.h"
       
    48  *
       
    49  * This class provides functions to
       
    50  * - update, because of SIP request sending with these credentials.
       
    51  *   In this case response is calculated.
       
    52  * - update, because of re-challenge, which causes update of user credentials 
       
    53  * - handle authentication info header
       
    54  * - handle security verify header
       
    55  */
       
    56 class CSIPSecCredentials : public CSIPSecDigestCacheEntry
       
    57     {
       
    58 public: // Constructors and destructor
       
    59 
       
    60     /**
       
    61     * Constructs the object. Leaves on Failure
       
    62     * @param aChallenge Challenge, ownership is transferred.
       
    63     * @param aMechanism the mechanism
       
    64     * @param aContext Response context
       
    65     * @return Return A new CSIPSecCredentials object, ownership is transferred.
       
    66     */
       
    67     static CSIPSecCredentials* NewL( CSIPSecChallenge* aChallenge,
       
    68                                      CSIPSecDigest& aMechanism,
       
    69                                      TSIPSecPluginCtxResponse& aContext );
       
    70 
       
    71     /**
       
    72     * Destructor
       
    73     */
       
    74     ~CSIPSecCredentials();
       
    75 
       
    76 public: // From CSIPSecDigestCacheEntry
       
    77 
       
    78     void UpdateL( CSIPSecUserRecord& aUserCredentials );
       
    79 
       
    80     void UpdateL( TSIPSecPluginCtxRequest& aContext );
       
    81 
       
    82     void HandleL( TSIPSecPluginCtxInfo& aAuthenticationInfo );
       
    83 
       
    84     void HandleL( TSIPSecPluginCtxVerify& aSecurityVerifyCtx );
       
    85 
       
    86     CSIPSecDigest::TChallengeType Type() const;
       
    87     
       
    88     CSIPSecDigest::TChallengeType
       
    89     	Type( const TSIPSecPluginContext& aContext ) const;
       
    90 
       
    91 public: // New functions
       
    92 
       
    93     /**
       
    94     * Returns type of challenge
       
    95     * @param aChallenge The challenge who's type is requested
       
    96     * @param aContext Context in which the challenge type is resolved
       
    97     * @return Type of aChallenge
       
    98     */
       
    99     CSIPSecDigest::TChallengeType
       
   100 		ChallengeType( const CSIPSecChallenge& aChallenge,
       
   101 		               const TSIPSecPluginContext* aContext = 0 ) const;
       
   102 
       
   103     /**
       
   104     * Returns content (SIP proxy/WWW authorization header)
       
   105     * @return Content
       
   106     */
       
   107     CSIPAuthorizationHeaderBase& Content();
       
   108 
       
   109     /**
       
   110     * Updates entry based on a SIP response 
       
   111     * @param aContext Response context
       
   112     * @param aAskCredentials OUT: ETrue If the credentials for the challenge(s)
       
   113     *		 present in the current SIP response, must be asked now.
       
   114     *		 EFalse If there is no need to ask the credentials, and maybe they
       
   115     *	     are already being asked for due to some earlier SIP response.
       
   116     * @return ETrue If credentials must be obtained, EFalse otherwise
       
   117     */
       
   118     TBool DigestUpdateL( TSIPSecDigestCtxSetup& aContext,
       
   119     					 TBool& aAskCredentials );
       
   120 
       
   121     /**
       
   122     * Handles new challenge reception and determines action
       
   123     * @param aNewChallenge New challenge that has been received
       
   124     * @return ETrue If this credentials instance must be removed,
       
   125     *		  EFalse otherwise
       
   126     */
       
   127     TBool ChallengeReceived( CSIPSecChallenge& aNewChallenge );
       
   128 
       
   129     /**
       
   130     * Returns challenge
       
   131     * @return Challenge
       
   132     */
       
   133     CSIPSecChallenge& Challenge();
       
   134 
       
   135     /**
       
   136     * Returns mechanism
       
   137     * @return Mechanism
       
   138     */
       
   139     CSIPSecDigest& Mechanism() const;
       
   140 
       
   141 	/**
       
   142     * Get the qop value
       
   143     * @return Qop value, or empty descriptor if qop is undefined
       
   144     */
       
   145 	const TPtrC8 Qop() const;
       
   146 
       
   147 	/**
       
   148     * Compares aChallenge to the challenge in this CSIPSecCredentials object.
       
   149     * @param aChallenge Challenge
       
   150     * @param aUser SIPSec user processing SIP response where the aChallenge is
       
   151     *	received.
       
   152     * @param aRegistrationId Registration id
       
   153     * @return ETrue If the challenges match
       
   154     *		  EFalse otherwise
       
   155     */
       
   156 	TBool DoesMatch( const CSIPSecChallenge& aChallenge,
       
   157 					 const MSIPSecUser& aUser,
       
   158 					 TRegistrationId aRegistrationId ) const;
       
   159 
       
   160 private: // Constructors, for internal use
       
   161 
       
   162 	/*
       
   163      * Constructor
       
   164      * @param aMechanism the mechanism     
       
   165      * @param aUser SIPSec user
       
   166      */
       
   167     CSIPSecCredentials( CSIPSecDigest& aMechanism, const MSIPSecUser& aUser );
       
   168 
       
   169     /*
       
   170      * Second phase constructor
       
   171      * @param aChallenge Challenge, ownership is transferred.
       
   172      * @param aContext Response context     
       
   173      */
       
   174     void ConstructL( CSIPSecChallenge* aChallenge,
       
   175     				 TSIPSecPluginCtxResponse& aContext );    
       
   176 
       
   177 private: // New functions, for internal use
       
   178 
       
   179     /*
       
   180      * Creates the content
       
   181      */
       
   182     void CreateContentL( CSIPSecChallenge& aChallenge );
       
   183 
       
   184     /*
       
   185      * Updates content
       
   186      * @param aContext Digest context
       
   187      */
       
   188     void UpdateContentL( TSIPSecDigestCtxSetup& aContext );
       
   189 
       
   190     /*
       
   191      * Updates content
       
   192      * @param aContext Digest context
       
   193      */
       
   194     void UpdateContentL( TSIPSecDigestCtxProcess& aContext );
       
   195 
       
   196     /*
       
   197      * Sets nonce count
       
   198      * @param aNonceCount Nonce count
       
   199      */
       
   200     void SetNonceCountL( TUint aNonceCount );
       
   201 
       
   202 private: // Data
       
   203 
       
   204     // Owned
       
   205     CSIPSecChallenge* iChallenge;
       
   206 
       
   207     // Owned
       
   208     CSIPAuthorizationHeaderBase* iAuthorizationHeader;
       
   209 
       
   210     TUint iNonceCount;
       
   211 
       
   212     CSIPSecDigest& iMechanism;
       
   213 
       
   214 	// For testing purposes
       
   215 #ifdef CPPUNIT_TEST
       
   216     friend class CSIPSecCredentialsTest;
       
   217 #endif
       
   218     };
       
   219 
       
   220 #endif // end of __CSIPSEC_CREDENTIALS_H__
       
   221 
       
   222 // End of File