|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <charconv.h> |
|
21 #include <secdlg.h> |
|
22 |
|
23 #include "cstsapduexchanger.h" |
|
24 #include "cstsaccesscontrol.h" |
|
25 #include "cstspinmanager.h" |
|
26 #include "cstsauthtype.h" |
|
27 #include "cstspinattributes.h" |
|
28 #include "stsapduconstants.h" |
|
29 #include "cstspinapdu.h" |
|
30 #include "cstspinapduresp.h" |
|
31 #include "cstsresphandler.h" |
|
32 #include "cstspinconverter.h" |
|
33 #include "logger.h" |
|
34 |
|
35 |
|
36 using namespace java::util; |
|
37 |
|
38 namespace java |
|
39 { |
|
40 namespace satsa |
|
41 { |
|
42 |
|
43 // CONSTANTS |
|
44 const TInt KSTSMaxPinAttempts = 3; |
|
45 const TInt KSTSPinHeaderLength = 4; |
|
46 |
|
47 CSTSPinManager::CSTSPinManager(CSTSApduExchanger* aApduExchanger, |
|
48 CSTSAccessControl* aAccessControl, MSTSRespHandler* aRespHandler) : |
|
49 CActive(EPriorityNormal) |
|
50 { |
|
51 |
|
52 CActiveScheduler::Add(this); |
|
53 iApduExchanger = aApduExchanger; |
|
54 iAccessControl = aAccessControl; |
|
55 iRespHandler = aRespHandler; |
|
56 |
|
57 } |
|
58 |
|
59 void CSTSPinManager::ConstructL() |
|
60 { |
|
61 // create pinUI |
|
62 iSecurityDialog = SecurityDialogFactory::CreateL(); |
|
63 |
|
64 iAuthTypeFirstPin = CSTSAuthType::NewL(); |
|
65 iAuthTypeSecondPin = CSTSAuthType::NewL(); |
|
66 |
|
67 } |
|
68 |
|
69 CSTSPinManager* CSTSPinManager::NewL(JNIEnv* aJni, jobject aPeer, |
|
70 CSTSApduExchanger* aApduExchanger, CSTSAccessControl* aAccessControl, |
|
71 MSTSRespHandler* aRespHandler) |
|
72 { |
|
73 CSTSPinManager |
|
74 * self = |
|
75 new(ELeave) CSTSPinManager(aApduExchanger, aAccessControl, aRespHandler); |
|
76 |
|
77 self->mJni = aJni; |
|
78 self->mPeer = aPeer; |
|
79 CleanupStack::PushL(self); |
|
80 self->ConstructL(); |
|
81 |
|
82 CleanupStack::Pop(self); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // Destructor |
|
87 CSTSPinManager::~CSTSPinManager() |
|
88 { |
|
89 Cancel(); |
|
90 delete iAuthTypeSecondPin; |
|
91 delete iAuthTypeFirstPin; |
|
92 if (iSecurityDialog) |
|
93 { |
|
94 iSecurityDialog->Release(); // Release deletes the object |
|
95 } |
|
96 delete iPinApdu; |
|
97 delete iPinApduResp; |
|
98 delete iResponseBuf; |
|
99 delete mJni; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSTSPinManager::DisablePinL |
|
104 // Calls proper private methods. |
|
105 // (other items were commented in a header). |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 void CSTSPinManager::DisablePinL(TInt aPinID) |
|
109 { |
|
110 PreparePinMethodL(CSTSPinApdu::ESTSDisablePin, aPinID); |
|
111 ShowPinUI(CSTSPinApdu::ESTSDisablePin); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CSTSPinManager::ChangePinL |
|
116 // Calls proper private methods. |
|
117 // (other items were commented in a header). |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CSTSPinManager::ChangePinL(TInt aPinID) |
|
121 { |
|
122 |
|
123 PreparePinMethodL(CSTSPinApdu::ESTSChangePin, aPinID); |
|
124 ShowPinUI(CSTSPinApdu::ESTSChangePin); |
|
125 |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CSTSPinManager::EnablePinL |
|
130 // Calls proper private methods. |
|
131 // (other items were commented in a header). |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CSTSPinManager::EnablePinL(TInt aPinID) |
|
135 { |
|
136 |
|
137 PreparePinMethodL(CSTSPinApdu::ESTSEnablePin, aPinID); |
|
138 ShowPinUI(CSTSPinApdu::ESTSEnablePin); |
|
139 |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CSTSPinManager::EnterPinL |
|
144 // Calls proper private methods. |
|
145 // (other items were commented in a header). |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 void CSTSPinManager::EnterPinL(TInt aPinID) |
|
149 { |
|
150 PreparePinMethodL(CSTSPinApdu::ESTSVerifyPin, aPinID); |
|
151 ShowPinUI(CSTSPinApdu::ESTSVerifyPin); |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSTSPinManager::UnblockPinL |
|
156 // Calls proper private methods. |
|
157 // (other items were commented in a header). |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CSTSPinManager::UnblockPinL(TInt aBlockedPinID, TInt aUnblockedPinID) |
|
161 { |
|
162 PreparePinMethodL(CSTSPinApdu::ESTSUnblockPin, aBlockedPinID, |
|
163 aUnblockedPinID); |
|
164 ShowPinUI(CSTSPinApdu::ESTSUnblockPin); |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CSTSPinManager::CancelOperation |
|
169 // Cancels any pending operation |
|
170 // (other items were commented in a header). |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CSTSPinManager::CancelOperation() |
|
174 { |
|
175 LOG(ESATSA, EInfo, "CSTSPinManager::CancelOperation called!"); |
|
176 Cancel(); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CSTSPinManager::RunL |
|
181 // If PIN value is got from UI, converts user gived PIN values in proper form |
|
182 // and sends PIN apdu to card. If user has selected cancel option, informs it |
|
183 // to java side. When apdu sending has returned, checks was user gived value |
|
184 // correct one and if was not, shows proper PIN ui again. If no retries is left |
|
185 // shows blocked PIN UI. Supplies response apdus to java side and in error |
|
186 // conditions supplies proper error code. |
|
187 // (other items were commented in a header). |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CSTSPinManager::RunL() |
|
191 { |
|
192 LOG1(ESATSA, EInfo, "CSTSPinManager::RunL called!:%d", iStatus.Int()); |
|
193 |
|
194 if (iStatus == KErrCancel) |
|
195 { |
|
196 LOG(ESATSA, EInfo, "CSTSPinManager::RunL, Cancel selected"); |
|
197 // if the user selected cancel option. we return null |
|
198 iRespHandler->OperationComplete(mJni, mPeer, NULL, KSTSErrCancel); |
|
199 |
|
200 } |
|
201 else if (iStatus != KErrNone) |
|
202 { |
|
203 LOG(ESATSA, EInfo, "CSTSPinManager::RunL, Error Occurred!!"); |
|
204 // in other error conditions supply error code |
|
205 iRespHandler->OperationComplete(mJni, mPeer, NULL, iStatus.Int()); |
|
206 } |
|
207 else // no problems |
|
208 { |
|
209 switch (iState) |
|
210 { |
|
211 case ESendingPINApdu: |
|
212 { |
|
213 LOG(ESATSA, EInfo, "CSTSPinManager::RunL, case ESendingPINApdu"); |
|
214 DoAfterSendApduL(); |
|
215 break; |
|
216 } |
|
217 case EShowingPinBlockedUI: |
|
218 { |
|
219 LOG(ESATSA, EInfo, "CSTSPinManager::RunL, case EShowingPinBlockedUI"); |
|
220 //return PIN method blocked value to java side |
|
221 //that value is already got from card |
|
222 DeliverResponseL(); |
|
223 break; |
|
224 } |
|
225 case EShowing1ValuePinUI: |
|
226 { |
|
227 LOG(ESATSA, EInfo, "CSTSPinManager::RunL, case EShowing1ValuePinUI"); |
|
228 DoAfter1ValuePinUIL(); |
|
229 break; |
|
230 } |
|
231 case EShowing2ValuePinUI: |
|
232 { |
|
233 LOG(ESATSA, EInfo, "CSTSPinManager::RunL, case EShowing2ValuePinUI"); |
|
234 DoAfter2ValuePinUIL(); |
|
235 break; |
|
236 } |
|
237 default: |
|
238 { |
|
239 break; |
|
240 } |
|
241 } |
|
242 } |
|
243 } |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CSTSPinManager::DoCancel |
|
246 // Cancels all possible active actions like PIN UIs or apdu exchange |
|
247 // (other items were commented in a header). |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void CSTSPinManager::DoCancel() |
|
251 { |
|
252 LOG(ESATSA, EInfo, "CSTSPinManager::DoCancel, called"); |
|
253 iSecurityDialog->Cancel(); |
|
254 iApduExchanger->CancelExchange(); |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CSTSPinManager::RunError |
|
259 // If leave occures in RunL,this method is called. Notifies java side with |
|
260 // leave code. |
|
261 // (other items were commented in a header). |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 TInt CSTSPinManager::RunError(TInt aError) |
|
265 { |
|
266 LOG1(ESATSA, EInfo, "CSTSPinManager::RunError, called: %d", aError); |
|
267 iRespHandler->OperationComplete(mJni, mPeer, NULL, aError); |
|
268 // must return KErrNone |
|
269 return KErrNone; |
|
270 } |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CSTSPinManager::ConvertPINL Converts PIN to correct form for presenting it |
|
274 // to card. Implementation done according to document "PKCS #15 v1.1: |
|
275 // Cryptographic Token Information Syntax Standard" chapter "6.8.2.1 |
|
276 // Transforming a supplied PIN". |
|
277 // |
|
278 // EXAMPLE (ascii-) Numeric PIN ‘1234’(10), stored length 8 bytes, and padding |
|
279 // character ‘FF’(16) gives that the value presented to the card will be |
|
280 // ‘31323334FFFFFFFF’(16) |
|
281 // |
|
282 // Returns: aConvertedPIN: PIN converted to needed format. |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CSTSPinManager::ConvertPINL(const CSTSPinAttributes& aPinAttributes, |
|
286 const TDes& aPinValue, HBufC8*& aConvertedPIN) |
|
287 { |
|
288 LOG(ESATSA, EInfo, "CSTSPinManager::ConvertPINL called "); |
|
289 |
|
290 TPtr8 convertedPtr(aConvertedPIN->Des()); |
|
291 |
|
292 CSTSPinAttributes::TPinType pinType = aPinAttributes.PinType(); |
|
293 LOG1(ESATSA, EInfo, "CSTSPinManager::ConvertPINL, pintype: %d", pinType); |
|
294 |
|
295 if (pinType == CSTSPinAttributes::EUTF8) |
|
296 { |
|
297 // if case-sensitive bit is off, convert to uppercase |
|
298 TBool upperCase = !aPinAttributes.IsPinFlagSet( |
|
299 CSTSPinAttributes::ECaseSensitive); |
|
300 CSTSPinConverter::ConvertToUTF8L(aPinValue, convertedPtr, upperCase); |
|
301 } |
|
302 else if (pinType == CSTSPinAttributes::EBCD) |
|
303 { |
|
304 CSTSPinConverter::ConvertToBCDL(aPinValue, convertedPtr, EFalse); // not half BCD |
|
305 } |
|
306 else if (pinType == CSTSPinAttributes::EAsciiNumeric || pinType |
|
307 == CSTSPinAttributes::EISO9564_1) |
|
308 { |
|
309 CSTSPinConverter::ConvertToASCIIL(aPinValue, convertedPtr); |
|
310 |
|
311 } |
|
312 else if (pinType == CSTSPinAttributes::EHalfNibbleBCD) |
|
313 { |
|
314 CSTSPinConverter::ConvertToBCDL(aPinValue, convertedPtr, ETrue); // Half BCD |
|
315 } |
|
316 else |
|
317 { |
|
318 User::Leave(KErrCorrupt); |
|
319 } |
|
320 |
|
321 // If indicated in the pinFlags field, pad to the right with the |
|
322 // padding character, to stored length |
|
323 |
|
324 |
|
325 // must be popped from cleanupstack before padding |
|
326 CleanupStack::Pop(aConvertedPIN); |
|
327 TInt err = CSTSPinConverter::DoBadding(aPinValue, aConvertedPIN, |
|
328 aPinAttributes.StoredLength(), aPinAttributes.PadChar()[0]); |
|
329 CleanupStack::PushL(aConvertedPIN); |
|
330 User::LeaveIfError(err); |
|
331 |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CSTSPinManager::PreparePinMethodL Makes preparation common for all PIN |
|
336 // methods. Checks, is PIN method allowed to use. Gets PIN headers from the |
|
337 // card and if there was not any, generates it. Sets needed PIN UI parameters. |
|
338 // Returns: |
|
339 // iPinApdu: Saves APDU into this member variable |
|
340 // iPinApduResp: Saves response APDU into this member variable |
|
341 // iAuthTypeFirstPin: Saves PIN attributes into this member variable |
|
342 // iAuthTypeSecondPin: Saves PIN attributes into this member variable |
|
343 // iPINParamsFirstPin: Saves PIN UI parameters into this member variable |
|
344 // iPINParamsSecondPin: Saves PIN UI parameters into this member variable |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void CSTSPinManager::PreparePinMethodL( |
|
348 CSTSPinApdu::TSTSPinApduType aPinApduType, TInt aFirstPinID, |
|
349 TInt aUnblockedPinID) |
|
350 { |
|
351 LOG(ESATSA, EInfo, "CSTSPinManager::PreparePinMethodL called"); |
|
352 |
|
353 iPinApduType = aPinApduType; |
|
354 |
|
355 // is pinmethods supported to use with card application |
|
356 if (!iAccessControl->IsAllowedPinMethod()) |
|
357 { |
|
358 ELOG(ESATSA, "CSTSPinManager::PreparePinMethodL, Not supported"); |
|
359 User::Leave(KSTSErrSecurity + KSTSErrSECNoRightsPin); |
|
360 } |
|
361 |
|
362 // gets the pin apdu header part from the card, if there is any |
|
363 TPtrC8 headerPtr(iAccessControl->GetPinHeaderL(aFirstPinID, |
|
364 (TPinApduType) aPinApduType)); |
|
365 |
|
366 iAuthTypeFirstPin->CopyL(iAccessControl->GetPinAttributesL(aFirstPinID)); |
|
367 |
|
368 // leaves if PIN flags does not allow this PIN apdu |
|
369 iAccessControl->CheckPinFlagsL((TPinApduType) aPinApduType); |
|
370 |
|
371 // if pin headers are not found, |
|
372 if (headerPtr == KNullDesC8()) |
|
373 { |
|
374 // Pin reference is used if the APDU headers are not specified in the ACL |
|
375 CSTSPinApdu* pinApdu = CSTSPinApdu::NewL(aPinApduType, |
|
376 iAuthTypeFirstPin->PinAttributes().PinReference(), |
|
377 CSTSApdu::ESTSUICC); |
|
378 delete iPinApdu; |
|
379 iPinApdu = pinApdu; |
|
380 } |
|
381 else |
|
382 { |
|
383 LOG(ESATSA, EInfo, "CSTSPinManager::PreparePinMethodL, specified header used"); |
|
384 CSTSCmdApdu* tmp = CSTSCmdApdu::NewL(headerPtr, CSTSApdu::ESTSUICC); |
|
385 delete iPinApdu; |
|
386 iPinApdu = tmp; |
|
387 } |
|
388 |
|
389 // check is the J2ME application allowed to use this apdu |
|
390 if (!iAccessControl->IsAllowedApduL(iPinApdu->Header())) |
|
391 { |
|
392 ELOG(ESATSA, "CSTSPinManager::PreparePinMethodL, Not allowed"); |
|
393 // if not allowed |
|
394 User::Leave(KSTSErrSecurity + KSTSErrSECIllegalApdu); |
|
395 } |
|
396 |
|
397 SetPINUIParametersL(iAuthTypeFirstPin, iPINParamsFirstPin); |
|
398 |
|
399 // In unblockPIN case we need to initialize parameters of unblocked PIN |
|
400 if (aPinApduType == EUnblockPinAPDU) |
|
401 { |
|
402 LOG(ESATSA, EInfo, "unblock parameters"); |
|
403 iAuthTypeSecondPin->CopyL(iAccessControl->GetPinAttributesL( |
|
404 aUnblockedPinID)); |
|
405 SetPINUIParametersL(iAuthTypeSecondPin, iPINParamsSecondPin); |
|
406 } |
|
407 |
|
408 iRetries = EFirstTime; |
|
409 LOG(ESATSA, EInfo, "-- CSTSPinManager::PreparePinMethodL"); |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // CSTSPinManager::ShowPinUI Shows PIN UI for getting PIN value or values. |
|
414 // Shows correct UI depending on which PIN method is used. |
|
415 // |
|
416 // ----------------------------------------------------------------------------- |
|
417 // |
|
418 void CSTSPinManager::ShowPinUI(CSTSPinApdu::TSTSPinApduType aPinApduType) |
|
419 { |
|
420 LOG(ESATSA, EInfo, "CSTSPinManager::ShowPinUI+"); |
|
421 TBool retrying = iRetries == ERetrying; |
|
422 TPinManagerState state = EShowing1ValuePinUI; |
|
423 // get PIN from the user with UI |
|
424 if (aPinApduType == EVerifyPinAPDU) |
|
425 { |
|
426 iSecurityDialog->EnterPIN(iPINParamsFirstPin, retrying, |
|
427 iPinValueForFirstPin, iStatus); |
|
428 } |
|
429 else if (aPinApduType == EEnablePinAPDU) |
|
430 { |
|
431 iSecurityDialog->EnablePIN(iPINParamsFirstPin, retrying, |
|
432 iPinValueForFirstPin, iStatus); |
|
433 |
|
434 } |
|
435 else if (aPinApduType == EDisablePinAPDU) |
|
436 { |
|
437 iSecurityDialog->DisablePIN(iPINParamsFirstPin, retrying, |
|
438 iPinValueForFirstPin, iStatus); |
|
439 } |
|
440 else if (aPinApduType == EChangePinAPDU) |
|
441 { |
|
442 state = EShowing2ValuePinUI; |
|
443 iSecurityDialog->ChangePIN(iPINParamsFirstPin, retrying, |
|
444 iPinValueForFirstPin, iPinValueForSecondPin, iStatus); |
|
445 } |
|
446 else if (aPinApduType == EUnblockPinAPDU) |
|
447 { |
|
448 state = EShowing2ValuePinUI; |
|
449 iSecurityDialog->UnblockPIN(iPINParamsFirstPin, iPINParamsSecondPin, |
|
450 retrying, iPinValueForFirstPin, iPinValueForSecondPin, iStatus); |
|
451 } |
|
452 else |
|
453 { |
|
454 |
|
455 } |
|
456 |
|
457 SetActive(); |
|
458 iState = state; |
|
459 |
|
460 } |
|
461 |
|
462 // ----------------------------------------------------------------------------- |
|
463 // CSTSPinManager::DeliverResponseL |
|
464 // Saves responsebytes to member variable and delivers them to java side with |
|
465 // help of response handler. |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 void CSTSPinManager::DeliverResponseL() |
|
469 { |
|
470 LOG(ESATSA, EInfo, "CSTSPinManager::DeliverResponseL, called"); |
|
471 HBufC8* tmp = iPinApduResp->ResponseBytes().AllocL(); |
|
472 delete iResponseBuf; |
|
473 iResponseBuf = tmp; |
|
474 |
|
475 iRespHandler->OperationComplete(mJni, mPeer, iResponseBuf, KErrNone); |
|
476 |
|
477 } |
|
478 |
|
479 // ----------------------------------------------------------------------------- |
|
480 // CSTSPinManager::SetPINUIParametersL |
|
481 // Uses authtype parameter to get needed values and sets them to gived PINParams |
|
482 // variable. |
|
483 // ----------------------------------------------------------------------------- |
|
484 // |
|
485 void CSTSPinManager::SetPINUIParametersL(const CSTSAuthType* aAuthType, |
|
486 TPINParams& aPINParams) |
|
487 { |
|
488 // maximum length is optional in card, so we need to set something for |
|
489 // PIN UI needs |
|
490 TInt maxLength = PINMaxLength(aAuthType); |
|
491 TInt minLength = aAuthType->PinAttributes().MinLength(); |
|
492 |
|
493 // create TPINParams |
|
494 |
|
495 // label that identifies the PIN |
|
496 aPINParams.iPINLabel = aAuthType->Label(); |
|
497 aPINParams.iTokenLabel = iAccessControl->TokenLabelL(); |
|
498 aPINParams.iMinLength = minLength; |
|
499 aPINParams.iMaxLength = maxLength; |
|
500 |
|
501 } |
|
502 |
|
503 // ----------------------------------------------------------------------------- |
|
504 // CSTSPinManager::DoAfterSendApduL |
|
505 // Checks response adpu and depending on response delivers response bytes |
|
506 // to response handler, shows PIN Blocked UI or shows previous PIN UI again. |
|
507 // ----------------------------------------------------------------------------- |
|
508 // |
|
509 void CSTSPinManager::DoAfterSendApduL() |
|
510 { |
|
511 //check response apdu, and show UI again if wrong pin value |
|
512 CSTSPinApduResp* resp = CSTSPinApduResp::NewL(); |
|
513 delete iPinApduResp; |
|
514 iPinApduResp = resp; |
|
515 iApduExchanger->GetResponseBytes(*iPinApduResp); |
|
516 |
|
517 TInt retriesLeft = iPinApduResp->RetriesLeft(); |
|
518 |
|
519 //if response not indicate retresleft value |
|
520 if (retriesLeft == KErrNotFound) |
|
521 { |
|
522 // return response bytes to java side |
|
523 DeliverResponseL(); |
|
524 } |
|
525 |
|
526 //if pin is blocked, call iSecurityDialog::PINBlocked method |
|
527 else if (iPinApduResp->IsBlocked()) |
|
528 { |
|
529 // save state to member variable that we can return asynchronous |
|
530 // after SetActive call |
|
531 iRetries = EPINBlocked; |
|
532 |
|
533 iSecurityDialog->PINBlocked(iPINParamsFirstPin, iStatus); |
|
534 iState = EShowingPinBlockedUI; |
|
535 SetActive(); |
|
536 } |
|
537 // if user gived pin value was incorrect |
|
538 else if (retriesLeft < KSTSMaxPinAttempts && retriesLeft > 0) |
|
539 { |
|
540 iRetries = ERetrying; |
|
541 // "initialize" header |
|
542 iPinApdu->ApduBytes().SetLength(KSTSPinHeaderLength); |
|
543 // show UI again, because PIN value was wrong |
|
544 ShowPinUI(iPinApduType); |
|
545 } |
|
546 // if max pin attemps is left, user gived pin value was correct |
|
547 // one and we can supply response bytes to java side |
|
548 else if (retriesLeft == KSTSMaxPinAttempts) |
|
549 { |
|
550 // return response bytes to java side |
|
551 DeliverResponseL(); |
|
552 } |
|
553 else |
|
554 { |
|
555 User::Leave(KSTSErrIO + KSTSErrIOCommProblems); |
|
556 } |
|
557 } |
|
558 |
|
559 // ----------------------------------------------------------------------------- |
|
560 // CSTSPinManager::DoAfter1ValuePinUIL |
|
561 // Convers PIN value gor from UI to proper form and sends proper PIN apdu to |
|
562 // smart card. |
|
563 // ----------------------------------------------------------------------------- |
|
564 // |
|
565 void CSTSPinManager::DoAfter1ValuePinUIL() |
|
566 { |
|
567 HBufC8* convertedBuf = |
|
568 HBufC8::NewLC(PINMaxLength(iAuthTypeFirstPin, ETrue)); |
|
569 |
|
570 ConvertPINL(iAuthTypeFirstPin->PinAttributes(), iPinValueForFirstPin, |
|
571 convertedBuf); |
|
572 TPtr8 convertedPin(convertedBuf->Des()); |
|
573 |
|
574 iPinApdu->AppendDatabytesL(convertedPin); |
|
575 |
|
576 CleanupStack::PopAndDestroy(convertedBuf); |
|
577 |
|
578 iApduExchanger->ExchangeApduAsync(iStatus, *iPinApdu); |
|
579 iState = ESendingPINApdu; |
|
580 SetActive(); |
|
581 |
|
582 } |
|
583 |
|
584 // ----------------------------------------------------------------------------- |
|
585 // CSTSPinManager::DoAfter2ValuePinUIL |
|
586 // Convers PIN values gor from UI to proper form and sends proper PIN apdu to |
|
587 // smart card. |
|
588 // ----------------------------------------------------------------------------- |
|
589 // |
|
590 void CSTSPinManager::DoAfter2ValuePinUIL() |
|
591 { |
|
592 |
|
593 // in changePIN case we use same pin parameters for both pins |
|
594 if (iPinApduType == EChangePinAPDU) |
|
595 { |
|
596 iAuthTypeSecondPin->CopyL(*iAuthTypeFirstPin); |
|
597 } |
|
598 |
|
599 // finds maximum length to create large enough buffer |
|
600 TInt pinValue2MaxLength = PINMaxLength(iAuthTypeSecondPin, ETrue); |
|
601 |
|
602 HBufC8* convertedBuf1 = HBufC8::NewLC((PINMaxLength(iAuthTypeFirstPin, |
|
603 ETrue)) +pinValue2MaxLength); |
|
604 |
|
605 ConvertPINL(iAuthTypeFirstPin->PinAttributes(), iPinValueForFirstPin, |
|
606 convertedBuf1); |
|
607 |
|
608 HBufC8* convertedBuf2 = HBufC8::NewLC(pinValue2MaxLength); |
|
609 ConvertPINL(iAuthTypeSecondPin->PinAttributes(), iPinValueForSecondPin, |
|
610 convertedBuf2); |
|
611 |
|
612 TPtr8 convertedPins(convertedBuf1->Des()); |
|
613 convertedPins.Append(convertedBuf2->Des()); |
|
614 |
|
615 iPinApdu->AppendDatabytesL(convertedPins); |
|
616 |
|
617 CleanupStack::PopAndDestroy(convertedBuf2); |
|
618 CleanupStack::PopAndDestroy(convertedBuf1); |
|
619 |
|
620 iApduExchanger->ExchangeApduAsync(iStatus, *iPinApdu); |
|
621 iState = ESendingPINApdu; |
|
622 SetActive(); |
|
623 |
|
624 } |
|
625 |
|
626 // ----------------------------------------------------------------------------- |
|
627 // CSTSPinManager::PINMaxLength |
|
628 // Is used to find PIN value max length for UI and for buffer creation. For UI |
|
629 // needs aReturnBiggest parameter is not used and method will return proper |
|
630 // maxLength of PIN. If is used for creating buffer for converted PIN |
|
631 // aReturnBiggest parameter must be set to ETrue. Then method will return either |
|
632 // maxlength or stored length value depending on which one is bigger. |
|
633 // ----------------------------------------------------------------------------- |
|
634 // |
|
635 TInt CSTSPinManager::PINMaxLength(const CSTSAuthType* aAuthType, |
|
636 TBool aReturnBiggest) const |
|
637 { |
|
638 TInt returnValue; |
|
639 TInt maxLength = aAuthType->PinAttributes().MaxLength(); |
|
640 TInt storedLength = aAuthType->PinAttributes().StoredLength(); |
|
641 |
|
642 // maximum length is optional in card, so we need to set something for |
|
643 // PIN UI needs |
|
644 if (maxLength == KErrNotFound) |
|
645 { |
|
646 // if optional maxLength is not found, we use mandatory stored length |
|
647 maxLength = storedLength; |
|
648 } |
|
649 returnValue = maxLength; |
|
650 |
|
651 // compares maxlength and stored length |
|
652 if (aReturnBiggest) |
|
653 { |
|
654 if (storedLength > maxLength) |
|
655 { |
|
656 returnValue = storedLength; |
|
657 } |
|
658 } |
|
659 |
|
660 return returnValue; |
|
661 } |
|
662 |
|
663 } // namespace satsa |
|
664 } // namespace java |
|
665 // End of File |
|
666 |