1 /* |
1 /* |
2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
66 // ----------------------------------------------------------------------------- |
66 // ----------------------------------------------------------------------------- |
67 // CWimCertHandler::NewL |
67 // CWimCertHandler::NewL |
68 // Two-phased constructor. |
68 // Two-phased constructor. |
69 // ----------------------------------------------------------------------------- |
69 // ----------------------------------------------------------------------------- |
70 // |
70 // |
71 CWimCertHandler* CWimCertHandler::NewL() |
71 CWimCertHandler* CWimCertHandler::NewL() |
72 { |
72 { |
73 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::NewL | Begin")); |
73 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::NewL | Begin")); |
74 CWimCertHandler* self = new( ELeave ) CWimCertHandler; |
74 CWimCertHandler* self = new( ELeave ) CWimCertHandler; |
75 CleanupStack::PushL( self ); |
75 CleanupStack::PushL( self ); |
76 self->ConstructL(); |
76 self->ConstructL(); |
77 CleanupStack::Pop( self ); |
77 CleanupStack::Pop( self ); |
78 return self; |
78 return self; |
79 } |
79 } |
80 |
80 |
81 |
81 |
82 // Destructor |
82 // Destructor |
83 CWimCertHandler::~CWimCertHandler() |
83 CWimCertHandler::~CWimCertHandler() |
84 { |
84 { |
85 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::~CWimCertHandler | Begin")); |
85 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::~CWimCertHandler | Begin")); |
86 delete iWimUtilFuncs; |
86 delete iWimUtilFuncs; |
99 // CWimCertHandler::GetCertificatesFromWimL |
99 // CWimCertHandler::GetCertificatesFromWimL |
100 // Fetches certificates from WIM card. |
100 // Fetches certificates from WIM card. |
101 // ----------------------------------------------------------------------------- |
101 // ----------------------------------------------------------------------------- |
102 // |
102 // |
103 void CWimCertHandler::GetCertificatesFromWimL( |
103 void CWimCertHandler::GetCertificatesFromWimL( |
104 const RMessage2& aMessage, |
104 const RMessage2& aMessage, |
105 CWimMemMgmt* aWimMgmt ) |
105 CWimMemMgmt* aWimMgmt ) |
106 { |
106 { |
107 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificatesFromWimL | Begin")); |
107 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificatesFromWimL | Begin")); |
108 WIMI_STAT callStatus = WIMI_Ok; |
108 WIMI_STAT callStatus = WIMI_Ok; |
109 TUint8 certNum = 0; |
109 TUint8 certNum = 0; |
115 TWimEntryType certEntryType = ( TWimEntryType ) aMessage.Int2(); |
115 TWimEntryType certEntryType = ( TWimEntryType ) aMessage.Int2(); |
116 |
116 |
117 TUint32* pCertRefLst = ( TUint32* )( certRefLst->Des().Ptr() ); |
117 TUint32* pCertRefLst = ( TUint32* )( certRefLst->Des().Ptr() ); |
118 TWimCertInfo* pCertInfoLst = ( TWimCertInfo* )( certInfoLst->Des().Ptr() ); |
118 TWimCertInfo* pCertInfoLst = ( TWimCertInfo* )( certInfoLst->Des().Ptr() ); |
119 |
119 |
120 temp = aWimMgmt->WimRef(); |
120 __ASSERT_ALWAYS( aWimMgmt, User::Leave( KErrArgument ) ); |
121 if ( !temp ) |
121 temp = MainWimRef( *aWimMgmt ); |
122 { |
|
123 temp = WIMI_GetWIMRef( 0 ); |
|
124 aWimMgmt->SetWIMRef( temp ); // takes ownership |
|
125 } |
|
126 |
122 |
127 if ( temp ) |
123 if ( temp ) |
128 { |
124 { |
129 if ( EWimEntryTypeAll == certEntryType || |
125 if ( EWimEntryTypeAll == certEntryType || |
130 EWimEntryTypeCA == certEntryType ) |
126 EWimEntryTypeCA == certEntryType ) |
131 { |
127 { |
132 callStatus = GetCertificateFromWimRefL( temp, WIMI_CU_CA, |
128 callStatus = GetCertificateFromWimRefL( temp, WIMI_CU_CA, |
133 certNum, pCertRefLst, |
129 certNum, pCertRefLst, |
134 pCertInfoLst, aMessage ); |
130 pCertInfoLst, aMessage ); |
135 |
131 |
136 } |
132 } |
137 if ( callStatus == WIMI_Ok && ( EWimEntryTypeAll == certEntryType || |
133 if ( callStatus == WIMI_Ok && ( EWimEntryTypeAll == certEntryType || |
138 EWimEntryTypePersonal == certEntryType ) ) |
134 EWimEntryTypePersonal == certEntryType ) ) |
139 { |
135 { |
140 callStatus = GetCertificateFromWimRefL( temp, WIMI_CU_Client, |
136 callStatus = GetCertificateFromWimRefL( temp, WIMI_CU_Client, |
141 certNum, pCertRefLst, |
137 certNum, pCertRefLst, |
142 pCertInfoLst, aMessage ); |
138 pCertInfoLst, aMessage ); |
143 |
139 |
144 } |
140 } |
145 |
141 |
146 //record the ref for sanity checking, deallocate old refs first |
142 //record the ref for sanity checking, deallocate old refs first |
147 for( TInt index = 0; index < iCertRefLst.Count(); ++index ) |
143 for( TInt index = 0; index < iCertRefLst.Count(); ++index ) |
148 { |
144 { |
149 WIMI_Ref_t* ref = reinterpret_cast< WIMI_Ref_t* >( iCertRefLst[ index ] ); |
145 WIMI_Ref_t* ref = reinterpret_cast< WIMI_Ref_t* >( iCertRefLst[ index ] ); |
150 _WIMTRACE2(_L("WIM | WIMServer | CWimCertHandler::GetCertificatesFromWimL, -ref 0x%08x"), ref); |
146 _WIMTRACE2(_L("WIM | WIMServer | CWimCertHandler::GetCertificatesFromWimL, -ref 0x%08x"), ref); |
155 for( TInt index = 0; index < certNum; ++index ) |
151 for( TInt index = 0; index < certNum; ++index ) |
156 { |
152 { |
157 _WIMTRACE2(_L("WIM | WIMServer | CWimCertHandler::GetCertificatesFromWimL, +ref 0x%08x"), pCertRefLst[ index ]); |
153 _WIMTRACE2(_L("WIM | WIMServer | CWimCertHandler::GetCertificatesFromWimL, +ref 0x%08x"), pCertRefLst[ index ]); |
158 iCertRefLst.AppendL( pCertRefLst[ index ] ); |
154 iCertRefLst.AppendL( pCertRefLst[ index ] ); |
159 } |
155 } |
160 |
156 |
161 aMessage.WriteL( 0, certRefLst->Des() ); |
157 aMessage.WriteL( 0, certRefLst->Des() ); |
162 aMessage.WriteL( 1, certInfoLst->Des() ); |
158 aMessage.WriteL( 1, certInfoLst->Des() ); |
163 } |
159 } |
164 else |
160 else |
165 { |
161 { |
183 const RMessage2& aMessage ) |
179 const RMessage2& aMessage ) |
184 { |
180 { |
185 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificateFromWimRefL | Begin")); |
181 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificateFromWimRefL | Begin")); |
186 TUint8 tempCrtCount; |
182 TUint8 tempCrtCount; |
187 WIMI_RefList_t refList = NULL; |
183 WIMI_RefList_t refList = NULL; |
188 WIMI_STAT callStatus = WIMI_Ok; |
184 WIMI_STAT callStatus = WIMI_ERR_BadReference; |
189 |
185 |
190 if ( aTmpWimRef ) |
186 if ( aTmpWimRef ) |
191 { |
187 { |
192 callStatus = WIMI_GetCertificateListByWIM( aTmpWimRef, |
188 callStatus = WIMI_GetCertificateListByWIM( aTmpWimRef, |
193 aUsage, |
189 aUsage, |
194 &tempCrtCount, |
190 &tempCrtCount, |
195 &refList ); |
191 &refList ); |
196 |
192 |
197 if ( callStatus == WIMI_Ok ) |
193 if ( callStatus == WIMI_Ok ) |
198 { |
194 { |
199 // If the certifcate length is 0, |
195 // If the certifcate length is 0, |
216 // ingore certificate info and continue with the next |
212 // ingore certificate info and continue with the next |
217 step++; |
213 step++; |
218 free_WIMI_Ref_t( refList[certIndex] ); |
214 free_WIMI_Ref_t( refList[certIndex] ); |
219 } |
215 } |
220 } |
216 } |
221 //variable step is equal to the number of certificate in CDF whose |
217 //variable step is equal to the number of certificate in CDF whose |
222 //length is set as 0. |
218 //length is set as 0. |
223 aCertNum = static_cast< TUint8 >( aCertNum + tempCrtCount - step ); |
219 aCertNum = static_cast< TUint8 >( aCertNum + tempCrtCount - step ); |
224 |
220 |
225 // Because list items are moved to aCertRefLst, only refList array |
221 // Because list items are moved to aCertRefLst, only refList array |
226 // needs to be freed. Cannot use free_WIMI_RefList_t() as it would |
222 // needs to be freed. Cannot use free_WIMI_RefList_t() as it would |
227 // delete also items contained in refList. |
223 // delete also items contained in refList. |
253 TUint8 uiCDFRefs; |
249 TUint8 uiCDFRefs; |
254 TUint8 usage; |
250 TUint8 usage; |
255 TUint8 type; |
251 TUint8 type; |
256 TUint16 certLen; |
252 TUint16 certLen; |
257 TUint8 modifiable = 0; |
253 TUint8 modifiable = 0; |
258 WIMI_STAT callStatus = WIMI_GetCertificateInfo( |
254 WIMI_STAT callStatus = WIMI_GetCertificateInfo( |
259 aCert, |
255 aCert, |
260 &tempRef, |
256 &tempRef, |
261 &ptLabel, |
257 &ptLabel, |
262 &ptKeyID, /* Key Id (hash)*/ |
258 &ptKeyID, /* Key Id (hash)*/ |
263 &ptCAID, |
259 &ptCAID, |
264 &ptIssuerHash, |
260 &ptIssuerHash, |
265 &ptTrustedUsage, |
261 &ptTrustedUsage, |
266 &uiCDFRefs, |
262 &uiCDFRefs, |
267 &usage, /* 0 = client, 1 = CA */ |
263 &usage, /* 0 = client, 1 = CA */ |
268 &type, /* WTLSCert(1), |
264 &type, /* WTLSCert(1), |
269 X509Cert(2), |
265 X509Cert(2), |
270 X968Cert(3), |
266 X968Cert(3), |
271 CertURL(4) */ |
267 CertURL(4) */ |
272 &certLen, /* cert. content or URL length */ |
268 &certLen, /* cert. content or URL length */ |
273 &modifiable ); |
269 &modifiable ); |
274 |
270 |
275 if ( callStatus == WIMI_Ok ) |
271 if ( callStatus == WIMI_Ok ) |
276 { |
272 { |
305 } |
301 } |
306 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::CopyCertificateInfoL | X509 check ok")); |
302 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::CopyCertificateInfoL | X509 check ok")); |
307 |
303 |
308 aCertInfo.iLabel.Copy( |
304 aCertInfo.iLabel.Copy( |
309 TPtr8( |
305 TPtr8( |
310 ptLabel.pb_buf, |
306 ptLabel.pb_buf, |
311 ptLabel.ui_buf_length, |
307 ptLabel.ui_buf_length, |
312 ptLabel.ui_buf_length ) ); |
308 ptLabel.ui_buf_length ) ); |
313 |
309 |
314 aCertInfo.iKeyId.Copy( |
310 aCertInfo.iKeyId.Copy( |
315 TPtr8( |
311 TPtr8( |
316 ptKeyID.pb_buf, |
312 ptKeyID.pb_buf, |
317 ptKeyID.ui_buf_length, |
313 ptKeyID.ui_buf_length, |
318 ptKeyID.ui_buf_length ) ); |
314 ptKeyID.ui_buf_length ) ); |
319 |
315 |
320 aCertInfo.iCAId.Copy( |
316 aCertInfo.iCAId.Copy( |
321 TPtr8( |
317 TPtr8( |
322 ptCAID.pb_buf, |
318 ptCAID.pb_buf, |
323 ptCAID.ui_buf_length, |
319 ptCAID.ui_buf_length, |
324 ptCAID.ui_buf_length ) ); |
320 ptCAID.ui_buf_length ) ); |
325 |
321 |
326 aCertInfo.iIssuerHash.Copy( |
322 aCertInfo.iIssuerHash.Copy( |
327 TPtr8( |
323 TPtr8( |
328 ptIssuerHash.pb_buf, |
324 ptIssuerHash.pb_buf, |
329 ptIssuerHash.ui_buf_length, |
325 ptIssuerHash.ui_buf_length, |
330 ptIssuerHash.ui_buf_length ) ); |
326 ptIssuerHash.ui_buf_length ) ); |
331 |
327 |
332 aCertInfo.iUsage = usage; |
328 aCertInfo.iUsage = usage; |
333 aCertInfo.iType = type; |
329 aCertInfo.iType = type; |
334 aCertInfo.iCertlen = certLen; |
330 aCertInfo.iCertlen = certLen; |
335 aCertInfo.iModifiable = modifiable; |
331 aCertInfo.iModifiable = modifiable; |
336 |
332 |
337 // Certificate location |
333 // Certificate location |
338 aCertInfo.iCDFRefs = iWimUtilFuncs->MapCertLocation( uiCDFRefs ); |
334 aCertInfo.iCDFRefs = iWimUtilFuncs->MapCertLocation( uiCDFRefs ); |
339 |
335 |
340 //Allocate enough memory for OID |
336 //Allocate enough memory for OID |
341 aCertInfo.iTrustedUsageLength = ptTrustedUsage.ui_buf_length * 16; |
337 aCertInfo.iTrustedUsageLength = ptTrustedUsage.ui_buf_length * 16; |
355 // Fetches certificate's extra info from WIM card. In this case it is |
351 // Fetches certificate's extra info from WIM card. In this case it is |
356 // trusted usage info. |
352 // trusted usage info. |
357 // ----------------------------------------------------------------------------- |
353 // ----------------------------------------------------------------------------- |
358 // |
354 // |
359 void CWimCertHandler::GetExtrasFromWimL( |
355 void CWimCertHandler::GetExtrasFromWimL( |
360 const RMessage2& aMessage, |
356 const RMessage2& aMessage, |
361 CWimMemMgmt* aWimMgmt ) |
357 CWimMemMgmt* aWimMgmt ) |
362 { |
358 { |
363 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetExtrasFromWimL | Begin")); |
359 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetExtrasFromWimL | Begin")); |
364 |
360 |
365 WIMI_STAT callStatus = WIMI_Ok; |
361 WIMI_STAT callStatus = WIMI_Ok; |
366 TInt8 certUsage = 0; |
362 TInt8 certUsage = 0; |
367 |
363 |
368 HBufC8* keyIdBuf = iWimUtilFuncs->DesLC( 0, aMessage ); |
364 HBufC8* keyIdBuf = iWimUtilFuncs->DesLC( 0, aMessage ); |
369 TPtrC8 keyIdHash = keyIdBuf->Des(); |
365 TPtrC8 keyIdHash = keyIdBuf->Des(); |
370 |
366 |
371 WIMI_Ref_t* wimTempRef = aWimMgmt->WimRef(); |
367 __ASSERT_ALWAYS( aWimMgmt, User::Leave( KErrArgument ) ); |
372 if ( !wimTempRef ) |
368 WIMI_Ref_t* wimTempRef = MainWimRef( *aWimMgmt ); |
373 { |
|
374 wimTempRef = WIMI_GetWIMRef( 0 ); |
|
375 aWimMgmt->SetWIMRef( wimTempRef ); // takes ownership |
|
376 } |
|
377 |
369 |
378 if ( wimTempRef ) |
370 if ( wimTempRef ) |
379 { |
371 { |
380 TWimEntryType certEntryType = static_cast< TWimEntryType >( aMessage.Int2() ); |
372 TWimEntryType certEntryType = static_cast< TWimEntryType >( aMessage.Int2() ); |
381 switch ( certEntryType ) |
373 switch ( certEntryType ) |
425 TInt8 aUsage, |
417 TInt8 aUsage, |
426 TDesC8& aKeyHash, |
418 TDesC8& aKeyHash, |
427 const RMessage2& aMessage ) |
419 const RMessage2& aMessage ) |
428 { |
420 { |
429 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetExtrasFromWimRefL | Begin")); |
421 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetExtrasFromWimRefL | Begin")); |
430 |
422 |
431 TUint8 tempCertCount = 0; |
423 TUint8 tempCertCount = 0; |
432 WIMI_RefList_t certRefList = NULL; |
424 WIMI_RefList_t certRefList = NULL; |
433 WIMI_STAT callStatus = WIMI_Ok; |
425 WIMI_STAT callStatus = WIMI_Ok; |
434 TInt certIndex = 0; |
426 TInt certIndex = 0; |
435 TPtrC8 keyHash; |
427 TPtrC8 keyHash; |
436 |
428 |
437 if ( aTmpWimRef ) |
429 if ( aTmpWimRef ) |
438 { |
430 { |
439 // List all certificates (by WIM and usage) |
431 // List all certificates (by WIM and usage) |
440 callStatus = WIMI_GetCertificateListByWIM( aTmpWimRef, |
432 callStatus = WIMI_GetCertificateListByWIM( aTmpWimRef, |
441 aUsage, |
433 aUsage, |
442 &tempCertCount, |
434 &tempCertCount, |
443 &certRefList ); |
435 &certRefList ); |
444 } |
436 } |
445 else |
437 else |
446 { |
438 { |
447 callStatus = WIMI_ERR_BadReference; |
439 callStatus = WIMI_ERR_BadReference; |
448 } |
440 } |
449 CleanupPushWimRefListL( certRefList ); |
441 |
450 |
|
451 if ( callStatus == WIMI_Ok ) |
442 if ( callStatus == WIMI_Ok ) |
452 { |
443 { |
|
444 CleanupPushWimRefListL( certRefList ); |
|
445 |
453 WIMI_Ref_t* tempRef = NULL; |
446 WIMI_Ref_t* tempRef = NULL; |
454 WIMI_BinData_t ptLabel; |
447 WIMI_BinData_t ptLabel; |
455 WIMI_BinData_t ptKeyID; |
448 WIMI_BinData_t ptKeyID; |
456 WIMI_BinData_t ptCAID; |
449 WIMI_BinData_t ptCAID; |
457 WIMI_BinData_t ptIssuerHash; |
450 WIMI_BinData_t ptIssuerHash; |
546 |
539 |
547 TCertExtrasInfo certExtraInfo; |
540 TCertExtrasInfo certExtraInfo; |
548 certExtraInfo.iCDFRefs = 0; |
541 certExtraInfo.iCDFRefs = 0; |
549 certExtraInfo.iTrustedUsage = NULL; |
542 certExtraInfo.iTrustedUsage = NULL; |
550 |
543 |
551 WIMI_STAT callStatus = WIMI_GetCertificateInfo( |
544 WIMI_STAT callStatus = WIMI_GetCertificateInfo( |
552 aCert, |
545 aCert, |
553 &tempref, |
546 &tempref, |
554 &ptLabel, |
547 &ptLabel, |
555 &ptKeyID, /* Key Id (hash)*/ |
548 &ptKeyID, /* Key Id (hash)*/ |
556 &ptCAID, |
549 &ptCAID, |
557 &ptIssuerHash, |
550 &ptIssuerHash, |
558 &ptTrustedUsage, |
551 &ptTrustedUsage, |
559 &uiCDFRefs, |
552 &uiCDFRefs, |
560 &usage, /* 0 = client, 1 = CA */ |
553 &usage, /* 0 = client, 1 = CA */ |
561 &type, |
554 &type, |
562 &certlen, /* cert. content or URL length */ |
555 &certlen, /* cert. content or URL length */ |
563 &modifiable); |
556 &modifiable); |
564 if ( callStatus == WIMI_Ok ) |
557 if ( callStatus == WIMI_Ok ) |
565 { |
558 { |
566 free_WIMI_Ref_t( tempref ); |
559 free_WIMI_Ref_t( tempref ); |
567 WSL_OS_Free( ptLabel.pb_buf ); |
560 WSL_OS_Free( ptLabel.pb_buf ); |
568 WSL_OS_Free( ptKeyID.pb_buf ); |
561 WSL_OS_Free( ptKeyID.pb_buf ); |
631 // Alloc new buffer for all OID's |
624 // Alloc new buffer for all OID's |
632 HBufC* trustedUsagesBuf = HBufC::NewLC( trustedUsagesBufMaxLength ); |
625 HBufC* trustedUsagesBuf = HBufC::NewLC( trustedUsagesBufMaxLength ); |
633 pushedItemCount++; |
626 pushedItemCount++; |
634 |
627 |
635 trustedUsage.Set( trustedUsagesBuf->Des() ); |
628 trustedUsage.Set( trustedUsagesBuf->Des() ); |
636 |
629 |
637 // Add OID's to one buffer from separate buffers |
630 // Add OID's to one buffer from separate buffers |
638 for ( TInt i = 0; i < decodedOIDArray.Count(); i++ ) |
631 for ( TInt i = 0; i < decodedOIDArray.Count(); i++ ) |
639 { |
632 { |
640 if ( i == 0 ) //First one |
633 if ( i == 0 ) //First one |
641 { |
634 { |
649 } |
642 } |
650 } |
643 } |
651 |
644 |
652 TPckgBuf<TCertExtrasInfo> wimCertExtraPckg( certExtraInfo ); |
645 TPckgBuf<TCertExtrasInfo> wimCertExtraPckg( certExtraInfo ); |
653 aMessage.ReadL( 1, wimCertExtraPckg ); |
646 aMessage.ReadL( 1, wimCertExtraPckg ); |
654 |
647 |
655 wimCertExtraPckg().iCDFRefs = iWimUtilFuncs->MapCertLocation( uiCDFRefs ); |
648 wimCertExtraPckg().iCDFRefs = iWimUtilFuncs->MapCertLocation( uiCDFRefs ); |
656 |
649 |
657 if ( oidsLength > 0 ) // OID's found, write buffer to client |
650 if ( oidsLength > 0 ) // OID's found, write buffer to client |
658 { |
651 { |
659 aMessage.WriteL( 3, trustedUsage ); |
652 aMessage.WriteL( 3, trustedUsage ); |
660 } |
653 } |
661 aMessage.WriteL( 1, wimCertExtraPckg ); |
654 aMessage.WriteL( 1, wimCertExtraPckg ); |
668 // CWimCertHandler::GetCerticateCountL |
661 // CWimCertHandler::GetCerticateCountL |
669 // Fetches count of certicates in certain WIM card. |
662 // Fetches count of certicates in certain WIM card. |
670 // ----------------------------------------------------------------------------- |
663 // ----------------------------------------------------------------------------- |
671 // |
664 // |
672 void CWimCertHandler::GetCerticateCountL( |
665 void CWimCertHandler::GetCerticateCountL( |
673 const RMessage2& aMessage, |
666 const RMessage2& aMessage, |
674 CWimMemMgmt* aWimMgmt ) const |
667 CWimMemMgmt* aWimMgmt ) const |
675 { |
668 { |
676 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCerticateCountL | Begin")); |
669 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCerticateCountL | Begin")); |
677 WIMI_STAT callStatus = WIMI_Ok; |
670 WIMI_STAT callStatus = WIMI_Ok; |
678 TWimEntryType certEntryType = ( TWimEntryType )aMessage.Int1(); |
671 TWimEntryType certEntryType = ( TWimEntryType )aMessage.Int1(); |
679 |
672 |
680 __ASSERT_ALWAYS( certEntryType != EWimEntryTypeAll || |
673 __ASSERT_ALWAYS( certEntryType != EWimEntryTypeAll || |
681 certEntryType != EWimEntryTypeCA || |
674 certEntryType != EWimEntryTypeCA || |
682 certEntryType != EWimEntryTypePersonal, User::Leave( KErrArgument ) ); |
675 certEntryType != EWimEntryTypePersonal, User::Leave( KErrArgument ) ); |
683 |
676 |
684 WIMI_Ref_t* wimRef = NULL; |
677 WIMI_Ref_t* wimRef = NULL; |
685 TUint8 certCount = 0; |
678 TUint8 certCount = 0; |
686 |
679 |
687 wimRef = aWimMgmt->WimRef(); |
680 __ASSERT_ALWAYS( aWimMgmt, User::Leave( KErrArgument ) ); |
688 if ( !wimRef ) |
681 wimRef = MainWimRef( *aWimMgmt ); |
689 { |
|
690 wimRef = WIMI_GetWIMRef( 0 ); |
|
691 aWimMgmt->SetWIMRef( wimRef ); // takes ownership |
|
692 } |
|
693 |
682 |
694 if ( wimRef ) |
683 if ( wimRef ) |
695 { |
684 { |
696 if ( EWimEntryTypeAll == certEntryType || |
685 if ( EWimEntryTypeAll == certEntryType || |
697 EWimEntryTypeCA == certEntryType ) |
686 EWimEntryTypeCA == certEntryType ) |
698 { |
687 { |
699 callStatus = GetCertificateCountByWIM( wimRef, |
688 callStatus = GetCertificateCountByWIM( wimRef, |
700 certCount, |
689 certCount, |
701 WIMI_CU_CA ); |
690 WIMI_CU_CA ); |
702 } |
691 } |
703 |
692 |
704 if ( callStatus == WIMI_Ok && ( EWimEntryTypeAll == certEntryType || |
693 if ( callStatus == WIMI_Ok && ( EWimEntryTypeAll == certEntryType || |
705 EWimEntryTypePersonal == certEntryType ) ) |
694 EWimEntryTypePersonal == certEntryType ) ) |
706 { |
695 { |
707 callStatus = GetCertificateCountByWIM( wimRef, |
696 callStatus = GetCertificateCountByWIM( wimRef, |
708 certCount, |
697 certCount, |
709 WIMI_CU_Client ); |
698 WIMI_CU_Client ); |
710 } |
699 } |
711 } |
700 } |
712 else |
701 else |
713 { |
702 { |
728 // Fetches count of certicates in certain WIM card. |
717 // Fetches count of certicates in certain WIM card. |
729 // This function MAY NOT leave. |
718 // This function MAY NOT leave. |
730 // ----------------------------------------------------------------------------- |
719 // ----------------------------------------------------------------------------- |
731 // |
720 // |
732 WIMI_STAT CWimCertHandler::GetCertificateCountByWIM( |
721 WIMI_STAT CWimCertHandler::GetCertificateCountByWIM( |
733 WIMI_Ref_t* aRef, |
722 WIMI_Ref_t* aRef, |
734 TUint8& aCertCount, |
723 TUint8& aCertCount, |
735 TUint8 aUsage ) const |
724 TUint8 aUsage ) const |
736 { |
725 { |
737 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificateCountByWIM | Begin")); |
726 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificateCountByWIM | Begin")); |
738 |
727 |
739 // Get the number of certificates from smart card. |
728 // Get the number of certificates from smart card. |
740 TUint8 certNum = 0; |
729 TUint8 certNum = 0; |
741 WIMI_RefList_t refList ; |
730 WIMI_RefList_t refList ; |
742 WIMI_STAT callStatus = WIMI_GetCertificateListByWIM( aRef, |
731 WIMI_STAT callStatus = WIMI_GetCertificateListByWIM( aRef, |
743 aUsage, |
732 aUsage, |
744 &certNum, |
733 &certNum, |
745 &refList ); |
734 &refList ); |
746 |
735 |
747 if ( callStatus != WIMI_Ok ) |
736 if ( callStatus != WIMI_Ok ) |
748 { |
737 { |
749 return callStatus; |
738 return callStatus; |
750 } |
739 } |
751 |
740 |
752 // Find out how many certificate has zero length |
741 // Find out how many certificate has zero length |
753 TInt certLenZero = 0; |
742 TInt certLenZero = 0; |
754 TInt certMalformat = 0; |
743 TInt certMalformat = 0; |
755 for ( TInt i = 0; i < certNum ; i++ ) |
744 for ( TInt i = 0; i < certNum ; i++ ) |
756 { |
745 { |
763 TUint8 uiCDFRefs; |
752 TUint8 uiCDFRefs; |
764 TUint8 usage; |
753 TUint8 usage; |
765 TUint8 type; |
754 TUint8 type; |
766 TUint16 certLen; |
755 TUint16 certLen; |
767 TUint8 modifiable = 0; |
756 TUint8 modifiable = 0; |
768 callStatus = WIMI_GetCertificateInfo( |
757 callStatus = WIMI_GetCertificateInfo( |
769 refList[i], |
758 refList[i], |
770 &tempRef, |
759 &tempRef, |
771 &ptLabel, |
760 &ptLabel, |
772 &ptKeyID, /* Key Id (hash)*/ |
761 &ptKeyID, /* Key Id (hash)*/ |
773 &ptCAID, |
762 &ptCAID, |
774 &ptIssuerHash, |
763 &ptIssuerHash, |
775 &ptTrustedUsage, |
764 &ptTrustedUsage, |
776 &uiCDFRefs, |
765 &uiCDFRefs, |
777 &usage, /* 0 = client, 1 = CA */ |
766 &usage, /* 0 = client, 1 = CA */ |
778 &type, /* WTLSCert(1), |
767 &type, /* WTLSCert(1), |
779 X509Cert(2), |
768 X509Cert(2), |
780 X968Cert(3), |
769 X968Cert(3), |
781 CertURL(4) */ |
770 CertURL(4) */ |
782 &certLen, /* cert. content or URL length */ |
771 &certLen, /* cert. content or URL length */ |
783 &modifiable ); |
772 &modifiable ); |
784 |
773 |
785 if ( callStatus == WIMI_Ok ) |
774 if ( callStatus == WIMI_Ok ) |
786 { |
775 { |
787 free_WIMI_Ref_t( tempRef ); |
776 free_WIMI_Ref_t( tempRef ); |
788 |
777 |
789 if ( certLen == 0 ) |
778 if ( certLen == 0 ) |
790 { |
779 { |
791 certLenZero++; |
780 certLenZero++; |
792 } |
781 } |
793 |
782 |
794 // it is x509cert |
783 // it is x509cert |
795 if ( type == 2 && certLen != 0 ) |
784 if ( type == WIMI_CT_X509 && certLen != 0 ) |
796 { |
785 { |
797 |
786 |
798 //use this rough sanity checking |
787 //use this rough sanity checking |
799 if ( certLen < 10 ) |
788 if ( certLen < 10 ) |
800 { |
789 { |
824 // ----------------------------------------------------------------------------- |
813 // ----------------------------------------------------------------------------- |
825 // CWimCertHandler::StoreCertificateL |
814 // CWimCertHandler::StoreCertificateL |
826 // Stores certificate to the WIM card. |
815 // Stores certificate to the WIM card. |
827 // ----------------------------------------------------------------------------- |
816 // ----------------------------------------------------------------------------- |
828 // |
817 // |
829 void CWimCertHandler::StoreCertificateL( |
818 void CWimCertHandler::StoreCertificateL( |
830 TWimServRqst /*aOpcode*/, |
819 TWimServRqst /*aOpcode*/, |
831 const RMessage2& aMessage ) const |
820 const RMessage2& aMessage ) const |
832 { |
821 { |
833 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::StoreCertificateL | Begin")); |
822 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::StoreCertificateL | Begin")); |
834 aMessage.Complete( KErrNotSupported ); |
823 aMessage.Complete( KErrNotSupported ); |
837 // ----------------------------------------------------------------------------- |
826 // ----------------------------------------------------------------------------- |
838 // CWimCertHandler::RemoveCertificateL |
827 // CWimCertHandler::RemoveCertificateL |
839 // Removes certificate from a WIM card. |
828 // Removes certificate from a WIM card. |
840 // ----------------------------------------------------------------------------- |
829 // ----------------------------------------------------------------------------- |
841 // |
830 // |
842 void CWimCertHandler::RemoveCertificateL( |
831 void CWimCertHandler::RemoveCertificateL( |
843 const RMessage2& aMessage, |
832 const RMessage2& aMessage, |
844 CWimMemMgmt* /*aWimMgmt*/ ) const |
833 CWimMemMgmt* /*aWimMgmt*/ ) const |
845 { |
834 { |
846 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::RemoveCertificateL | Begin")); |
835 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::RemoveCertificateL | Begin")); |
847 aMessage.Complete( KErrNotSupported ); |
836 aMessage.Complete( KErrNotSupported ); |
873 // CWimCertHandler::GetCertificateDetailsL |
862 // CWimCertHandler::GetCertificateDetailsL |
874 // Fetches certificate details. |
863 // Fetches certificate details. |
875 // ----------------------------------------------------------------------------- |
864 // ----------------------------------------------------------------------------- |
876 // |
865 // |
877 void CWimCertHandler::GetCertificateDetailsL( |
866 void CWimCertHandler::GetCertificateDetailsL( |
878 TWimServRqst aOpCode, |
867 TWimServRqst aOpCode, |
879 const RMessage2& aMessage ) |
868 const RMessage2& aMessage ) |
880 { |
869 { |
881 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificateDetailsL | Begin")); |
870 _WIMTRACE(_L("WIM | WIMServer | CWimCertHandler::GetCertificateDetailsL | Begin")); |
882 TBool IsOk = SanityCheck( (TUint32)aMessage.Ptr0() ); |
871 TBool IsOk = SanityCheck( (TUint32)aMessage.Ptr0() ); |
883 if ( ! IsOk ) |
872 if ( ! IsOk ) |
884 { |
873 { |
885 aMessage.Panic(_L("WIM"), KErrBadHandle ); |
874 aMessage.Panic(_L("WIM"), KErrBadHandle ); |
886 return; |
875 return; |
887 } |
876 } |
888 |
877 |
889 //capability checking |
878 //capability checking |
890 TUint8 usage = 255; |
879 TUint8 usage = 255; |
891 WIMI_STAT callStatus = ResolveCertUsage( aMessage, usage ); |
880 WIMI_STAT callStatus = ResolveCertUsage( aMessage, usage ); |
892 if ( WIMI_Ok == callStatus ) |
881 if ( WIMI_Ok == callStatus ) |
893 { |
882 { |
894 if( !CheckReadCapsForUsage( aMessage, usage ) ) |
883 if( !CheckReadCapsForUsage( aMessage, usage ) ) |
895 { |
884 { |
896 aMessage.Complete(KErrPermissionDenied); |
885 aMessage.Complete(KErrPermissionDenied); |
897 return; |
886 return; |
898 } |
887 } |
899 } |
888 } |
900 |
889 |
901 //capabilty ok, go to fetch the details of the certificate. |
890 //capabilty ok, go to fetch the details of the certificate. |
924 TUint8& aUsage ) |
913 TUint8& aUsage ) |
925 { |
914 { |
926 _WIMTRACE(_L("CWimServer::ResolveCertUsage | Begin")); |
915 _WIMTRACE(_L("CWimServer::ResolveCertUsage | Begin")); |
927 |
916 |
928 // aMsg.Ptr0 contains reference to certificate |
917 // aMsg.Ptr0 contains reference to certificate |
929 |
918 |
930 WIMI_Ref_pt pCertRef = const_cast< WIMI_Ref_pt >( aMsg.Ptr0() ); |
919 WIMI_Ref_pt pCertRef = const_cast< WIMI_Ref_pt >( aMsg.Ptr0() ); |
931 _WIMTRACE2(_L("CWimServer::ResolveCertUsage | Begin aMsg.Ptr0() = %d"), aMsg.Ptr0()); |
920 _WIMTRACE2(_L("CWimServer::ResolveCertUsage | Begin aMsg.Ptr0() = %d"), aMsg.Ptr0()); |
932 |
921 |
933 WIMI_STAT callStatus = GetCertificateInfo( pCertRef, aUsage ); |
922 WIMI_STAT callStatus = GetCertificateInfo( pCertRef, aUsage ); |
934 |
923 |
1039 // Export public key from certificate. |
1028 // Export public key from certificate. |
1040 // ----------------------------------------------------------------------------- |
1029 // ----------------------------------------------------------------------------- |
1041 // |
1030 // |
1042 void CWimCertHandler::ExportPublicKeyL( const RMessage2& aMessage ) const |
1031 void CWimCertHandler::ExportPublicKeyL( const RMessage2& aMessage ) const |
1043 { |
1032 { |
1044 _WIMTRACE(_L("WIM | WIMServer | CWimPublicKeyHandler::ExportPublicKeyParamsL | Begin")); |
1033 _WIMTRACE(_L("WIM | WIMServer | CWimPublicKeyHandler::ExportPublicKeyL | Begin")); |
1045 |
1034 |
1046 TUint8 certType = 0; |
1035 TUint8 certType = 0; |
1047 |
1036 |
1048 TPckgBuf<TExportPublicKey> keyExportPckg; |
1037 TPckgBuf<TExportPublicKey> keyExportPckg; |
1049 aMessage.ReadL( 0, keyExportPckg ); |
1038 aMessage.ReadL( 0, keyExportPckg ); |
1050 |
1039 |
1051 HBufC8* publicKeyBuf = HBufC8::NewLC( KPublicKeyLength ); |
1040 HBufC8* publicKeyBuf = HBufC8::NewLC( KPublicKeyLength ); |
1052 |
1041 |
1053 TBuf8<KKeyIdLen> keyIdBuf = keyExportPckg().iKeyId; |
1042 TBuf8<KKeyIdLen> keyIdBuf = keyExportPckg().iKeyId; |
1054 |
1043 |
1055 WIMI_STAT callStatus = WIMI_Ok; |
1044 WIMI_STAT callStatus = WIMI_Ok; |
1140 { |
1129 { |
1141 callStatus = WIMI_ERR_UnsupportedCertificate; |
1130 callStatus = WIMI_ERR_UnsupportedCertificate; |
1142 } |
1131 } |
1143 } |
1132 } |
1144 } |
1133 } |
1145 |
1134 |
1146 // Retrieve certificate data from WIM |
1135 // Retrieve certificate data from WIM |
1147 if ( callStatus == WIMI_Ok ) |
1136 if ( callStatus == WIMI_Ok ) |
1148 { |
1137 { |
1149 callStatus = WIMI_CertificateReqT( trId, pCert, &ptCertData ); |
1138 callStatus = WIMI_CertificateReqT( trId, pCert, &ptCertData ); |
1150 if ( callStatus == WIMI_Ok ) |
1139 if ( callStatus == WIMI_Ok ) |
1152 CleanupPushWimBufL( ptCertData ); |
1141 CleanupPushWimBufL( ptCertData ); |
1153 |
1142 |
1154 TPtrC8 certPtr( ptCertData.pb_buf, ptCertData.ui_buf_length ); |
1143 TPtrC8 certPtr( ptCertData.pb_buf, ptCertData.ui_buf_length ); |
1155 TPtr8 publicKeyPtr = publicKeyBuf->Des(); |
1144 TPtr8 publicKeyPtr = publicKeyBuf->Des(); |
1156 |
1145 |
1157 TRAPD( parseOk, ParseCertPublicKeyL( certPtr, publicKeyPtr, certType ) ); |
1146 TRAPD( parseError, ParseCertPublicKeyL( certPtr, publicKeyPtr, certType ) ); |
1158 if ( parseOk ) |
1147 _WIMTRACE2(_L("WIM | WIMServer | CWimPublicKeyHandler::ExportPublicKeyL parseError %d"), parseError ); |
|
1148 if ( !parseError ) |
1159 { |
1149 { |
1160 aMessage.WriteL( 1, publicKeyPtr ); |
1150 aMessage.WriteL( 1, publicKeyPtr ); |
1161 } |
1151 } |
1162 else |
1152 else |
1163 { |
1153 { |
1165 } |
1155 } |
1166 |
1156 |
1167 CleanupStack::PopAndDestroy( ptCertData.pb_buf ); |
1157 CleanupStack::PopAndDestroy( ptCertData.pb_buf ); |
1168 } |
1158 } |
1169 } |
1159 } |
1170 |
1160 |
1171 CleanupStack::PopAndDestroy( certRefList ); |
1161 CleanupStack::PopAndDestroy( certRefList ); |
1172 } |
1162 } |
1173 |
1163 |
1174 CleanupStack::PopAndDestroy( publicKeyBuf ); |
1164 CleanupStack::PopAndDestroy( publicKeyBuf ); |
1175 |
1165 |
|
1166 _WIMTRACE2(_L("WIM | WIMServer | CWimPublicKeyHandler::ExportPublicKeyL callStatus %d"), callStatus); |
1176 aMessage.Complete( CWimUtilityFuncs::MapWIMError( callStatus ) ); |
1167 aMessage.Complete( CWimUtilityFuncs::MapWIMError( callStatus ) ); |
|
1168 _WIMTRACE(_L("WIM | WIMServer | CWimPublicKeyHandler::ExportPublicKeyL | End")); |
1177 } |
1169 } |
1178 |
1170 |
1179 // ----------------------------------------------------------------------------- |
1171 // ----------------------------------------------------------------------------- |
1180 // CWimCertHandler::ParseCertPublicKeyL |
1172 // CWimCertHandler::ParseCertPublicKeyL |
1181 // Parse public key from certificate. |
1173 // Parse public key from certificate. |
1184 void CWimCertHandler::ParseCertPublicKeyL( |
1176 void CWimCertHandler::ParseCertPublicKeyL( |
1185 const TDesC8& aCertData, |
1177 const TDesC8& aCertData, |
1186 TDes8& aPublicKey, |
1178 TDes8& aPublicKey, |
1187 const TUint8 aCertType ) const |
1179 const TUint8 aCertType ) const |
1188 { |
1180 { |
|
1181 _WIMTRACE2(_L("WIM | WIMServer | CWimPublicKeyHandler::ParseCertPublicKeyL | Begin, type %d"), aCertType); |
1189 CCertificate* certificate = NULL; |
1182 CCertificate* certificate = NULL; |
1190 CRSAPublicKey* publicKey = NULL; |
1183 CRSAPublicKey* publicKey = NULL; |
1191 |
1184 |
1192 switch ( aCertType ) |
1185 switch ( aCertType ) |
1193 { |
1186 { |
1225 } |
1218 } |
1226 // Write encoded key to prealloced buffer |
1219 // Write encoded key to prealloced buffer |
1227 encoded->WriteDERL( aPublicKey, pos ); |
1220 encoded->WriteDERL( aPublicKey, pos ); |
1228 |
1221 |
1229 CleanupStack::PopAndDestroy( 3, certificate ); // encoded, publicKey, certificate |
1222 CleanupStack::PopAndDestroy( 3, certificate ); // encoded, publicKey, certificate |
1230 } |
1223 _WIMTRACE(_L("WIM | WIMServer | CWimPublicKeyHandler::ParseCertPublicKeyL | End")); |
|
1224 } |
|
1225 |
|
1226 // ----------------------------------------------------------------------------- |
|
1227 // CWimCertHandler::MainWimRef() |
|
1228 // Returns cached WIM ref using WIM memory manager |
|
1229 // ----------------------------------------------------------------------------- |
|
1230 // |
|
1231 WIMI_Ref_t* CWimCertHandler::MainWimRef( CWimMemMgmt& aWimMgmt ) const |
|
1232 { |
|
1233 WIMI_Ref_t* ref = aWimMgmt.WimRef(); |
|
1234 if( !ref ) |
|
1235 { |
|
1236 ref = WIMI_GetWIMRef( 0 ); |
|
1237 aWimMgmt.SetWIMRef( ref ); // takes ownership |
|
1238 } |
|
1239 return ref; |
|
1240 } |
|
1241 |
1231 |
1242 |
1232 // End of File |
1243 // End of File |