gba/gbafilter/inc/HTTPFilterGBA.h
changeset 0 164170e6151a
child 1 d5423fbb4f29
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2007 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:  GBA Filter definitions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __HTTPFILTERGBA_H_
       
    20 #define __HTTPFILTERGBA_H_
       
    21 
       
    22 #include <http/mhttpfilter.h>
       
    23 #include <http/rhttpsession.h>
       
    24 #include <http/cecomfilter.h>
       
    25 #include <http/framework/httplogger.h>
       
    26 
       
    27 #include <gbautility.h>
       
    28 
       
    29 class RHTTPResponse;
       
    30 class RHTTPTransaction;
       
    31 class CMD5;
       
    32 
       
    33 const TInt KMaxTypeLength = 255;
       
    34 const TInt KBsfAddressSize = 128;
       
    35 
       
    36 
       
    37 class CHTTPFilterGBA : public CEComFilter, public MHTTPFilter, public MGbaObserver
       
    38 {
       
    39     enum
       
    40         {
       
    41         EAlgUnknown,
       
    42         EAlgMd5,
       
    43         EAlgMd5Sess
       
    44         };
       
    45 
       
    46     enum
       
    47         {
       
    48         EQopNone,
       
    49         EQopAuth = 1,
       
    50         EQopAuthInt = 2
       
    51         };
       
    52 public:
       
    53 
       
    54 	static CEComFilter* InstallFilterL(TAny* aSession);
       
    55  
       
    56 	virtual ~CHTTPFilterGBA();
       
    57 
       
    58 public:	// Methods from MHTTPFilterBase
       
    59 
       
    60 	/// @see MHTTPFilterBase::MHFRunL
       
    61 	virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
       
    62 
       
    63 	/// @see MHTTPFilterBase::MHFSessionRunL
       
    64 	virtual void MHFSessionRunL(const THTTPSessionEvent& aEvent);
       
    65 
       
    66 	/// @see MHTTPFilterBase::MHFRunError
       
    67 	virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
       
    68 
       
    69 	/// @see MHTTPFilterBase::MHFSessionRunError
       
    70 	virtual TInt MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent);
       
    71 
       
    72 public:	// Methods from MHTTPFilter
       
    73 
       
    74 	/// @see MHTTPFilter::MHFUnload
       
    75 	virtual void MHFUnload(RHTTPSession aSession, THTTPFilterHandle aHandle);
       
    76 
       
    77 	/// @see MHTTPFilter::MHFLoad
       
    78 	virtual void MHFLoad(RHTTPSession aSession, THTTPFilterHandle aHandle);
       
    79 	
       
    80 	inline void SetProtocolIdentifierL( const TDesC8& aIdentifier){
       
    81 	    iProtocolIdentifier = aIdentifier;
       
    82 	}
       
    83 	
       
    84 	inline void SetGBAFlags(const TUint8 aFlags){
       
    85 	    iFlags = aFlags;
       
    86 	}
       
    87 	
       
    88 	inline void SetGBALabel(const TDesC8& aLabel){
       
    89 	    iUICCLabel =  aLabel ;
       
    90 	}
       
    91 
       
    92     //Only for testing purpose
       
    93 	//To force BSF address for use
       
    94 	inline void SetBSFAddress(const TDesC8& aBsfAddress){
       
    95 	        iBsfAddress = aBsfAddress;
       
    96 	};
       
    97 
       
    98  private:
       
    99 	
       
   100 	CHTTPFilterGBA();
       
   101 
       
   102 	///ContructL also Installs the filter.
       
   103 	void ConstructL( RHTTPSession aSession );
       
   104 	
       
   105 #if defined (_DEBUG)
       
   106 	void DumpResponseHeadersL( RHTTPResponse& aResponse );
       
   107 #endif
       
   108 
       
   109 	void CheckHeadersL( RHTTPTransaction& aTrans );
       
   110 	
       
   111 	void ProcessBodyPartL( RHTTPTransaction& aTrans );
       
   112 	
       
   113 	void Cleanup( const RHTTPTransaction& aTrans );
       
   114 	
       
   115 	void CleanupAll();
       
   116 	
       
   117     TInt FindHeaderPartToUseL(RHTTPTransaction aTransaction) const;
       
   118     
       
   119 	TBool FindAuth(const TDesC8& aQop) const;
       
   120 	
       
   121 	void DoSubmitL( RHTTPTransaction aTransaction );
       
   122 	
       
   123 	void EncodeDigestAuthL( TInt aCred, RHTTPTransaction aTransaction );
       
   124 	
       
   125     void DAddCredentialsToListL( 	RString aUsernameStr,
       
   126     								RString aPasswordStr,
       
   127     								RString aRealmStr,
       
   128     								RStringF aUriStr,
       
   129     								RString aOpaque,
       
   130     								RString aNonce,
       
   131     								TInt aQop,
       
   132     								TInt aAuthAlg );
       
   133    /**
       
   134     * Calculate H(A1). See section 3.2.2.2
       
   135     */
       
   136     void HAOneL( int aAlgorithm,
       
   137                const RString& aUsername,
       
   138                const RString& aPW,
       
   139 		       const RString& aRealm,
       
   140                const RString& aNonceValue,
       
   141                TDesC8& aCNonce,
       
   142                TDes8& aResult);
       
   143 
       
   144     
       
   145     /**
       
   146     * Calculate H(A2). See section 3.2.2.3
       
   147     */
       
   148     void HATwoL(const RStringF& aMethod, const RString& aRequestUri, TDes8& aResult);
       
   149 
       
   150     /**
       
   151     * Calculate a hash and in the form of a 32 character hex result.
       
   152     */
       
   153     void Hash(const TDesC8& aMessage, TDes8& aHash);
       
   154 
       
   155     /**
       
   156     * Generate a cnonce value
       
   157     */	
       
   158     void GenerateCNonce( TDes8& aNonce );
       
   159 
       
   160     /**
       
   161     * Returns the requested uri 
       
   162     * that can be used in uri field or request header
       
   163     *
       
   164     * @param aTransaction current transaction
       
   165     * @return requested URI
       
   166     */
       
   167     RString RequestUriL( RHTTPTransaction& aTransaction);
       
   168                    
       
   169     /**
       
   170     * Check and return QoP from the response header.
       
   171     * @param aHeader authentication header
       
   172     * @param aWwwAuthHeader authentication header name
       
   173     * @param aHeaderPart which authentication header field in the response header
       
   174     * @return one of KQopXXX enum. KQopAuth is prefered.
       
   175     */    
       
   176     TInt CheckQop( RHTTPHeaders& headers,
       
   177                    RStringF& aWwwAuthHeader,
       
   178                    TInt aHeaderPart );
       
   179  
       
   180  	void DGetCredentialsFromPropertiesL( RHTTPTransaction& aTransaction );
       
   181  	
       
   182  	TInt DFindCredentialsForURI( const TUriC8& aURI );
       
   183  	
       
   184  	void DRemoveCredentialsFromList( TInt aCredId );
       
   185  	
       
   186  	TInt DFindCredentials( const RString& aRealm, const TUriC8& aURI );
       
   187  	
       
   188  	//Inherited from MGbaObserver
       
   189     void BootstrapComplete(TInt error);
       
   190  	
       
   191      class TDCredentials
       
   192         {
       
   193         public:
       
   194             RStringToken iUser;  //username
       
   195             RStringToken iPassword; //password
       
   196             RStringTokenF iURI;  //uri
       
   197             RStringToken iRealm; //Realm used - there may be multiple for each host
       
   198             RStringToken iOpaque;
       
   199             RStringToken iNonce;
       
   200             TInt iQop;
       
   201             TInt iAlgorithm;
       
   202             TInt iNc;   // nonce-count
       
   203         };
       
   204 
       
   205 	/// A count to make sure we delete at the right time.
       
   206 	TInt        iLoadCount;
       
   207 	RStringPool iStringPool;
       
   208     RStringF    iOpaqueStr;
       
   209     RStringF    iNonceStr;
       
   210 	RStringF    iQopStr;
       
   211 	RStringF 	iStaleStr;
       
   212 	RStringF    iAuthInfo;
       
   213 	RStringF 	iUsernameStr;
       
   214 	RStringF 	iPasswordStr;
       
   215     RStringF    iQopAuthStr;
       
   216     RStringF    iMd5Str;
       
   217     RStringF    iMd5SessStr;
       
   218     RStringF    iRealmStr;
       
   219 	RStringF 	iUserAgent;
       
   220     TInt64      iSeed;
       
   221     CMD5*       iMD5Calculator;
       
   222 	TInt		iOffset;
       
   223 	TUint8      iFlags;
       
   224 	TBuf8<5>    iProtocolIdentifier;
       
   225 	TInt        iBootstrapCount;
       
   226 	TBool       iBootstrapPending;
       
   227 	TBool       iHaveGbaBootstrapCredentials;
       
   228 	TBool       iGBAU;
       
   229 	TBuf8<KMaxTypeLength>     iUICCLabel;
       
   230 	CActiveSchedulerWait      iBootstrapWait;
       
   231 	CGbaUtility*              iGbaUtility;
       
   232     TGBABootstrapInputParams  iGbaInputParams;
       
   233     TGBABootstrapOutputParams iGbaOutputParams;
       
   234     //Only for testing  purpose
       
   235     TBuf8<KBsfAddressSize>    iBsfAddress;
       
   236     // Internal list of valid credentials
       
   237     RArray<TDCredentials>     iDCredentials;
       
   238 
       
   239 };
       
   240 
       
   241 #endif //__HTTPFILTERGBA_H_
       
   242 
       
   243 //EOF