|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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 * Implementation of CSessionAndSecurity |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "Browser.hrh" |
|
24 #include <es_sock.h> |
|
25 #include "SessionAndSecurity.h" |
|
26 #include <MConnection.h> |
|
27 #include <BrowserNG.rsg> |
|
28 #include <AknQueryDialog.h> |
|
29 #include <AknMessageQueryDialog.h> |
|
30 #include <StringLoader.h> |
|
31 #include <FeatMgr.h> |
|
32 |
|
33 #include "BrowserUtil.h" |
|
34 #include "ApiProvider.h" |
|
35 #include <ssl.h> // for TCertInfo |
|
36 #include <BrCtlInterface.h> |
|
37 |
|
38 // CONSTANTS |
|
39 const TInt KWmlSessionInfoMaxLength = 1000; |
|
40 const TInt KWmlSecurityInfoMaxLength = 1000; |
|
41 const TInt KMaxLengthTextDateString = 16; |
|
42 _LIT( KWmlConnSpeed9600, "9600" ); |
|
43 _LIT( KWmlConnSpeed14400, "14400" ); |
|
44 _LIT( KWmlConnSpeed19200, "19200" ); |
|
45 _LIT( KWmlConnSpeed28800, "28800" ); |
|
46 _LIT( KWmlConnSpeed38400, "38400" ); |
|
47 _LIT( KWmlConnSpeed43200, "43200" ); |
|
48 _LIT( KWmlNewLine, "\n" ); |
|
49 _LIT( KWmlSeparatorComma, "," ); |
|
50 |
|
51 // ================= MEMBER FUNCTIONS ======================= |
|
52 |
|
53 // ---------------------------------------------------- |
|
54 // CSessionAndSecurity::CSessionAndSecurity |
|
55 // ---------------------------------------------------- |
|
56 // |
|
57 CSessionAndSecurity::CSessionAndSecurity(MApiProvider& aApiProvider) |
|
58 : iApiProvider(aApiProvider) |
|
59 { |
|
60 } |
|
61 |
|
62 //----------------------------------------------------------------------------- |
|
63 // CSessionAndSecurity::NewL |
|
64 //----------------------------------------------------------------------------- |
|
65 // |
|
66 CSessionAndSecurity* CSessionAndSecurity::NewL(MApiProvider& aApiProvider) |
|
67 { |
|
68 CSessionAndSecurity* self = CSessionAndSecurity::NewLC(aApiProvider); |
|
69 CleanupStack::Pop(); |
|
70 return self; |
|
71 } |
|
72 |
|
73 //----------------------------------------------------------------------------- |
|
74 // CSessionAndSecurity::NewLC |
|
75 //----------------------------------------------------------------------------- |
|
76 // |
|
77 CSessionAndSecurity* CSessionAndSecurity::NewLC(MApiProvider& aApiProvider) |
|
78 { |
|
79 CSessionAndSecurity* self = new(ELeave) CSessionAndSecurity(aApiProvider); |
|
80 CleanupStack::PushL(self); |
|
81 self->ConstructL(); |
|
82 return self; |
|
83 } |
|
84 |
|
85 //----------------------------------------------------------------------------- |
|
86 // CSessionAndSecurity::~CSessionAndSecurity |
|
87 //----------------------------------------------------------------------------- |
|
88 // |
|
89 CSessionAndSecurity::~CSessionAndSecurity() |
|
90 { |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------- |
|
94 // CSessionAndSecurity::ConstructL |
|
95 // ---------------------------------------------------- |
|
96 // |
|
97 void CSessionAndSecurity::ConstructL() |
|
98 { |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------- |
|
102 // CSessionAndSecurity::ShowPageInfoL |
|
103 // ---------------------------------------------------- |
|
104 // |
|
105 void CSessionAndSecurity::ShowPageInfoL() |
|
106 { |
|
107 HBufC* messagebody = NULL; |
|
108 HBufC* header = StringLoader::LoadLC( R_BROWSER_QUERY_CURRENT_PAGE ); |
|
109 HBufC* urltxt = StringLoader::LoadLC( R_BROWSER_QUERY_CURRENT_PAGE_URL ); |
|
110 HBufC* currentUrl = ApiProvider().BrCtlInterface(). |
|
111 PageInfoLC( TBrCtlDefs::EPageInfoUrl ); |
|
112 if( currentUrl == NULL ) |
|
113 { |
|
114 CleanupStack::PopAndDestroy( currentUrl ); |
|
115 currentUrl = KNullDesC().AllocLC(); |
|
116 } |
|
117 TInt length = currentUrl->Length(); |
|
118 messagebody = HBufC::NewLC( length + urltxt->Length()+2 + KWmlSecurityInfoMaxLength); |
|
119 messagebody->Des().Append( *urltxt ); |
|
120 messagebody->Des().Append( KWmlNewLine() ); |
|
121 messagebody->Des().Append( *currentUrl ); |
|
122 |
|
123 |
|
124 // append security info |
|
125 const TCertInfo* certInfo = ApiProvider().BrCtlInterface().CertInfo(); |
|
126 HBufC* message = HBufC::NewLC( KWmlSecurityInfoMaxLength ); |
|
127 HttpSecurityInfoL( certInfo, *message); |
|
128 messagebody->Des().Append( KWmlNewLine() ); |
|
129 messagebody->Des().Append( KWmlNewLine() ); |
|
130 messagebody->Des().Append( *message ); |
|
131 |
|
132 |
|
133 // output page and security info to dialog |
|
134 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *messagebody ); |
|
135 dlg->PrepareLC( R_BROWSER_PAGE_INFO ); |
|
136 CAknPopupHeadingPane* hPane = dlg->QueryHeading(); |
|
137 if ( hPane ) |
|
138 { |
|
139 hPane->SetTextL( *header ); |
|
140 } |
|
141 dlg->RunLD(); |
|
142 CleanupStack::PopAndDestroy( 5 ); // header, urltxt, currentUrl, messagebody, message |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------- |
|
146 // CSessionAndSecurity::ShowSessionInfoL |
|
147 // ---------------------------------------------------- |
|
148 // |
|
149 void CSessionAndSecurity::ShowSessionInfoL() |
|
150 { |
|
151 HBufC* header = StringLoader::LoadLC( R_WML_SESSION_VIEW_TITLE ); |
|
152 HBufC* message = HBufC::NewLC( KWmlSessionInfoMaxLength ); |
|
153 |
|
154 HBufC* value = StringLoader::LoadLC( R_WML_SESSION_VIEW_AP ); |
|
155 message->Des().Append( *value ); |
|
156 message->Des().Append( TChar( '\n' ) ); |
|
157 CleanupStack::PopAndDestroy(); // value |
|
158 |
|
159 value = ApiProvider().Connection().CurrentApNameLC(); |
|
160 message->Des().Append( value->Des() ); |
|
161 message->Des().Append( TChar( '\n' ) ); |
|
162 CleanupStack::PopAndDestroy(); // value |
|
163 |
|
164 // |
|
165 // Bearer type |
|
166 // |
|
167 value = StringLoader::LoadLC( R_WML_SESSION_VIEW_BT ); |
|
168 message->Des().Append( *value ); |
|
169 message->Des().Append( TChar( '\n' ) ); |
|
170 CleanupStack::PopAndDestroy(); // value |
|
171 |
|
172 TApBearerType bt = ApiProvider().Connection().CurrentBearerTypeL(); |
|
173 switch ( bt ) |
|
174 { |
|
175 case EApBearerTypeCSD: |
|
176 { |
|
177 value = StringLoader::LoadLC( R_WML_BEARER_DATA_CALL ); |
|
178 break; |
|
179 } |
|
180 case EApBearerTypeGPRS: |
|
181 { |
|
182 value = StringLoader::LoadLC( R_WML_BEARER_PACKET_DATA ); |
|
183 break; |
|
184 } |
|
185 case EApBearerTypeHSCSD: |
|
186 { |
|
187 value = StringLoader::LoadLC( R_WML_BEARER_HSCSD ); |
|
188 break; |
|
189 } |
|
190 default: |
|
191 value = HBufC::NewLC( 1 ); |
|
192 break; |
|
193 } |
|
194 |
|
195 message->Des().Append( value->Des() ); |
|
196 message->Des().Append( TChar( '\n' ) ); |
|
197 CleanupStack::PopAndDestroy(); // value |
|
198 |
|
199 // |
|
200 // Max conn. speed |
|
201 // |
|
202 value = StringLoader::LoadLC( R_WML_SESSION_VIEW_CS ); |
|
203 message->Des().Append( *value ); |
|
204 message->Des().Append( TChar( '\n' ) ); |
|
205 CleanupStack::PopAndDestroy(); // value |
|
206 TApCallSpeed speed = ApiProvider().Connection().CurrentConnectionSpeed(); |
|
207 value = HBufC::NewLC( sizeof( KWmlConnSpeed43200 ) ); |
|
208 switch ( speed ) |
|
209 { |
|
210 case KSpeed9600: |
|
211 { |
|
212 *value = KWmlConnSpeed9600(); |
|
213 break; |
|
214 } |
|
215 case KSpeed14400: |
|
216 { |
|
217 *value = KWmlConnSpeed14400(); |
|
218 break; |
|
219 } |
|
220 case KSpeed19200: |
|
221 { |
|
222 *value = KWmlConnSpeed19200(); |
|
223 break; |
|
224 } |
|
225 case KSpeed28800: |
|
226 { |
|
227 *value = KWmlConnSpeed28800(); |
|
228 break; |
|
229 } |
|
230 case KSpeed38400: |
|
231 { |
|
232 *value = KWmlConnSpeed38400(); |
|
233 break; |
|
234 } |
|
235 case KSpeed43200: |
|
236 { |
|
237 *value = KWmlConnSpeed43200(); |
|
238 break; |
|
239 } |
|
240 case KSpeedAutobaud: // default value |
|
241 default: |
|
242 { |
|
243 CleanupStack::PopAndDestroy(); // value |
|
244 value = StringLoader::LoadLC( R_WML_CONN_SPEED_AD ); |
|
245 break; |
|
246 } |
|
247 } |
|
248 |
|
249 message->Des().Append( value->Des() ); |
|
250 message->Des().Append( TChar( '\n' ) ); |
|
251 CleanupStack::PopAndDestroy(); // value |
|
252 |
|
253 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message ); |
|
254 dlg->PrepareLC( R_BROWSER_SESSION_INFO ); |
|
255 CAknPopupHeadingPane* hPane = dlg->QueryHeading(); |
|
256 if ( hPane ) |
|
257 { |
|
258 hPane->SetTextL( *header ); |
|
259 } |
|
260 dlg->RunLD(); |
|
261 CleanupStack::PopAndDestroy( 2 ); // header, message |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------------------------------- |
|
265 // CSessionAndSecurity::HttpSecurityInfoL |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 void CSessionAndSecurity::HttpSecurityInfoL( const TCertInfo* aCertInfo, |
|
269 HBufC& aMessage ) |
|
270 { |
|
271 HBufC* value; |
|
272 HBufC* prompt; |
|
273 |
|
274 if ( !aCertInfo ) |
|
275 { |
|
276 // Connection: Unsecure |
|
277 value = StringLoader::LoadLC( R_WML_SECURITY_CONN_UNSECURE ); |
|
278 prompt = StringLoader::LoadLC( R_WML_SECURITY_CONN_TYPE, *value ); |
|
279 aMessage.Des().Append( *prompt ); |
|
280 aMessage.Des().Append( TChar( '\n' ) ); |
|
281 aMessage.Des().Append( TChar( '\n' ) ); |
|
282 CleanupStack::PopAndDestroy(2); // value, prompt |
|
283 } |
|
284 else |
|
285 { |
|
286 // Connection: Secure |
|
287 value = StringLoader::LoadLC( R_WML_SECURITY_CONN_SECURE ); |
|
288 prompt = StringLoader::LoadLC( R_WML_SECURITY_CONN_TYPE, *value ); |
|
289 aMessage.Des().Append( *prompt ); |
|
290 aMessage.Des().Append( TChar( '\n' ) ); |
|
291 aMessage.Des().Append( TChar( '\n' ) ); |
|
292 CleanupStack::PopAndDestroy(2); // value, prompt |
|
293 |
|
294 HBufC* buf2 = HBufC::NewMaxLC(256); |
|
295 |
|
296 // Server authentication |
|
297 value = StringLoader::LoadLC( R_WML_SECURITY_SERVER_AUT, KNullDesC ); |
|
298 aMessage.Des().Append( *value ); |
|
299 aMessage.Des().Append( TChar( '\n' ) ); |
|
300 CleanupStack::PopAndDestroy(); //value |
|
301 |
|
302 // Subject |
|
303 FillDNinfoL( aCertInfo->iSubjectDNInfo, buf2 ); |
|
304 value = StringLoader::LoadLC( R_WML_SECURITY_CERT_OWNER, buf2->Des() ); |
|
305 aMessage.Des().Append( *value ); |
|
306 aMessage.Des().Append( TChar( '\n' ) ); |
|
307 aMessage.Des().Append( TChar( '\n' ) ); |
|
308 CleanupStack::PopAndDestroy(2); //value, buf2 |
|
309 |
|
310 //Issuer |
|
311 buf2 = HBufC::NewMaxLC(256); |
|
312 FillDNinfoL( aCertInfo->iIssuerDNInfo, buf2 ); |
|
313 value = StringLoader::LoadLC( R_WML_SECURITY_INFO_ISSUER, buf2->Des() ); |
|
314 aMessage.Des().Append( *value ); |
|
315 aMessage.Des().Append( TChar( '\n' ) ); |
|
316 aMessage.Des().Append( TChar( '\n' ) ); |
|
317 CleanupStack::PopAndDestroy(2); //value, buf2 |
|
318 |
|
319 // Valid from |
|
320 TBuf< KMaxLengthTextDateString > validFromString; |
|
321 HBufC* dateFormatString = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
322 aCertInfo->iStartValDate.FormatL( validFromString, *dateFormatString ); |
|
323 CleanupStack::PopAndDestroy(); //dateFormatString |
|
324 value = StringLoader::LoadLC( R_WML_SECURITY_VALID_FROM, validFromString ); |
|
325 aMessage.Des().Append( *value ); |
|
326 aMessage.Des().Append( TChar( '\n' ) ); |
|
327 aMessage.Des().Append( TChar( '\n' ) ); |
|
328 CleanupStack::PopAndDestroy(); //value |
|
329 |
|
330 // Valid to |
|
331 dateFormatString = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO ); |
|
332 aCertInfo->iEndValDate.FormatL( validFromString, *dateFormatString ); |
|
333 CleanupStack::PopAndDestroy(); //dateFormatString |
|
334 value = StringLoader::LoadLC( R_WML_SECURITY_VALID_TO, validFromString ); |
|
335 aMessage.Des().Append( *value ); |
|
336 aMessage.Des().Append( TChar( '\n' ) ); |
|
337 aMessage.Des().Append( TChar( '\n' ) ); |
|
338 CleanupStack::PopAndDestroy(); //value |
|
339 |
|
340 // hex formatting |
|
341 TBuf<2> buf; |
|
342 _LIT( KHexFormat, "%02X"); |
|
343 |
|
344 // Serial number |
|
345 HBufC* buffer = HBufC::NewLC( aCertInfo->iSerialNo.Length()*2 ); |
|
346 for (TInt i = 0; i < aCertInfo->iSerialNo.Length(); i++) |
|
347 { |
|
348 buf.Format( KHexFormat, aCertInfo->iSerialNo[i] ); |
|
349 buffer->Des().Append( buf ); |
|
350 } |
|
351 value = StringLoader::LoadLC( R_WML_SECURITY_SERIALNO, *buffer ); |
|
352 aMessage.Des().Append( *value ); |
|
353 aMessage.Des().Append( TChar( '\n' ) ); |
|
354 aMessage.Des().Append( TChar( '\n' ) ); |
|
355 CleanupStack::PopAndDestroy( 2 ); // value, buffer |
|
356 |
|
357 // Fingerprint |
|
358 { |
|
359 TInt emptyChars = aCertInfo->iFingerprint.Length()/2; |
|
360 emptyChars++; |
|
361 HBufC* buffer = HBufC::NewLC( aCertInfo->iFingerprint.Length()*2 + emptyChars ); |
|
362 TInt ind = 1; |
|
363 for (TInt i = 0; i < aCertInfo->iFingerprint.Length(); i++) |
|
364 { |
|
365 buf.Format( KHexFormat, aCertInfo->iFingerprint[i] ); |
|
366 buffer->Des().Append( buf ); |
|
367 if ( ind == 2 ) |
|
368 { |
|
369 buffer->Des().Append( TChar( ' ' ) ); |
|
370 ind = 0; |
|
371 } |
|
372 ind++; |
|
373 } |
|
374 value = StringLoader::LoadLC( R_WML_SECURITY_FINGERPRINT, *buffer ); |
|
375 aMessage.Des().Append( *value ); |
|
376 CleanupStack::PopAndDestroy( 2 ); // value, buffer |
|
377 } |
|
378 } |
|
379 |
|
380 } |
|
381 |
|
382 // ---------------------------------------------------- |
|
383 // CSessionAndSecurity::ConvertTDesC8ToHBufC16LC |
|
384 // ---------------------------------------------------- |
|
385 // |
|
386 void CSessionAndSecurity::ConvertTDesC8ToHBufC16LC( TDesC8& aSource, |
|
387 HBufC16*& aDestination) |
|
388 { |
|
389 const TInt length = aSource.Length(); // length of name |
|
390 TPtrC8 ptr ( aSource.Ptr(), aSource.Length() ); |
|
391 aDestination = HBufC::NewLC( length ); |
|
392 aDestination->Des().Copy( ptr ); |
|
393 } |
|
394 |
|
395 // ---------------------------------------------------- |
|
396 // CSessionAndSecurity::FillDNinfoL |
|
397 // ---------------------------------------------------- |
|
398 // |
|
399 void CSessionAndSecurity::FillDNinfoL( TDNInfo aDNInfo, HBufC* aBuf ) |
|
400 { |
|
401 HBufC16* buf2 = NULL; |
|
402 TInt num = 0; |
|
403 if ( aDNInfo.iCommonName.Length() ) |
|
404 { |
|
405 aBuf->Des().Copy( aDNInfo.iCommonName ); |
|
406 num++; |
|
407 } |
|
408 if ( aDNInfo.iOrganization.Length() ) |
|
409 { |
|
410 if ( !num ) |
|
411 { |
|
412 aBuf->Des().Copy( aDNInfo.iOrganization ); |
|
413 } |
|
414 else |
|
415 { |
|
416 aBuf->Des().Append( KWmlSeparatorComma() ); |
|
417 ConvertTDesC8ToHBufC16LC( aDNInfo.iOrganization, buf2 ); |
|
418 aBuf->Des().Append( buf2->Ptr(),aDNInfo.iOrganization.Length() ); |
|
419 CleanupStack::PopAndDestroy(); //buf2 |
|
420 } |
|
421 num++; |
|
422 } |
|
423 if ( aDNInfo.iOrganizationUnit.Length() && num < 2 ) |
|
424 { |
|
425 if ( !num ) |
|
426 { |
|
427 aBuf->Des().Copy( aDNInfo.iOrganizationUnit ); |
|
428 } |
|
429 else |
|
430 { |
|
431 aBuf->Des().Append( KWmlSeparatorComma() ); |
|
432 ConvertTDesC8ToHBufC16LC( aDNInfo.iOrganizationUnit, buf2 ); |
|
433 aBuf->Des().Append( buf2->Ptr(),aDNInfo.iOrganizationUnit.Length() ); |
|
434 CleanupStack::PopAndDestroy(); //buf2 |
|
435 } |
|
436 num++; |
|
437 } |
|
438 if ( aDNInfo.iLocality.Length() && num < 2 ) |
|
439 { |
|
440 if ( !num ) |
|
441 { |
|
442 aBuf->Des().Copy( aDNInfo.iLocality ); |
|
443 } |
|
444 else |
|
445 { |
|
446 aBuf->Des().Append( KWmlSeparatorComma() ); |
|
447 ConvertTDesC8ToHBufC16LC( aDNInfo.iLocality, buf2 ); |
|
448 aBuf->Des().Append( buf2->Ptr(),aDNInfo.iLocality.Length() ); |
|
449 CleanupStack::PopAndDestroy(); //buf2 |
|
450 } |
|
451 num++; |
|
452 } |
|
453 if ( aDNInfo.iCountry.Length() && num < 2 ) |
|
454 { |
|
455 if ( !num ) |
|
456 { |
|
457 aBuf->Des().Copy( aDNInfo.iCountry ); |
|
458 } |
|
459 else |
|
460 { |
|
461 aBuf->Des().Append( KWmlSeparatorComma() ); |
|
462 ConvertTDesC8ToHBufC16LC( aDNInfo.iCountry, buf2 ); |
|
463 aBuf->Des().Append( buf2->Ptr(),aDNInfo.iCountry.Length() ); |
|
464 CleanupStack::PopAndDestroy(); //buf2 |
|
465 } |
|
466 } |
|
467 } |
|
468 |
|
469 // ---------------------------------------------------- |
|
470 // CSessionAndSecurity::ShowSecurityInfoL |
|
471 // ---------------------------------------------------- |
|
472 // |
|
473 void CSessionAndSecurity::ShowSecurityInfoL() |
|
474 { |
|
475 const TCertInfo* certInfo = ApiProvider().BrCtlInterface().CertInfo(); |
|
476 |
|
477 HBufC* header; |
|
478 HBufC* message = HBufC::NewLC( KWmlSecurityInfoMaxLength ); |
|
479 |
|
480 header = StringLoader::LoadLC( R_WML_SECURITY_VIEW_TITLE ); |
|
481 HttpSecurityInfoL( certInfo, *message); |
|
482 |
|
483 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message ); |
|
484 |
|
485 dlg->PrepareLC( R_BROWSER_SECURITY_INFO ); |
|
486 CAknPopupHeadingPane* hPane = dlg->QueryHeading(); |
|
487 if ( hPane ) |
|
488 { |
|
489 hPane->SetTextL( *header ); |
|
490 } |
|
491 |
|
492 dlg->RunLD(); |
|
493 CleanupStack::PopAndDestroy( 2 ); // header, message, |
|
494 } |
|
495 |
|
496 // End of File |