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> |
|
29 #include <CertSaver.rsg> |
28 #include <CertSaver.rsg> |
30 #include <StringLoader.h> |
29 #include <StringLoader.h> |
31 #include <securityerr.h> |
30 #include <securityerr.h> |
32 #include <aknnotewrappers.h> // Note dialogs |
31 #include <aknnotewrappers.h> // Note dialogs text, TODO: could be removed after localization is ready |
33 #include <apmrec.h> |
32 #include <apmrec.h> |
34 #include "certparser.h" |
33 #include "certparser.h" |
|
34 |
|
35 #include "SecQueryUi.h" // needed for password dialog |
|
36 |
|
37 #include <hbdevicemessageboxsymbian.h> // needed for Note dialogs |
35 |
38 |
36 // CONSTANTS |
39 // CONSTANTS |
37 _LIT( KPKCS12DllName, "crpkcs12.dll" ); // PKCS12 DLL name |
40 _LIT( KPKCS12DllName, "crpkcs12.dll" ); // PKCS12 DLL name |
38 const TInt KX509Version3 = 3; |
41 const TInt KX509Version3 = 3; |
39 const TInt KPwMaxLength = 32; |
42 const TInt KPwMaxLength = 32; |
171 while ( !done ) |
177 while ( !done ) |
172 { |
178 { |
173 if ( !GetPasswordL( password, aFileName ) ) |
179 if ( !GetPasswordL( password, aFileName ) ) |
174 { |
180 { |
175 buffer = iEikEnv->AllocReadResourceLC( R_CERTSAVER_PKCS12_DISCARDED ); |
181 buffer = iEikEnv->AllocReadResourceLC( R_CERTSAVER_PKCS12_DISCARDED ); |
176 CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue ); |
182 CHbDeviceMessageBoxSymbian::InformationL(buffer->Des()); |
177 note->ExecuteLD(buffer->Des()); |
|
178 CleanupStack::PopAndDestroy( buffer ); |
183 CleanupStack::PopAndDestroy( buffer ); |
179 User::Leave( KErrExitApp ); |
184 User::Leave( KErrExitApp ); |
180 } |
185 } |
181 TRAPD( err, iPKCS12->ParseL( aPKCS12, password ) ); |
186 TRAPD( err, iPKCS12->ParseL( aPKCS12, password ) ); |
182 if ( err != KErrBadPassphrase ) |
187 if ( err != KErrBadPassphrase ) |
224 // |
229 // |
225 // ---------------------------------------------------------- |
230 // ---------------------------------------------------------- |
226 // |
231 // |
227 TInt CCertParser::GetPasswordL( TDes& aPassword, const TDesC& aFileName ) |
232 TInt CCertParser::GetPasswordL( TDes& aPassword, const TDesC& aFileName ) |
228 { |
233 { |
229 CAknTextQueryDialog* query = CAknTextQueryDialog::NewL( aPassword ); |
234 CSecQueryUi* SecQueryUi = CSecQueryUi::NewL(); |
230 CleanupStack::PushL( query ); |
235 HBufC* prompt =StringLoader::LoadLC( R_QTN_CM_TITLE_P12_PASSWORD, aFileName ); |
231 HBufC* prompt = |
236 TInt queryAccepted = SecQueryUi->SecQueryDialog(prompt->Des(), aPassword, |
232 StringLoader::LoadLC( R_QTN_CM_TITLE_P12_PASSWORD, aFileName ); |
237 1,KPwMaxLength, |
233 query->SetPromptL( *prompt ); |
238 ESecUiAlphaSupported | |
234 CleanupStack::PopAndDestroy( prompt ); |
239 ESecUiCancelSupported | |
235 CleanupStack::Pop( query ); |
240 ESecUiSecretSupported | |
236 return query->ExecuteLD( R_PKCS12_PW_QUERY_DIALOG ); |
241 ESecUiEmergencyNotSupported); |
237 } |
242 CleanupStack::PopAndDestroy( prompt ); |
|
243 delete SecQueryUi; |
|
244 SecQueryUi=NULL; |
|
245 return (queryAccepted==KErrNone); |
|
246 } |
238 |
247 |
239 // ---------------------------------------------------------- |
248 // ---------------------------------------------------------- |
240 // CCertParser::CheckIfX509CertificateL() |
249 // CCertParser::CheckIfX509CertificateL() |
241 // Returns the type of the certificate. |
250 // Returns the type of the certificate. |
242 // ---------------------------------------------------------- |
251 // ---------------------------------------------------------- |
243 // |
252 // |
244 TBool CCertParser::CheckIfX509CertificateL(const TDesC8& aCert) |
253 TBool CCertParser::CheckIfX509CertificateL(const TDesC8& aCert) |
245 { |
254 { |
|
255 |
246 TRAPD( err, |
256 TRAPD( err, |
247 iCert = CX509Certificate::NewL(aCert); |
257 iCert = CX509Certificate::NewL(aCert); |
248 ); |
258 ); |
249 |
259 |
250 if ( err != KErrNone ) |
260 if ( err != KErrNone ) |
300 // CCertParser::CACertificates() |
310 // CCertParser::CACertificates() |
301 // ---------------------------------------------------------- |
311 // ---------------------------------------------------------- |
302 // |
312 // |
303 const CArrayPtr<CX509Certificate>& CCertParser::CACertificates() const |
313 const CArrayPtr<CX509Certificate>& CCertParser::CACertificates() const |
304 { |
314 { |
|
315 |
305 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
316 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
306 return iPKCS12->CACertificates(); |
317 return iPKCS12->CACertificates(); |
307 } |
318 } |
308 |
319 |
309 // ---------------------------------------------------------- |
320 // ---------------------------------------------------------- |
310 // CCertParser::UserCertificates() |
321 // CCertParser::UserCertificates() |
311 // ---------------------------------------------------------- |
322 // ---------------------------------------------------------- |
312 // |
323 // |
313 const CArrayPtr<CX509Certificate>& CCertParser::UserCertificates() const |
324 const CArrayPtr<CX509Certificate>& CCertParser::UserCertificates() const |
314 { |
325 { |
|
326 |
315 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
327 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
316 return iPKCS12->UserCertificates(); |
328 return iPKCS12->UserCertificates(); |
317 } |
329 } |
318 |
330 |
319 // ---------------------------------------------------------- |
331 // ---------------------------------------------------------- |
320 // CCertParser::Keys() |
332 // CCertParser::Keys() |
321 // ---------------------------------------------------------- |
333 // ---------------------------------------------------------- |
322 // |
334 // |
323 const CArrayPtr<HBufC8>& CCertParser::Keys() const |
335 const CArrayPtr<HBufC8>& CCertParser::Keys() const |
324 { |
336 { |
|
337 |
325 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
338 __ASSERT_ALWAYS( iPKCS12, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
326 return iPKCS12->PrivateKeys(); |
339 return iPKCS12->PrivateKeys(); |
327 } |
340 } |
328 |
341 |
329 // ---------------------------------------------------------- |
342 // ---------------------------------------------------------- |
330 // CCertParser::CertType() |
343 // CCertParser::CertType() |
331 // ---------------------------------------------------------- |
344 // ---------------------------------------------------------- |
332 // |
345 // |
333 CCertParser::TCertType CCertParser::CertType() const |
346 CCertParser::TCertType CCertParser::CertType() const |
334 { |
347 { |
|
348 |
335 return iCertType; |
349 return iCertType; |
336 } |
350 } |
337 |
351 |
338 // ---------------------------------------------------------- |
352 // ---------------------------------------------------------- |
339 // CCertParser::CertificateBuf() |
353 // CCertParser::CertificateBuf() |
340 // Returns the content of the certificate. |
354 // Returns the content of the certificate. |
341 // ---------------------------------------------------------- |
355 // ---------------------------------------------------------- |
342 // |
356 // |
343 const TPtrC8 CCertParser::CertificateBuf() const |
357 const TPtrC8 CCertParser::CertificateBuf() const |
344 { |
358 { |
|
359 |
345 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
360 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
346 return iCert->Encoding(); |
361 return iCert->Encoding(); |
347 } |
362 } |
348 |
363 |
349 // ---------------------------------------------------------- |
364 // ---------------------------------------------------------- |
351 // Returns the X.509 certificate object. |
366 // Returns the X.509 certificate object. |
352 // ---------------------------------------------------------- |
367 // ---------------------------------------------------------- |
353 // |
368 // |
354 const CX509Certificate& CCertParser::Certificate() const |
369 const CX509Certificate& CCertParser::Certificate() const |
355 { |
370 { |
|
371 |
356 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
372 __ASSERT_ALWAYS( iCert, User::Panic( KCertSaverPanic, KPanicNullPointer ) ); |
357 return *((CX509Certificate*)iCert); |
373 return *((CX509Certificate*)iCert); |
358 } |
374 } |
359 |
375 |
360 // ---------------------------------------------------------- |
376 // ---------------------------------------------------------- |