xdmprotocols/XcapProtocol/XcapHttpTransport/src/XcapHttpAuthManager.cpp
branchRCL_3
changeset 18 fbd2e7cec7ef
equal deleted inserted replaced
17:2669f8761a99 18:fbd2e7cec7ef
       
     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             {
       
   227             SetNextNonceL( value );
       
   228             #ifdef _DEBUG
       
   229                 TPtrC8 nonce( iServerNonce->Des() );
       
   230                 iTransportMain.WriteToLog( _L8( "  -> Nonce set to %S" ), &nonce );
       
   231             #endif
       
   232             }
       
   233             break;
       
   234         case ENfoRspauth:
       
   235             /* TODO */
       
   236             break;
       
   237         case ENfoCnonce:
       
   238             #ifdef _DEBUG
       
   239                 iTransportMain.WriteToLog( _L8( "  -> Current cnonce %S" ), &iClientNonce );
       
   240             #endif
       
   241             break;
       
   242             //ret = value.Compare( iClientNonce ) == 0;
       
   243         case ENfoNc:
       
   244             {
       
   245             TBuf8<8> nonceCount;
       
   246             nonceCount.AppendFormat( _L8( "%08x" ), iNonceCount );
       
   247             #ifdef _DEBUG
       
   248                 iTransportMain.WriteToLog( _L8( "  -> Current nonce count %S" ), &nonceCount );
       
   249             #endif
       
   250             //ret = nonceCount.Compare( value ) == 0;
       
   251             break;
       
   252             }
       
   253         case ENfoQop:
       
   254             ret = ETrue;
       
   255             break;
       
   256         default:
       
   257             ret = ETrue;
       
   258             break;
       
   259         }
       
   260     return ret;
       
   261     }
       
   262 
       
   263 // ----------------------------------------------------------
       
   264 // CXcapHttpAuthManager::GenerateClientNonce
       
   265 // 
       
   266 // ----------------------------------------------------------
       
   267 //
       
   268 void CXcapHttpAuthManager::SetNextNonceL( const TDesC8& aNextnonce )
       
   269     {
       
   270     delete iServerNonce;
       
   271     iServerNonce = NULL;
       
   272     iServerNonce = aNextnonce.AllocL();
       
   273     }
       
   274 
       
   275 // ----------------------------------------------------------
       
   276 // CXcapHttpAuthManager::Unquote
       
   277 // 
       
   278 // ----------------------------------------------------------
       
   279 //
       
   280 void CXcapHttpAuthManager::Unquote( TPtr8& aParamValue )
       
   281     {
       
   282     TInt index = aParamValue.Locate( '"' );
       
   283     while( index >= 0 )
       
   284         {
       
   285         aParamValue.Delete( index, 1 );
       
   286         index = aParamValue.Locate( '\"');
       
   287         }
       
   288     }
       
   289        
       
   290 // ----------------------------------------------------------
       
   291 // CXcapHttpAuthManager::RequestDigestLC
       
   292 // 
       
   293 // ----------------------------------------------------------
       
   294 //
       
   295 HBufC8* CXcapHttpAuthManager::RequestDigestLC( CXcapHttpRequest& aHttpRequest )
       
   296     {
       
   297     #ifdef _DEBUG
       
   298         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::RequestDigestLC()" ) );
       
   299     #endif
       
   300     HBufC8* ret = NULL;
       
   301     if( iQop == EXcapAuth || iQop == EXcapAuthInt )
       
   302         {
       
   303         TBuf8<8> nonceCount;
       
   304         TBuf8<KXcapHashLength> hashBush;
       
   305         nonceCount.AppendFormat( _L8( "%08x" ), iNonceCount );
       
   306         TPtrC8 nonce( iServerNonce ? iServerNonce->Des() : TPtrC8() );
       
   307         TPtrC8 qop( iQop == EXcapAuth ? _L8( "auth" ) : _L8( "auth-int" ) );
       
   308         HBufC8* stringToHash = HBufC8::NewLC( nonce.Length() + qop.Length() +
       
   309                                               3 * KXcapHashLength + 8 + 5 );
       
   310         TPtr8 desc( stringToHash->Des() );
       
   311         ConstructHA1L( desc );
       
   312         desc.Append( ':' );
       
   313         desc.Append( nonce );
       
   314         desc.Append( ':' );
       
   315         desc.Append( nonceCount );
       
   316         desc.Append( ':' );
       
   317         desc.Append( iClientNonce );
       
   318         desc.Append(':');
       
   319         desc.Append( qop );
       
   320         desc.Append(':');
       
   321         ConstructHA2L( hashBush, aHttpRequest );
       
   322         desc.Append( hashBush ); 
       
   323         hashBush.Zero();
       
   324         ret = HBufC8::NewL( KXcapHashLength );
       
   325         Hash( *stringToHash, hashBush );
       
   326         ret->Des().Copy( hashBush );
       
   327         CleanupStack::PopAndDestroy();  //stringToHash
       
   328         CleanupStack::PushL( ret );
       
   329         }
       
   330     else
       
   331         {
       
   332         /*
       
   333         * This case is for compatibility with RFC 2069:
       
   334         * request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
       
   335         */
       
   336         #ifdef _DEBUG
       
   337             iTransportMain.WriteToLog( _L8( "  Qop not defined, ignore" ) );
       
   338         #endif
       
   339         }
       
   340     return ret;
       
   341     }
       
   342 
       
   343 // ----------------------------------------------------------
       
   344 // CXcapHttpAuthManager::GenerateClientNonce
       
   345 // 
       
   346 // ----------------------------------------------------------
       
   347 //
       
   348 void CXcapHttpAuthManager::GenerateClientNonce()
       
   349     {
       
   350     TTime time;
       
   351     TBuf8<33> key;
       
   352     time.UniversalTime();
       
   353     TInt64 randomNumber = Math::Rand( iSeed );
       
   354     randomNumber <<= 32;
       
   355     randomNumber += Math::Rand( iSeed );
       
   356     key.Zero();
       
   357     key.AppendNum( time.Int64(), EHex );
       
   358     key.Append( _L8( ":" ) );
       
   359     key.AppendNum( randomNumber, EHex );
       
   360     Hash( key, iClientNonce );
       
   361     }
       
   362 
       
   363 // ----------------------------------------------------------
       
   364 // CXcapHttpAuthManager::Hash
       
   365 // 
       
   366 // ----------------------------------------------------------
       
   367 //
       
   368 void CXcapHttpAuthManager::Hash( const TDesC8& aMessage, TDes8& aHash )
       
   369     {
       
   370     TBuf8<2> buf;
       
   371     aHash.Zero();
       
   372     iMD5->Reset();
       
   373     TPtrC8 hash = iMD5->Hash( aMessage );
       
   374     _LIT8( formatStr, "%02x" );
       
   375     for( TInt i = 0;i < KXcapRawHashLength;i++ )
       
   376         {
       
   377         buf.Zero();
       
   378         buf.Format( formatStr, hash[i] );
       
   379         aHash.Append( buf );
       
   380         }
       
   381     }
       
   382 
       
   383 // ----------------------------------------------------------
       
   384 // CXcapHttpAuthManager::ParseQopL
       
   385 // 
       
   386 // ----------------------------------------------------------
       
   387 //
       
   388 void CXcapHttpAuthManager::ParseQopL( const TDesC8& aQopString )
       
   389     {
       
   390     _LIT8( KXcapAuthInt, "auth-int" );
       
   391     iQop = aQopString.FindF( KXcapAuthInt ) == 0 ? EXcapAuthInt : EXcapAuth;
       
   392     delete iQopString;
       
   393     iQopString = NULL;
       
   394     iQopString = HBufC8::NewL( 8 );
       
   395     iQopString->Des().Copy( iQop == EXcapAuth ? _L8( "auth" ) : _L8( "auth-int" )  );
       
   396     #ifdef _DEBUG
       
   397         TPtrC8 qop( iQopString->Des() );
       
   398         iTransportMain.WriteToLog( _L8( "  Qop:         %S" ), &qop );
       
   399     #endif
       
   400     GenerateClientNonce();
       
   401     iNonceCount = 1;    
       
   402     }
       
   403        
       
   404 // ----------------------------------------------------------
       
   405 // CXcapHttpAuthManager::ParseHeaderL
       
   406 // 
       
   407 // ----------------------------------------------------------
       
   408 //
       
   409 TBool CXcapHttpAuthManager::ParseHeaderL( RHTTPTransaction& aTransaction, TInt aAuthType )
       
   410     {
       
   411     #ifdef _DEBUG
       
   412         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ParseHeaderL()" ) );
       
   413     #endif
       
   414     TBool ret = EFalse;
       
   415     THTTPHdrVal fieldVal;
       
   416     RHTTPHeaders headers = aTransaction.Response().GetHeaderCollection();
       
   417     RStringF auth = aAuthType == KAuthTypeNormal ? 
       
   418         iStringPool.StringF( HTTP::EWWWAuthenticate, RHTTPSession::GetTable() ) :
       
   419         iStringPool.StringF( HTTP::EProxyAuthenticate, RHTTPSession::GetTable() );
       
   420     headers.GetField( auth, 0, fieldVal );
       
   421     if( fieldVal.StrF() == iStringPool.StringF( HTTP::EDigest, RHTTPSession::GetTable() ) )
       
   422         {
       
   423         ret = ETrue;
       
   424         TInt error = headers.GetParam( auth, iStringPool.StringF( HTTP::ERealm, RHTTPSession::GetTable() ), fieldVal );
       
   425         if( KErrNone == error )
       
   426             {
       
   427             delete iRealm;
       
   428             iRealm = NULL;
       
   429             iRealm = fieldVal.Str().DesC().AllocL();
       
   430             #ifdef _DEBUG
       
   431                 TPtrC8 realm( fieldVal.Str().DesC() );
       
   432                 iTransportMain.WriteToLog( _L8( "  Realm:       %S" ), &realm );
       
   433             #endif
       
   434             }
       
   435         //In a proper WWW-Authentication request there SHOULD have been 
       
   436         //a qop value. In case there was not, call the whole thing off
       
   437         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EQop, RHTTPSession::GetTable() ), fieldVal );
       
   438         if( KErrNone == error )
       
   439             ParseQopL( fieldVal.Str().DesC() );
       
   440         else
       
   441             {
       
   442             delete iQopString;
       
   443             iQopString = NULL;
       
   444             ret = EFalse;
       
   445             }
       
   446         error = headers.GetParam( auth, iStringPool.StringF( HTTP::ENonce, RHTTPSession::GetTable() ), fieldVal );
       
   447         if( ret && KErrNone == error )
       
   448             {
       
   449             SetNextNonceL( fieldVal.Str().DesC() );
       
   450             #ifdef _DEBUG
       
   451                 TPtrC8 nonce( iServerNonce->Des() );
       
   452                 iTransportMain.WriteToLog( _L8( "  Nonce:       %S" ), &nonce );
       
   453             #endif
       
   454             }
       
   455         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EOpaque, RHTTPSession::GetTable() ), fieldVal );
       
   456         if( ret && KErrNone == error )
       
   457             {
       
   458             delete iOpaque;
       
   459             iOpaque = NULL;
       
   460             iOpaque = fieldVal.Str().DesC().AllocL();
       
   461             #ifdef _DEBUG
       
   462                 TPtrC8 opaque( iOpaque->Des() );
       
   463                 iTransportMain.WriteToLog( _L8( "  Opaque:      %S" ), &opaque );
       
   464             #endif
       
   465             }
       
   466         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EStale, RHTTPSession::GetTable() ), fieldVal );
       
   467         if( ret && KErrNone == error )
       
   468             {
       
   469             #ifdef _DEBUG
       
   470                 TPtrC8 stale( fieldVal.Str().DesC() );
       
   471                 iTransportMain.WriteToLog( _L8( "  Stale:       %S" ), &stale );
       
   472             #endif
       
   473             }
       
   474         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EDomain, RHTTPSession::GetTable() ), fieldVal );
       
   475         if( ret && KErrNone == error )
       
   476             {
       
   477             delete iDomain;
       
   478             iDomain = NULL;
       
   479             iDomain = fieldVal.Str().DesC().AllocL();
       
   480             #ifdef _DEBUG
       
   481                 TPtrC8 domain( iDomain->Des() );
       
   482                 iTransportMain.WriteToLog( _L8( "  Domain:       %S" ), &domain );
       
   483             #endif
       
   484             }
       
   485         error = headers.GetParam( auth, iStringPool.StringF( HTTP::EAlgorithm, RHTTPSession::GetTable() ), fieldVal );
       
   486         if( ret && KErrNone == error )
       
   487             {
       
   488             delete iAlgorithm;
       
   489             iAlgorithm = NULL;
       
   490             iAlgorithm = fieldVal.Str().DesC().AllocL();
       
   491             #ifdef _DEBUG
       
   492                 TPtrC8 algorithm( iAlgorithm->Des() );
       
   493                 iTransportMain.WriteToLog( _L8( "  Algorithm:   %S" ), &algorithm );
       
   494             #endif
       
   495             }
       
   496         }
       
   497     iUnauthReceived = ETrue;
       
   498     return ret;
       
   499     }
       
   500 
       
   501 // ----------------------------------------------------------
       
   502 // CXcapHttpAuthManager::ConstructHA1L
       
   503 // 
       
   504 // ----------------------------------------------------------
       
   505 //
       
   506 void CXcapHttpAuthManager::ConstructHA1L( TDes8& aResult )
       
   507     {
       
   508     #ifdef _DEBUG
       
   509         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ConstructHA1L()" ) );
       
   510     #endif
       
   511 
       
   512     TPtrC8 realm( iRealm ? iRealm->Des() : TPtrC8() );
       
   513 
       
   514     HBufC8* buffer = HBufC8::NewLC( iUserName.Length() +
       
   515                      iPassword.Length() + realm.Length() + 2 );
       
   516     TPtr8 desc( buffer->Des() );
       
   517     desc.Copy( iUserName );
       
   518     desc.Append(':');
       
   519     desc.Append( realm );
       
   520     desc.Append(':');
       
   521     desc.Append( iPassword );
       
   522     Hash( *buffer, aResult );
       
   523     CleanupStack::PopAndDestroy();  //buffer
       
   524     }
       
   525 
       
   526 // ----------------------------------------------------------
       
   527 // CXcapHttpAuthManager::ConstructHA2L
       
   528 // 
       
   529 // ----------------------------------------------------------
       
   530 //
       
   531 void CXcapHttpAuthManager::ConstructHA2L( TDes8& aResult, CXcapHttpRequest& aHttpRequest )
       
   532     {
       
   533     #ifdef _DEBUG
       
   534         iTransportMain.WriteToLog( _L8( "CXcapHttpAuthManager::ConstructHA2L()" ) );
       
   535     #endif
       
   536     TPtrC8 uri( aHttpRequest.RelativeUri() );
       
   537     TPtrC8 method( aHttpRequest.Transaction().Request().Method().DesC() );
       
   538     switch( iQop )
       
   539         {
       
   540         case EXcapAuth:
       
   541         case EXcapAuthNone:
       
   542             {
       
   543             HBufC8* buffer = HBufC8::NewLC( uri.Length() + method.Length() + 1 );
       
   544             TPtr8 desc( buffer->Des() );
       
   545             desc.Copy( method );
       
   546             desc.Append( ':' );
       
   547             desc.Append( uri );
       
   548             Hash( desc, aResult );
       
   549             CleanupStack::PopAndDestroy();  //buffer
       
   550             }
       
   551             break;
       
   552         case EXcapAuthInt:
       
   553             {
       
   554             TPtrC8 body( _L8( "" ) );
       
   555             TBuf8<KXcapHashLength> bodyHash;
       
   556             if( aHttpRequest.Transaction().Request().HasBody() )
       
   557                 aHttpRequest.Transaction().Request().Body()->GetNextDataPart( body );
       
   558             bodyHash.Zero();
       
   559             Hash( body, bodyHash );
       
   560             HBufC8* buffer = HBufC8::NewLC( uri.Length() + method.Length() +
       
   561                                             KXcapHashLength + 2  );
       
   562             TPtr8 desc( buffer->Des() );
       
   563             desc.Copy( method );
       
   564             desc.Append( ':' );
       
   565             desc.Append( uri );
       
   566             desc.Append( ':' );
       
   567             desc.Append( bodyHash );
       
   568             Hash( desc, aResult );
       
   569             CleanupStack::PopAndDestroy();  //buffer
       
   570             }
       
   571             break;
       
   572         default:
       
   573             break;
       
   574         }
       
   575    
       
   576     }
       
   577      
       
   578 // End of File