30 #include <asymmetric.h> |
28 #include <asymmetric.h> |
31 #include <CCMSX509Certificate.h> |
29 #include <CCMSX509Certificate.h> |
32 #include <CCMSSignerInfo.h> |
30 #include <CCMSSignerInfo.h> |
33 #include <CCMSEncapsulatedContentInfo.h> |
31 #include <CCMSEncapsulatedContentInfo.h> |
34 #include <CCMSSignedData.h> |
32 #include <CCMSSignedData.h> |
35 #include <PKIDlg.h> |
33 |
36 #include "cstsseprompt.h" |
34 #include "cstsseprompt.h" |
37 |
35 |
38 #include <hash.h> |
36 #include <hash.h> |
39 #include "fs_methodcall.h" |
37 #include "fs_methodcall.h" |
40 #include <jutils.h> |
38 #include <jutils.h> |
41 #include "satsajnitools.h" |
39 #include "satsajnitools.h" |
42 #include "logger.h" |
40 #include "logger.h" |
43 #include "jstringutils.h" |
41 #include "jstringutils.h" |
44 |
42 |
45 // CONSTANTS |
43 #include <hbdevicemessageboxsymbian.h> |
|
44 #include <hbpopup.h> |
|
45 |
|
46 |
46 const TInt KDefaultGranularity = 1; |
47 const TInt KDefaultGranularity = 1; |
47 |
48 |
48 const TInt KOptionIncludeContent = 1; |
49 const TInt KOptionIncludeContent = 1; |
49 const TInt KOptionIncludeCertificate = 2; |
50 const TInt KOptionIncludeCertificate = 2; |
50 |
51 |
124 // |
122 // |
125 HBufC8* CSTSSignatureService::AuthenticateL(const TDesC8& abytesToAuthenticate, |
123 HBufC8* CSTSSignatureService::AuthenticateL(const TDesC8& abytesToAuthenticate, |
126 TInt aOptions, const CDesCArray& aCaNames, |
124 TInt aOptions, const CDesCArray& aCaNames, |
127 const TDesC& asecurityElementPrompt, TBool aShowData) |
125 const TDesC& asecurityElementPrompt, TBool aShowData) |
128 { |
126 { |
129 LOG(ESATSA, EInfo, "+ CSTSSignatureService::AuthenticateL"); |
|
130 if (iState != EReady) |
127 if (iState != EReady) |
131 { |
128 { |
132 ELOG(ESATSA, "CSTSSignatureService::AuthenticateL: Not Ready"); |
129 ELOG(ESATSA, "CSTSSignatureService::AuthenticateL: Not Ready"); |
133 User::Leave(KErrNotReady); |
130 User::Leave(KErrNotReady); |
134 } |
131 } |
135 |
132 |
136 LOG(ESATSA, EInfo, "CSTSSignatureService::AuthenticateL:After convertions"); |
|
137 // First we need to convert the data to unicode, if we have to display it |
133 // First we need to convert the data to unicode, if we have to display it |
138 HBufC* textToDisplay = NULL; |
134 HBufC* textToDisplay = NULL; |
139 if (aShowData) |
135 if (aShowData) |
140 { |
136 { |
141 textToDisplay = ConvertUTF8ToUnicodeL(abytesToAuthenticate); |
137 textToDisplay = ConvertUTF8ToUnicodeL(abytesToAuthenticate); |
153 iMessage.Set(abytesToAuthenticate); |
149 iMessage.Set(abytesToAuthenticate); |
154 |
150 |
155 iOptions = aOptions; |
151 iOptions = aOptions; |
156 |
152 |
157 iShowNotes = EFalse; |
153 iShowNotes = EFalse; |
158 |
|
159 LOG(ESATSA, EInfo, "CSTSSignatureService::AuthenticateL:Going to call CreateSignatureL"); |
|
160 // get handles to applicable certificates |
154 // get handles to applicable certificates |
161 HBufC8* retVal = CreateSignatureL(aCaNames, EX509UsageDigitalSignature, |
155 HBufC8* retVal = CreateSignatureL(aCaNames, EX509UsageDigitalSignature, |
162 asecurityElementPrompt); |
156 asecurityElementPrompt); |
163 LOG(ESATSA, EInfo, "CSTSSignatureService::AuthenticateL:After call to CreateSignatureL"); |
|
164 |
|
165 LOG(ESATSA, EInfo, "-- CSTSSignatureService::AuthenticateL"); |
|
166 return retVal; |
157 return retVal; |
167 } |
158 } |
168 |
159 |
169 TInt CSTSSignatureService::StaticAuthenticateL(JNIEnv* aJniEnv, |
160 TInt CSTSSignatureService::StaticAuthenticateL(JNIEnv* aJniEnv, |
170 CSTSSignatureService* service, jbyteArray aByteArrayToAuthenticate, |
161 CSTSSignatureService* service, jbyteArray aByteArrayToAuthenticate, |
171 jint aOptions, jobjectArray aCaNames, jstring aSecurityElementPrompt, |
162 jint aOptions, jobjectArray aCaNames, jstring aSecurityElementPrompt, |
172 jboolean aShowData, HBufC8** aRetVal) |
163 jboolean aShowData, HBufC8** aRetVal) |
173 { |
164 { |
174 LOG(ESATSA, EInfo, "+ CSTSSignatureService::StaticAuthenticateL"); |
|
175 const TInt byteArrayLength = aJniEnv->GetArrayLength( |
165 const TInt byteArrayLength = aJniEnv->GetArrayLength( |
176 aByteArrayToAuthenticate); |
166 aByteArrayToAuthenticate); |
177 jbyte* bytesToAuthenticate = aJniEnv->GetByteArrayElements( |
167 jbyte* bytesToAuthenticate = aJniEnv->GetByteArrayElements( |
178 aByteArrayToAuthenticate, NULL); |
168 aByteArrayToAuthenticate, NULL); |
179 |
169 |
187 byteArrayLength); |
177 byteArrayLength); |
188 |
178 |
189 CDesCArrayFlat* nativeCaNames = STSCreateNativeStringArrayL(aJniEnv, |
179 CDesCArrayFlat* nativeCaNames = STSCreateNativeStringArrayL(aJniEnv, |
190 aCaNames); |
180 aCaNames); |
191 |
181 |
192 LOG(ESATSA, EInfo, "CSTSSignatureService::StaticAuthenticateL: prepare se prompt"); |
|
193 const JStringUtils securityElementPrompt(*aJniEnv, aSecurityElementPrompt); |
182 const JStringUtils securityElementPrompt(*aJniEnv, aSecurityElementPrompt); |
194 |
183 |
195 LOG(ESATSA, EInfo, "CSTSSignatureService::StaticAuthenticateL: start convertions to TInt"); |
|
196 TBool ShowData = static_cast<TBool>(aShowData); |
184 TBool ShowData = static_cast<TBool>(aShowData); |
197 const TDesC* sec = static_cast<const TDesC*>(&securityElementPrompt); |
185 const TDesC* sec = static_cast<const TDesC*>(&securityElementPrompt); |
198 |
186 |
199 LOG(ESATSA, EInfo, "CSTSSignatureService::StaticAuthenticateL: After convertions,going to call CallMethodL"); |
|
200 TRAPD(err, CallMethodL(*aRetVal, service, |
187 TRAPD(err, CallMethodL(*aRetVal, service, |
201 &CSTSSignatureService::AuthenticateL, desToAuthenticate, aOptions, |
188 &CSTSSignatureService::AuthenticateL, desToAuthenticate, aOptions, |
202 *nativeCaNames, *sec, ShowData, service)); |
189 *nativeCaNames, *sec, ShowData, service)); |
203 |
190 |
204 LOG(ESATSA, EInfo, "+ CSTSSignatureService::StaticAuthenticateL:After CallmethodL"); |
|
205 LOG(ESATSA, EInfo, "-- return CSTSSignatureService::StaticAuthenticateL"); |
|
206 return err; |
191 return err; |
207 |
192 |
208 } |
193 } |
209 |
194 |
210 // ----------------------------------------------------------------------------- |
195 // ----------------------------------------------------------------------------- |
214 // ----------------------------------------------------------------------------- |
199 // ----------------------------------------------------------------------------- |
215 |
200 |
216 HBufC8* CSTSSignatureService::SignL(const TDesC8& aBytesToSign, TInt aOptions, |
201 HBufC8* CSTSSignatureService::SignL(const TDesC8& aBytesToSign, TInt aOptions, |
217 const CDesCArray& aCaNames, const TDesC& aSecurityElementPrompt) |
202 const CDesCArray& aCaNames, const TDesC& aSecurityElementPrompt) |
218 { |
203 { |
219 LOG(ESATSA, EInfo, "+ CSTSSignatureService::SignL"); |
|
220 if (iState != EReady) |
204 if (iState != EReady) |
221 { |
205 { |
222 ELOG(ESATSA, "CSTSSignatureService::SignL: Not Ready"); |
206 ELOG(ESATSA, "CSTSSignatureService::SignL: Not Ready"); |
223 User::Leave(KErrNotReady); |
207 User::Leave(KErrNotReady); |
224 } |
208 } |
225 |
209 |
226 LOG(ESATSA, EInfo, "CSTSSignatureService::SignL: start convertions!"); |
|
227 LOG(ESATSA, EInfo, "CSTSSignatureService::SignL: After convertions"); |
|
228 // convert text from UTF8 |
210 // convert text from UTF8 |
229 HBufC* textToDisplay = ConvertUTF8ToUnicodeL(aBytesToSign); |
211 HBufC* textToDisplay = ConvertUTF8ToUnicodeL(aBytesToSign); |
230 delete iTextToDisplay; |
212 delete iTextToDisplay; |
231 iTextToDisplay = textToDisplay; |
213 iTextToDisplay = textToDisplay; |
232 |
214 |
254 // |
234 // |
255 TInt CSTSSignatureService::StaticSignL(JNIEnv* aJniEnv, |
235 TInt CSTSSignatureService::StaticSignL(JNIEnv* aJniEnv, |
256 CSTSSignatureService* service, jbyteArray aBytesToSign, jint aOptions, |
236 CSTSSignatureService* service, jbyteArray aBytesToSign, jint aOptions, |
257 jobjectArray aCaNames, jstring aSecurityElementPrompt, HBufC8** aRetVal) |
237 jobjectArray aCaNames, jstring aSecurityElementPrompt, HBufC8** aRetVal) |
258 { |
238 { |
259 LOG(ESATSA, EInfo, "+ CSTSSignatureService::StaticSignL"); |
|
260 const TInt byteArrayLength = aJniEnv->GetArrayLength(aBytesToSign); |
239 const TInt byteArrayLength = aJniEnv->GetArrayLength(aBytesToSign); |
261 jbyte* bytesToSign = aJniEnv->GetByteArrayElements(aBytesToSign, NULL); |
240 jbyte* bytesToSign = aJniEnv->GetByteArrayElements(aBytesToSign, NULL); |
262 |
241 |
263 if (!bytesToSign) |
242 if (!bytesToSign) |
264 { |
243 { |
265 LOG(ESATSA, EInfo, "CSTSSignatureService::StaticSignL: No memory"); |
244 ELOG(ESATSA, "CSTSSignatureService::StaticSignL: No memory"); |
266 return NULL; |
245 return NULL; |
267 } |
246 } |
268 |
247 |
269 TPtrC8 desToSign(reinterpret_cast<TUint8*>(bytesToSign), byteArrayLength); |
248 TPtrC8 desToSign(reinterpret_cast<TUint8*>(bytesToSign), byteArrayLength); |
270 |
249 |
271 CDesCArrayFlat* nativeCaNames = STSCreateNativeStringArrayL(aJniEnv, |
250 CDesCArrayFlat* nativeCaNames = STSCreateNativeStringArrayL(aJniEnv, |
272 aCaNames); |
251 aCaNames); |
273 |
252 |
274 const JStringUtils securityElementPrompt(*aJniEnv, aSecurityElementPrompt); |
253 const JStringUtils securityElementPrompt(*aJniEnv, aSecurityElementPrompt); |
275 |
254 |
276 LOG(ESATSA, EInfo, "CSTSSignatureService::StaticSignL: Start convertions"); |
255 |
277 LOG(ESATSA, EInfo, "CSTSSignatureService::StaticSignL: Before callmethodl"); |
|
278 |
|
279 const TDesC* sec = static_cast<const TDesC*>(&securityElementPrompt); |
256 const TDesC* sec = static_cast<const TDesC*>(&securityElementPrompt); |
280 |
257 |
281 TRAPD(err, CallMethodL(*aRetVal, service, &CSTSSignatureService::SignL, |
258 TRAPD(err, CallMethodL(*aRetVal, service, &CSTSSignatureService::SignL, |
282 desToSign, aOptions, *nativeCaNames, *sec, service)); |
259 desToSign, aOptions, *nativeCaNames, *sec, service)); |
283 |
260 |
284 LOG(ESATSA, EInfo, "-- ret CSTSSignatureService::StaticSignL"); |
|
285 return err; |
261 return err; |
286 } |
262 } |
287 |
263 |
288 // ----------------------------------------------------------------------------- |
264 // ----------------------------------------------------------------------------- |
289 // CSTSSignatureService::RunL |
265 // CSTSSignatureService::RunL |
290 // CActive callback |
266 // CActive callback |
291 // ----------------------------------------------------------------------------- |
267 // ----------------------------------------------------------------------------- |
292 // |
268 // |
293 void CSTSSignatureService::RunL() |
269 void CSTSSignatureService::RunL() |
294 { |
270 { |
295 LOG(ESATSA, EInfo, "+ CSTSSignatureService::RunL"); |
|
296 if (iStatus == KErrCancel) |
271 if (iStatus == KErrCancel) |
297 { |
272 { |
298 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: KErrCancel"); |
|
299 if (iShowNotes) |
273 if (iShowNotes) |
300 { |
274 { |
301 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: ShowNote"); |
|
302 iState = EFinalNote; |
275 iState = EFinalNote; |
303 iStatus = KErrNone; |
276 iStatus = KErrNone; |
304 iPKIDialog->Note(MPKIDialog::ESigningCancelled, iStatus); |
277 |
|
278 // Using Orbit API |
|
279 CHbDeviceMessageBoxSymbian* messageBox |
|
280 = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EWarning); |
|
281 CleanupStack::PushL(messageBox); |
|
282 |
|
283 _LIT(KQuestion, "Do you want to sign the data?"); |
|
284 messageBox->SetTextL(KQuestion); |
|
285 messageBox->SetTimeout(HbPopup::NoTimeout); |
|
286 |
|
287 // Read localised versions instead of hard coded values. |
|
288 _LIT(KAllowButtonText, "Allow"); |
|
289 _LIT(KDenyButtonText, "Deny"); |
|
290 |
|
291 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::EAcceptButton, KAllowButtonText); |
|
292 messageBox->SetButton(CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue); |
|
293 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::ERejectButton, KDenyButtonText); |
|
294 messageBox->SetButton(CHbDeviceMessageBoxSymbian::ERejectButton, ETrue); |
|
295 |
|
296 // by default the answer is Allow |
|
297 if (messageBox->ExecL() == CHbDeviceMessageBoxSymbian::ERejectButton) |
|
298 { |
|
299 |
|
300 } |
|
301 |
|
302 messageBox->Close(); |
|
303 CleanupStack::PopAndDestroy(messageBox); |
|
304 |
305 SetActive(); |
305 SetActive(); |
306 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: Done ShowNote"); |
306 } |
307 } |
|
308 else |
307 else |
309 { |
308 { |
310 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: Complete"); |
309 Complete(KErrNone); |
311 Complete(KErrNone); |
|
312 } |
310 } |
313 } |
311 } |
314 else if (iStatus != KErrNone) |
312 else if (iStatus != KErrNone) |
315 { |
313 { |
316 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: Error occured"); |
314 ELOG(ESATSA, "CSTSSignatureService::RunL: Error occured"); |
317 // Error has occured; inform java |
315 // Error has occured; inform java |
318 Complete(iStatus.Int()); |
316 Complete(iStatus.Int()); |
319 } |
317 } |
320 else |
318 else |
321 { |
319 { |
322 switch (iState) |
320 switch (iState) |
323 { |
321 { |
324 case EInitialising: |
322 case EInitialising: |
325 { |
323 { |
326 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EInitialising"); |
|
327 iState = EKeyStoreInit; |
324 iState = EKeyStoreInit; |
328 iKeyStore->Initialize(iStatus); |
325 iKeyStore->Initialize(iStatus); |
329 SetActive(); |
326 SetActive(); |
330 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: over case EInitialising"); |
|
331 break; |
327 break; |
332 } |
328 } |
333 case EKeyStoreInit: |
329 case EKeyStoreInit: |
334 { |
330 { |
335 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EKeyStoreInit"); |
|
336 Complete(KErrNone); |
331 Complete(KErrNone); |
337 break; |
332 break; |
338 } |
333 } |
339 case EListing: |
334 case EListing: |
340 { |
335 { |
341 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EListing"); |
|
342 HandlesFromCertInfosL(); |
336 HandlesFromCertInfosL(); |
343 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: over case EListing"); |
|
344 break; |
337 break; |
345 } |
338 } |
346 case EDialog: |
339 case EDialog: |
347 { |
340 { |
348 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EDialog"); |
|
349 iState = EGetCert; |
341 iState = EGetCert; |
350 if (iCertificate) |
342 if (iCertificate) |
351 { |
343 { |
352 iCertificate->Release(); |
344 iCertificate->Release(); |
353 iCertificate = NULL; |
345 iCertificate = NULL; |
358 iCertificateHandle = iCertificateArray[0]; |
350 iCertificateHandle = iCertificateArray[0]; |
359 } |
351 } |
360 |
352 |
361 iCertStore->GetCert(iCertificate, iCertificateHandle, iStatus); |
353 iCertStore->GetCert(iCertificate, iCertificateHandle, iStatus); |
362 SetActive(); |
354 SetActive(); |
363 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: over case EDialog"); |
|
364 break; |
355 break; |
365 } |
356 } |
366 case EGetCert: |
357 case EGetCert: |
367 { |
358 { |
368 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EGetCert"); |
|
369 if (iX509Certificate) |
359 if (iX509Certificate) |
370 { |
360 { |
371 delete iX509Certificate; |
361 delete iX509Certificate; |
372 iX509Certificate = NULL; |
362 iX509Certificate = NULL; |
373 } |
363 } |
374 iState = ERetrieveCert; |
364 iState = ERetrieveCert; |
375 iCertStore->Retrieve(*iCertificate, iX509Certificate, iStatus); |
365 iCertStore->Retrieve(*iCertificate, iX509Certificate, iStatus); |
376 SetActive(); |
366 SetActive(); |
377 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: over case EGetCert"); |
|
378 break; |
367 break; |
379 } |
368 } |
380 case ERetrieveCert: |
369 case ERetrieveCert: |
381 { |
370 { |
382 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case ERetrieveCert"); |
|
383 FindKeyL(); |
371 FindKeyL(); |
384 break; |
372 break; |
385 } |
373 } |
386 case EFindKey: |
374 case EFindKey: |
387 { |
375 { |
388 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EFindKey"); |
|
389 OpenSignerL(); |
376 OpenSignerL(); |
390 break; |
377 break; |
391 } |
378 } |
392 case EOpenSigner: |
379 case EOpenSigner: |
393 { |
380 { |
394 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EOpenSigner"); |
|
395 SignL(); |
381 SignL(); |
396 break; |
382 break; |
397 } |
383 } |
398 case ESign: |
384 case ESign: |
399 { |
385 { |
400 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case ESign"); |
|
401 CreateSignedDataL(); |
386 CreateSignedDataL(); |
402 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: over case ESign"); |
|
403 break; |
387 break; |
404 } |
388 } |
405 case EFinalNote: |
389 case EFinalNote: |
406 { |
390 { |
407 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case EFinalNote"); |
|
408 Complete(KErrNone); |
391 Complete(KErrNone); |
409 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: over case EFinalNote"); |
|
410 break; |
392 break; |
411 } |
393 } |
412 default: |
394 default: |
413 { |
395 { |
414 LOG(ESATSA, EInfo, "CSTSSignatureService::RunL: case default"); |
|
415 Complete(KErrGeneral); |
396 Complete(KErrGeneral); |
416 } |
397 } |
417 } |
398 } |
418 } |
399 } |
419 } |
400 } |
540 // Completes the operation |
519 // Completes the operation |
541 // ----------------------------------------------------------------------------- |
520 // ----------------------------------------------------------------------------- |
542 // |
521 // |
543 void CSTSSignatureService::Complete(TInt aError) |
522 void CSTSSignatureService::Complete(TInt aError) |
544 { |
523 { |
545 LOG(ESATSA, EInfo, "+ CSTSSignatureService::Complete"); |
|
546 if (KErrNone == aError) |
524 if (KErrNone == aError) |
547 { |
525 { |
548 iState = EReady; |
526 iState = EReady; |
549 } |
527 } |
550 else |
528 else |
551 { |
529 { |
552 iState = EERROR; |
530 iState = EERROR; |
553 iError = aError; |
531 iError = aError; |
554 } |
532 } |
555 iWait->AsyncStop(); |
533 iWait->AsyncStop(); |
556 LOG(ESATSA, EInfo, "-- ret CSTSSignatureService::Complete"); |
534 |
557 } |
535 } |
558 |
536 |
559 // ----------------------------------------------------------------------------- |
537 // ----------------------------------------------------------------------------- |
560 // CSTSSignatureService::WaitForCompletionL() |
538 // CSTSSignatureService::WaitForCompletionL() |
561 // Wait for completion, leave on error |
539 // Wait for completion, leave on error |
562 // ----------------------------------------------------------------------------- |
540 // ----------------------------------------------------------------------------- |
563 // |
541 // |
564 void CSTSSignatureService::WaitForCompletionL() |
542 void CSTSSignatureService::WaitForCompletionL() |
565 { |
543 { |
566 LOG(ESATSA, EInfo, "+ CSTSSignatureService::WaitForCompletionL"); |
|
567 SetActive(); |
544 SetActive(); |
568 iWait->Start(); |
545 iWait->Start(); |
569 if (iState != EReady) |
546 if (iState != EReady) |
570 { |
547 { |
571 // we need to be ready for the next request |
548 // we need to be ready for the next request |
572 iState = EReady; |
549 iState = EReady; |
573 |
|
574 User::Leave(iError); |
550 User::Leave(iError); |
575 } |
551 } |
576 LOG(ESATSA, EInfo, "- ret CSTSSignatureService::WaitForCompletionL"); |
|
577 } |
552 } |
578 |
553 |
579 // ----------------------------------------------------------------------------- |
554 // ----------------------------------------------------------------------------- |
580 // CSTSSignatureService::CreateSignatureL() |
555 // CSTSSignatureService::CreateSignatureL() |
581 // Creates the signature |
556 // Creates the signature |
582 // ----------------------------------------------------------------------------- |
557 // ----------------------------------------------------------------------------- |
583 // |
558 // |
584 HBufC8* CSTSSignatureService::CreateSignatureL(const CDesCArray& aCaNames, |
559 HBufC8* CSTSSignatureService::CreateSignatureL(const CDesCArray& aCaNames, |
585 const TKeyUsageX509 aUsage, const TDesC& aSecurityElementPrompt) |
560 const TKeyUsageX509 aUsage, const TDesC& aSecurityElementPrompt) |
586 { |
561 { |
587 LOG(ESATSA, EInfo, "+ CSTSSignatureService::CreateSignatureL"); |
|
588 HBufC* sePrompt = NULL; |
562 HBufC* sePrompt = NULL; |
589 if (aSecurityElementPrompt != KNullDesC()) |
563 if (aSecurityElementPrompt != KNullDesC()) |
590 { |
564 { |
591 sePrompt = aSecurityElementPrompt.AllocL(); |
565 sePrompt = aSecurityElementPrompt.AllocL(); |
592 } |
566 } |
593 delete iSecurityElementPrompt; |
567 delete iSecurityElementPrompt; |
594 iSecurityElementPrompt = sePrompt; |
568 iSecurityElementPrompt = sePrompt; |
595 LOG(ESATSA, EInfo, "CSTSSignatureService::CreateSignatureL: call findcertificates"); |
|
596 FindCertificatesL(aCaNames, aUsage); |
569 FindCertificatesL(aCaNames, aUsage); |
597 LOG(ESATSA, EInfo, "CSTSSignatureService::CreateSignatureL: After call to findcertificates"); |
|
598 WaitForCompletionL(); |
570 WaitForCompletionL(); |
599 LOG(ESATSA, EInfo, "CSTSSignatureService::CreateSignatureL: call WaitForCompletion"); |
|
600 HBufC8* retVal = iSignature; |
571 HBufC8* retVal = iSignature; |
601 iSignature = NULL; |
572 iSignature = NULL; |
602 LOG(ESATSA, EInfo, "-- ret CSTSSignatureService::CreateSignatureL"); |
|
603 return retVal; |
573 return retVal; |
604 } |
574 } |
605 // ----------------------------------------------------------------------------- |
575 // ----------------------------------------------------------------------------- |
606 // CSTSSignatureService::FindCertificatesL() |
576 // CSTSSignatureService::FindCertificatesL() |
607 // Find applicable certificates |
577 // Find applicable certificates |
652 } |
621 } |
653 |
622 |
654 iState = EListing; |
623 iState = EListing; |
655 iCertStore->List(iCertInfos, *iFilter, iDERNames, iStatus); |
624 iCertStore->List(iCertInfos, *iFilter, iDERNames, iStatus); |
656 } |
625 } |
657 LOG(ESATSA, EInfo, "-- ret CSTSSignatureService::FindCertificatesL"); |
626 |
658 } |
627 } |
659 |
628 |
660 // ----------------------------------------------------------------------------- |
629 // ----------------------------------------------------------------------------- |
661 // CSTSSignatureService::HandlesFromCertInfosL() |
630 // CSTSSignatureService::HandlesFromCertInfosL() |
662 // Fills iCertificateArray from iCertInfos. |
631 // Fills iCertificateArray from iCertInfos. |
663 // ----------------------------------------------------------------------------- |
632 // ----------------------------------------------------------------------------- |
664 // |
633 // |
665 void CSTSSignatureService::HandlesFromCertInfosL() |
634 void CSTSSignatureService::HandlesFromCertInfosL() |
666 { |
635 { |
667 LOG(ESATSA, EInfo, "+ CSTSSignatureService::HandlesFromCertInfosL"); |
|
668 TInt certificateCount = iCertInfos.Count(); |
636 TInt certificateCount = iCertInfos.Count(); |
669 if (certificateCount == 0) |
637 if (certificateCount == 0) |
670 { |
638 { |
671 ELOG(ESATSA, "CSTSSignatureService::HandlesFromCertInfosL, KErrNotFound"); |
639 ELOG(ESATSA, "CSTSSignatureService::HandlesFromCertInfosL, KErrNotFound"); |
672 User::Leave(KErrNotFound); |
640 User::Leave(KErrNotFound); |
673 } |
641 } |
674 |
642 |
675 iCertificateArray.Reset(); |
643 iCertificateArray.Reset(); |
676 for (TInt i = 0; i < certificateCount; i++) |
644 for (TInt i = 0; i < certificateCount; i++) |
677 { |
645 { |
678 LOG(ESATSA, EInfo, "+ CSTSSignatureService::HandlesFromCertInfosL: No Certificates"); |
|
679 User::LeaveIfError(iCertificateArray.Append(iCertInfos[i]->Handle())); |
646 User::LeaveIfError(iCertificateArray.Append(iCertInfos[i]->Handle())); |
680 } |
647 } |
681 |
648 |
682 // next is a dialog shown depending on the authentication type |
649 // next is a dialog shown depending on the authentication type |
683 switch (iAuthType) |
650 switch (iAuthType) |
684 { |
651 { |
685 case EAuthWithoutText: |
652 case EAuthWithoutText: |
686 { |
653 { |
687 LOG(ESATSA, EInfo, "CSTSSignatureService::HandlesFromCertInfosL: case EAuthWithoutText"); |
654 // Use Orbit API |
688 iPKIDialog->UserAuthentication(iCertificateArray, iCertificateHandle, |
655 CHbDeviceMessageBoxSymbian* messageBox |
689 iStatus); |
656 = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EWarning); |
690 LOG(ESATSA, EInfo, "CSTSSignatureService::HandlesFromCertInfosL: over case EAuthWithoutText"); |
657 CleanupStack::PushL(messageBox); |
|
658 |
|
659 _LIT(KQuestion, "Do you want to sign the data?"); |
|
660 messageBox->SetTextL(KQuestion); |
|
661 messageBox->SetTimeout(HbPopup::NoTimeout); |
|
662 |
|
663 // Read localised versions instead of hard coded values. |
|
664 _LIT(KAllowButtonText, "Allow"); |
|
665 _LIT(KDenyButtonText, "Deny"); |
|
666 |
|
667 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::EAcceptButton, KAllowButtonText); |
|
668 messageBox->SetButton(CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue); |
|
669 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::ERejectButton, KDenyButtonText); |
|
670 messageBox->SetButton(CHbDeviceMessageBoxSymbian::ERejectButton, ETrue); |
|
671 |
|
672 // by default the answer is Allow |
|
673 if (messageBox->ExecL() == CHbDeviceMessageBoxSymbian::ERejectButton) |
|
674 { |
|
675 |
|
676 } |
|
677 messageBox->Close(); |
|
678 CleanupStack::PopAndDestroy(messageBox); |
691 break; |
679 break; |
692 } |
680 } |
693 case EAuthWithText: |
681 case EAuthWithText: |
694 { |
682 { |
695 LOG(ESATSA, EInfo, "CSTSSignatureService::HandlesFromCertInfosL: case EAuthWithText"); |
683 // Use Orbit API |
696 iPKIDialog->UserAuthenticationText(*iTextToDisplay, iCertificateArray, |
684 CHbDeviceMessageBoxSymbian* messageBox |
697 iCertificateHandle, iStatus); |
685 = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EWarning); |
698 LOG(ESATSA, EInfo, "CSTSSignatureService::HandlesFromCertInfosL: over case EAuthWithText"); |
686 CleanupStack::PushL(messageBox); |
|
687 |
|
688 _LIT(KQuestion, "Do you want to sign the data?"); |
|
689 messageBox->SetTextL(KQuestion); |
|
690 messageBox->SetTimeout(HbPopup::NoTimeout); |
|
691 |
|
692 // Read localised versions instead of hard coded values. |
|
693 _LIT(KAllowButtonText, "Allow"); |
|
694 _LIT(KDenyButtonText, "Deny"); |
|
695 |
|
696 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::EAcceptButton, KAllowButtonText); |
|
697 messageBox->SetButton(CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue); |
|
698 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::ERejectButton, KDenyButtonText); |
|
699 messageBox->SetButton(CHbDeviceMessageBoxSymbian::ERejectButton, ETrue); |
|
700 |
|
701 // by default the answer is Allow |
|
702 if (messageBox->ExecL() == CHbDeviceMessageBoxSymbian::ERejectButton) |
|
703 { |
|
704 |
|
705 } |
|
706 messageBox->Close(); |
|
707 CleanupStack::PopAndDestroy(messageBox); |
699 break; |
708 break; |
700 } |
709 } |
701 case ESignWithText: |
710 case ESignWithText: |
702 { |
711 { |
703 iDialog->SignText(*iTextToDisplay, iCertificateArray, |
712 iDialog->SignText(*iTextToDisplay, iCertificateArray, |
985 |
989 |
986 CleanupStack::PopAndDestroy(8); |
990 CleanupStack::PopAndDestroy(8); |
987 if (iShowNotes) |
991 if (iShowNotes) |
988 { |
992 { |
989 iState = EFinalNote; |
993 iState = EFinalNote; |
990 iPKIDialog->Note(MPKIDialog::ESignatureDone, iStatus); |
994 |
|
995 //proper string for user prompt |
|
996 CHbDeviceMessageBoxSymbian* messageBox |
|
997 = CHbDeviceMessageBoxSymbian::NewL(CHbDeviceMessageBoxSymbian::EWarning); |
|
998 CleanupStack::PushL(messageBox); |
|
999 |
|
1000 _LIT(KQuestion, "Do you want to sign the data?"); |
|
1001 messageBox->SetTextL(KQuestion); |
|
1002 messageBox->SetTimeout(HbPopup::NoTimeout); |
|
1003 |
|
1004 // Read localised versions instead of hard coded values. |
|
1005 _LIT(KAllowButtonText, "Allow"); |
|
1006 _LIT(KDenyButtonText, "Deny"); |
|
1007 |
|
1008 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::EAcceptButton, KAllowButtonText); |
|
1009 messageBox->SetButton(CHbDeviceMessageBoxSymbian::EAcceptButton, ETrue); |
|
1010 messageBox->SetButtonTextL(CHbDeviceMessageBoxSymbian::ERejectButton, KDenyButtonText); |
|
1011 messageBox->SetButton(CHbDeviceMessageBoxSymbian::ERejectButton, ETrue); |
|
1012 |
|
1013 // by default the answer is Allow |
|
1014 if (messageBox->ExecL() == CHbDeviceMessageBoxSymbian::ERejectButton) |
|
1015 { |
|
1016 |
|
1017 } |
|
1018 messageBox->Close(); |
|
1019 CleanupStack::PopAndDestroy(messageBox); |
991 SetActive(); |
1020 SetActive(); |
992 } |
1021 } |
993 else |
1022 else |
994 { |
1023 { |
995 Complete(KErrNone); |
1024 Complete(KErrNone); |
996 } |
1025 } |
997 LOG(ESATSA, EInfo, "-- ret CSTSSignatureService::CreateSignedDataL"); |
1026 |
998 } |
1027 } |
999 |
1028 |
1000 // ----------------------------------------------------------------------------- |
1029 // ----------------------------------------------------------------------------- |
1001 // CSTSSignatureService::ConvertUTF8ToUnicodeLC() |
1030 // CSTSSignatureService::ConvertUTF8ToUnicodeLC() |
1002 // Converts UTF8 data to Unicode |
1031 // Converts UTF8 data to Unicode |