|
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 "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: API which handles certificate extra data related operations. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "WimCertMgmt.h" |
|
20 #include "WimMgmt.h" |
|
21 #include "WimCert.h" |
|
22 #include "WimTrace.h" |
|
23 #include "Wimi.h" |
|
24 |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // CWimCert::CWimCert() |
|
28 // Default constructor |
|
29 // ----------------------------------------------------------------------------- |
|
30 CWimCert::CWimCert() : CActive( EPriorityStandard ) |
|
31 { |
|
32 } |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CWimCert::NewL() |
|
36 // Symbian 2nd phase constructor can leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 EXPORT_C CWimCert* CWimCert::NewL() |
|
39 { |
|
40 _WIMTRACE ( _L( "CWimCert::NewL()" ) ); |
|
41 CWimCert* self = new( ELeave ) CWimCert(); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CWimCert::ConstructL() |
|
50 // Second phase |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void CWimCert::ConstructL() |
|
54 { |
|
55 CActiveScheduler::Add( this ); |
|
56 _WIMTRACE ( _L( "CWimCert::ConstructL() completed" ) ); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CWimCert::Initialize() |
|
61 // Initializes the WIM server cache and restores certificates to |
|
62 // WimClient memory area. This is the most time consuming call. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C void CWimCert::Initialize( TRequestStatus& aStatus ) |
|
66 { |
|
67 _WIMTRACE ( _L( "CWimCert::Initialize()" ) ); |
|
68 aStatus = KRequestPending; |
|
69 iClientStatus = &aStatus; |
|
70 if ( iClientSession ) |
|
71 { |
|
72 iClientSession->Close(); |
|
73 delete iClientSession; |
|
74 iClientSession = NULL; |
|
75 } |
|
76 if ( iConnectionHandle ) |
|
77 { |
|
78 iConnectionHandle->Close(); |
|
79 delete iConnectionHandle; |
|
80 iConnectionHandle = NULL; |
|
81 } |
|
82 iPhase = ECreateNewSession; |
|
83 SignalOwnStatusAndComplete(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CWimCert::CancelInitialize() |
|
88 // Cancels the initialization process. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C void CWimCert::CancelInitialize() |
|
92 { |
|
93 _WIMTRACE ( _L( "CWimCert::CancelInitialize" ) ); |
|
94 Cancel(); |
|
95 } |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CWimCert::SignalOwnStatusAndComplete() |
|
99 // Sets own iStatus to KRequestPending, and signals it |
|
100 // with User::RequestComplete() -request. This gives chance |
|
101 // active scheduler to run other active objects. After a quick |
|
102 // visit in active scheduler, signal returns to RunL() and starts next |
|
103 // phase of operation. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CWimCert::SignalOwnStatusAndComplete() |
|
107 { |
|
108 _WIMTRACE ( _L( "CWimCert::SignalOwnStatusAndComplete()" ) ); |
|
109 iStatus = KRequestPending; |
|
110 SetActive(); |
|
111 TRequestStatus* status = &iStatus; |
|
112 User::RequestComplete( status, KErrNone ); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CWimCert::GetExtras() |
|
117 // Returns the extra data from certificate that is |
|
118 // not possible yet to fetch from crypto token framework |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C void CWimCert::GetExtras( const TDesC8& aKeyId, |
|
122 RCPointerArray<HBufC>& aTrustedUsages, |
|
123 TCertLocation& aLocation, |
|
124 TRequestStatus& aStatus ) |
|
125 { |
|
126 _WIMTRACE ( _L( "CWimCert::GetExtras()" ) ); |
|
127 aStatus = KRequestPending; |
|
128 iClientStatus = &aStatus; |
|
129 |
|
130 if ( !iClientSession || !iConnectionHandle ) |
|
131 { |
|
132 User::RequestComplete( iClientStatus, KErrNotReady ); |
|
133 return; |
|
134 } |
|
135 if ( !iCertCount || aKeyId.Length() != KKeyIdLen ) |
|
136 { |
|
137 User::RequestComplete( iClientStatus, KErrNotFound ); |
|
138 } |
|
139 else |
|
140 { |
|
141 if ( iKeyIdToBeMatched ) |
|
142 { |
|
143 delete iKeyIdToBeMatched; |
|
144 iKeyIdToBeMatched = NULL; |
|
145 } |
|
146 |
|
147 TRAPD ( err, iKeyIdToBeMatched = aKeyId.AllocL() ); |
|
148 if ( err ) |
|
149 { |
|
150 User::RequestComplete( iClientStatus, KErrNoMemory ); |
|
151 } |
|
152 else |
|
153 { |
|
154 iTrustedUsages = &aTrustedUsages; |
|
155 iLocation = &aLocation; |
|
156 iPhase = ELocateCertificate; |
|
157 SignalOwnStatusAndComplete(); |
|
158 } |
|
159 } |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CWimCert::CancelGetExtras() |
|
164 // Cancels GetExtras -request. |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C void CWimCert::CancelGetExtras() |
|
168 { |
|
169 _WIMTRACE ( _L( "CWimCert::CancelGetExtras" ) ); |
|
170 Cancel(); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CWimCert::~CWimCert() |
|
175 // Allocated memory is released. |
|
176 // ----------------------------------------------------------------------------- |
|
177 EXPORT_C CWimCert::~CWimCert() |
|
178 { |
|
179 _WIMTRACE ( _L( "CWimCert::~CWimCert()" ) ); |
|
180 Cancel(); |
|
181 if ( iConnectionHandle ) |
|
182 { |
|
183 iConnectionHandle->Close(); |
|
184 delete iConnectionHandle; |
|
185 } |
|
186 if ( iClientSession ) |
|
187 { |
|
188 iClientSession->Close(); |
|
189 delete iClientSession; |
|
190 } |
|
191 DeallocWimCertInfo(); |
|
192 DeAllocMemoryForExtraDataRetrieve(); |
|
193 DeallocRArrays(); |
|
194 |
|
195 delete iKeyIdToBeMatched; |
|
196 delete iKeyIdPointer; |
|
197 |
|
198 iCertTypes.Close(); |
|
199 iTrustedUsageLengths.Close(); |
|
200 iKeyIds.Close(); |
|
201 iUsages.Close(); |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CWimCert::RunL() |
|
206 // Different phases are handled here. This might be considered as state machine. |
|
207 // iPhase = ECreateNewSession: Gets ClientSession handle. Tries to connect |
|
208 // to existing session. If there is no existing session, a new session |
|
209 // is created. |
|
210 // iPhase = EConnectClientSession: If new session was needed to be created, |
|
211 // new connecting request is needed. |
|
212 // iPhase = EInitializeWim: Sends initialize request to server and waits |
|
213 // asyncronously. |
|
214 // iPhase = EGetCertClientSession:Create certificate clientsession and connect |
|
215 // it to WIM server. |
|
216 // iPhase = EListCertsFromWim: List certificates from WimServer. |
|
217 // iPhase = ELocateCertificate: Try to find matching certificate hash from array |
|
218 // (Application has sent a Key ID, which is used to indentify a |
|
219 // certificate. If matching certificate has found, retrieve possible |
|
220 // extra data from WimServer. |
|
221 // iPhase = EGiveExtraData: Extra data is retrieved from WimServer. Chop it to |
|
222 // correct pieces. |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CWimCert::RunL() |
|
226 { |
|
227 //Check for error |
|
228 if ( iStatus.Int() != KErrNone ) |
|
229 { |
|
230 if ( iPhase == EGiveExtraData ) |
|
231 { |
|
232 iConnectionHandle->DeallocGetExtrasPckgBuf(); |
|
233 DeAllocMemoryForExtraDataRetrieve(); |
|
234 } |
|
235 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
236 _WIMTRACE2 ( _L( "CWimCert::RunL() error = %d" ), iStatus.Int() ); |
|
237 _WIMTRACE2 ( _L( "CWimCert::RunL() phase = %d" ), iPhase ); |
|
238 return; |
|
239 } |
|
240 |
|
241 switch ( iPhase ) |
|
242 { |
|
243 case ECreateNewSession: |
|
244 { |
|
245 //get ClientSession handle |
|
246 iClientSession = RWimMgmt::ClientSessionL(); |
|
247 |
|
248 iPhase = EConnectClientSession; |
|
249 TInt retVal = 0; |
|
250 iWimStartErr = iClientSession->Connect(); |
|
251 if ( iWimStartErr == KErrNotFound ) |
|
252 { |
|
253 retVal = iClientSession->StartWim(); |
|
254 if( retVal != KErrNone ) |
|
255 { |
|
256 User::RequestComplete( iClientStatus, retVal ); |
|
257 } |
|
258 else |
|
259 { |
|
260 SignalOwnStatusAndComplete(); |
|
261 } |
|
262 } |
|
263 else |
|
264 { |
|
265 SignalOwnStatusAndComplete(); |
|
266 } |
|
267 break; |
|
268 } |
|
269 case EConnectClientSession: |
|
270 { |
|
271 //Raise iPhase |
|
272 iPhase = EInitializeWim; |
|
273 if ( iWimStartErr ) |
|
274 { |
|
275 //New session was needed to be created. Try to reconnect. |
|
276 iWimStartErr = iClientSession->Connect(); |
|
277 if ( iWimStartErr ) |
|
278 { |
|
279 //Failed to connect. No reason to continue |
|
280 User::RequestComplete( iClientStatus, iWimStartErr ); |
|
281 } |
|
282 else |
|
283 { |
|
284 SignalOwnStatusAndComplete(); |
|
285 } |
|
286 } |
|
287 else |
|
288 { |
|
289 SignalOwnStatusAndComplete(); |
|
290 } |
|
291 break; |
|
292 } |
|
293 case EInitializeWim: |
|
294 { |
|
295 //Initialize WIM |
|
296 SetActive(); |
|
297 iClientSession->Initialize( iStatus ); |
|
298 iPhase = EGetCertClientSession; |
|
299 break; |
|
300 } |
|
301 case EGetCertClientSession: |
|
302 { |
|
303 // Create certificate clientsession and connect |
|
304 // it to WIM server. |
|
305 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
306 case:EGetCertClientSession") ); |
|
307 iConnectionHandle = RWimCertMgmt::ClientSessionL(); |
|
308 iPhase = EListCertsFromWim; |
|
309 SignalOwnStatusAndComplete(); |
|
310 break; |
|
311 } |
|
312 case EListCertsFromWim: //get certificates from WIM. |
|
313 { |
|
314 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
315 case:EListCertsFromWim") ); |
|
316 |
|
317 if ( iCertCount ) //Delete previous preferences. |
|
318 { |
|
319 DeallocWimCertInfo(); |
|
320 DeallocRArrays(); |
|
321 } |
|
322 //Ok ready to begin. First get Cert count |
|
323 iCertCount = iConnectionHandle->CertCount( EWimEntryTypeAll ); |
|
324 _WIMTRACE2 ( _L( "CWimCert::RunL() certCount =%d" ), |
|
325 iCertCount ); |
|
326 if ( !iCertCount ) |
|
327 { |
|
328 User::RequestComplete( iClientStatus, KErrNotFound ); |
|
329 } |
|
330 else |
|
331 { |
|
332 TCertificateAddressList certRefLst = |
|
333 new( ELeave ) TCertificateAddress[iCertCount]; |
|
334 |
|
335 CleanupStack::PushL( TCleanupItem( CleanupRefLst, |
|
336 certRefLst ) ); |
|
337 |
|
338 TWimCertInfo* certInfoArr = new( ELeave ) |
|
339 TWimCertInfo[iCertCount]; |
|
340 |
|
341 CleanupStack::PushL( TCleanupItem( Cleanup, certInfoArr ) ); |
|
342 |
|
343 _WIMTRACE ( _L( "CWimCert::RunL(), Allocated certRefLst") ); |
|
344 |
|
345 //Create arrays |
|
346 TUint8 index = 0; |
|
347 iLabel = new( ELeave ) PHBufC8[iCertCount]; |
|
348 iKeyId = new( ELeave ) PHBufC8[iCertCount]; |
|
349 iCAId = new( ELeave ) PHBufC8[iCertCount]; |
|
350 iIssuerHash = new( ELeave ) PHBufC8[iCertCount]; |
|
351 |
|
352 iLabelPtr = new( ELeave ) PTPtr8[iCertCount]; |
|
353 iKeyIdPtr = new( ELeave ) PTPtr8[iCertCount]; |
|
354 iCAIdPtr = new( ELeave ) PTPtr8[iCertCount]; |
|
355 iIssuerHashPtr = new( ELeave ) PTPtr8[iCertCount]; |
|
356 |
|
357 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
358 Allocated Member variable arrays") ); |
|
359 |
|
360 |
|
361 for ( index = 0; index < iCertCount; index++ ) |
|
362 { |
|
363 iLabel[index] = HBufC8::NewL( KLabelLen ); |
|
364 iKeyId[index] = HBufC8::NewL( KKeyIdLen ); |
|
365 iCAId[index] = HBufC8::NewL( KPkcs15IdLen ); |
|
366 iIssuerHash[index] = HBufC8::NewL( KIssuerHash ); |
|
367 |
|
368 iLabelPtr[index] = new( ELeave ) |
|
369 TPtr8( iLabel[index]->Des() ); |
|
370 iKeyIdPtr[index] = new( ELeave ) |
|
371 TPtr8( iKeyId[index]->Des() ); |
|
372 iCAIdPtr[index] = new( ELeave ) |
|
373 TPtr8( iCAId[index]->Des() ); |
|
374 iIssuerHashPtr[index] = new( ELeave ) |
|
375 TPtr8( iIssuerHash[index]->Des() ); |
|
376 |
|
377 certInfoArr[index].iLabel.Copy( iLabelPtr[index]->Ptr(), |
|
378 iLabelPtr[index]->Length() ); |
|
379 certInfoArr[index].iKeyId.Copy( iKeyIdPtr[index]->Ptr(), |
|
380 iKeyIdPtr[index]->Length() ); |
|
381 certInfoArr[index].iCAId.Copy( iCAIdPtr[index]->Ptr(), |
|
382 iCAIdPtr[index]->Length() ); |
|
383 certInfoArr[index].iIssuerHash.Copy( |
|
384 iIssuerHashPtr[index]->Ptr(), |
|
385 iIssuerHashPtr[index]->Length() ); |
|
386 |
|
387 _WIMTRACE2 ( _L( "CWimCert::RunL(), \ |
|
388 Assigned data to array, loopCount =%d"),index ); |
|
389 |
|
390 } |
|
391 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
392 Array ready for retrieving") ); |
|
393 |
|
394 //Quick synchronous visit in server. |
|
395 TInt ret = iConnectionHandle->CertRefLst( certRefLst, |
|
396 certInfoArr, |
|
397 iCertCount, |
|
398 EWimEntryTypeAll ); |
|
399 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
400 Retrieve call issued") ); |
|
401 |
|
402 if ( ret == KErrNone ) |
|
403 { |
|
404 //Add necessary certificate information to API arrays |
|
405 for ( TInt i = 0; i < iCertCount; i++ ) |
|
406 { |
|
407 iCertTypes.Append( certInfoArr[i].iType ); |
|
408 iTrustedUsageLengths.Append( |
|
409 certInfoArr[i].iTrustedUsageLength ); |
|
410 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
411 Trusted usage appended") ); |
|
412 |
|
413 iKeyIds.Append( certInfoArr[i].iKeyId.AllocL() ); |
|
414 |
|
415 _WIMTRACE ( _L( "CWimCert::RunL(), KeyId appended") ); |
|
416 |
|
417 iUsages.Append( certInfoArr[i].iUsage ); |
|
418 |
|
419 _WIMTRACE2 ( _L( "CWimCert::RunL(), \ |
|
420 Allocating data to RArrays, loopCount =%d"),i ); |
|
421 } |
|
422 |
|
423 } |
|
424 //Clean up unwanted member variable arrays |
|
425 DeallocWimCertInfo(); |
|
426 |
|
427 //Delete local arrays. |
|
428 CleanupStack::PopAndDestroy( 2 ); //certRefLst, certInfoArr |
|
429 |
|
430 _WIMTRACE ( _L( "CWimCert::RunL(), All done") ); |
|
431 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
432 } |
|
433 break; |
|
434 } |
|
435 case ELocateCertificate: |
|
436 { |
|
437 _WIMTRACE ( _L( "CWimCert::RunL(), \ |
|
438 case:ELocateCertificate") ); |
|
439 TInt retVal = CertificateLocated(); |
|
440 |
|
441 delete iKeyIdToBeMatched; |
|
442 iKeyIdToBeMatched = NULL; |
|
443 |
|
444 if ( retVal == KErrNone ) |
|
445 { |
|
446 //Allocate memory for Trusted usage string |
|
447 AllocMemoryForExtraDataRetrieveL(); |
|
448 TCertExtrasInfo certExtrasInfo; |
|
449 certExtrasInfo.iTrustedUsage = |
|
450 iCertHBufTrustedUsageFromServerPtr; |
|
451 |
|
452 //Get reference to right keyId from Array, create pointer and |
|
453 //get extra information |
|
454 HBufC8* keyId = iKeyIds.operator[]( iCertIndex ); |
|
455 iKeyIdPointer = new( ELeave ) TPtr8( keyId->Des() ); |
|
456 iConnectionHandle->GetCertExtrasL( |
|
457 iKeyIdPointer, |
|
458 certExtrasInfo, |
|
459 iUsages.operator[]( iCertIndex ), |
|
460 iStatus ); |
|
461 iPhase = EGiveExtraData; |
|
462 SetActive(); |
|
463 } |
|
464 else |
|
465 { |
|
466 User::RequestComplete( iClientStatus, retVal ); |
|
467 } |
|
468 break; |
|
469 } |
|
470 case EGiveExtraData: |
|
471 { |
|
472 _WIMTRACE ( _L( "CWimCert::RunL(), case:EGiveExtraData") ); |
|
473 ExtraDataFoundL(); |
|
474 delete iKeyIdPointer; |
|
475 iKeyIdPointer = NULL; |
|
476 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
477 break; |
|
478 } |
|
479 default: |
|
480 { |
|
481 _WIMTRACE2 ( _L( "CWimCert::RunL(), \ |
|
482 case:default, iPhase=%d" ), iPhase ); |
|
483 User::RequestComplete( iClientStatus, KErrCorrupt ); |
|
484 break; |
|
485 } |
|
486 } |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CWimCert::CertificateLocated() |
|
491 // Compares received KeyId to our KeyIds and if match is found, |
|
492 // check does that certificate have any extra data. If certificate is not found, |
|
493 // return KErrNotFound. If TrustedUsage(Location) is not valid, return |
|
494 // KErrPathNotFound. |
|
495 // ----------------------------------------------------------------------------- |
|
496 // |
|
497 TInt CWimCert::CertificateLocated() |
|
498 { |
|
499 _WIMTRACE ( _L( "CWimCert::CertificateLocated" ) ); |
|
500 TInt found = 0; |
|
501 TBool certificateMatch = EFalse; |
|
502 //Check, do we have that kind of certificate what user asks. |
|
503 TUint8 i; |
|
504 for ( i = 0; i < iCertCount && !certificateMatch; i++ ) |
|
505 { |
|
506 //KeyId must match and certificate type must be X509 |
|
507 if ( !iKeyIds.operator []( i )->Compare( *iKeyIdToBeMatched ) && |
|
508 iCertTypes.operator[]( i ) == WIMI_CT_X509 ) |
|
509 { |
|
510 iCertIndex = i; |
|
511 certificateMatch = ETrue; |
|
512 } |
|
513 } |
|
514 |
|
515 if ( certificateMatch ) //Certificate was found, check location validity |
|
516 { |
|
517 //Ok, we have found certificate, check does it have any |
|
518 //extra data. |
|
519 if ( !iTrustedUsageLengths.operator []( iCertIndex ) ) |
|
520 { |
|
521 found = KErrPathNotFound; |
|
522 } |
|
523 } |
|
524 else //Certificate was not found, return KErrNotFound |
|
525 { |
|
526 found = KErrNotFound; |
|
527 } |
|
528 return found; |
|
529 } |
|
530 |
|
531 // ----------------------------------------------------------------------------- |
|
532 // CWimCert::AllocMemoryForExtraDataRetrieveL() |
|
533 // Allocates memory for TrustedUsage String, which is fetched from server. |
|
534 // ----------------------------------------------------------------------------- |
|
535 // |
|
536 void CWimCert::AllocMemoryForExtraDataRetrieveL() |
|
537 { |
|
538 _WIMTRACE ( _L( "CWimCert::AllocMemoryForExtraDataRetrieveL" ) ); |
|
539 //Trusted usage |
|
540 iCertHBufTrustedUsageFromServer = |
|
541 HBufC::NewL( iTrustedUsageLengths.operator[]( iCertIndex ) ); |
|
542 iCertHBufTrustedUsageFromServerPtr = new( ELeave ) TPtr( |
|
543 iCertHBufTrustedUsageFromServer->Des() ); |
|
544 } |
|
545 |
|
546 // ----------------------------------------------------------------------------- |
|
547 // CWimCert::DeAllocMemoryForExtraDataRetrieve() |
|
548 // DeAllocates memory from TrustedUsage String, which was fetched from server. |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 void CWimCert::DeAllocMemoryForExtraDataRetrieve() |
|
552 { |
|
553 _WIMTRACE ( _L( "CWimCert::DeAllocMemoryForExtraDataRetrieve" ) ); |
|
554 delete iCertHBufTrustedUsageFromServer; |
|
555 iCertHBufTrustedUsageFromServer = NULL; |
|
556 |
|
557 delete iCertHBufTrustedUsageFromServerPtr; |
|
558 iCertHBufTrustedUsageFromServerPtr = NULL; |
|
559 } |
|
560 |
|
561 // ----------------------------------------------------------------------------- |
|
562 // CWimCert::ExtraDataFoundL() |
|
563 // Now we have got whole Trusted usage information in one buffer. We need |
|
564 // to chop it to corrects pieces and append it to iTrustedUsage array. |
|
565 // Location is added to a member variable . |
|
566 // ----------------------------------------------------------------------------- |
|
567 // |
|
568 void CWimCert::ExtraDataFoundL() |
|
569 { |
|
570 _WIMTRACE ( _L( "CWimCert::ExtraDataFoundL" ) ); |
|
571 TLex16 lex( *iCertHBufTrustedUsageFromServer ); |
|
572 TPtrC16 lexToken; |
|
573 for ( TBool extrasDone = EFalse; extrasDone == EFalse; ) |
|
574 { |
|
575 lexToken.Set( lex.NextToken() ); |
|
576 if ( lexToken.Length() ) |
|
577 { |
|
578 HBufC* oid = lexToken.AllocLC(); |
|
579 User::LeaveIfError( iTrustedUsages->Append( oid ) ); |
|
580 CleanupStack::Pop( oid ); //oid |
|
581 } |
|
582 else |
|
583 { |
|
584 extrasDone = ETrue; |
|
585 } |
|
586 } |
|
587 |
|
588 TPckgBuf<TCertExtrasInfo> certInfoPckg; |
|
589 |
|
590 certInfoPckg.operator = |
|
591 ( *iConnectionHandle->CertExtrasPckgBuf()->PckgBuf() ); |
|
592 |
|
593 switch ( certInfoPckg().iCDFRefs ) |
|
594 { |
|
595 case EWimTrustedCertsCDF: |
|
596 { |
|
597 *iLocation = ETrustedCerts_CDF; |
|
598 break; |
|
599 } |
|
600 case EWimCertificatesCDF: |
|
601 { |
|
602 *iLocation = ECertificates_CDF; |
|
603 break; |
|
604 } |
|
605 case EWimUsefulCertsCDF: |
|
606 { |
|
607 *iLocation = EUsefulCerts_CDF; |
|
608 break; |
|
609 } |
|
610 default: |
|
611 { |
|
612 *iLocation = EUnknown_CDF; |
|
613 break; |
|
614 } |
|
615 } |
|
616 |
|
617 iConnectionHandle->DeallocGetExtrasPckgBuf(); |
|
618 DeAllocMemoryForExtraDataRetrieve(); |
|
619 } |
|
620 |
|
621 // ----------------------------------------------------------------------------- |
|
622 // CWimCert::DoCancel() |
|
623 // Deallocates member variables and completes client status with |
|
624 // KErrCancel error code. |
|
625 // ----------------------------------------------------------------------------- |
|
626 // |
|
627 void CWimCert::DoCancel() |
|
628 { |
|
629 if ( iConnectionHandle && |
|
630 ( iPhase == EGiveExtraData || iPhase == ELocateCertificate ) ) |
|
631 { |
|
632 iConnectionHandle->DeallocGetExtrasPckgBuf(); |
|
633 DeAllocMemoryForExtraDataRetrieve(); |
|
634 delete iKeyIdPointer; |
|
635 iKeyIdPointer = NULL; |
|
636 delete iKeyIdToBeMatched; |
|
637 iKeyIdToBeMatched = NULL; |
|
638 } |
|
639 else |
|
640 {//Cancelled initialization |
|
641 DeallocWimCertInfo(); |
|
642 DeAllocMemoryForExtraDataRetrieve(); |
|
643 DeallocRArrays(); |
|
644 } |
|
645 User::RequestComplete( iClientStatus, KErrCancel ); |
|
646 } |
|
647 |
|
648 // ----------------------------------------------------------------------------- |
|
649 // CWimCert::RunError() |
|
650 // The active scheduler calls this function if this active object's RunL() |
|
651 // function leaves. This gives this active object the opportunity to perform |
|
652 // any necessary cleanup. |
|
653 // After array's cleanup, complete request with received error code. |
|
654 // ----------------------------------------------------------------------------- |
|
655 TInt CWimCert::RunError( TInt aError ) |
|
656 { |
|
657 _WIMTRACE2 ( _L( "CWimCert::RunError, aError = %d" ), aError ); |
|
658 _WIMTRACE2 ( _L( "CWimCert::RunError, iPhase = %d" ), iPhase ); |
|
659 DeallocWimCertInfo(); |
|
660 DeAllocMemoryForExtraDataRetrieve(); |
|
661 DeallocRArrays(); |
|
662 |
|
663 delete iKeyIdPointer; |
|
664 iKeyIdPointer = NULL; |
|
665 |
|
666 User::RequestComplete( iClientStatus, aError ); |
|
667 return KErrNone; |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CWimCert::Cleanup() |
|
672 // Handles cleanup for an object which is not derived from CBase |
|
673 // ----------------------------------------------------------------------------- |
|
674 // |
|
675 void CWimCert::Cleanup( TAny* aObject ) |
|
676 { |
|
677 _WIMTRACE ( _L( "CWimCert::Cleanup()" ) ); |
|
678 delete[] static_cast<TWimCertInfo*>(aObject); |
|
679 aObject = NULL; |
|
680 } |
|
681 |
|
682 // ----------------------------------------------------------------------------- |
|
683 // CWimCert::CleanupRefLst() |
|
684 // Handles cleanup for an object which is not derived from CBase |
|
685 // ----------------------------------------------------------------------------- |
|
686 // |
|
687 void CWimCert::CleanupRefLst( TAny* aObject ) |
|
688 { |
|
689 _WIMTRACE ( _L( "CWimCert::CleanupRefLst()" ) ); |
|
690 delete[] aObject; |
|
691 aObject = NULL; |
|
692 } |
|
693 |
|
694 // ----------------------------------------------------------------------------- |
|
695 // CWimCert::DeallocRArrays() |
|
696 // Deallocates member variable RArrays |
|
697 // ----------------------------------------------------------------------------- |
|
698 // |
|
699 void CWimCert::DeallocRArrays() |
|
700 { |
|
701 for ( TInt i = 0; i< iKeyIds.Count(); i++ ) |
|
702 { |
|
703 delete iKeyIds[i]; |
|
704 iKeyIds[i] = NULL; |
|
705 } |
|
706 iKeyIds.Close(); |
|
707 iCertTypes.Close(); |
|
708 iTrustedUsageLengths.Close(); |
|
709 iKeyIds.Close(); |
|
710 } |
|
711 |
|
712 // ----------------------------------------------------------------------------- |
|
713 // CWimCert::DeallocWimCertInfo() |
|
714 // Deallocates memory. If something has leaved during asynchronous request, we |
|
715 // will deallocate all member data. |
|
716 // ----------------------------------------------------------------------------- |
|
717 void CWimCert::DeallocWimCertInfo() |
|
718 { |
|
719 _WIMTRACE ( _L( "CWimCert::DeallocWimCertInfo()" ) ); |
|
720 TUint8 index; |
|
721 for ( index = 0; index < iCertCount; index++ ) |
|
722 { |
|
723 if ( iLabel ) |
|
724 { |
|
725 delete iLabel[index]; |
|
726 } |
|
727 if ( iKeyId ) |
|
728 { |
|
729 delete iKeyId[index]; |
|
730 } |
|
731 if ( iCAId ) |
|
732 { |
|
733 delete iCAId[index]; |
|
734 } |
|
735 if ( iIssuerHash ) |
|
736 { |
|
737 delete iIssuerHash[index]; |
|
738 } |
|
739 if ( iLabelPtr ) |
|
740 { |
|
741 delete iLabelPtr[index]; |
|
742 } |
|
743 if ( iKeyIdPtr ) |
|
744 { |
|
745 delete iKeyIdPtr[index]; |
|
746 } |
|
747 if ( iCAIdPtr ) |
|
748 { |
|
749 delete iCAIdPtr[index]; |
|
750 } |
|
751 if ( iIssuerHashPtr ) |
|
752 { |
|
753 delete iIssuerHashPtr[index]; |
|
754 } |
|
755 } |
|
756 |
|
757 delete[] iLabel; |
|
758 delete[] iKeyId; |
|
759 delete[] iCAId; |
|
760 delete[] iIssuerHash; |
|
761 delete[] iLabelPtr; |
|
762 delete[] iKeyIdPtr; |
|
763 delete[] iCAIdPtr; |
|
764 delete[] iIssuerHashPtr; |
|
765 iLabel = NULL; |
|
766 iKeyId = NULL; |
|
767 iCAId = NULL; |
|
768 iIssuerHash = NULL; |
|
769 iLabelPtr = NULL; |
|
770 iKeyIdPtr = NULL; |
|
771 iCAIdPtr = NULL; |
|
772 iIssuerHashPtr = NULL; |
|
773 } |
|
774 |
|
775 // End of File |