|
1 /* |
|
2 * Copyright (c) 2006-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CTSecurityDialogsAO.h" |
|
21 #include "CTSecurityDialogNotifier.h" |
|
22 #include "CTPinQueryDialog.h" |
|
23 #include "CTSignTextDialog.h" |
|
24 #include "CTSelectCertificateDialog.h" |
|
25 #include "CTQueryDialog.h" |
|
26 #include "CTPinPinQueryDialog.h" |
|
27 #include "CTNoTrustQuery.h" |
|
28 #include "CTInvalidCertNote.h" |
|
29 #include <PKIDlg.h> |
|
30 #include <badesca.h> |
|
31 #include <StringLoader.h> |
|
32 #include <aknnotewrappers.h> |
|
33 #include <unifiedcertstore.h> |
|
34 #include <unifiedkeystore.h> |
|
35 #include <mctkeystore.h> |
|
36 #include <cctcertinfo.h> |
|
37 #include <DocumentHandler.h> |
|
38 #include <apmstd.h> |
|
39 #include <DigSigningNote.h> |
|
40 #include <certmanui.rsg> |
|
41 #include <X509CertNameParser.h> |
|
42 #include <x509cert.h> |
|
43 #include <x500dn.h> |
|
44 #include <hash.h> |
|
45 #include <x509certext.h> |
|
46 #include <TrustedSitesStore.h> |
|
47 #include <mctwritablecertstore.h> |
|
48 |
|
49 // LOCAL CONSTANTS AND MACROS |
|
50 const TInt KCertArrayGranularity = 3; |
|
51 const TInt KMaxLengthTextDetailsBody = 5000; |
|
52 // CertLabel, Issuer, Owner max length 510 bytes |
|
53 const TInt KMaxLengthTextCertLabel = 510; |
|
54 // CertLabel, Issuer, Owner max visible length |
|
55 const TInt KMaxLengthTextCertLabelVisible = 200; |
|
56 // "dd/mm/yyyy0" |
|
57 const TInt KMaxLengthTextDateString = 20; |
|
58 // HH0 |
|
59 const TInt KMaxLengthTextSerialNumberFormatting = 3; |
|
60 // Maximum length of a certificate |
|
61 const TInt KMaxCertificateLength = 5000; |
|
62 |
|
63 // Maximum length of key store password |
|
64 const TInt KMaxKeystorePwLength = 6; |
|
65 |
|
66 const TInt KMinImportKeyPwLen = 1; |
|
67 |
|
68 const TInt KMaxCNLength = 64; |
|
69 |
|
70 _LIT(KCertManUIDetailsViewHexFormat, "%02X"); |
|
71 |
|
72 const TInt KFileCertStoreUid( 0x101F501A ); |
|
73 const TInt KWIMCertStoreUid ( 0x101F79D9 ); |
|
74 const TUid KTrustedServerTokenUid = { 0x101FB66F }; |
|
75 const TUid KDeviceCertStoreTokenUid = { 0x101FB668 }; |
|
76 |
|
77 _LIT( KBlockSeparator, " " ); |
|
78 _LIT( KEnter, "\n" ); |
|
79 _LIT( KEnterEnter, "\n\n" ); |
|
80 _LIT( KKeyStoreEnterPwLabel, "Key store passphrase" ); |
|
81 _LIT( KKeyStoreCreatePwLabel, "New key store passphrase" ); |
|
82 _LIT( KKeyStoreImportKeyLabel, "Passphrase of the imported key file" ); |
|
83 _LIT( KKeyStoreExportKeyLabel, "Passphrase of the exported key file" ); |
|
84 _LIT( KPKCS12TokenLabel, "PKCS12"); |
|
85 |
|
86 // ============================ MEMBER FUNCTIONS =============================== |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CCTSecurityDialogsAO::CCTSecurityDialogsAO |
|
90 // C++ default constructor can NOT contain any code, that |
|
91 // might leave. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CCTSecurityDialogsAO::CCTSecurityDialogsAO( CCTSecurityDialogNotifier* aNotifier, |
|
95 TBool& aDeleted ) : |
|
96 CActive( EPriorityStandard ), iNotifier( aNotifier ), |
|
97 iNextStep( EOperationCompleted ), iTrustedSiteCertStore( 0 ), |
|
98 iHandleIndex( -1 ), iCertPtr( 0, 0 ), iDeleted( aDeleted ) |
|
99 { |
|
100 CActiveScheduler::Add( this ); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CCTSecurityDialogsAO::ConstructL |
|
105 // Symbian 2nd phase constructor can leave. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CCTSecurityDialogsAO::ConstructL() |
|
109 { |
|
110 iDeleted = EFalse; |
|
111 |
|
112 iQueryDialog = NULL; |
|
113 iQueryDialogDeleted = ETrue; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CCTSecurityDialogsAO::NewL |
|
118 // Two-phased constructor. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CCTSecurityDialogsAO* CCTSecurityDialogsAO::NewL( CCTSecurityDialogNotifier* aNotifier, |
|
122 TBool& aDeleted ) |
|
123 { |
|
124 CCTSecurityDialogsAO* self = new( ELeave ) CCTSecurityDialogsAO( aNotifier, aDeleted ); |
|
125 |
|
126 CleanupStack::PushL( self ); |
|
127 self->ConstructL(); |
|
128 CleanupStack::Pop(); |
|
129 |
|
130 return self; |
|
131 } |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CCTSecurityDialogsAO::~CCTSecurityDialogsAO |
|
136 // Destructor |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 CCTSecurityDialogsAO::~CCTSecurityDialogsAO() |
|
140 { |
|
141 Cancel(); |
|
142 delete iText; |
|
143 delete iFilter; |
|
144 iCertHandleList.Close(); |
|
145 if ( iCertArray ) |
|
146 { |
|
147 //iCertArray->Reset(); // Should we reset this? |
|
148 //delete iCertArray; |
|
149 } |
|
150 iCertInfos.Close(); |
|
151 if ( iCertInfo ) |
|
152 { |
|
153 iCertInfo->Release(); // Should we release this? |
|
154 } |
|
155 iKeyInfos.Close(); |
|
156 if ( iKeyInfo ) |
|
157 { |
|
158 iKeyInfo->Release(); // Should we release this? |
|
159 } |
|
160 |
|
161 iServerCerts.ResetAndDestroy(); |
|
162 delete iCertBuf; |
|
163 delete iServerName; |
|
164 delete iCertLabel; |
|
165 delete iKeyStore; |
|
166 delete iCertStore; |
|
167 iFs.Close(); |
|
168 |
|
169 iDeleted = ETrue; |
|
170 } |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CCTSecurityDialogsAO::StartLD() |
|
175 // Handles all the operations calls appropriate handler functionq |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CCTSecurityDialogsAO::StartLD( |
|
179 const TDesC8& aBuffer, |
|
180 TInt aReplySlot, |
|
181 const RMessagePtr2& aMessage ) |
|
182 { |
|
183 iOperation = *reinterpret_cast<const TInt *>( aBuffer.Ptr() ) & KSecurityDialogOperationMask; |
|
184 iRetry = *reinterpret_cast<const TInt *>( aBuffer.Ptr() ) & EPINValueIncorrect; |
|
185 iReplySlot = aReplySlot; |
|
186 iMessagePtr = aMessage; |
|
187 |
|
188 WIMSECURITYDIALOGS_WRITE_FORMAT( "CCTSecurityDialogsAO::StartLD iOperation=%d", iOperation ); |
|
189 |
|
190 MapTlsProviderOperation( iOperation ); |
|
191 |
|
192 switch ( iOperation ) |
|
193 { |
|
194 case EEnablePIN: // flow thru |
|
195 case EDisablePIN: // flow thru |
|
196 case EEnterPIN: |
|
197 case EChangePIN: |
|
198 { |
|
199 TPINInput PINInput = reinterpret_cast<const TPINInput&>( *aBuffer.Ptr() ); |
|
200 iPIN = PINInput.iPIN; |
|
201 DoHandlePinOperationL(); |
|
202 iStatus = KRequestPending; |
|
203 SetActive(); |
|
204 break; |
|
205 } |
|
206 case EUnblockPIN: |
|
207 { |
|
208 TUnblockPINInput unblockPINInput = reinterpret_cast<const TUnblockPINInput&>( *aBuffer.Ptr() ); |
|
209 iPIN = unblockPINInput.iPIN; |
|
210 iUnblockPIN = unblockPINInput.iUnblockPIN; |
|
211 DoHandleUnblockPinOperationL(); |
|
212 iStatus = KRequestPending; |
|
213 SetActive(); |
|
214 break; |
|
215 } |
|
216 |
|
217 case EPINBlocked: |
|
218 { |
|
219 TPINInput PINInput = reinterpret_cast<const TPINInput&>( *aBuffer.Ptr() ); |
|
220 iPIN = PINInput.iPIN; |
|
221 DoHandleMessageL( EErrorPinCodeBlocked, iPIN.iPINLabel, iPIN.iTokenLabel, 0, 0 ); |
|
222 iMessagePtr.Complete( KErrNone ); |
|
223 break; |
|
224 } |
|
225 case ETotalBlocked: |
|
226 { |
|
227 TPINInput PINInput = reinterpret_cast<const TPINInput&>( *aBuffer.Ptr() ); |
|
228 iPIN = PINInput.iPIN; |
|
229 DoHandleMessageL( EErrorPukCodeBlocked, iPIN.iPINLabel, iPIN.iTokenLabel, 0, 0 ); |
|
230 iMessagePtr.Complete( KErrNone ); |
|
231 break; |
|
232 } |
|
233 case ESignText: |
|
234 case EUserAuthenticationText: |
|
235 case EUserAuthentication: |
|
236 { |
|
237 iSignInput = reinterpret_cast<const TSignInput&>( *aBuffer.Ptr() ); |
|
238 DoHandleSignTextL( aBuffer ); |
|
239 break; |
|
240 } |
|
241 case ECreateCSR: |
|
242 { |
|
243 DoHandleCSRL( aBuffer.Mid( sizeof(TInt) ) ); |
|
244 break; |
|
245 } |
|
246 case EDeleteCert: |
|
247 case ECertDetails: |
|
248 { |
|
249 DoHandleCertDetailsL( aBuffer.Mid( sizeof(TInt) ) ); |
|
250 break; |
|
251 } |
|
252 case ESaveCert: |
|
253 { |
|
254 DoHandleSaveCertL( aBuffer ); |
|
255 break; |
|
256 } |
|
257 case EUnblockPINInClear: |
|
258 { |
|
259 User::Leave( KErrNotSupported ); |
|
260 break; |
|
261 } |
|
262 case EPinCodeBlockedInfo: |
|
263 { |
|
264 TPtrC8 pinLabelPtr = aBuffer.Mid( sizeof(TInt) + 1 ); |
|
265 TPINLabel pinLabel; |
|
266 pinLabel.Copy( pinLabelPtr ); |
|
267 HBufC* text = iNotifier->LoadResourceStringLC( iOperation, pinLabel ); |
|
268 |
|
269 CCTSignTextDialog::RunDlgLD( R_WIM_UNBLOCK_INFO_DIALOG, *text, iStatus, iRetValue ); |
|
270 CleanupStack::PopAndDestroy( text ); |
|
271 iStatus = KRequestPending; |
|
272 SetActive(); |
|
273 break; |
|
274 } |
|
275 case EServerAuthenticationFailure: |
|
276 { |
|
277 DoHandleServerAuthFailL( aBuffer ); |
|
278 break; |
|
279 } |
|
280 case MPKIDialog::ESignatureRequested: |
|
281 { |
|
282 DoHandleMessageL( EInfoSignTextRequested, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
283 iRetValue = ETrue; |
|
284 HandleResponseAndCompleteL(); |
|
285 break; |
|
286 } |
|
287 case MPKIDialog::ESignatureDone: |
|
288 { |
|
289 DoHandleMessageL( EInfoSignTextDone, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
290 iRetValue = ETrue; |
|
291 HandleResponseAndCompleteL(); |
|
292 break; |
|
293 } |
|
294 case MPKIDialog::ESigningCancelled: |
|
295 { |
|
296 DoHandleMessageL( EInfoSignTextCancelled, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
297 iRetValue = ETrue; |
|
298 HandleResponseAndCompleteL(); |
|
299 break; |
|
300 } |
|
301 case MPKIDialog::ENoMatchCert: |
|
302 { |
|
303 DoHandleMessageL( ENoMatchingPersonalCert, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
304 break; |
|
305 } |
|
306 case MPKIDialog::ENoSecurityModule: |
|
307 { |
|
308 DoHandleMessageL( EErrorWimNotAvailable, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
309 iRetValue = ETrue; |
|
310 HandleResponseAndCompleteL(); |
|
311 break; |
|
312 } |
|
313 case MPKIDialog::EInternalError: |
|
314 { |
|
315 DoHandleMessageL( EErrorInternal, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
316 iRetValue = ETrue; |
|
317 HandleResponseAndCompleteL(); |
|
318 break; |
|
319 } |
|
320 case ESaveReceipt: |
|
321 { |
|
322 SaveReceiptL( aBuffer.Mid( sizeof(TInt) ) ); |
|
323 break; |
|
324 } |
|
325 default: |
|
326 User::Panic( _L("CTestSecDlgNotifier"), 0 ); |
|
327 break; |
|
328 } |
|
329 |
|
330 // Note that CCTSecurityDialogsAO::StartLD() must complete the given message and |
|
331 // delete itself when ready. However, there may be several steps before it can be |
|
332 // deleted. CCTSecurityDialogsAO::HandleResponseAndCompleteL() completes the given |
|
333 // message and deletes CCTSecurityDialogsAO object. Hence, every operation handling |
|
334 // function called above must call HandleResponseAndCompleteL() when it is ready. |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CCTSecurityDialogsAO::DoHandleServerAuthFailL(const TDesC8& aBuffer) |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void CCTSecurityDialogsAO::DoHandleServerAuthFailL( const TDesC8& aBuffer ) |
|
342 { |
|
343 CServerAuthenticationFailureInput* srvAuthFail = |
|
344 CServerAuthenticationFailureInput::NewLC( aBuffer ); |
|
345 TPtrC8 cert; |
|
346 TPtrC8 serverName; |
|
347 |
|
348 srvAuthFail->GetEncodedCert( cert ); |
|
349 srvAuthFail->GetServerName( serverName ); |
|
350 iAuthFailReason = srvAuthFail->FailureReason(); |
|
351 CleanupStack::PopAndDestroy( srvAuthFail ); |
|
352 |
|
353 iServerName = HBufC::NewL( serverName.Length() ); |
|
354 iServerName->Des().Copy( serverName ); |
|
355 |
|
356 HBufC* cn = NULL; |
|
357 iCertLabel = NULL; |
|
358 // Site will be checked later. For now it is not trusted |
|
359 iTrustedSite = EFalse; |
|
360 |
|
361 |
|
362 CX509Certificate* serverCert = CX509Certificate::NewLC( cert ); |
|
363 // Retrieve subject name |
|
364 const CX500DistinguishedName& dName = serverCert->SubjectName(); |
|
365 // Retrieve CN |
|
366 cn = dName.ExtractFieldL( KX520CommonName ); |
|
367 if ( cn != NULL ) |
|
368 { |
|
369 // commonName exist in the certificate. |
|
370 // Check the length of CN. RFC 3280 states |
|
371 // that max length of CN is 64. |
|
372 if ( cn->Length() <= KMaxCNLength ) |
|
373 { |
|
374 iCertLabel = HBufC::NewL( cn->Length() ); |
|
375 iCertLabel->Des().Append( cn->Des() ); |
|
376 } |
|
377 } |
|
378 |
|
379 if ( iCertLabel == NULL ) |
|
380 { |
|
381 // No or invalid commonName. Use domain name as label |
|
382 iCertLabel = HBufC::NewL( iServerName->Length() ); |
|
383 iCertLabel->Des().Append( iServerName->Des() ); |
|
384 } |
|
385 |
|
386 CleanupStack::PopAndDestroy( serverCert ); |
|
387 |
|
388 iCertBuf = HBufC8::NewL( cert.Length() ); |
|
389 *iCertBuf = cert; |
|
390 |
|
391 InitCertStoreL(); |
|
392 } |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // CCTSecurityDialogsAO::DoHandleCertDetailsL(const TDesC8& aBuffer) |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 void CCTSecurityDialogsAO::DoHandleCertDetailsL( const TDesC8& aBuffer ) |
|
399 { |
|
400 TCTTokenObjectHandle tokenHandle = |
|
401 reinterpret_cast<const TCTTokenObjectHandle&>( *aBuffer.Ptr() ); |
|
402 |
|
403 iTokenHandle.iTokenHandle.iTokenTypeUid = tokenHandle.iTokenHandle.iTokenTypeUid; |
|
404 iTokenHandle.iTokenHandle.iTokenId = tokenHandle.iTokenHandle.iTokenId; |
|
405 iTokenHandle.iObjectId = tokenHandle.iObjectId; |
|
406 |
|
407 InitCertStoreL(); |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CCTSecurityDialogsAO::DoHandleSaveCertL(const TDesC8& aBuffer) |
|
412 // ----------------------------------------------------------------------------- |
|
413 // |
|
414 void CCTSecurityDialogsAO::DoHandleSaveCertL( const TDesC8& aBuffer ) |
|
415 { |
|
416 TSaveCertInput saveCertInput = |
|
417 reinterpret_cast<const TSaveCertInput&>( *aBuffer.Ptr() ); |
|
418 |
|
419 TInt start = sizeof( TSaveCertInput ); |
|
420 delete iCertBuf; |
|
421 iCertBuf = NULL; |
|
422 iCertBuf = HBufC8::NewL( saveCertInput.iDataSize ); |
|
423 const TUint8* certPtr = reinterpret_cast<const TUint8*>( aBuffer.Mid(start).Ptr() ); |
|
424 iCertBuf->Des().Append( certPtr, saveCertInput.iDataSize ); |
|
425 ShowCertDialogL(); |
|
426 } |
|
427 |
|
428 // ----------------------------------------------------------------------------- |
|
429 // CCTSecurityDialogsAO::DoHandleCSRL(const TDesC8& aBuffer) |
|
430 // ----------------------------------------------------------------------------- |
|
431 // |
|
432 void CCTSecurityDialogsAO::DoHandleCSRL( const TDesC8& aBuffer ) |
|
433 { |
|
434 WIMSECURITYDIALOGS_ENTERFN("CCTSecurityDialogsAO::DoHandleCSRL"); |
|
435 TInt length = reinterpret_cast<const TInt&>( *aBuffer.Ptr() ); |
|
436 TInt start = sizeof( TInt ) + 1; |
|
437 iText = HBufC::NewL( length ); |
|
438 iText->Des().Copy( aBuffer.Mid( start, length ) ); |
|
439 |
|
440 start = start + length; |
|
441 |
|
442 const TUint8* bufferPtr = aBuffer.Ptr(); |
|
443 bufferPtr += start; |
|
444 |
|
445 TCTTokenObjectHandle tokenHandle; |
|
446 TCTTokenObjectHandle* tokenHandlePtr = &tokenHandle; |
|
447 TUint8* copyPtr = reinterpret_cast< TUint8* >( tokenHandlePtr ); |
|
448 for( TInt i = 0; i < 12; i++ ) |
|
449 { |
|
450 copyPtr[ i ] = bufferPtr[ i ]; |
|
451 } |
|
452 |
|
453 iTokenHandle.iTokenHandle.iTokenTypeUid = tokenHandle.iTokenHandle.iTokenTypeUid; |
|
454 iTokenHandle.iTokenHandle.iTokenId = tokenHandle.iTokenHandle.iTokenId; |
|
455 iTokenHandle.iObjectId = tokenHandle.iObjectId; |
|
456 |
|
457 InitKeyStoreL(); |
|
458 iNextStep = EGetKeyInfoByHandle; |
|
459 WIMSECURITYDIALOGS_LEAVEFN("CCTSecurityDialogsAO::DoHandleCSRL"); |
|
460 } |
|
461 |
|
462 // ----------------------------------------------------------------------------- |
|
463 // CCTSecurityDialogsAO::DoHandleSignTextL() |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 void CCTSecurityDialogsAO::DoHandleSignTextL( const TDesC8& aBuffer ) |
|
467 { |
|
468 TInt arraySize = sizeof( TCTTokenObjectHandle ) * iSignInput.iCertHandleArrayTotal; |
|
469 TInt start = sizeof( TSignInput ); |
|
470 TInt end = start + arraySize; |
|
471 for (; start < end; start+=sizeof( TCTTokenObjectHandle )) |
|
472 { |
|
473 TCTTokenObjectHandle handle = |
|
474 reinterpret_cast<const TCTTokenObjectHandle&>(*aBuffer.Mid(start).Ptr()); |
|
475 User::LeaveIfError( iCertHandleList.Append( handle ) ); |
|
476 } |
|
477 start = end; |
|
478 HBufC* textToSign = NULL; |
|
479 if ( iOperation != EUserAuthentication ) |
|
480 { |
|
481 textToSign = HBufC::NewLC( iSignInput.iVariableDataSize / 2 ); // 8 bit -> 16 bit descriptor |
|
482 //textToSign->Des().Copy(aBuffer.Mid(start)); |
|
483 const TUint16* textToSignPtr = reinterpret_cast<const TUint16*>( aBuffer.Mid(start).Ptr() ); |
|
484 textToSign->Des().Append( textToSignPtr, (iSignInput.iVariableDataSize / 2) ); |
|
485 } |
|
486 |
|
487 if ( iCertHandleList.Count() > 0 ) |
|
488 { |
|
489 iNextStep = EOperationSignTextShown; |
|
490 } |
|
491 else |
|
492 { |
|
493 iNextStep = EOperationCompleted; |
|
494 iCertHandleList.Close(); |
|
495 } |
|
496 switch( iOperation ) |
|
497 { |
|
498 case EUserAuthenticationText: |
|
499 { |
|
500 CCTSignTextDialog::RunDlgLD( R_WIM_USERAUTHTEXT_DIALOG, |
|
501 *textToSign, iStatus, iRetValue ); |
|
502 break; |
|
503 } |
|
504 case EUserAuthentication: |
|
505 { |
|
506 DoHandleMessageL( EUserAuthentication, KNullDesC, KNullDesC, 1, KMaxTInt ); |
|
507 break; |
|
508 } |
|
509 case ESignText: |
|
510 { |
|
511 CCTSignTextDialog::RunDlgLD( R_WIM_SIGNTEXT_DIALOG,*textToSign, iStatus, iRetValue ); |
|
512 break; |
|
513 } |
|
514 default: |
|
515 { |
|
516 __ASSERT_DEBUG( EFalse, |
|
517 _L( "CCTSecurityDialogsAO::DoHandleSignTextL: Invalid operation" ) ); |
|
518 break; |
|
519 } |
|
520 } |
|
521 iStatus = KRequestPending; |
|
522 SetActive(); |
|
523 if ( iOperation == EUserAuthentication ) |
|
524 { |
|
525 TRequestStatus* status = &iStatus; |
|
526 User::RequestComplete( status, KErrNone ); |
|
527 } |
|
528 else |
|
529 { |
|
530 CleanupStack::PopAndDestroy( textToSign ); |
|
531 } |
|
532 } |
|
533 |
|
534 // ----------------------------------------------------------------------------- |
|
535 // CCTSecurityDialogsAO::DoHandleUnblockPinOperationL() |
|
536 // ----------------------------------------------------------------------------- |
|
537 // |
|
538 void CCTSecurityDialogsAO::DoHandleUnblockPinOperationL() |
|
539 { |
|
540 if ( iRetry ) // Is this new try? |
|
541 { |
|
542 // Previous attempt was failed |
|
543 DoHandleMessageL( EErrorPukCodeIncorrect, KNullDesC, KNullDesC, 0, 0 ); |
|
544 } |
|
545 // Ask the PUK code |
|
546 // The label is iPIN instead of iUnblockPIN, since we need to show to |
|
547 // the user which PIN to unblock |
|
548 DoHandleMessageL( EEnterPukNR, iPIN.iPINLabel, |
|
549 iPIN.iTokenLabel, iUnblockPIN.iMinLength, iUnblockPIN.iMaxLength ); |
|
550 iNextStep = EEnterNewPIN; |
|
551 iMultiLineDlgType = EEnterNewPinNR; |
|
552 } |
|
553 |
|
554 // ----------------------------------------------------------------------------- |
|
555 // CCTSecurityDialogsAO::DoHandlePinOperationL() |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CCTSecurityDialogsAO::DoHandlePinOperationL() |
|
559 { |
|
560 if ( iRetry ) // Is this new try? |
|
561 { |
|
562 // Previous attempt was failed |
|
563 DoHandleMessageL( EErrorPinCodeIncorrect, KNullDesC, KNullDesC, 0, 0 ); |
|
564 } |
|
565 // Ask the PIN code or PUK code |
|
566 if ( iPIN.iPINLabel == KKeyStoreEnterPwLabel ) |
|
567 { |
|
568 HBufC* header = StringLoader::LoadLC( |
|
569 R_QTN_CM_HEADING_PHONE_KEYSTORE, CEikonEnv::Static() ); |
|
570 iPIN.iMinLength = KMaxKeystorePwLength; |
|
571 DoHandleMessageL( EEnterKeyStorePw, KNullDesC, *header, |
|
572 iPIN.iMinLength, iPIN.iMaxLength ); |
|
573 iMultiLineDlgType = EEnterNewKeyStorePw; |
|
574 CleanupStack::PopAndDestroy( header ); |
|
575 } |
|
576 else if ( iPIN.iPINLabel == KKeyStoreImportKeyLabel ) |
|
577 { |
|
578 iPIN.iMinLength = KMaxKeystorePwLength; |
|
579 DoHandleMessageL( EImportKeyPw, KNullDesC, KNullDesC, |
|
580 KMinImportKeyPwLen, iPIN.iMaxLength ); |
|
581 iMultiLineDlgType = EEnterNewKeyStorePw; |
|
582 } |
|
583 else if ( iPIN.iPINLabel == KKeyStoreExportKeyLabel ) |
|
584 { |
|
585 DoHandleMultilinePinQueryL( EExportKeyPw ); |
|
586 iNextStep = EVerifyPINs; |
|
587 } |
|
588 else if ( iPIN.iPINLabel == KKeyStoreCreatePwLabel ) |
|
589 { |
|
590 iPIN.iMinLength = KMaxKeystorePwLength; |
|
591 DoHandleMessageL( EInfoPwCreating, KNullDesC, KNullDesC, 0, 0 ); |
|
592 DoHandleMultilinePinQueryL( EEnterNewKeyStorePw ); |
|
593 iNextStep = EVerifyPINs; |
|
594 } |
|
595 else if ( iPIN.iTokenLabel == KPKCS12TokenLabel ) |
|
596 { |
|
597 DoHandleMessageL( EEnterPw, iPIN.iPINLabel, KNullDesC, |
|
598 iPIN.iMinLength, iPIN.iMaxLength ); |
|
599 } |
|
600 else |
|
601 { |
|
602 DoHandleMessageL( EEnterPinNR, iPIN.iPINLabel, iPIN.iTokenLabel, |
|
603 iPIN.iMinLength, iPIN.iMaxLength ); |
|
604 iMultiLineDlgType = EEnterNewPinNR; |
|
605 } |
|
606 if ( EChangePIN == iOperation ) |
|
607 { |
|
608 iNextStep = EEnterNewPIN; |
|
609 } |
|
610 } |
|
611 |
|
612 // ----------------------------------------------------------------------------- |
|
613 // CCTSecurityDialogsAO::DoHandleMultilinePinQueryL() |
|
614 // ----------------------------------------------------------------------------- |
|
615 // |
|
616 void CCTSecurityDialogsAO::DoHandleMultilinePinQueryL( const TInt& aDlgType ) |
|
617 { |
|
618 iMultiLineDlgType = aDlgType; |
|
619 HBufC* dlgText1 = NULL; |
|
620 HBufC* dlgText2 = NULL; |
|
621 CCTPinPinQueryDialog* dlg = NULL; |
|
622 TDialogType dlgType = ( TDialogType )aDlgType; |
|
623 if ( EEnterNewKeyStorePw == dlgType ) |
|
624 { |
|
625 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, KNullDesC ); |
|
626 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyKeyStorePw, KNullDesC ); |
|
627 dlg = CCTPinPinQueryDialog::NewL( *dlgText1, *dlgText2, iPINValue2, |
|
628 iPINValueVerify, iPIN.iMinLength, iPIN.iMaxLength, iRetValue ); |
|
629 dlg->RunDlgLD( iStatus, R_WIM_PWPW_QUERY_DIALOG ); |
|
630 CleanupStack::PopAndDestroy( 2, dlgText1 ); // dlgText1, dlgText2 |
|
631 } |
|
632 else if ( EExportKeyPw == dlgType ) |
|
633 { |
|
634 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, KNullDesC ); |
|
635 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyKeyStorePw, KNullDesC ); |
|
636 dlg = CCTPinPinQueryDialog::NewL( *dlgText1, *dlgText2, iPINValue2, |
|
637 iPINValueVerify, iPIN.iMinLength, iPIN.iMaxLength, iRetValue ); |
|
638 dlg->RunDlgLD( iStatus, R_WIM_PWPW_QUERY_DIALOG ); |
|
639 CleanupStack::PopAndDestroy( 2, dlgText1 ); // dlgText1, dlgText2 |
|
640 } |
|
641 else // Enter new PIN |
|
642 { |
|
643 dlgText1 = iNotifier->LoadResourceStringLC( dlgType, iPIN.iPINLabel ); |
|
644 dlgText2 = iNotifier->LoadResourceStringLC( EVerifyPinNR, iPIN.iPINLabel ); |
|
645 dlg = CCTPinPinQueryDialog::NewL( *dlgText1, *dlgText2, iPINValue2, |
|
646 iPINValueVerify, iPIN.iMinLength, iPIN.iMaxLength, iRetValue ); |
|
647 dlg->RunDlgLD( iStatus, R_WIM_PINPIN_QUERY_DIALOG ); |
|
648 CleanupStack::PopAndDestroy( 2, dlgText1 ); // dlgText1, dlgText2 |
|
649 } |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // CCTSecurityDialogsAO::DoHandleMessageL() |
|
654 // ----------------------------------------------------------------------------- |
|
655 // |
|
656 void CCTSecurityDialogsAO::DoHandleMessageL( |
|
657 const TInt& aDlgType, |
|
658 const TDesC& aDynamicText, |
|
659 const TDesC& aPinQueryHeading, |
|
660 const TInt aMinLength, |
|
661 const TInt aMaxLength ) |
|
662 { |
|
663 TDialogType dlgType = ( TDialogType )aDlgType; |
|
664 |
|
665 HBufC* dlgText = iNotifier->LoadResourceStringLC( dlgType, aDynamicText, aPinQueryHeading ); |
|
666 |
|
667 TDialogTypeItem item = iNotifier->GetDialogTypeItem( dlgType ); |
|
668 |
|
669 CAknResourceNoteDialog* dlg = NULL; |
|
670 |
|
671 TInt resource = 0; |
|
672 |
|
673 switch ( item.iNoteType ) |
|
674 { |
|
675 case EInfoNote: |
|
676 { |
|
677 dlg = new ( ELeave ) CAknInformationNote( ETrue ); |
|
678 break; |
|
679 } |
|
680 |
|
681 case EErrorNote: |
|
682 { |
|
683 dlg = new ( ELeave ) CAknErrorNote( ETrue ); |
|
684 break; |
|
685 } |
|
686 case EConfirmationNote: |
|
687 { |
|
688 dlg = new ( ELeave ) CAknConfirmationNote( ETrue ); |
|
689 break; |
|
690 } |
|
691 case EInfoDialog: |
|
692 { |
|
693 CCTQueryDialog::RunDlgLD( iStatus, |
|
694 iRetValue, |
|
695 *dlgText, item.iSoftKeyResource, |
|
696 ECTInfoDialog ); |
|
697 iStatus = KRequestPending; |
|
698 SetActive(); |
|
699 break; |
|
700 } |
|
701 case EEnterPwPwDialog: |
|
702 { |
|
703 CCTPinPinQueryDialog* dialog = |
|
704 CCTPinPinQueryDialog::NewL( *dlgText, *dlgText, |
|
705 iPINValue2, iPINValueVerify, aMinLength, aMaxLength, iRetValue ); |
|
706 dialog->RunDlgLD( iStatus, R_WIM_PWPW_QUERY_DIALOG ); |
|
707 break; |
|
708 } |
|
709 case EEnterPinPinCodeDialog: |
|
710 { |
|
711 CCTPinPinQueryDialog* dialog = |
|
712 CCTPinPinQueryDialog::NewL( *dlgText, *dlgText, |
|
713 iPINValue2, iPINValueVerify, aMinLength, aMaxLength, iRetValue ); |
|
714 dialog->RunDlgLD( iStatus, R_WIM_PINPIN_QUERY_DIALOG ); |
|
715 break; |
|
716 } |
|
717 case EEnterPwDialog: |
|
718 case EEnterPinNRCodeDialog: |
|
719 case EVerifyPinNRCodeDialog: |
|
720 { |
|
721 if ( item.iNoteType == EEnterPwDialog ) |
|
722 { |
|
723 resource = R_WIM_PASSWORD_QUERY_DIALOG; |
|
724 } |
|
725 else |
|
726 { |
|
727 resource = R_WIM_PIN_QUERY_DIALOG; |
|
728 } |
|
729 |
|
730 TPINValue* pinValue = NULL; |
|
731 switch ( aDlgType ) |
|
732 { |
|
733 case EEnterPinNR: // fall thru |
|
734 case EEnterPukNR: |
|
735 case EEnterKeyStorePw: |
|
736 case EImportKeyPw: |
|
737 { |
|
738 pinValue = &iPINValue1; |
|
739 break; |
|
740 } |
|
741 case EEnterNewPinNR: |
|
742 case EEnterNewKeyStorePw: |
|
743 case EExportKeyPw: |
|
744 { |
|
745 pinValue = &iPINValue2; |
|
746 break; |
|
747 } |
|
748 case EVerifyPinNR: |
|
749 { |
|
750 pinValue = &iPINValueVerify; |
|
751 break; |
|
752 } |
|
753 default: |
|
754 { |
|
755 User::Panic(_L("CSecDlgNotifier"), 0); |
|
756 } |
|
757 } |
|
758 iPinQueryDialogDeleted = EFalse; |
|
759 CCTPinQueryDialog::RunDlgLD( iStatus, |
|
760 *dlgText, |
|
761 *pinValue, |
|
762 aMinLength, |
|
763 aMaxLength, |
|
764 iRetValue, |
|
765 resource, |
|
766 iPinQueryDialog, |
|
767 iPinQueryDialogDeleted ); |
|
768 break; |
|
769 } |
|
770 default: |
|
771 { |
|
772 break; |
|
773 } |
|
774 |
|
775 } |
|
776 |
|
777 if ( dlg ) |
|
778 { |
|
779 dlg->ExecuteLD( *dlgText ); |
|
780 dlg = NULL; |
|
781 } |
|
782 |
|
783 CleanupStack::PopAndDestroy( dlgText ); // dlgText |
|
784 } |
|
785 |
|
786 // ----------------------------------------------------------------------------- |
|
787 // CCTSecurityDialogsAO::RunError(TInt aError) |
|
788 // ?implementation_description |
|
789 // (other items were commented in a header). |
|
790 // ----------------------------------------------------------------------------- |
|
791 // |
|
792 TInt CCTSecurityDialogsAO::RunError( TInt aError ) |
|
793 { |
|
794 iMessagePtr.Complete( aError ); |
|
795 return KErrNone; |
|
796 } |
|
797 |
|
798 // ----------------------------------------------------------------------------- |
|
799 // CCTSecurityDialogsAO::InitCertStoreL() |
|
800 // ?implementation_description |
|
801 // (other items were commented in a header). |
|
802 // ----------------------------------------------------------------------------- |
|
803 // |
|
804 void CCTSecurityDialogsAO::InitCertStoreL() |
|
805 { |
|
806 switch(iOperation) |
|
807 { |
|
808 case ESignText: |
|
809 case EUserAuthenticationText: |
|
810 case EUserAuthentication: |
|
811 { |
|
812 iNextStep = EOperationRetrieveCertInfos; |
|
813 break; |
|
814 } |
|
815 case EDeleteCert: |
|
816 case ECertDetails: |
|
817 { |
|
818 iNextStep = EGetCertInfo; |
|
819 break; |
|
820 } |
|
821 case EServerAuthenticationFailure: |
|
822 { |
|
823 iNextStep = EProcessTrustedSite;; |
|
824 break; |
|
825 } |
|
826 default: |
|
827 { |
|
828 User::Panic( _L("CTestSecDlgNotifier"), 0 ); |
|
829 } |
|
830 } |
|
831 |
|
832 if ( iCertStore == NULL ) |
|
833 { |
|
834 TInt err = KErrNone; |
|
835 err = iFs.Connect(); |
|
836 |
|
837 if( err != KErrNone && err != KErrAlreadyExists ) |
|
838 { |
|
839 User::Leave( KErrGeneral ); |
|
840 } |
|
841 |
|
842 iCertStore = CUnifiedCertStore::NewL( iFs, ETrue ); |
|
843 iCertArray = new (ELeave) CDesCArrayFlat( KCertArrayGranularity ); |
|
844 iCertStore->Initialize( iStatus ); |
|
845 iStatus = KRequestPending; |
|
846 SetActive(); |
|
847 } |
|
848 else |
|
849 { |
|
850 iStatus = KRequestPending; |
|
851 SetActive(); |
|
852 TRequestStatus* status = &iStatus; |
|
853 User::RequestComplete( status, KErrNone ); |
|
854 } |
|
855 } |
|
856 |
|
857 // ----------------------------------------------------------------------------- |
|
858 // CCTSecurityDialogsAO::InitKeyStoreL() |
|
859 // ?implementation_description |
|
860 // (other items were commented in a header). |
|
861 // ----------------------------------------------------------------------------- |
|
862 // |
|
863 void CCTSecurityDialogsAO::InitKeyStoreL() |
|
864 { |
|
865 if ( NULL == iKeyStore ) |
|
866 { |
|
867 TInt err = KErrNone; |
|
868 err = iFs.Connect(); |
|
869 if( err != KErrNone && err != KErrAlreadyExists ) |
|
870 { |
|
871 User::Leave( KErrGeneral ); |
|
872 } |
|
873 |
|
874 iKeyStore = CUnifiedKeyStore::NewL( iFs ); |
|
875 iKeyStore->Initialize( iStatus ); |
|
876 iStatus = KRequestPending; |
|
877 SetActive(); |
|
878 } |
|
879 else |
|
880 { |
|
881 iStatus = KRequestPending; |
|
882 SetActive(); |
|
883 TRequestStatus* status = &iStatus; |
|
884 User::RequestComplete( status, KErrNone ); |
|
885 } |
|
886 } |
|
887 // ----------------------------------------------------------------------------- |
|
888 // CCTSecurityDialogsAO::GetKeyInfosL() |
|
889 // ?implementation_description |
|
890 // (other items were commented in a header). |
|
891 // ----------------------------------------------------------------------------- |
|
892 // |
|
893 void CCTSecurityDialogsAO::GetKeyInfosL() |
|
894 { |
|
895 if ( NULL == iKeyStore ) |
|
896 { |
|
897 iStatus = KRequestPending; |
|
898 SetActive(); |
|
899 TRequestStatus* status = &iStatus; |
|
900 User::RequestComplete( status, KErrNone ); |
|
901 } |
|
902 else |
|
903 { |
|
904 iStatus = KRequestPending; |
|
905 iKeyFilter.iKeyId = iCertInfo->SubjectKeyId(); |
|
906 iKeyStore->List( iKeyInfos, iKeyFilter, iStatus ); |
|
907 SetActive(); |
|
908 } |
|
909 } |
|
910 |
|
911 // ----------------------------------------------------------------------------- |
|
912 // CCTSecurityDialogsAO::GetKeyInfoByHandleL() |
|
913 // ?implementation_description |
|
914 // (other items were commented in a header). |
|
915 // ----------------------------------------------------------------------------- |
|
916 // |
|
917 void CCTSecurityDialogsAO::GetKeyInfoByHandleL() |
|
918 { |
|
919 if ( NULL == iKeyStore ) |
|
920 { |
|
921 User::Panic( _L("CCTSecurityDialogsAO::GetKeyInfoByHandleL()"), 0 ); |
|
922 } |
|
923 else |
|
924 { |
|
925 iStatus = KRequestPending; |
|
926 iKeyStore->GetKeyInfo( iTokenHandle, iKeyInfo, iStatus ); |
|
927 SetActive(); |
|
928 } |
|
929 } |
|
930 |
|
931 // ----------------------------------------------------------------------------- |
|
932 // CCTSecurityDialogsAO::RunL() |
|
933 // ?implementation_description |
|
934 // (other items were commented in a header). |
|
935 // ----------------------------------------------------------------------------- |
|
936 // |
|
937 void CCTSecurityDialogsAO::RunL() |
|
938 { |
|
939 WIMSECURITYDIALOGS_WRITE_FORMAT( "CCTSecurityDialogsAO::RunL, iStatus %d", iStatus.Int() ); |
|
940 WIMSECURITYDIALOGS_WRITE_FORMAT( " iNextStep %d", iNextStep ); |
|
941 |
|
942 if ( iStatus != KErrNone ) |
|
943 { |
|
944 User::Leave( iStatus.Int() ); |
|
945 } // if |
|
946 |
|
947 switch ( iNextStep ) |
|
948 { |
|
949 case EOperationCompleted: |
|
950 { |
|
951 WIMSECURITYDIALOGS_WRITE( "EOperationCompleted" ); |
|
952 HandleResponseAndCompleteL(); |
|
953 break; |
|
954 } |
|
955 case ECheckServerCerts: |
|
956 { |
|
957 WIMSECURITYDIALOGS_WRITE( "ECheckServerCerts" ); |
|
958 |
|
959 TBool foundCert( EFalse ); |
|
960 |
|
961 if ( iServerCerts.Count() ) |
|
962 { |
|
963 // Found certificates in the trusted site certificate storage. |
|
964 // Compare them with the one received from TlsProvider |
|
965 iCertPtr.Set( iCertBuf->Des() ); |
|
966 CX509Certificate* serverCert = CX509Certificate::NewLC( iCertPtr ); |
|
967 |
|
968 for (TInt i=0; i<iServerCerts.Count(); i++ ) |
|
969 { |
|
970 TPtr8 certPtr( iServerCerts[i]->Des() ); |
|
971 |
|
972 CX509Certificate* cert = CX509Certificate::NewLC( certPtr ); |
|
973 |
|
974 // Compare fingerprints |
|
975 if ( cert->Fingerprint() == serverCert->Fingerprint() ) |
|
976 { |
|
977 // Fingerprints match |
|
978 foundCert = ETrue; |
|
979 } |
|
980 CleanupStack::PopAndDestroy( cert ); |
|
981 } |
|
982 CleanupStack::PopAndDestroy( serverCert ); |
|
983 if ( foundCert ) |
|
984 { |
|
985 // Found matching certificate. Complete the operation |
|
986 iRetValue = EServerCertAcceptedPermanently; |
|
987 iNextStep = EOperationCompleted; |
|
988 HandleResponseAndCompleteL(); |
|
989 } |
|
990 } |
|
991 |
|
992 if ( !foundCert ) |
|
993 { |
|
994 // Couldn't find matching certificate. Prompt user |
|
995 ShowNoTrustDialogL(); |
|
996 } |
|
997 |
|
998 break; |
|
999 } |
|
1000 case EProcessTrustedSite: |
|
1001 { |
|
1002 WIMSECURITYDIALOGS_WRITE( "EProcessTrustedSite" ); |
|
1003 TInt count = iCertStore->WritableCertStoreCount(); |
|
1004 for ( TInt i = 0; i < count; i++ ) |
|
1005 { |
|
1006 MCTWritableCertStore *certstore = &iCertStore->WritableCertStore( i ); |
|
1007 MCTToken& token = certstore->Token(); |
|
1008 TUid tokenuid = token.Handle().iTokenTypeUid; |
|
1009 if ( tokenuid == KTrustedServerTokenUid ) |
|
1010 { |
|
1011 iTrustedSiteCertStore = certstore; |
|
1012 } |
|
1013 } |
|
1014 |
|
1015 CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL(); |
|
1016 CleanupStack::PushL( trustedSitesStore ); |
|
1017 |
|
1018 // Find out whether or not site associated with certificate is trusted |
|
1019 iTrustedSite = trustedSitesStore->IsTrustedSiteL( *iCertBuf, *iServerName ); |
|
1020 |
|
1021 if ( iTrustedSite ) |
|
1022 { |
|
1023 TBool allowOutOfDate = trustedSitesStore->IsOutOfDateAllowedL(*iCertBuf, *iServerName ); |
|
1024 |
|
1025 if (!allowOutOfDate) |
|
1026 { |
|
1027 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
|
1028 |
|
1029 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
|
1030 const TTime& startValue = validityPeriod.Start(); |
|
1031 const TTime& finishValue = validityPeriod.Finish(); |
|
1032 TTime current; |
|
1033 current.UniversalTime(); |
|
1034 |
|
1035 // First check certificate validity period |
|
1036 if ( ( startValue > current ) || ( finishValue < current ) ) |
|
1037 { |
|
1038 iTrustedSite = EFalse; |
|
1039 } |
|
1040 |
|
1041 CleanupStack::PopAndDestroy(); //cert |
|
1042 } |
|
1043 } |
|
1044 CleanupStack::PopAndDestroy( trustedSitesStore ); // trustedSitesStore |
|
1045 |
|
1046 if ( iTrustedSite ) |
|
1047 { |
|
1048 // Site is trusted. Next step is to check that server |
|
1049 // certificate is in the trusted site certificate storage |
|
1050 iNextStep = ERetrieveServerCerts; |
|
1051 iStatus = KRequestPending; |
|
1052 SetActive(); |
|
1053 TRequestStatus* status = &iStatus; |
|
1054 User::RequestComplete( status, KErrNone ); |
|
1055 } |
|
1056 else |
|
1057 { |
|
1058 // Site is not trusted. Prompt user |
|
1059 ShowNoTrustDialogL(); |
|
1060 } |
|
1061 |
|
1062 break; |
|
1063 } |
|
1064 |
|
1065 case ERetrieveServerCerts: |
|
1066 { |
|
1067 WIMSECURITYDIALOGS_WRITE( "ERetrieveServerCerts" ); |
|
1068 if ( iHandleIndex == -1 ) |
|
1069 { |
|
1070 iFilter = CCertAttributeFilter::NewL(); |
|
1071 iFilter->SetOwnerType( EPeerCertificate ); |
|
1072 if ( iTrustedSiteCertStore ) |
|
1073 { |
|
1074 // Thet the list of all certificates from Trusted site certificate |
|
1075 // storage |
|
1076 iTrustedSiteCertStore->List( iCertInfos, *iFilter, iStatus ); |
|
1077 iNextStep = ERetrieveServerCerts; |
|
1078 iStatus = KRequestPending; |
|
1079 SetActive(); |
|
1080 ++iHandleIndex; |
|
1081 } |
|
1082 else |
|
1083 { |
|
1084 // Trusted Site certificate storage doesn't exist |
|
1085 // or something went wrong. |
|
1086 User::Leave( KErrGeneral ); |
|
1087 } |
|
1088 } |
|
1089 else if ( iHandleIndex < iCertInfos.Count() ) |
|
1090 { |
|
1091 iStatus = KRequestPending; |
|
1092 iServerCert = HBufC8::NewL( KMaxCertificateLength ); |
|
1093 iCertPtr.Set( iServerCert->Des() ); |
|
1094 |
|
1095 iTrustedSiteCertStore->Retrieve( *(iCertInfos[iHandleIndex]), iCertPtr, iStatus ); |
|
1096 |
|
1097 iServerCerts.Append( iServerCert ); |
|
1098 |
|
1099 iNextStep = ERetrieveServerCerts; |
|
1100 SetActive(); |
|
1101 ++iHandleIndex; |
|
1102 } |
|
1103 else |
|
1104 { |
|
1105 iNextStep = ECheckServerCerts; |
|
1106 iStatus = KRequestPending; |
|
1107 SetActive(); |
|
1108 TRequestStatus* status = &iStatus; |
|
1109 User::RequestComplete( status, KErrNone ); |
|
1110 } |
|
1111 break; |
|
1112 } |
|
1113 case EAddTrustedSite: |
|
1114 { |
|
1115 if ( iStatus.Int() == KErrNone ) |
|
1116 { |
|
1117 //Added server certificate succesfully |
|
1118 CTrustSitesStore* trustedSitesStore = CTrustSitesStore::NewL(); |
|
1119 CleanupStack::PushL( trustedSitesStore ); |
|
1120 |
|
1121 TInt status = trustedSitesStore->AddL( *iCertBuf, *iServerName ); |
|
1122 |
|
1123 CleanupStack::PopAndDestroy( trustedSitesStore ); |
|
1124 if ( status == KErrNone ) |
|
1125 { |
|
1126 iRetValue = EServerCertAcceptedPermanently; |
|
1127 } |
|
1128 else |
|
1129 { |
|
1130 iRetValue = EServerCertNotAccepted; |
|
1131 } |
|
1132 |
|
1133 iNextStep = EOperationCompleted; |
|
1134 HandleResponseAndCompleteL(); |
|
1135 } |
|
1136 else |
|
1137 { |
|
1138 //Adding server certificate failed |
|
1139 iNextStep = EOperationCompleted; |
|
1140 iRetValue = EServerCertNotAccepted; |
|
1141 HandleResponseAndCompleteL(); |
|
1142 } |
|
1143 break; |
|
1144 } |
|
1145 |
|
1146 case ESaveServerCert: |
|
1147 { |
|
1148 WIMSECURITYDIALOGS_WRITE( "ESaveServerCert" ); |
|
1149 DoHandleSaveServerCertL(); |
|
1150 break; |
|
1151 } |
|
1152 case EServerCertCheckUserResp: |
|
1153 { |
|
1154 WIMSECURITYDIALOGS_WRITE( "EServerCertCheckUserResp" ); |
|
1155 if ( iRetValue == EServerCertAcceptedPermanently ) |
|
1156 { |
|
1157 // User accepted to select certificate permanently. |
|
1158 // First add server certificate |
|
1159 iNextStep = ESaveServerCert; |
|
1160 iStatus = KRequestPending; |
|
1161 SetActive(); |
|
1162 TRequestStatus* status = &iStatus; |
|
1163 User::RequestComplete( status, KErrNone ); |
|
1164 } |
|
1165 else |
|
1166 { |
|
1167 // User declined or temporarily accepted server certificate |
|
1168 HandleResponseAndCompleteL(); |
|
1169 } |
|
1170 break; |
|
1171 } |
|
1172 case EOperationSignTextShown: |
|
1173 { |
|
1174 if ( iRetValue || iOperation == EUserAuthentication ) |
|
1175 { |
|
1176 iNextStep = EOperationInitCertStore; |
|
1177 } |
|
1178 else |
|
1179 { |
|
1180 iNextStep = EOperationCompleted; |
|
1181 } |
|
1182 iStatus = KRequestPending; |
|
1183 SetActive(); |
|
1184 TRequestStatus* status = &iStatus; |
|
1185 User::RequestComplete( status, KErrNone ); |
|
1186 break; |
|
1187 } |
|
1188 case EOperationInitCertStore: |
|
1189 { |
|
1190 TInt err = KErrNone; |
|
1191 err = iFs.Connect(); |
|
1192 if( err != KErrNone && err != KErrAlreadyExists ) |
|
1193 { |
|
1194 User::Leave( KErrGeneral ); |
|
1195 } |
|
1196 |
|
1197 iCertStore = CUnifiedCertStore::NewL( iFs, EFalse ); |
|
1198 iCertArray = new (ELeave) CDesCArrayFlat( KCertArrayGranularity ); |
|
1199 iCertStore->Initialize( iStatus ); |
|
1200 iStatus = KRequestPending; |
|
1201 SetActive(); |
|
1202 iNextStep = EOperationRetrieveCertInfos; |
|
1203 break; |
|
1204 } |
|
1205 case EOperationRetrieveCertInfos: |
|
1206 { |
|
1207 if ( iCertInfo ) |
|
1208 { |
|
1209 iCertArray->AppendL( iCertInfo->Label() ); |
|
1210 iCertInfo = NULL; |
|
1211 } |
|
1212 if ( iHandleIndex == -1 ) |
|
1213 { |
|
1214 iFilter = CCertAttributeFilter::NewL(); |
|
1215 iCertStore->List( iCertInfos, *iFilter, iStatus ); |
|
1216 iNextStep = EOperationRetrieveCertInfos; |
|
1217 iStatus = KRequestPending; |
|
1218 SetActive(); |
|
1219 ++iHandleIndex; |
|
1220 } |
|
1221 else if ( iHandleIndex < iCertHandleList.Count() ) |
|
1222 { |
|
1223 iStatus = KRequestPending; |
|
1224 iCertStore->GetCert( iCertInfo, iCertHandleList[iHandleIndex], iStatus ); |
|
1225 ++iHandleIndex; |
|
1226 iNextStep = EOperationRetrieveCertInfos; |
|
1227 SetActive(); |
|
1228 } |
|
1229 else |
|
1230 { |
|
1231 iHandleIndex = -1; |
|
1232 iNextStep = EOperationSelectCert; |
|
1233 iStatus = KRequestPending; |
|
1234 SetActive(); |
|
1235 TRequestStatus* status = &iStatus; |
|
1236 User::RequestComplete( status, KErrNone ); |
|
1237 } |
|
1238 break; |
|
1239 } |
|
1240 case EOperationSelectCert: |
|
1241 { |
|
1242 DoHandleSelectCertificateL(); |
|
1243 break; |
|
1244 } |
|
1245 case EGetCertInfo: |
|
1246 { |
|
1247 iStatus = KRequestPending; |
|
1248 iCertInfo = NULL; |
|
1249 iCertStore->GetCert( iCertInfo, iTokenHandle, iStatus ); |
|
1250 iNextStep = EGetCertificate; |
|
1251 SetActive(); |
|
1252 break; |
|
1253 } |
|
1254 case EGetCertificate: |
|
1255 { |
|
1256 iStatus = KRequestPending; |
|
1257 if ( iCertInfo ) |
|
1258 { |
|
1259 iCertBuf = HBufC8::NewL( KMaxCertificateLength ); |
|
1260 iCertPtr.Set( iCertBuf->Des() ); |
|
1261 iCertStore->Retrieve( *iCertInfo, iCertPtr, iStatus ); |
|
1262 SetActive(); |
|
1263 } |
|
1264 else |
|
1265 { |
|
1266 SetActive(); |
|
1267 TRequestStatus* status = &iStatus; |
|
1268 User::RequestComplete( status, KErrNone ); |
|
1269 } |
|
1270 iNextStep = EInitKeyStore; |
|
1271 break; |
|
1272 } |
|
1273 case EInitKeyStore: |
|
1274 { |
|
1275 InitKeyStoreL(); |
|
1276 iNextStep = EGetKeyInfos; |
|
1277 break; |
|
1278 } |
|
1279 case EGetKeyInfos: |
|
1280 { |
|
1281 GetKeyInfosL(); |
|
1282 iNextStep = EShowCertDialog; |
|
1283 break; |
|
1284 } |
|
1285 case EGetKeyInfoByHandle: |
|
1286 { |
|
1287 GetKeyInfoByHandleL(); |
|
1288 iNextStep = EShowCSRDialog; |
|
1289 break; |
|
1290 } |
|
1291 case EShowCSRDialog: |
|
1292 { |
|
1293 ShowCSRDialogL(); |
|
1294 iNextStep = EOperationCompleted; |
|
1295 break; |
|
1296 } |
|
1297 case EShowCertDialog: |
|
1298 { |
|
1299 ShowCertDialogL(); |
|
1300 iNextStep = EOperationCompleted; |
|
1301 break; |
|
1302 } |
|
1303 ///////////// |
|
1304 // PIN steps |
|
1305 ///////////// |
|
1306 case EEnterNewPIN: |
|
1307 { |
|
1308 if ( iRetValue) |
|
1309 { |
|
1310 DoHandleMultilinePinQueryL( iMultiLineDlgType ); |
|
1311 iNextStep = EVerifyPINs; |
|
1312 iStatus = KRequestPending; |
|
1313 SetActive(); |
|
1314 } |
|
1315 else |
|
1316 { |
|
1317 iNextStep = EOperationCompleted; |
|
1318 iPINValue1 = KNullDesC; |
|
1319 iPINValue2 = KNullDesC; |
|
1320 HandleResponseAndCompleteL(); |
|
1321 } |
|
1322 break; |
|
1323 } |
|
1324 |
|
1325 case EVerifyNewPin: |
|
1326 { |
|
1327 if ( iRetValue ) |
|
1328 { |
|
1329 DoHandleMessageL( EVerifyPinNR, iPIN.iPINLabel, iPIN.iTokenLabel, |
|
1330 iPIN.iMinLength, iPIN.iMaxLength ); |
|
1331 iNextStep = EVerifyPINs; |
|
1332 iStatus = KRequestPending; |
|
1333 SetActive(); |
|
1334 } |
|
1335 //Dialog was cancelled by user |
|
1336 else |
|
1337 { |
|
1338 iNextStep = EOperationCompleted; |
|
1339 iPINValue1 = KNullDesC; |
|
1340 iPINValue2 = KNullDesC; |
|
1341 HandleResponseAndCompleteL(); |
|
1342 } |
|
1343 break; |
|
1344 } |
|
1345 case EVerifyPINs: |
|
1346 { |
|
1347 VerifyPinsL(); |
|
1348 break; |
|
1349 } |
|
1350 default: |
|
1351 { |
|
1352 User::Panic( _L("CTestSecDlgNotifier"), 0 ); |
|
1353 } |
|
1354 } |
|
1355 |
|
1356 } |
|
1357 |
|
1358 // ----------------------------------------------------------------------------- |
|
1359 // CCTSecurityDialogsAO::VerifyPinsL() |
|
1360 // ----------------------------------------------------------------------------- |
|
1361 // |
|
1362 void CCTSecurityDialogsAO::VerifyPinsL() |
|
1363 { |
|
1364 if ( iRetValue ) |
|
1365 { |
|
1366 if ( iPINValue2 == iPINValueVerify ) |
|
1367 { |
|
1368 HandleResponseAndCompleteL(); |
|
1369 } |
|
1370 else |
|
1371 { |
|
1372 DoHandleMessageL( EErrorCodesDoNotMatch, KNullDesC, KNullDesC, 0, 0 ); |
|
1373 iNextStep = EVerifyPINs; |
|
1374 iPINValue2.Zero(); |
|
1375 iPINValueVerify.Zero(); |
|
1376 DoHandleMultilinePinQueryL( iMultiLineDlgType ); |
|
1377 iStatus = KRequestPending; |
|
1378 SetActive(); |
|
1379 } |
|
1380 } |
|
1381 else |
|
1382 { |
|
1383 iPINValue1 = KNullDesC; |
|
1384 iPINValue2 = KNullDesC; |
|
1385 iNextStep = EOperationCompleted; |
|
1386 HandleResponseAndCompleteL(); |
|
1387 } |
|
1388 } |
|
1389 |
|
1390 // ----------------------------------------------------------------------------- |
|
1391 // CCTSecurityDialogsAO::DoHandleSelectCertificateL() |
|
1392 // ----------------------------------------------------------------------------- |
|
1393 // |
|
1394 void CCTSecurityDialogsAO::DoHandleSelectCertificateL() |
|
1395 { |
|
1396 TBool foundDevCert = EFalse; |
|
1397 |
|
1398 // Check certificate list to find out if there is certificate from |
|
1399 // Device Certificate Store. |
|
1400 for ( TInt ii = 0; ii < iCertHandleList.Count(); ii++) |
|
1401 { |
|
1402 TCTTokenObjectHandle handle = iCertHandleList[ii]; |
|
1403 if ( handle.iTokenHandle.iTokenTypeUid == KDeviceCertStoreTokenUid ) |
|
1404 { |
|
1405 // Found a certificate from Device Certificate Store. |
|
1406 foundDevCert = ETrue; |
|
1407 iTokenHandle = handle; |
|
1408 iRetValue = ETrue; |
|
1409 iNextStep = EOperationCompleted; |
|
1410 iStatus = KRequestPending; |
|
1411 SetActive(); |
|
1412 TRequestStatus* status = &iStatus; |
|
1413 User::RequestComplete( status, KErrNone ); |
|
1414 break; |
|
1415 } |
|
1416 |
|
1417 } |
|
1418 |
|
1419 if ( !foundDevCert ) |
|
1420 { |
|
1421 // No certificate from Device Certificate Store. Prompt user |
|
1422 // for certificate selection |
|
1423 CCTSelectCertificateDialog::RunDlgLD( |
|
1424 iCertArray, iCertHandleList, iTokenHandle, |
|
1425 iStatus, iRetValue ); // Takes ownerhip of array |
|
1426 |
|
1427 iNextStep = EOperationCompleted; |
|
1428 iStatus = KRequestPending; |
|
1429 SetActive(); |
|
1430 } |
|
1431 } |
|
1432 |
|
1433 // ----------------------------------------------------------------------------- |
|
1434 // CCTSecurityDialogsAO::ShowNoTrustDialogL() |
|
1435 // ----------------------------------------------------------------------------- |
|
1436 // |
|
1437 void CCTSecurityDialogsAO::ShowNoTrustDialogL() |
|
1438 { |
|
1439 CX509Certificate* cert = CX509Certificate::NewLC( iCertBuf->Des() ); |
|
1440 TInt resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
|
1441 TBool showPermAccept = ETrue; |
|
1442 |
|
1443 if( iAuthFailReason == ESignatureInvalid || iAuthFailReason == ECertificateRevoked ) |
|
1444 { |
|
1445 // Invalid or revoked certificate |
|
1446 CCTInvalidCertificateNote* note = |
|
1447 new( ELeave ) CCTInvalidCertificateNote( *this, iStatus ); |
|
1448 note->ExecuteLD( R_WIM_INVALID_CERTIFICATE_INFORMATION_NOTE ); |
|
1449 iRetValue = EServerCertNotAccepted; |
|
1450 } |
|
1451 else |
|
1452 { |
|
1453 if( iAuthFailReason == EValidatedOK || iAuthFailReason == EDateOutOfRange ) |
|
1454 { |
|
1455 // Trusted certificate, but problems with CN or date |
|
1456 |
|
1457 // Retrieve subject name |
|
1458 const CX500DistinguishedName& dName = cert->SubjectName(); |
|
1459 |
|
1460 // Retrieve common name |
|
1461 HBufC* cn = dName.ExtractFieldL( KX520CommonName ); |
|
1462 |
|
1463 // Check common name first and then date |
|
1464 if( !cn ) |
|
1465 { |
|
1466 // Couldn't retrieve CN from certificate |
|
1467 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
|
1468 } |
|
1469 else if( iServerName->Des() != cn->Des() ) |
|
1470 { |
|
1471 // Domain name doesn't match with CN |
|
1472 resourceid = R_WIM_NO_TRUST_QUERY_SITE; |
|
1473 } |
|
1474 else if( iAuthFailReason == EDateOutOfRange ) |
|
1475 { |
|
1476 // Certificate is out of date |
|
1477 resourceid = R_WIM_NO_TRUST_QUERY_OOD; |
|
1478 showPermAccept = EFalse; |
|
1479 } |
|
1480 else |
|
1481 { |
|
1482 // Otherwise show general untrusted note |
|
1483 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
|
1484 } |
|
1485 } |
|
1486 else |
|
1487 { |
|
1488 // Untrusted certificate |
|
1489 resourceid = R_WIM_NO_TRUST_QUERY_UNTRUSTED; |
|
1490 } |
|
1491 |
|
1492 // No "Accept Permanently" option if certificate is out of date, or |
|
1493 // if domain name is not defined. |
|
1494 const CValidityPeriod& validityPeriod = cert->ValidityPeriod(); |
|
1495 const TTime& startValue = validityPeriod.Start(); |
|
1496 const TTime& finishValue = validityPeriod.Finish(); |
|
1497 TTime current; |
|
1498 current.UniversalTime(); |
|
1499 |
|
1500 if( (( startValue > current ) || ( finishValue < current )) || |
|
1501 ( iServerName->Des().Length() == 0 ) ) |
|
1502 { |
|
1503 showPermAccept = EFalse; |
|
1504 } |
|
1505 |
|
1506 iQueryDialog = new( ELeave ) CCTNoTrustQuery( *this, iRetValue, iStatus, iServerName, |
|
1507 showPermAccept, iQueryDialogDeleted ); |
|
1508 iQueryDialog->ExecuteLD( resourceid ); |
|
1509 } |
|
1510 |
|
1511 CleanupStack::PopAndDestroy( cert ); |
|
1512 |
|
1513 iNextStep = EServerCertCheckUserResp; |
|
1514 iStatus = KRequestPending; |
|
1515 SetActive(); |
|
1516 } |
|
1517 |
|
1518 // ----------------------------------------------------------------------------- |
|
1519 // CCTSecurityDialogsAO::ShowCSRDialogL() |
|
1520 // ----------------------------------------------------------------------------- |
|
1521 // |
|
1522 void CCTSecurityDialogsAO::ShowCSRDialogL() |
|
1523 { |
|
1524 HBufC* message = HBufC::NewLC( KMaxLengthTextDetailsBody ); |
|
1525 TPtr messagePtr = message->Des(); |
|
1526 |
|
1527 DetailsResourceL( messagePtr, R_QTN_SN_CERT_SIGN_EXPLANATION ); |
|
1528 |
|
1529 messagePtr.Append( KEnter ); |
|
1530 |
|
1531 DetailsFieldDynamicL( messagePtr, *iText, |
|
1532 R_TEXT_RESOURCE_DETAILS_VIEW_SUBJECT, |
|
1533 R_TEXT_RESOURCE_VIEW_NO_SUBJECT_DETAILS ); |
|
1534 |
|
1535 AddKeyUsageL( messagePtr, iKeyInfo ); |
|
1536 AddKeyAlgorithmL( messagePtr, iKeyInfo ); |
|
1537 AddKeySizeL( messagePtr, iKeyInfo ); |
|
1538 AddKeyLocationL( messagePtr, iKeyInfo ); |
|
1539 |
|
1540 CCTSignTextDialog::RunDlgLD( R_WIM_CSR_DIALOG, *message, iStatus, iRetValue ); |
|
1541 CleanupStack::PopAndDestroy( message ); |
|
1542 |
|
1543 iStatus = KRequestPending; |
|
1544 SetActive(); |
|
1545 } |
|
1546 |
|
1547 // ----------------------------------------------------------------------------- |
|
1548 // CCTSecurityDialogsAO::ShowCertDialogL() |
|
1549 // ----------------------------------------------------------------------------- |
|
1550 // |
|
1551 void CCTSecurityDialogsAO::ShowCertDialogL() |
|
1552 { |
|
1553 CCTKeyInfo* keyInfo = NULL; |
|
1554 if ( 0 < iKeyInfos.Count() ) |
|
1555 { |
|
1556 keyInfo = iKeyInfos[0]; // There should be only one keyInfo. |
|
1557 } |
|
1558 else if ( iKeyInfo ) |
|
1559 { |
|
1560 keyInfo = iKeyInfo; |
|
1561 } |
|
1562 else |
|
1563 { |
|
1564 } |
|
1565 |
|
1566 HBufC* message = NULL; |
|
1567 |
|
1568 if (iOperation == ESaveCert) |
|
1569 { |
|
1570 message = MessageQueryCertDetailsL( *iCertBuf, NULL, iSaveCertInput.iCertFormat, NULL ); |
|
1571 } |
|
1572 else |
|
1573 { |
|
1574 message = MessageQueryCertDetailsL( *iCertBuf, iCertInfo, iCertInfo->CertificateFormat(), keyInfo ); |
|
1575 } |
|
1576 |
|
1577 CleanupStack::PushL( message ); |
|
1578 TInt resource = 0; |
|
1579 switch( iOperation ) |
|
1580 { |
|
1581 case ECertDetails: |
|
1582 { |
|
1583 resource = R_WIM_CERTDETAILS_DIALOG; |
|
1584 break; |
|
1585 } |
|
1586 case ESaveCert: |
|
1587 { |
|
1588 resource = R_WIM_SAVE_CERT_DIALOG; |
|
1589 break; |
|
1590 } |
|
1591 case EDeleteCert: |
|
1592 { |
|
1593 resource = R_WIM_DELETE_CERT_DIALOG; |
|
1594 break; |
|
1595 } |
|
1596 default: |
|
1597 { |
|
1598 User::Panic(_L("CTestSecDlgNotifier"), 0); |
|
1599 } |
|
1600 } |
|
1601 CCTSignTextDialog::RunDlgLD( resource, *message, iStatus, iRetValue ); |
|
1602 CleanupStack::PopAndDestroy( message ); |
|
1603 |
|
1604 iStatus = KRequestPending; |
|
1605 SetActive(); |
|
1606 } |
|
1607 |
|
1608 // --------------------------------------------------------- |
|
1609 // CCertManUICertificateHelper::MessageQueryViewDetailsL(TInt aIndex) |
|
1610 // Creates the whole of certificate details view |
|
1611 // Appends strings from both resources and CertManAPI to one |
|
1612 // message body text and displays it. |
|
1613 // --------------------------------------------------------- |
|
1614 // |
|
1615 HBufC* CCTSecurityDialogsAO::MessageQueryCertDetailsL( |
|
1616 const TDesC8& aCert, |
|
1617 const CCTCertInfo* aCertInfo, |
|
1618 TCertificateFormat aCertFormat, |
|
1619 const CCTKeyInfo* aKeyInfo) |
|
1620 { |
|
1621 // Create message buffer |
|
1622 HBufC* message = HBufC::NewLC( KMaxLengthTextDetailsBody ); |
|
1623 TPtr messagePtr = message->Des(); |
|
1624 // Label |
|
1625 if ( aCertInfo ) |
|
1626 { |
|
1627 DetailsFieldDynamicL( messagePtr, aCertInfo->Label(), |
|
1628 R_TEXT_RESOURCE_DETAILS_VIEW_LABEL, |
|
1629 R_TEXT_RESOURCE_VIEW_NO_LABEL_DETAILS ); |
|
1630 } |
|
1631 |
|
1632 switch ( aCertFormat ) |
|
1633 { |
|
1634 case EX509Certificate: |
|
1635 { |
|
1636 CX509Certificate* cert = CX509Certificate::NewLC( aCert ); |
|
1637 // Let's append all the fields to the message |
|
1638 AddSiteL( messagePtr ); |
|
1639 AddIssuerAndSubjectL( messagePtr, *cert ); |
|
1640 if( aKeyInfo ) |
|
1641 { |
|
1642 AddKeyUsageL( messagePtr, aKeyInfo ); |
|
1643 } |
|
1644 else |
|
1645 { |
|
1646 AddKeyUsageL( messagePtr, *cert ); |
|
1647 } |
|
1648 |
|
1649 AddValidityPeriodL( messagePtr, *cert ); |
|
1650 AddCertLocationL( messagePtr, aCertInfo ); |
|
1651 AddCertFormatL( messagePtr, aCertFormat ); |
|
1652 AddKeyLocationL( messagePtr, aKeyInfo ); |
|
1653 AddCertAlgorithmsL( messagePtr, *cert ); |
|
1654 AddCertSerialNumberL( messagePtr, *cert ); |
|
1655 AddCertFingerprintsL( messagePtr, *cert ); |
|
1656 CleanupStack::PopAndDestroy( cert ); |
|
1657 break; |
|
1658 } |
|
1659 case EX509CertificateUrl: |
|
1660 { |
|
1661 AddKeyUsageL( messagePtr, aKeyInfo ); |
|
1662 |
|
1663 if( aCertInfo ) |
|
1664 { |
|
1665 DetailsFieldDynamicL( messagePtr, aCertInfo->Label(), |
|
1666 R_TEXT_RESOURCE_DETAILS_VIEW_LABEL, |
|
1667 R_TEXT_RESOURCE_VIEW_NO_LABEL_DETAILS ); |
|
1668 } |
|
1669 HBufC* url = HBufC::NewLC( aCert.Length() ); |
|
1670 url->Des().Copy( aCert ); |
|
1671 DetailsFieldDynamicL( messagePtr, *url, |
|
1672 R_TEXT_RESOURCE_DETAILS_VIEW_CERTIFICATE_LOCATION, |
|
1673 R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED ); |
|
1674 CleanupStack::PopAndDestroy( url ); |
|
1675 AddCertFormatL( messagePtr, aCertFormat ); |
|
1676 AddKeyLocationL( messagePtr, aKeyInfo ); |
|
1677 break; |
|
1678 } |
|
1679 default: |
|
1680 { |
|
1681 User::Leave( KErrNotSupported ); |
|
1682 } |
|
1683 } |
|
1684 |
|
1685 CleanupStack::Pop( message ); |
|
1686 return message; |
|
1687 } |
|
1688 |
|
1689 // ----------------------------------------------------------------------------- |
|
1690 // CCTSecurityDialogsAO::AddIssuerAndSubjectL(...) |
|
1691 // ----------------------------------------------------------------------------- |
|
1692 // |
|
1693 void CCTSecurityDialogsAO::AddSiteL( TDes& aMessage ) |
|
1694 { |
|
1695 if ( iServerName ) |
|
1696 { |
|
1697 DetailsFieldDynamicL( aMessage, iServerName->Des(), |
|
1698 R_QTN_CM_SITE, |
|
1699 R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED ); |
|
1700 } |
|
1701 } |
|
1702 |
|
1703 // ----------------------------------------------------------------------------- |
|
1704 // CCTSecurityDialogsAO::AddIssuerAndSubjectL(...) |
|
1705 // ----------------------------------------------------------------------------- |
|
1706 // |
|
1707 void CCTSecurityDialogsAO::AddIssuerAndSubjectL( TDes& aMessage, const CX509Certificate& aCert ) |
|
1708 { |
|
1709 HBufC* issuer = NULL; |
|
1710 HBufC* owner = NULL; |
|
1711 X509CertNameParser::SubjectFullNameL( aCert, owner ); |
|
1712 CleanupStack::PushL( owner ); |
|
1713 X509CertNameParser::IssuerFullNameL( aCert, issuer ); |
|
1714 CleanupStack::PushL( issuer ); |
|
1715 |
|
1716 DetailsFieldDynamicL( aMessage, issuer->Des(), |
|
1717 R_TEXT_RESOURCE_DETAILS_VIEW_ISSUER, |
|
1718 R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED ); |
|
1719 CleanupStack::PopAndDestroy( issuer ); //issuer |
|
1720 |
|
1721 // certificate subject |
|
1722 DetailsFieldDynamicL( aMessage, owner->Des(), |
|
1723 R_TEXT_RESOURCE_DETAILS_VIEW_SUBJECT, |
|
1724 R_TEXT_RESOURCE_VIEW_NO_SUBJECT_DETAILS ); |
|
1725 CleanupStack::PopAndDestroy( owner ); //owner |
|
1726 } |
|
1727 |
|
1728 // ----------------------------------------------------------------------------- |
|
1729 // CCTSecurityDialogsAO::AddKeySizeL(...) |
|
1730 // ----------------------------------------------------------------------------- |
|
1731 // |
|
1732 void CCTSecurityDialogsAO::AddKeySizeL( TDes& aMessage, const CCTKeyInfo* aKeyInfo ) |
|
1733 { |
|
1734 TUint keySize = aKeyInfo->Size(); |
|
1735 |
|
1736 TBuf<KMaxLengthTextDateString> sizeBuf; |
|
1737 if ( 0 < keySize ) |
|
1738 { |
|
1739 sizeBuf.AppendNum( keySize, EDecimal ); |
|
1740 } |
|
1741 |
|
1742 DetailsFieldDynamicL( aMessage, sizeBuf, |
|
1743 R_QTN_SN_KEY_LENGTH_LABEL, |
|
1744 R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED ); |
|
1745 |
|
1746 aMessage.Append( KEnterEnter ); |
|
1747 } |
|
1748 |
|
1749 // ----------------------------------------------------------------------------- |
|
1750 // CCTSecurityDialogsAO::AddKeyUsageL(...) |
|
1751 // ----------------------------------------------------------------------------- |
|
1752 // |
|
1753 void CCTSecurityDialogsAO::AddKeyUsageL( TDes& aMessage, const CCTKeyInfo* aKeyInfo ) |
|
1754 { |
|
1755 if ( aKeyInfo != NULL ) |
|
1756 { |
|
1757 TKeyUsagePKCS15 keyUsage = aKeyInfo->Usage(); |
|
1758 |
|
1759 TInt usage = 0; |
|
1760 switch( keyUsage ) |
|
1761 { |
|
1762 case EPKCS15UsageSignSignRecover: |
|
1763 case EPKCS15UsageSign: |
|
1764 case EPKCS15UsageSignDecrypt: |
|
1765 usage = R_TEXT_RESOURCE_DETAILS_VIEW_CLIENT_AUTHENTICATION; |
|
1766 break; |
|
1767 case EPKCS15UsageNonRepudiation: |
|
1768 usage = R_TEXT_RESOURCE_DETAILS_VIEW_DIGITAL_SIGNING; |
|
1769 break; |
|
1770 default: |
|
1771 usage = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED; |
|
1772 break; |
|
1773 } |
|
1774 DetailsFieldResourceL( aMessage, |
|
1775 R_TEXT_RESOURCE_DETAILS_VIEW_KEY_USAGE, usage); |
|
1776 } |
|
1777 } |
|
1778 |
|
1779 // ----------------------------------------------------------------------------- |
|
1780 // CCTSecurityDialogsAO::AddKeyUsageL(...) |
|
1781 // ----------------------------------------------------------------------------- |
|
1782 // |
|
1783 void CCTSecurityDialogsAO::AddKeyUsageL( TDes& aMessage, const CX509Certificate& aCert ) |
|
1784 { |
|
1785 TKeyUsageX509 x509Usage = EX509UsageNone; |
|
1786 TKeyUsagePKCS15 pkcs15KeyUsage = EPKCS15UsageNone; |
|
1787 const CX509CertExtension* ext = aCert.Extension(KKeyUsage); |
|
1788 if ( ext ) |
|
1789 { |
|
1790 CX509KeyUsageExt* keyUsageExt = |
|
1791 CX509KeyUsageExt::NewLC(ext->Data()); |
|
1792 if ( keyUsageExt->IsSet( EX509DigitalSignature ) ) |
|
1793 { |
|
1794 x509Usage |= EX509UsageDigitalSignature; |
|
1795 } |
|
1796 if ( keyUsageExt->IsSet( EX509NonRepudiation ) ) |
|
1797 { |
|
1798 x509Usage |= EX509UsageNonRepudiation; |
|
1799 } |
|
1800 if ( keyUsageExt->IsSet( EX509KeyEncipherment ) ) |
|
1801 { |
|
1802 x509Usage |= EX509UsageKeyEncipherment; |
|
1803 } |
|
1804 if ( keyUsageExt->IsSet( EX509DataEncipherment ) ) |
|
1805 { |
|
1806 x509Usage |= EX509UsageDataEncipherment; |
|
1807 } |
|
1808 if ( keyUsageExt->IsSet( EX509KeyAgreement ) ) |
|
1809 { |
|
1810 x509Usage |= EX509UsageKeyAgreement; |
|
1811 } |
|
1812 if ( keyUsageExt->IsSet( EX509KeyCertSign ) ) |
|
1813 { |
|
1814 x509Usage |= EX509UsageKeyCertSign; |
|
1815 } |
|
1816 if ( keyUsageExt->IsSet( EX509CRLSign ) ) |
|
1817 { |
|
1818 x509Usage |= EX509UsageCRLSign; |
|
1819 } |
|
1820 if ( keyUsageExt->IsSet( EX509EncipherOnly ) ) |
|
1821 { |
|
1822 x509Usage |= EX509UsageEncipherOnly; |
|
1823 } |
|
1824 if ( keyUsageExt->IsSet( EX509DecipherOnly ) ) |
|
1825 { |
|
1826 x509Usage |= EX509UsageDecipherOnly; |
|
1827 } |
|
1828 CleanupStack::PopAndDestroy( keyUsageExt ); |
|
1829 } |
|
1830 |
|
1831 pkcs15KeyUsage = KeyUsageX509ToPKCS15Private( x509Usage ); |
|
1832 |
|
1833 TInt usage = 0; |
|
1834 switch( pkcs15KeyUsage ) |
|
1835 { |
|
1836 case EPKCS15UsageSignSignRecover: |
|
1837 case EPKCS15UsageSign: |
|
1838 case EPKCS15UsageSignDecrypt: |
|
1839 { |
|
1840 usage = R_TEXT_RESOURCE_DETAILS_VIEW_CLIENT_AUTHENTICATION; |
|
1841 break; |
|
1842 } |
|
1843 case EPKCS15UsageNonRepudiation: |
|
1844 { |
|
1845 usage = R_TEXT_RESOURCE_DETAILS_VIEW_DIGITAL_SIGNING; |
|
1846 break; |
|
1847 } |
|
1848 default: |
|
1849 { |
|
1850 usage = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED; |
|
1851 break; |
|
1852 } |
|
1853 |
|
1854 } |
|
1855 DetailsFieldResourceL( aMessage, |
|
1856 R_TEXT_RESOURCE_DETAILS_VIEW_KEY_USAGE, usage ); |
|
1857 } |
|
1858 |
|
1859 // ----------------------------------------------------------------------------- |
|
1860 // CCTSecurityDialogsAO::AddKeyAlgorithmL(...) |
|
1861 // ----------------------------------------------------------------------------- |
|
1862 // |
|
1863 void CCTSecurityDialogsAO::AddKeyAlgorithmL( TDes& aMessage, const CCTKeyInfo* aKeyInfo ) |
|
1864 { |
|
1865 TInt algRes = 0; |
|
1866 switch( aKeyInfo->Algorithm()) |
|
1867 { |
|
1868 case CKeyInfoBase::ERSA: |
|
1869 { |
|
1870 algRes = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_RSA; |
|
1871 break; |
|
1872 } |
|
1873 case CKeyInfoBase::EDSA: |
|
1874 { |
|
1875 algRes = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_DSA; |
|
1876 break; |
|
1877 } |
|
1878 case CKeyInfoBase::EDH: |
|
1879 { |
|
1880 algRes = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_DH; |
|
1881 break; |
|
1882 } |
|
1883 case CKeyInfoBase::EInvalidAlgorithm: |
|
1884 { |
|
1885 algRes = R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN; |
|
1886 break; |
|
1887 } |
|
1888 default: |
|
1889 { |
|
1890 algRes = R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN; |
|
1891 } |
|
1892 } |
|
1893 DetailsFieldResourceL( aMessage, |
|
1894 R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM, algRes); |
|
1895 } |
|
1896 |
|
1897 // ----------------------------------------------------------------------------- |
|
1898 // CCTSecurityDialogsAO::AddCertLocationL(...) |
|
1899 // ----------------------------------------------------------------------------- |
|
1900 // |
|
1901 void CCTSecurityDialogsAO::AddCertLocationL( TDes& aMessage, const CCTCertInfo* aCertInfo ) |
|
1902 { |
|
1903 if ( aCertInfo ) |
|
1904 { |
|
1905 AddLocationInfoL( aMessage, aCertInfo->Token().TokenType().Type(), ETrue ); |
|
1906 } |
|
1907 } |
|
1908 |
|
1909 // ----------------------------------------------------------------------------- |
|
1910 // CCTSecurityDialogsAO::AddKeyLocationL(...) |
|
1911 // ----------------------------------------------------------------------------- |
|
1912 // |
|
1913 void CCTSecurityDialogsAO::AddKeyLocationL( TDes& aMessage, const CCTKeyInfo* aKeyInfo ) |
|
1914 { |
|
1915 if ( aKeyInfo ) |
|
1916 { |
|
1917 AddLocationInfoL( aMessage, aKeyInfo->Token().TokenType().Type(), EFalse ); |
|
1918 } |
|
1919 } |
|
1920 |
|
1921 // --------------------------------------------------------- |
|
1922 // CCTSecurityDialogsAO::SetLocationInfo( (HBufC& aMessage, |
|
1923 // TBool aCertificate, |
|
1924 // TUid* aLocUid) |
|
1925 // Adds certificate/private key's location info to certificate details |
|
1926 // --------------------------------------------------------- |
|
1927 // |
|
1928 void CCTSecurityDialogsAO::AddLocationInfoL( |
|
1929 TDes& aMessage, TUid aUid, TBool aCertificate ) |
|
1930 { |
|
1931 TInt location = 0; |
|
1932 TInt locationRes =0; |
|
1933 |
|
1934 switch ( aUid.iUid ) |
|
1935 { |
|
1936 case KFileCertStoreUid: |
|
1937 case KTokenTypeFileKeystore: |
|
1938 { |
|
1939 location = R_TEXT_RESOURCE_DETAILS_VIEW_LOCATION_PHONE_MEMORY; |
|
1940 break; |
|
1941 } |
|
1942 case KWIMCertStoreUid: |
|
1943 { |
|
1944 location = R_TEXT_RESOURCE_DETAILS_VIEW_LOCATION_SMART_CARD; |
|
1945 break; |
|
1946 } |
|
1947 default: |
|
1948 { |
|
1949 if ( aCertificate ) |
|
1950 { |
|
1951 location = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED; |
|
1952 } |
|
1953 else |
|
1954 { |
|
1955 location = R_TEXT_RESOURCE_DETAILS_VIEW_NO_PRIVATE_KEY; |
|
1956 } |
|
1957 break; |
|
1958 } |
|
1959 } |
|
1960 |
|
1961 if ( aCertificate ) |
|
1962 { |
|
1963 locationRes = R_TEXT_RESOURCE_DETAILS_VIEW_CERTIFICATE_LOCATION; |
|
1964 } |
|
1965 else |
|
1966 { |
|
1967 locationRes = R_TEXT_RESOURCE_DETAILS_VIEW_PRIVATE_KEY_LOCATION; |
|
1968 } |
|
1969 |
|
1970 DetailsFieldResourceL( aMessage, locationRes, location ); |
|
1971 } |
|
1972 |
|
1973 // ----------------------------------------------------------------------------- |
|
1974 // CCTSecurityDialogsAO::AddValidityPeriodL(...) |
|
1975 // ----------------------------------------------------------------------------- |
|
1976 // |
|
1977 void CCTSecurityDialogsAO::AddValidityPeriodL( |
|
1978 TDes& aMessage, const CX509Certificate& aCert ) |
|
1979 { |
|
1980 TLocale locale; |
|
1981 TTimeIntervalSeconds offSet = locale.UniversalTimeOffset(); |
|
1982 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_VALID_FROM ); |
|
1983 const CValidityPeriod& validityPeriod = aCert.ValidityPeriod(); |
|
1984 TTime startValue = validityPeriod.Start(); |
|
1985 startValue += offSet; |
|
1986 TBuf<KMaxLengthTextDateString> startString; |
|
1987 // read format string from AVKON resource |
|
1988 HBufC* dateFormatString = CEikonEnv::Static()->AllocReadResourceLC( |
|
1989 R_QTN_DATE_USUAL_WITH_ZERO ); |
|
1990 // format the date to user readable format. The format is locale dependent |
|
1991 startValue.FormatL( startString, *dateFormatString ); |
|
1992 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( startString ); |
|
1993 CleanupStack::PopAndDestroy(); // dateFormatString |
|
1994 aMessage.Append( startString ); |
|
1995 aMessage.Append( KEnterEnter ); |
|
1996 |
|
1997 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_VALID_UNTIL ); |
|
1998 TTime finishValue = validityPeriod.Finish(); |
|
1999 finishValue += offSet; |
|
2000 TBuf<KMaxLengthTextDateString> finishString; |
|
2001 // read format string from AVKON resource |
|
2002 dateFormatString = CEikonEnv::Static()->AllocReadResourceLC( |
|
2003 R_QTN_DATE_USUAL_WITH_ZERO ); |
|
2004 // format the date to user readable format. The format is locale dependent |
|
2005 finishValue.FormatL( finishString, *dateFormatString ); |
|
2006 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(finishString); |
|
2007 CleanupStack::PopAndDestroy(); // dateFormatString |
|
2008 aMessage.Append( finishString ); |
|
2009 aMessage.Append( KEnterEnter ); |
|
2010 } |
|
2011 |
|
2012 // ----------------------------------------------------------------------------- |
|
2013 // CCTSecurityDialogsAO::AddCertFormatL(...) |
|
2014 // ----------------------------------------------------------------------------- |
|
2015 // |
|
2016 void CCTSecurityDialogsAO::AddCertFormatL( TDes& aMessage, TCertificateFormat aCertFormat) |
|
2017 { |
|
2018 TInt fieldType = 0; |
|
2019 switch ( aCertFormat ) |
|
2020 { |
|
2021 case EX509CertificateUrl: |
|
2022 case EX509Certificate: |
|
2023 { |
|
2024 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_CERT_FORMAT_X509; |
|
2025 break; |
|
2026 } |
|
2027 default: |
|
2028 { |
|
2029 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_NOT_DEFINED; |
|
2030 break; |
|
2031 } |
|
2032 } |
|
2033 DetailsFieldResourceL( aMessage, |
|
2034 R_TEXT_RESOURCE_DETAILS_VIEW_CERT_FORMAT, fieldType ); |
|
2035 } |
|
2036 |
|
2037 // ----------------------------------------------------------------------------- |
|
2038 // CCTSecurityDialogsAO::AddCertAlgorithmsL(...) |
|
2039 // ----------------------------------------------------------------------------- |
|
2040 // |
|
2041 void CCTSecurityDialogsAO::AddCertAlgorithmsL( TDes& aMessage, const CX509Certificate& aCert ) |
|
2042 { |
|
2043 TInt fieldType = 0; |
|
2044 TInt fieldType2 = 0; |
|
2045 // digest algorithm |
|
2046 TAlgorithmId algorithmId = |
|
2047 aCert.SigningAlgorithm().DigestAlgorithm().Algorithm(); |
|
2048 switch ( algorithmId ) |
|
2049 { |
|
2050 case EMD2: |
|
2051 { |
|
2052 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_MD2; |
|
2053 break; |
|
2054 } |
|
2055 case EMD5: |
|
2056 { |
|
2057 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_MD5; |
|
2058 break; |
|
2059 } |
|
2060 case ESHA1: |
|
2061 { |
|
2062 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_SHA1; |
|
2063 break; |
|
2064 } |
|
2065 default: |
|
2066 { |
|
2067 fieldType = R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN; |
|
2068 break; |
|
2069 } |
|
2070 } |
|
2071 |
|
2072 // public-key algorithm |
|
2073 algorithmId = |
|
2074 aCert.SigningAlgorithm().AsymmetricAlgorithm().Algorithm(); |
|
2075 switch ( algorithmId ) |
|
2076 { |
|
2077 case ERSA: |
|
2078 { |
|
2079 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_RSA; |
|
2080 break; |
|
2081 } |
|
2082 case EDSA: |
|
2083 { |
|
2084 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_DSA; |
|
2085 break; |
|
2086 } |
|
2087 case EDH: |
|
2088 { |
|
2089 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM_DH; |
|
2090 break; |
|
2091 } |
|
2092 default: |
|
2093 { |
|
2094 fieldType2 = R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN; |
|
2095 } |
|
2096 } |
|
2097 |
|
2098 // If other algorithm is unknown |
|
2099 if ( fieldType == R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN || |
|
2100 fieldType2 == R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN ) |
|
2101 { |
|
2102 DetailsFieldResourceL( aMessage, |
|
2103 R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM, R_TEXT_RESOURCE_DETAILS_VIEW_UNKNOWN ); |
|
2104 } |
|
2105 else // Both are known. |
|
2106 { |
|
2107 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_ALGORITHM); |
|
2108 HBufC* stringHolder = StringLoader::LoadLC( fieldType ); |
|
2109 aMessage.Append( stringHolder->Des() ); |
|
2110 CleanupStack::PopAndDestroy(); |
|
2111 stringHolder = StringLoader::LoadLC( fieldType2 ); |
|
2112 aMessage.Append( stringHolder->Des() ); |
|
2113 CleanupStack::PopAndDestroy(); // stringHolder |
|
2114 aMessage.Append( KEnterEnter ); |
|
2115 } |
|
2116 } |
|
2117 |
|
2118 // ----------------------------------------------------------------------------- |
|
2119 // CCTSecurityDialogsAO::AddCertSerialNumberL(...) |
|
2120 // ----------------------------------------------------------------------------- |
|
2121 // |
|
2122 void CCTSecurityDialogsAO::AddCertSerialNumberL( TDes& aMessage, const CX509Certificate& aCert ) |
|
2123 { |
|
2124 // certificate serial number |
|
2125 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_SERIAL_NUMBER ); |
|
2126 TPtrC8 serialNumber = aCert.SerialNumber(); |
|
2127 TBuf<KMaxLengthTextSerialNumberFormatting> buf2; |
|
2128 |
|
2129 for ( TInt i = 0; i < serialNumber.Length(); i++ ) |
|
2130 { |
|
2131 buf2.Format( KCertManUIDetailsViewHexFormat, serialNumber[i] ); |
|
2132 aMessage.Append( buf2 ); |
|
2133 } |
|
2134 |
|
2135 aMessage.Append( KEnterEnter ); |
|
2136 } |
|
2137 |
|
2138 // ----------------------------------------------------------------------------- |
|
2139 // CCTSecurityDialogsAO::AddCertFingerprintsL(...) |
|
2140 // ----------------------------------------------------------------------------- |
|
2141 // |
|
2142 void CCTSecurityDialogsAO::AddCertFingerprintsL( TDes& aMessage, const CX509Certificate& aCert ) |
|
2143 { |
|
2144 // certificate fingerprint SHA-1 |
|
2145 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_FINGERPRINT ); |
|
2146 |
|
2147 TPtrC8 sha1_fingerprint = aCert.Fingerprint(); |
|
2148 DevideToBlocks( sha1_fingerprint, aMessage ); |
|
2149 |
|
2150 aMessage.Append( KEnterEnter ); |
|
2151 |
|
2152 // certificate fingerprint MD5 |
|
2153 DetailsResourceL( aMessage, R_TEXT_RESOURCE_DETAILS_VIEW_FINGERPRINT_MD5 ); |
|
2154 |
|
2155 CMD5* md5 = CMD5::NewL(); |
|
2156 CleanupStack::PushL( md5 ); |
|
2157 TBuf8<20> fingerprint = md5->Hash( aCert.Encoding() ); |
|
2158 CleanupStack::PopAndDestroy( md5 ); |
|
2159 |
|
2160 DevideToBlocks( fingerprint, aMessage ); |
|
2161 } |
|
2162 |
|
2163 // --------------------------------------------------------- |
|
2164 // CCTSecurityDialogsAO::DevideToBlocks |
|
2165 // --------------------------------------------------------- |
|
2166 // |
|
2167 void CCTSecurityDialogsAO::DevideToBlocks( const TDesC8& aInput, TDes& aOutput ) |
|
2168 { |
|
2169 const TInt KBlockLength = 2; |
|
2170 TInt blockIndex = 0; |
|
2171 for ( TInt j = 0 ; j < aInput.Length() ; j++ ) |
|
2172 { |
|
2173 if ( blockIndex == KBlockLength ) |
|
2174 { |
|
2175 aOutput.Append( KBlockSeparator ); |
|
2176 blockIndex = 0; |
|
2177 } |
|
2178 aOutput.AppendNumFixedWidthUC( (TUint)(aInput[ j ]), EHex, 2 ); |
|
2179 ++blockIndex; |
|
2180 } |
|
2181 } |
|
2182 |
|
2183 // --------------------------------------------------------- |
|
2184 // CCTSecurityDialogsAO::DetailsFieldResourceL( |
|
2185 // HBufC& aMessage, TInt aResourceOne, TInt aResourceTwo); |
|
2186 // Appends a field that has two strings from resources |
|
2187 // to the details view message body |
|
2188 // --------------------------------------------------------- |
|
2189 // |
|
2190 void CCTSecurityDialogsAO::DetailsFieldResourceL( |
|
2191 TDes& aMessage, TInt aResourceOne, |
|
2192 TInt aResourceTwo ) |
|
2193 { |
|
2194 DetailsResourceL( aMessage, aResourceOne ); |
|
2195 DetailsResourceL( aMessage, aResourceTwo ); |
|
2196 aMessage.Append( KEnter ); |
|
2197 } |
|
2198 |
|
2199 // --------------------------------------------------------- |
|
2200 // CCTSecurityDialogsAO::DetailsFieldDynamicL(HBufC& aMessage, TPtrC aValue, |
|
2201 // TInt aResourceOne, TInt aResourceTwo); |
|
2202 // Appends a field that has string from resources and string from CertManAPI |
|
2203 // to the details view message body |
|
2204 // --------------------------------------------------------- |
|
2205 // |
|
2206 void CCTSecurityDialogsAO::DetailsFieldDynamicL( |
|
2207 TDes& aMessage, |
|
2208 const TDesC& aValue, |
|
2209 TInt aResourceOne, |
|
2210 TInt aResourceTwo) |
|
2211 { |
|
2212 DetailsResourceL( aMessage, aResourceOne ); |
|
2213 DetailsDynamicL( aMessage, aValue, aResourceTwo ); |
|
2214 aMessage.Append( KEnter ); |
|
2215 } |
|
2216 |
|
2217 // --------------------------------------------------------- |
|
2218 // CCTSecurityDialogsAO::DetailsResourceL( |
|
2219 // HBufC& aMessage, TInt aResourceOne); |
|
2220 // Reads line from resources |
|
2221 // --------------------------------------------------------- |
|
2222 // |
|
2223 void CCTSecurityDialogsAO::DetailsResourceL( |
|
2224 TDes& aMessage, TInt aResource) |
|
2225 { |
|
2226 HBufC* stringHolder = StringLoader::LoadLC( aResource ); |
|
2227 aMessage.Append( stringHolder->Des() ); |
|
2228 CleanupStack::PopAndDestroy(); // stringHolder |
|
2229 aMessage.Append( KEnter ); |
|
2230 } |
|
2231 |
|
2232 // --------------------------------------------------------- |
|
2233 // CCTSecurityDialogsAO::DetailsDynamicL( |
|
2234 // HBufC& aMessage, TPtrC aValue, TInt aResourceOne) |
|
2235 // Reads dynamic text, if the string is empty |
|
2236 // put a not defined text from the resource in its place |
|
2237 // KMaxLengthTextCertLabel = 510, used by CertLabel(), Issuer(), Owner() |
|
2238 // --------------------------------------------------------- |
|
2239 // |
|
2240 void CCTSecurityDialogsAO::DetailsDynamicL( |
|
2241 TDes& aMessage, const TDesC& aValue, TInt aResource) |
|
2242 { |
|
2243 HBufC* buf = HBufC::NewLC( KMaxLengthTextCertLabel ); |
|
2244 buf->Des() = aValue; |
|
2245 buf->Des().TrimLeft(); |
|
2246 // Cut CertLabel after fourth semi colon |
|
2247 TPtrC trimmedCertLabel = CutCertificateField( buf->Des() ); |
|
2248 buf->Des().Copy( trimmedCertLabel ); |
|
2249 TInt length = buf->Des().Length(); |
|
2250 if (length == 0 ) |
|
2251 { |
|
2252 DetailsResourceL( aMessage, aResource ); |
|
2253 } |
|
2254 else |
|
2255 { |
|
2256 aMessage.Append( buf->Des() ); |
|
2257 aMessage.Append( KEnter ); |
|
2258 } |
|
2259 CleanupStack::PopAndDestroy(); // buf |
|
2260 } |
|
2261 |
|
2262 // --------------------------------------------------------- |
|
2263 // CCTSecurityDialogsAO::CutCertificateField(TPtrC aField) |
|
2264 // If CertLabel, Issuer and Owner length is over 80 characters, |
|
2265 // cut it down to 80 |
|
2266 // Returns the cut certificate field. |
|
2267 // --------------------------------------------------------- |
|
2268 // |
|
2269 TPtrC CCTSecurityDialogsAO::CutCertificateField( const TDesC& aField ) |
|
2270 { |
|
2271 TInt fieldLength = aField.Length(); |
|
2272 if ( fieldLength >= KMaxLengthTextCertLabelVisible ) |
|
2273 { |
|
2274 TPtrC cutCertLabel = aField.Mid( 0, KMaxLengthTextCertLabelVisible ); |
|
2275 return cutCertLabel; |
|
2276 } |
|
2277 return aField; |
|
2278 } |
|
2279 |
|
2280 // ----------------------------------------------------------------------------- |
|
2281 // CCTSecurityDialogsAO::HandleResponseAndCompleteL() |
|
2282 // ----------------------------------------------------------------------------- |
|
2283 // |
|
2284 void CCTSecurityDialogsAO::HandleResponseAndCompleteL() |
|
2285 { |
|
2286 WIMSECURITYDIALOGS_WRITE_FORMAT( "HandleResponseAndCompleteL: %d", iRetValue ); |
|
2287 |
|
2288 MapTlsProviderOperation(iOperation); |
|
2289 |
|
2290 switch (iOperation) |
|
2291 { |
|
2292 case EEnablePIN: // flow thru |
|
2293 case EDisablePIN: // flow thru |
|
2294 case EEnterPIN: |
|
2295 { |
|
2296 TPINValueBuf pinValueBufPtr; |
|
2297 if ( iPIN.iPINLabel == KKeyStoreCreatePwLabel || |
|
2298 iPIN.iPINLabel == KKeyStoreExportKeyLabel ) |
|
2299 { |
|
2300 pinValueBufPtr = iPINValue2; |
|
2301 } |
|
2302 else |
|
2303 { |
|
2304 pinValueBufPtr = iPINValue1; |
|
2305 } |
|
2306 iMessagePtr.WriteL( iReplySlot, pinValueBufPtr ); |
|
2307 break; |
|
2308 } |
|
2309 case EChangePIN: |
|
2310 case EUnblockPIN: |
|
2311 { |
|
2312 TTwoPINOutput twoPINOutput; |
|
2313 twoPINOutput.iPINValueToCheck = iPINValue1; |
|
2314 twoPINOutput.iNewPINValue = iPINValue2; |
|
2315 TTwoPINOutputBuf twoPINOutputBuf( twoPINOutput ); |
|
2316 iMessagePtr.WriteL( iReplySlot, twoPINOutputBuf ); |
|
2317 break; |
|
2318 } |
|
2319 case ESignText: // flow thru |
|
2320 case EUserAuthenticationText: // flow thru |
|
2321 case EUserAuthentication: |
|
2322 { |
|
2323 TCTTokenObjectHandleBuf tokenObjectHandleBuf( iTokenHandle ); |
|
2324 iMessagePtr.WriteL( iReplySlot, tokenObjectHandleBuf ); |
|
2325 break; |
|
2326 } |
|
2327 case EServerAuthenticationFailure: |
|
2328 { |
|
2329 TServerAuthenticationFailureDialogResult result = EStop; |
|
2330 |
|
2331 if ( iRetValue != EServerCertAcceptedPermanently ) |
|
2332 { |
|
2333 if ( iRetValue == EServerCertAcceptedTemporarily ) |
|
2334 { |
|
2335 result = EContinue; |
|
2336 } |
|
2337 else |
|
2338 { |
|
2339 result = EStop; |
|
2340 } |
|
2341 } |
|
2342 else |
|
2343 { |
|
2344 // User permanently accepted server certificate. |
|
2345 result = EContinue; |
|
2346 } |
|
2347 |
|
2348 TServerAuthenticationFailureOutputBuf output( result ); |
|
2349 iMessagePtr.WriteL( iReplySlot, output ); |
|
2350 iMessagePtr.Complete( KErrNone ); |
|
2351 |
|
2352 break; |
|
2353 } |
|
2354 case EPINBlocked: |
|
2355 case EUnblockPINInClear: |
|
2356 { |
|
2357 User::Leave( KErrNotSupported ); |
|
2358 break; |
|
2359 } |
|
2360 case ECreateCSR: |
|
2361 case ECertDetails: |
|
2362 case ESaveCert: |
|
2363 case EDeleteCert: |
|
2364 case ESaveReceipt: |
|
2365 case EPinCodeBlockedInfo: |
|
2366 case MDigSigningNote::ESignatureRequested: |
|
2367 case MDigSigningNote::ESignatureDone: |
|
2368 case MDigSigningNote::ESigningCancelled: |
|
2369 case MDigSigningNote::ENoMatchCert: |
|
2370 case MDigSigningNote::ENoSecurityModule: |
|
2371 case MDigSigningNote::EInternalError: |
|
2372 { |
|
2373 break; // Complete is enough |
|
2374 } |
|
2375 default: |
|
2376 User::Panic( _L("CTestSecDlgNotifier"), 0 ); |
|
2377 } |
|
2378 |
|
2379 if( iOperation != EServerAuthenticationFailure ) |
|
2380 { |
|
2381 iMessagePtr.Complete( iRetValue ? KErrNone : KErrCancel ); |
|
2382 } |
|
2383 |
|
2384 delete this; |
|
2385 } |
|
2386 |
|
2387 // ----------------------------------------------------------------------------- |
|
2388 // CCTSecurityDialogsAO::SaveReceiptL() |
|
2389 // ----------------------------------------------------------------------------- |
|
2390 // |
|
2391 void CCTSecurityDialogsAO::SaveReceiptL( const TDesC8& aBuffer ) |
|
2392 { |
|
2393 TInt size = reinterpret_cast<const TInt&>( *aBuffer.Ptr() ); |
|
2394 TInt start = sizeof(TInt) + 1; |
|
2395 HBufC* signedText = HBufC::NewLC( size ); |
|
2396 signedText->Des().Copy( aBuffer.Mid(start) ); |
|
2397 CEikProcess* process = CEikonEnv::Static()->Process(); |
|
2398 CDocumentHandler* docHandler = CDocumentHandler::NewLC( process ); |
|
2399 _LIT8( KPlainText, "text/plain" ); |
|
2400 TDataType dataType( KPlainText ); |
|
2401 // convert 16->8bits |
|
2402 HBufC8* content = HBufC8::NewLC( signedText->Length() ); |
|
2403 content->Des().Copy( *signedText ); |
|
2404 |
|
2405 docHandler->SaveL( *content, |
|
2406 dataType, |
|
2407 KEntryAttNormal); |
|
2408 |
|
2409 CleanupStack::PopAndDestroy( 3, signedText ); // content, docHandler, signedText |
|
2410 HandleResponseAndCompleteL(); |
|
2411 } |
|
2412 |
|
2413 // ----------------------------------------------------------------------------- |
|
2414 // CCTSecurityDialogsAO::DoCancel() |
|
2415 // ?implementation_description |
|
2416 // (other items were commented in a header). |
|
2417 // ----------------------------------------------------------------------------- |
|
2418 // |
|
2419 void CCTSecurityDialogsAO::DoCancel() |
|
2420 { |
|
2421 WIMSECURITYDIALOGS_WRITE( "CCTSecurityDialogsAO::DoCancel" ); |
|
2422 |
|
2423 // Note that iQueryDialog may point to already deleted memory. |
|
2424 // Dialogs need to set and reset iQueryDialogDeleted flag to |
|
2425 // allow deleting the dialog from CCTSecurityDialogsAO. |
|
2426 if( !iQueryDialogDeleted ) |
|
2427 { |
|
2428 delete iQueryDialog; |
|
2429 iQueryDialogDeleted = ETrue; |
|
2430 } |
|
2431 iQueryDialog = NULL; |
|
2432 |
|
2433 if ( !iPinQueryDialogDeleted ) |
|
2434 { |
|
2435 delete iPinQueryDialog; |
|
2436 iPinQueryDialogDeleted = ETrue; |
|
2437 } |
|
2438 iPinQueryDialog = NULL; |
|
2439 |
|
2440 // Complete message if it has not been completed earlier. |
|
2441 if( !iMessagePtr.IsNull() ) |
|
2442 { |
|
2443 iMessagePtr.Complete( KErrCancel ); |
|
2444 } |
|
2445 } |
|
2446 |
|
2447 // For server authentication failure |
|
2448 // ----------------------------------------------------------------------------- |
|
2449 // CCTSecurityDialogsAO::CreateMessageLC() |
|
2450 // ----------------------------------------------------------------------------- |
|
2451 |
|
2452 HBufC* CCTSecurityDialogsAO::CreateMessageL() |
|
2453 { |
|
2454 //TPtrC8 certPtrC; |
|
2455 //iSrvAuthFail->GetEncodedCert(certPtrC); |
|
2456 return MessageQueryCertDetailsL( |
|
2457 *iCertBuf, NULL, EX509Certificate, NULL ); |
|
2458 } |
|
2459 |
|
2460 // ----------------------------------------------------------------------------- |
|
2461 // CCTSecurityDialogsAO::DoHandleSaveServerCertL() |
|
2462 // ----------------------------------------------------------------------------- |
|
2463 // |
|
2464 void CCTSecurityDialogsAO::DoHandleSaveServerCertL() |
|
2465 { |
|
2466 if ( iTrustedSiteCertStore ) |
|
2467 { |
|
2468 iTrustedSiteCertStore->Add( *iCertLabel, EX509Certificate, |
|
2469 EPeerCertificate, NULL, NULL, *iCertBuf, iStatus ); |
|
2470 |
|
2471 // Next step is to update trust site db |
|
2472 iNextStep = EAddTrustedSite; |
|
2473 iStatus = KRequestPending; |
|
2474 SetActive(); |
|
2475 } |
|
2476 } |
|
2477 |
|
2478 // ----------------------------------------------------------------------------- |
|
2479 // CCTSecurityDialogsAO::MapTlsProviderOperation() |
|
2480 // ----------------------------------------------------------------------------- |
|
2481 // |
|
2482 void CCTSecurityDialogsAO::MapTlsProviderOperation( TUint aOperation ) |
|
2483 { |
|
2484 switch (aOperation) |
|
2485 { |
|
2486 case ESecureConnection: |
|
2487 { |
|
2488 iOperation = EUserAuthentication; |
|
2489 break; |
|
2490 } |
|
2491 default: |
|
2492 break; |
|
2493 } |
|
2494 } |
|
2495 |