xdmprotocols/XcapProtocol/XcapHttpTransport/src/XcapHttpAuthManager.cpp
changeset 26 04ca1926b01c
parent 20 76bddcd072ba
child 28 d9861ae9169c
child 32 32463a6c57b3
equal deleted inserted replaced
20:76bddcd072ba 26:04ca1926b01c
     1 /*
       
     2 * Copyright (c) 2003 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:   CXcapHttpAuthManager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <hash.h>
       
    23 #include <e32math.h>
       
    24 #include "XcapHttpRequest.h"
       
    25 #include "XcapHttpTransport.h"
       
    26 #include "XcapHttpAuthManager.h"
       
    27 
       
    28 // ----------------------------------------------------------
       
    29 // CXcapHttpAuthManager::CXcapHttpAuthManager
       
    30 // 
       
    31 // ----------------------------------------------------------
       
    32 //
       
    33 CXcapHttpAuthManager::CXcapHttpAuthManager( RHTTPSession& aHttpSession,
       
    34                                             CXcapHttpTransport& aTransportMain ) :
       
    35                                             iNonceCount( 1 ),
       
    36                                             iAuthorized( EFalse ),
       
    37                                             iHttpSession( aHttpSession ),
       
    38                                             iTransportMain( aTransportMain ),
       
    39                                             iStringPool( aHttpSession.StringPool() )
       
    40     { 
       
    41     }
       
    42 
       
    43 // ----------------------------------------------------------
       
    44 // CXcapHttpAuthManager::NewL
       
    45 // 
       
    46 // ----------------------------------------------------------
       
    47 //
       
    48 CXcapHttpAuthManager* CXcapHttpAuthManager::NewL( RHTTPSession& aHttpSession,
       
    49                                                   CXcapHttpTransport& aTransportMain,
       
    50                                                   const TXdmCredentials& aDigestCredentials )
       
    51     {
       
    52     CXcapHttpAuthManager* self = new ( ELeave ) CXcapHttpAuthManager( aHttpSession, aTransportMain );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL( aDigestCredentials );
       
    55     CleanupStack::Pop();  //self
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------
       
    60 // CXcapHttpAuthManager::~CXcapHttpAuthManager
       
    61 // 
       
    62 // ----------------------------------------------------
       
    63 //
       
    64 CXcapHttpAuthManager::~CXcapHttpAuthManager()
       
    65     {
       
    66     #ifdef _DEBUG
       
    67         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::~CXcapHttpAuthManager()" ) );
       
    68     #endif
       
    69     delete iMD5;
       
    70     delete iRealm;
       
    71     delete iOpaque;
       
    72     delete iDomain;
       
    73     delete iQopString;
       
    74     delete iAlgorithm;
       
    75     delete iServerNonce;
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------
       
    79 // CXcapHttpAuthManager::ConstructL
       
    80 // 
       
    81 // ----------------------------------------------------------
       
    82 //
       
    83 void CXcapHttpAuthManager::ConstructL( const TXdmCredentials& aDigestCredentials )
       
    84     {
       
    85     iMD5 = CMD5::NewL();
       
    86     iUserName.Copy( aDigestCredentials.iUserName );
       
    87     iPassword.Copy( aDigestCredentials.iPassword );
       
    88     } 
       
    89 
       
    90 // ----------------------------------------------------------
       
    91 // CXcapHttpAuthManager::SetAuthorized
       
    92 // 
       
    93 // ----------------------------------------------------------
       
    94 //
       
    95 void CXcapHttpAuthManager::SetAuthorized( TBool aAuthorized )
       
    96     {
       
    97     iAuthorized = aAuthorized;
       
    98     } 
       
    99 
       
   100 // ----------------------------------------------------------
       
   101 // CXcapHttpAuthManager::IsAuthorized
       
   102 // 
       
   103 // ----------------------------------------------------------
       
   104 //
       
   105 TBool CXcapHttpAuthManager::IsAuthorized() const
       
   106     {
       
   107     return iAuthorized;
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------
       
   111 // CXcapHttpAuthManager::AuthorizationL
       
   112 // 
       
   113 // ----------------------------------------------------------
       
   114 //
       
   115 HBufC8* CXcapHttpAuthManager::AuthorizationL( CXcapHttpRequest& aHttpRequest )
       
   116     {
       
   117     #ifdef _DEBUG
       
   118         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::AuthorizationL()" ) );
       
   119     #endif
       
   120     if( !iUnauthReceived )
       
   121         return NULL;
       
   122     TInt bufPtr = 0;
       
   123     HBufC8* ret = NULL;
       
   124     THTTPHdrVal requestUri;
       
   125     //All these strings should have been defined - except for
       
   126     //"opaque", maybe - in the WWW-Authentication header that
       
   127     //the server sent. In case some of them were not, let's just
       
   128     //keep going as if they were there, but were empty. The request
       
   129     //will then fail & be completed in the next MHFRunL() call. 
       
   130     TPtrC8 realm( iRealm ? iRealm->Des() : TPtrC8() );
       
   131     TPtrC8 qop( iQopString ? iQopString->Des() : TPtrC8() );
       
   132     TPtrC8 opaque( iOpaque ? iOpaque->Des() : TPtrC8() );
       
   133     TPtrC8 nonce( iServerNonce ? iServerNonce->Des() : TPtrC8() );
       
   134     TPtrC8 uri( aHttpRequest.RelativeUri() );
       
   135     TBuf8<8> nonceCount;
       
   136     nonceCount.AppendFormat( _L8( "%08x" ), iNonceCount );   
       
   137     CBufFlat* buffer = CBufFlat::NewL( 128 );
       
   138     CleanupStack::PushL( buffer ); 
       
   139     buffer->InsertL( bufPtr, KAuthHeaderStart );
       
   140     bufPtr = bufPtr + KAuthHeaderStart().Length();
       
   141     buffer->InsertL( bufPtr, iUserName );
       
   142     bufPtr = bufPtr + iUserName.Length();    
       
   143     buffer->InsertL( bufPtr, KAuthHeaderParamEndQ );
       
   144     bufPtr = bufPtr + KAuthHeaderParamEndQ().Length();    
       
   145     buffer->InsertL( bufPtr, KAuthHeaderRealm );
       
   146     bufPtr = bufPtr + KAuthHeaderRealm().Length();
       
   147     buffer->InsertL( bufPtr, realm );
       
   148     bufPtr = bufPtr + realm.Length();
       
   149     buffer->InsertL( bufPtr, KAuthHeaderParamEndQ );
       
   150     bufPtr = bufPtr + KAuthHeaderParamEndQ().Length();   
       
   151     buffer->InsertL( bufPtr, KAuthHeaderNonce );
       
   152     bufPtr = bufPtr + KAuthHeaderNonce().Length();
       
   153     buffer->InsertL( bufPtr, nonce );
       
   154     bufPtr = bufPtr + nonce.Length();
       
   155     buffer->InsertL( bufPtr, KAuthHeaderParamEndQ );
       
   156     bufPtr = bufPtr + KAuthHeaderParamEndQ().Length(); 
       
   157     buffer->InsertL( bufPtr, KAuthHeaderUri );
       
   158     bufPtr = bufPtr + KAuthHeaderUri().Length();
       
   159     buffer->InsertL( bufPtr, uri );
       
   160     bufPtr = bufPtr + uri.Length();
       
   161     buffer->InsertL( bufPtr, KAuthHeaderParamEndQ );
       
   162     bufPtr = bufPtr + KAuthHeaderParamEndQ().Length();
       
   163     buffer->InsertL( bufPtr, KAuthHeaderQop );
       
   164     bufPtr = bufPtr + KAuthHeaderQop().Length();
       
   165     buffer->InsertL( bufPtr, qop );
       
   166     bufPtr = bufPtr + qop.Length();
       
   167     buffer->InsertL( bufPtr, KAuthHeaderParamEnd );
       
   168     bufPtr = bufPtr + KAuthHeaderParamEnd().Length();
       
   169     buffer->InsertL( bufPtr, KAuthHeaderNonceCount );
       
   170     bufPtr = bufPtr + KAuthHeaderNonceCount().Length();
       
   171     buffer->InsertL( bufPtr, nonceCount );
       
   172     bufPtr = bufPtr + nonceCount.Length();
       
   173     buffer->InsertL( bufPtr, KAuthHeaderParamEnd );
       
   174     bufPtr = bufPtr + KAuthHeaderParamEnd().Length();
       
   175     buffer->InsertL( bufPtr, KAuthHeaderCNonce );
       
   176     bufPtr = bufPtr + KAuthHeaderCNonce().Length();
       
   177     buffer->InsertL( bufPtr, iClientNonce );
       
   178     bufPtr = bufPtr + iClientNonce.Length();
       
   179     buffer->InsertL( bufPtr, KAuthHeaderParamEndQ );
       
   180     bufPtr = bufPtr + KAuthHeaderParamEndQ().Length();    
       
   181     buffer->InsertL( bufPtr, KAuthHeaderResponse );
       
   182     bufPtr = bufPtr + KAuthHeaderResponse().Length();  
       
   183     TPtrC8 respDigest( RequestDigestLC( aHttpRequest )->Des() );
       
   184     buffer->InsertL( bufPtr, respDigest );
       
   185     bufPtr = bufPtr + respDigest.Length(); 
       
   186     CleanupStack::PopAndDestroy();  //RequestDigestLC()
       
   187     buffer->InsertL( bufPtr, KAuthHeaderParamEndQ );
       
   188     bufPtr = bufPtr + KAuthHeaderParamEndQ().Length();
       
   189     if( opaque.Length() > 0 )
       
   190         {
       
   191         buffer->InsertL( bufPtr, KAuthHeaderOpaque );
       
   192         bufPtr = bufPtr + KAuthHeaderOpaque().Length();
       
   193         buffer->InsertL( bufPtr, opaque );
       
   194         bufPtr = bufPtr + opaque.Length();
       
   195         buffer->InsertL( bufPtr, KAuthHeaderParamQuote );
       
   196         }
       
   197     ret = HBufC8::NewL( buffer->Size() );
       
   198     ret->Des().Copy( buffer->Ptr( 0 ) );
       
   199     buffer->Reset();
       
   200     iNonceCount++;
       
   201     CleanupStack::PopAndDestroy();  //buffer
       
   202     return ret;
       
   203     }
       
   204 
       
   205 // ----------------------------------------------------------
       
   206 // CXcapHttpAuthManager::ConsumeAuthInfoParamL
       
   207 // 
       
   208 // ----------------------------------------------------------
       
   209 //
       
   210 TBool CXcapHttpAuthManager::ConsumeAuthInfoParamL( TAuthInfoParam aName, const TDesC8& aValue )
       
   211     {
       
   212     //For the time being, always return ETrue
       
   213     TBool ret = ETrue;
       
   214     TInt length = aValue.Length();
       
   215     TPtr8 value( CONST_CAST( TUint8*, aValue.Ptr() ), length, length );
       
   216     Unquote( value );
       
   217     #ifdef _DEBUG
       
   218         TPtrC8 name( KAuthInfoParamArray[aName] );
       
   219         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ConsumeAuthInfoParamL()" ) );
       
   220         iTransportMain.WriteToLog( _L8( "  Name:   %S" ), &name );
       
   221         iTransportMain.WriteToLog( _L8( "  Value:  %S" ), &value );
       
   222     #endif
       
   223     switch( aName )
       
   224         {                                              
       
   225         case ENfoNextnonce:
       
   226             SetNextNonceL( value );
       
   227             #ifdef _DEBUG
       
   228                 TPtrC8 nonce( iServerNonce->Des() );
       
   229                 iTransportMain.WriteToLog( _L8( "  -> Nonce set to %S" ), &nonce );
       
   230             #endif
       
   231             break;
       
   232         case ENfoRspauth:
       
   233             /* TODO */
       
   234             break;
       
   235         case ENfoCnonce:
       
   236             #ifdef _DEBUG
       
   237                 iTransportMain.WriteToLog( _L8( "  -> Current cnonce %S" ), &iClientNonce );
       
   238             #endif
       
   239             break;
       
   240             //ret = value.Compare( iClientNonce ) == 0;
       
   241         case ENfoNc:
       
   242             {
       
   243             TBuf8<8> nonceCount;
       
   244             nonceCount.AppendFormat( _L8( "%08x" ), iNonceCount );
       
   245             #ifdef _DEBUG
       
   246                 iTransportMain.WriteToLog( _L8( "  -> Current nonce count %S" ), &nonceCount );
       
   247             #endif
       
   248             //ret = nonceCount.Compare( value ) == 0;
       
   249             break;
       
   250             }
       
   251         case ENfoQop:
       
   252             ret = ETrue;
       
   253             break;
       
   254         default:
       
   255             ret = ETrue;
       
   256             break;
       
   257         }
       
   258     return ret;
       
   259     }
       
   260 
       
   261 // ----------------------------------------------------------
       
   262 // CXcapHttpAuthManager::GenerateClientNonce
       
   263 // 
       
   264 // ----------------------------------------------------------
       
   265 //
       
   266 void CXcapHttpAuthManager::SetNextNonceL( const TDesC8& aNextnonce )
       
   267     {
       
   268     delete iServerNonce;
       
   269     iServerNonce = NULL;
       
   270     iServerNonce = aNextnonce.AllocL();
       
   271     }
       
   272 
       
   273 // ----------------------------------------------------------
       
   274 // CXcapHttpAuthManager::Unquote
       
   275 // 
       
   276 // ----------------------------------------------------------
       
   277 //
       
   278 void CXcapHttpAuthManager::Unquote( TPtr8& aParamValue )
       
   279     {
       
   280     TInt index = aParamValue.Locate( '"' );
       
   281     while( index >= 0 )
       
   282         {
       
   283         aParamValue.Delete( index, 1 );
       
   284         index = aParamValue.Locate( '\"');
       
   285         }
       
   286     }
       
   287        
       
   288 // ----------------------------------------------------------
       
   289 // CXcapHttpAuthManager::RequestDigestLC
       
   290 // 
       
   291 // ----------------------------------------------------------
       
   292 //
       
   293 HBufC8* CXcapHttpAuthManager::RequestDigestLC( CXcapHttpRequest& aHttpRequest )
       
   294     {
       
   295     #ifdef _DEBUG
       
   296         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::RequestDigestLC()" ) );
       
   297     #endif
       
   298     HBufC8* ret = NULL;
       
   299     TPtrC8 nonce( iServerNonce->Des() );
       
   300     if( iQop == EXcapAuth || iQop == EXcapAuthInt )
       
   301         {
       
   302         TBuf8<8> nonceCount;
       
   303         TBuf8<KXcapHashLength> hashBush;
       
   304         nonceCount.AppendFormat( _L8( "%08x" ), iNonceCount );
       
   305         TPtrC8 nonce( iServerNonce->Des() );
       
   306         TPtrC8 qop( iQop == EXcapAuth ? _L8( "auth" ) : _L8( "auth-int" ) );
       
   307         HBufC8* stringToHash = HBufC8::NewLC( nonce.Length() + qop.Length() +
       
   308                                               3 * KXcapHashLength + 8 + 5 );
       
   309         TPtr8 desc( stringToHash->Des() );
       
   310         ConstructHA1L( desc );
       
   311         desc.Append( ':' );
       
   312         desc.Append( nonce );
       
   313         desc.Append( ':' );
       
   314         desc.Append( nonceCount );
       
   315         desc.Append( ':' );
       
   316         desc.Append( iClientNonce );
       
   317         desc.Append(':');
       
   318         desc.Append( qop );
       
   319         desc.Append(':');
       
   320         ConstructHA2L( hashBush, aHttpRequest );
       
   321         desc.Append( hashBush ); 
       
   322         hashBush.Zero();		
       
   323         ret = HBufC8::NewL( KXcapHashLength );
       
   324         Hash( *stringToHash, hashBush );
       
   325         ret->Des().Copy( hashBush );
       
   326         CleanupStack::PopAndDestroy();  //stringToHash
       
   327         CleanupStack::PushL( ret );
       
   328         }
       
   329     else
       
   330         {
       
   331         /*
       
   332         * This case is for compatibility with RFC 2069:
       
   333         * request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
       
   334         */
       
   335         #ifdef _DEBUG
       
   336             iTransportMain.WriteToLog( _L8( "  Qop not defined, ignore" ) );
       
   337         #endif
       
   338         }
       
   339     return ret;
       
   340     }
       
   341 
       
   342 // ----------------------------------------------------------
       
   343 // CXcapHttpAuthManager::GenerateClientNonce
       
   344 // 
       
   345 // ----------------------------------------------------------
       
   346 //
       
   347 void CXcapHttpAuthManager::GenerateClientNonce()
       
   348     {
       
   349     TTime time;
       
   350     TBuf8<33> key;
       
   351     time.UniversalTime();
       
   352     TInt64 randomNumber = Math::Rand( iSeed );
       
   353     randomNumber <<= 32;
       
   354     randomNumber += Math::Rand( iSeed );
       
   355     key.Zero();
       
   356     key.AppendNum( time.Int64(), EHex );
       
   357     key.Append( _L8( ":" ) );
       
   358     key.AppendNum( randomNumber, EHex );
       
   359     Hash( key, iClientNonce );
       
   360     }
       
   361 
       
   362 // ----------------------------------------------------------
       
   363 // CXcapHttpAuthManager::Hash
       
   364 // 
       
   365 // ----------------------------------------------------------
       
   366 //
       
   367 void CXcapHttpAuthManager::Hash( const TDesC8& aMessage, TDes8& aHash )
       
   368     {
       
   369     TBuf8<2> buf;
       
   370     aHash.Zero();
       
   371     iMD5->Reset();
       
   372     TPtrC8 hash = iMD5->Hash( aMessage );
       
   373     _LIT8( formatStr, "%02x" );
       
   374     for( TInt i = 0;i < KXcapRawHashLength;i++ )
       
   375         {
       
   376         buf.Zero();
       
   377         buf.Format( formatStr, hash[i] );
       
   378         aHash.Append( buf );
       
   379         }
       
   380     }
       
   381 
       
   382 // ----------------------------------------------------------
       
   383 // CXcapHttpAuthManager::ParseQopL
       
   384 // 
       
   385 // ----------------------------------------------------------
       
   386 //
       
   387 void CXcapHttpAuthManager::ParseQopL( const TDesC8& aQopString )
       
   388     {
       
   389     _LIT8( KXcapAuthInt, "auth-int" );
       
   390     iQop = aQopString.FindF( KXcapAuthInt ) == 0 ? EXcapAuthInt : EXcapAuth;
       
   391     delete iQopString;
       
   392     iQopString = NULL;
       
   393     iQopString = HBufC8::NewL( 8 );
       
   394     iQopString->Des().Copy( iQop == EXcapAuth ? _L8( "auth" ) : _L8( "auth-int" )  );
       
   395     #ifdef _DEBUG
       
   396         TPtrC8 qop( iQopString->Des() );
       
   397         iTransportMain.WriteToLog( _L8( "  Qop:         %S" ), &qop );
       
   398     #endif
       
   399     GenerateClientNonce();
       
   400     iNonceCount = 1;    
       
   401     }
       
   402        
       
   403 // ----------------------------------------------------------
       
   404 // CXcapHttpAuthManager::ParseHeaderL
       
   405 // 
       
   406 // ----------------------------------------------------------
       
   407 //
       
   408 TBool CXcapHttpAuthManager::ParseHeaderL( RHTTPTransaction& aTransaction, TInt aAuthType )
       
   409     {
       
   410     #ifdef _DEBUG
       
   411         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ParseHeaderL()" ) );
       
   412     #endif
       
   413     TBool ret = EFalse;
       
   414     THTTPHdrVal fieldVal;
       
   415     RHTTPHeaders headers = aTransaction.Response().GetHeaderCollection();
       
   416     RStringF auth = aAuthType == KAuthTypeNormal ? 
       
   417         iStringPool.StringF( HTTP::EWWWAuthenticate, RHTTPSession::GetTable() ) :
       
   418         iStringPool.StringF( HTTP::EProxyAuthenticate, RHTTPSession::GetTable() );
       
   419     headers.GetField( auth, 0, fieldVal );
       
   420     if( fieldVal.StrF() == iStringPool.StringF( HTTP::EDigest, RHTTPSession::GetTable() ) )
       
   421         {
       
   422         ret = ETrue;
       
   423         TInt error = headers.GetParam( auth, iStringPool.StringF( HTTP::ERealm, RHTTPSession::GetTable() ), fieldVal );
       
   424         if( KErrNone == error )
       
   425             {
       
   426             delete iRealm;
       
   427             iRealm = NULL;
       
   428             iRealm = fieldVal.Str().DesC().AllocL();
       
   429             #ifdef _DEBUG
       
   430                 TPtrC8 realm( fieldVal.Str().DesC() );
       
   431                 iTransportMain.WriteToLog( _L8( "  Realm:       %S" ), &realm );
       
   432             #endif
       
   433             }
       
   434         //In a proper WWW-Authentication request there SHOULD have been 
       
   435         //a qop value. In case there was not, call the whole thing off
       
   436         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EQop, RHTTPSession::GetTable() ), fieldVal );
       
   437         if( KErrNone == error )
       
   438             ParseQopL( fieldVal.Str().DesC() );
       
   439         else
       
   440             {
       
   441             delete iQopString;
       
   442             iQopString = NULL;
       
   443             ret = EFalse;
       
   444             }
       
   445         error = headers.GetParam( auth, iStringPool.StringF( HTTP::ENonce, RHTTPSession::GetTable() ), fieldVal );
       
   446         if( ret && KErrNone == error )
       
   447             {
       
   448             SetNextNonceL( fieldVal.Str().DesC() );
       
   449             #ifdef _DEBUG
       
   450                 TPtrC8 nonce( iServerNonce->Des() );
       
   451                 iTransportMain.WriteToLog( _L8( "  Nonce:       %S" ), &nonce );
       
   452             #endif
       
   453             }
       
   454         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EOpaque, RHTTPSession::GetTable() ), fieldVal );
       
   455         if( ret && KErrNone == error )
       
   456             {
       
   457             delete iOpaque;
       
   458             iOpaque = NULL;
       
   459             iOpaque = fieldVal.Str().DesC().AllocL();
       
   460             #ifdef _DEBUG
       
   461                 TPtrC8 opaque( iOpaque->Des() );
       
   462                 iTransportMain.WriteToLog( _L8( "  Opaque:      %S" ), &opaque );
       
   463             #endif
       
   464             }
       
   465         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EStale, RHTTPSession::GetTable() ), fieldVal );
       
   466         if( ret && KErrNone == error )
       
   467             {
       
   468             #ifdef _DEBUG
       
   469                 TPtrC8 stale( fieldVal.Str().DesC() );
       
   470                 iTransportMain.WriteToLog( _L8( "  Stale:       %S" ), &stale );
       
   471             #endif
       
   472             }
       
   473         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EDomain, RHTTPSession::GetTable() ), fieldVal );
       
   474         if( ret && KErrNone == error )
       
   475             {
       
   476             delete iDomain;
       
   477             iDomain = NULL;
       
   478             iDomain = fieldVal.Str().DesC().AllocL();
       
   479             #ifdef _DEBUG
       
   480                 TPtrC8 domain( iDomain->Des() );
       
   481                 iTransportMain.WriteToLog( _L8( "  Domain:       %S" ), &domain );
       
   482             #endif
       
   483             }
       
   484         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EAlgorithm, RHTTPSession::GetTable() ), fieldVal );
       
   485         if( ret && KErrNone == error )
       
   486             {
       
   487             delete iAlgorithm;
       
   488             iAlgorithm = NULL;
       
   489             iAlgorithm = fieldVal.Str().DesC().AllocL();
       
   490             #ifdef _DEBUG
       
   491                 TPtrC8 algorithm( iAlgorithm->Des() );
       
   492                 iTransportMain.WriteToLog( _L8( "  Algorithm:   %S" ), &algorithm );
       
   493             #endif
       
   494             }
       
   495         }
       
   496     iUnauthReceived = ETrue;
       
   497     return ret;
       
   498     }
       
   499 
       
   500 // ----------------------------------------------------------
       
   501 // CXcapHttpAuthManager::ConstructHA1L
       
   502 // 
       
   503 // ----------------------------------------------------------
       
   504 //
       
   505 void CXcapHttpAuthManager::ConstructHA1L( TDes8& aResult )
       
   506     {
       
   507     #ifdef _DEBUG
       
   508         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ConstructHA1L()" ) );
       
   509     #endif
       
   510     HBufC8* buffer = HBufC8::NewLC( iUserName.Length() +
       
   511                      iPassword.Length() + iRealm->Des().Length() + 2 ); 
       
   512     TPtr8 desc( buffer->Des() );
       
   513     desc.Copy( iUserName );
       
   514     desc.Append(':');
       
   515     desc.Append( iRealm->Des() );
       
   516     desc.Append(':');
       
   517     desc.Append( iPassword );
       
   518     Hash( *buffer, aResult );
       
   519     CleanupStack::PopAndDestroy();  //buffer	
       
   520     }
       
   521 
       
   522 // ----------------------------------------------------------
       
   523 // CXcapHttpAuthManager::ConstructHA2L
       
   524 // 
       
   525 // ----------------------------------------------------------
       
   526 //
       
   527 void CXcapHttpAuthManager::ConstructHA2L( TDes8& aResult, CXcapHttpRequest& aHttpRequest )
       
   528     {
       
   529     #ifdef _DEBUG
       
   530         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ConstructHA2L()" ) );
       
   531     #endif
       
   532     TPtrC8 uri( aHttpRequest.RelativeUri() );
       
   533     TPtrC8 method( aHttpRequest.Transaction().Request().Method().DesC() );
       
   534     switch( iQop )
       
   535         {
       
   536         case EXcapAuth:
       
   537         case EXcapAuthNone:
       
   538             {
       
   539             HBufC8* buffer = HBufC8::NewLC( uri.Length() + method.Length() + 1 );
       
   540             TPtr8 desc( buffer->Des() );
       
   541             desc.Copy( method );
       
   542             desc.Append( ':' );
       
   543             desc.Append( uri );
       
   544             Hash( desc, aResult );
       
   545             CleanupStack::PopAndDestroy();  //buffer
       
   546             }
       
   547             break;
       
   548         case EXcapAuthInt:
       
   549             {
       
   550             TPtrC8 body( _L8( "" ) );
       
   551             TBuf8<KXcapHashLength> bodyHash;
       
   552             if( aHttpRequest.Transaction().Request().HasBody() )
       
   553                 aHttpRequest.Transaction().Request().Body()->GetNextDataPart( body );
       
   554             bodyHash.Zero();
       
   555             Hash( body, bodyHash );
       
   556             HBufC8* buffer = HBufC8::NewLC( uri.Length() + method.Length() +
       
   557                                             KXcapHashLength + 2  );
       
   558             TPtr8 desc( buffer->Des() );
       
   559             desc.Copy( method );
       
   560             desc.Append( ':' );
       
   561             desc.Append( uri );
       
   562             desc.Append( ':' );
       
   563             desc.Append( bodyHash );
       
   564             Hash( desc, aResult );
       
   565             CleanupStack::PopAndDestroy();  //buffer
       
   566             }
       
   567             break;
       
   568         default:
       
   569             break;
       
   570         }
       
   571    
       
   572     }
       
   573      
       
   574 // End of File