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