23 #include <x509certext.h> |
23 #include <x509certext.h> |
24 #include <hash.h> |
24 #include <hash.h> |
25 #include <X509CertNameParser.h> |
25 #include <X509CertNameParser.h> |
26 #include <featmgr.h> |
26 #include <featmgr.h> |
27 #include <data_caging_path_literals.hrh> |
27 #include <data_caging_path_literals.hrh> |
|
28 #include <AknQueryDialog.h> |
28 #include <CertSaver.rsg> |
29 #include <CertSaver.rsg> |
29 #include <StringLoader.h> |
30 #include <StringLoader.h> |
30 #include <securityerr.h> |
31 #include <securityerr.h> |
|
32 #include <aknnotewrappers.h> // Note dialogs |
31 #include <apmrec.h> |
33 #include <apmrec.h> |
32 #include <eikenv.h> // CEikonEnv |
|
33 #include "certparser.h" |
34 #include "certparser.h" |
34 |
|
35 #include "SecQueryUi.h" // needed for password dialog |
|
36 |
|
37 #include <hbdevicemessageboxsymbian.h> // needed for Note dialogs |
|
38 |
35 |
39 // CONSTANTS |
36 // CONSTANTS |
40 _LIT( KPKCS12DllName, "crpkcs12.dll" ); // PKCS12 DLL name |
37 _LIT( KPKCS12DllName, "crpkcs12.dll" ); // PKCS12 DLL name |
41 const TInt KX509Version3 = 3; |
38 const TInt KX509Version3 = 3; |
42 const TInt KPwMaxLength = 32; |
39 const TInt KPwMaxLength = 32; |
154 // |
149 // |
155 TBool CCertParser::CheckIfPKCS12L( |
150 TBool CCertParser::CheckIfPKCS12L( |
156 const TDesC8& aPKCS12, |
151 const TDesC8& aPKCS12, |
157 const TDesC& aFileName ) |
152 const TDesC& aFileName ) |
158 { |
153 { |
159 |
|
160 CreatePKCS12L(); |
154 CreatePKCS12L(); |
161 |
155 |
162 if ( !iPKCS12->IsPKCS12Data( aPKCS12 ) ) |
156 if ( !iPKCS12->IsPKCS12Data( aPKCS12 ) ) |
163 { |
157 { |
164 ShowErrorNoteL( R_CERTSAVER_PKCS12_FILE_CORRUPTED ); |
158 ShowErrorNoteL( R_CERTSAVER_PKCS12_FILE_CORRUPTED ); |
165 return EFalse; |
159 return EFalse; |
166 } |
160 } |
167 |
161 |
168 TBool done = EFalse; |
162 TBool done = EFalse; |
169 TBuf<KPwMaxLength> password; |
163 TBuf<KPwMaxLength> password; |
|
164 HBufC* buffer = NULL; |
|
165 |
|
166 if ( !iEikEnv ) |
|
167 { |
|
168 iEikEnv = CEikonEnv::Static(); |
|
169 } |
170 |
170 |
171 while ( !done ) |
171 while ( !done ) |
172 { |
172 { |
173 if ( !GetPasswordL( password, aFileName ) ) |
173 if ( !GetPasswordL( password, aFileName ) ) |
174 { |
174 { |
175 ShowErrorNoteL(R_CERTSAVER_PKCS12_DISCARDED); |
175 buffer = iEikEnv->AllocReadResourceLC( R_CERTSAVER_PKCS12_DISCARDED ); |
|
176 CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue ); |
|
177 note->ExecuteLD(buffer->Des()); |
|
178 CleanupStack::PopAndDestroy( buffer ); |
176 User::Leave( KErrExitApp ); |
179 User::Leave( KErrExitApp ); |
177 } |
180 } |
178 TRAPD( err, iPKCS12->ParseL( aPKCS12, password ) ); |
181 TRAPD( err, iPKCS12->ParseL( aPKCS12, password ) ); |
179 if ( err != KErrBadPassphrase ) |
182 if ( err != KErrBadPassphrase ) |
180 { |
183 { |
221 // |
224 // |
222 // ---------------------------------------------------------- |
225 // ---------------------------------------------------------- |
223 // |
226 // |
224 TInt CCertParser::GetPasswordL( TDes& aPassword, const TDesC& aFileName ) |
227 TInt CCertParser::GetPasswordL( TDes& aPassword, const TDesC& aFileName ) |
225 { |
228 { |
226 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
229 CAknTextQueryDialog* query = CAknTextQueryDialog::NewL( aPassword ); |
227 HBufC* prompt =StringLoader::LoadLC( R_QTN_CM_TITLE_P12_PASSWORD, aFileName ); |
230 CleanupStack::PushL( query ); |
228 TInt queryAccepted = SecQueryUi->SecQueryDialog(prompt->Des(), aPassword, |
231 HBufC* prompt = |
229 1,KPwMaxLength, |
232 StringLoader::LoadLC( R_QTN_CM_TITLE_P12_PASSWORD, aFileName ); |
230 ESecUiAlphaSupported | |
233 query->SetPromptL( *prompt ); |
231 ESecUiCancelSupported | |
234 CleanupStack::PopAndDestroy( prompt ); |
232 ESecUiSecretSupported | |
235 CleanupStack::Pop( query ); |
233 ESecUiEmergencyNotSupported); |
236 return query->ExecuteLD( R_PKCS12_PW_QUERY_DIALOG ); |
234 CleanupStack::PopAndDestroy( prompt ); |
237 } |
235 delete SecQueryUi; |
|
236 SecQueryUi=NULL; |
|
237 return (queryAccepted==KErrNone); |
|
238 } |
|
239 |
238 |
240 // ---------------------------------------------------------- |
239 // ---------------------------------------------------------- |
241 // CCertParser::CheckIfX509CertificateL() |
240 // CCertParser::CheckIfX509CertificateL() |
242 // Returns the type of the certificate. |
241 // Returns the type of the certificate. |
243 // ---------------------------------------------------------- |
242 // ---------------------------------------------------------- |
244 // |
243 // |
245 TBool CCertParser::CheckIfX509CertificateL(const TDesC8& aCert) |
244 TBool CCertParser::CheckIfX509CertificateL(const TDesC8& aCert) |
246 { |
245 { |
247 |
|
248 TRAPD( err, |
246 TRAPD( err, |
249 iCert = CX509Certificate::NewL(aCert); |
247 iCert = CX509Certificate::NewL(aCert); |
250 ); |
248 ); |
251 |
249 |
252 if ( err != KErrNone ) |
250 if ( err != KErrNone ) |
302 // CCertParser::CACertificates() |
300 // CCertParser::CACertificates() |
303 // ---------------------------------------------------------- |
301 // ---------------------------------------------------------- |
304 // |
302 // |
305 const CArrayPtr<CX509Certificate>& CCertParser::CACertificates() const |
303 const CArrayPtr<CX509Certificate>& CCertParser::CACertificates() const |
306 { |
304 { |
307 |
|
308 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
305 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
309 return iPKCS12->CACertificates(); |
306 return iPKCS12->CACertificates(); |
310 } |
307 } |
311 |
308 |
312 // ---------------------------------------------------------- |
309 // ---------------------------------------------------------- |
313 // CCertParser::UserCertificates() |
310 // CCertParser::UserCertificates() |
314 // ---------------------------------------------------------- |
311 // ---------------------------------------------------------- |
315 // |
312 // |
316 const CArrayPtr<CX509Certificate>& CCertParser::UserCertificates() const |
313 const CArrayPtr<CX509Certificate>& CCertParser::UserCertificates() const |
317 { |
314 { |
318 |
|
319 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
315 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
320 return iPKCS12->UserCertificates(); |
316 return iPKCS12->UserCertificates(); |
321 } |
317 } |
322 |
318 |
323 // ---------------------------------------------------------- |
319 // ---------------------------------------------------------- |
324 // CCertParser::Keys() |
320 // CCertParser::Keys() |
325 // ---------------------------------------------------------- |
321 // ---------------------------------------------------------- |
326 // |
322 // |
327 const CArrayPtr<HBufC8>& CCertParser::Keys() const |
323 const CArrayPtr<HBufC8>& CCertParser::Keys() const |
328 { |
324 { |
329 |
|
330 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
325 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
331 return iPKCS12->PrivateKeys(); |
326 return iPKCS12->PrivateKeys(); |
332 } |
327 } |
333 |
328 |
334 // ---------------------------------------------------------- |
329 // ---------------------------------------------------------- |
335 // CCertParser::CertType() |
330 // CCertParser::CertType() |
336 // ---------------------------------------------------------- |
331 // ---------------------------------------------------------- |
337 // |
332 // |
338 CCertParser::TCertType CCertParser::CertType() const |
333 CCertParser::TCertType CCertParser::CertType() const |
339 { |
334 { |
340 |
|
341 return iCertType; |
335 return iCertType; |
342 } |
336 } |
343 |
337 |
344 // ---------------------------------------------------------- |
338 // ---------------------------------------------------------- |
345 // CCertParser::CertificateBuf() |
339 // CCertParser::CertificateBuf() |
346 // Returns the content of the certificate. |
340 // Returns the content of the certificate. |
347 // ---------------------------------------------------------- |
341 // ---------------------------------------------------------- |
348 // |
342 // |
349 const TPtrC8 CCertParser::CertificateBuf() const |
343 const TPtrC8 CCertParser::CertificateBuf() const |
350 { |
344 { |
351 |
|
352 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
345 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
353 return iCert->Encoding(); |
346 return iCert->Encoding(); |
354 } |
347 } |
355 |
348 |
356 // ---------------------------------------------------------- |
349 // ---------------------------------------------------------- |
358 // Returns the X.509 certificate object. |
351 // Returns the X.509 certificate object. |
359 // ---------------------------------------------------------- |
352 // ---------------------------------------------------------- |
360 // |
353 // |
361 const CX509Certificate& CCertParser::Certificate() const |
354 const CX509Certificate& CCertParser::Certificate() const |
362 { |
355 { |
363 |
|
364 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
356 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
365 return *((CX509Certificate*)iCert); |
357 return *((CX509Certificate*)iCert); |
366 } |
358 } |
367 |
359 |
368 // ---------------------------------------------------------- |
360 // ---------------------------------------------------------- |
375 if ( !iEikEnv ) |
367 if ( !iEikEnv ) |
376 { |
368 { |
377 iEikEnv = CEikonEnv::Static(); |
369 iEikEnv = CEikonEnv::Static(); |
378 } |
370 } |
379 HBufC* buffer = iEikEnv->AllocReadResourceLC( aResourceID ); |
371 HBufC* buffer = iEikEnv->AllocReadResourceLC( aResourceID ); |
380 CHbDeviceMessageBoxSymbian* iMessageBox = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EWarning); |
372 CAknErrorNote* note = new (ELeave) CAknErrorNote( ETrue ); |
381 CleanupStack::PushL(iMessageBox); |
373 note->ExecuteLD(buffer->Des()); |
382 iMessageBox->SetTextL(buffer->Des()); |
374 CleanupStack::PopAndDestroy( buffer ); |
383 iMessageBox->SetTimeout(6000); |
|
384 iMessageBox->ExecL(); |
|
385 CleanupStack::PopAndDestroy(iMessageBox); |
|
386 CleanupStack::PopAndDestroy( buffer ); |
|
387 } |
375 } |
388 |
376 |
389 // End of File |
377 // End of File |
390 |
378 |