Skip to content

Commit 545da17

Browse files
committed
Moved the secondary pin length update inside a transaction, removed the jCardSim dependent tests until patches fixing the crypto and APDU handling are integrated.
1 parent fb934b4 commit 545da17

File tree

6 files changed

+20
-195
lines changed

6 files changed

+20
-195
lines changed

java/net/ss3t/javacard/gpg/Gpg.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,20 @@ private void verify(APDU apdu) {
395395
ISOException.throwIt((short) (SW_PIN_FAILED_00 + pins[pinOffset].getTriesRemaining()));
396396
}
397397

398+
/**
399+
* Udpate the PIN and its length in a transaction.
400+
* @param pinId which PIN will be updated.
401+
* @param data contains the new PIN.
402+
* @param dataOffset first byte of the new PIN in the data array.
403+
* @param newLength the new PIN length.
404+
*/
405+
private void updatePIN(short pinId, byte[] data, short dataOffset, byte newLength) {
406+
JCSystem.beginTransaction();
407+
pins[pinId].update(data, dataOffset, newLength);
408+
pinLength[pinId] = newLength;
409+
JCSystem.commitTransaction();
410+
}
411+
398412
/**
399413
* CHANGE REFERENCE DATA APDU implementation.
400414
*/
@@ -426,9 +440,8 @@ private void changeReferenceData(APDU apdu) {
426440
pinSubmitted[0] = false;
427441
ISOException.throwIt((short) (SW_PIN_FAILED_00 + pins[pinOffset].getTriesRemaining()));
428442
}
429-
pins[pinOffset].update(buffer, (short) (ISO7816.OFFSET_CDATA + currentLength),
430-
(byte) (length - currentLength));
431-
pinLength[pinOffset] = (byte) (length - currentLength);
443+
updatePIN(pinOffset, buffer, (short) (ISO7816.OFFSET_CDATA + currentLength),
444+
(byte) (length - currentLength));
432445
}
433446

434447
/**
@@ -455,9 +468,8 @@ private void resetRetryCounter(APDU apdu) {
455468
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
456469
}
457470
if (pins[PIN_INDEX_RC].check(buffer, ISO7816.OFFSET_CDATA, rcLength)) {
458-
pins[PIN_INDEX_PW1].update(buffer, (short) (ISO7816.OFFSET_CDATA + rcLength),
459-
(byte) (length - rcLength));
460-
pinLength[PIN_INDEX_PW1] = (byte) (length - rcLength);
471+
updatePIN(PIN_INDEX_PW1, buffer, (short) (ISO7816.OFFSET_CDATA + rcLength),
472+
(byte) (length - rcLength));
461473
} else {
462474
ISOException.throwIt((short) (SW_PIN_FAILED_00 + pins[PIN_INDEX_RC].getTriesRemaining()));
463475
}
@@ -469,8 +481,7 @@ private void resetRetryCounter(APDU apdu) {
469481
if (length < MIN_PIN1_LENGTH || length > MAX_PIN_LENGTH) {
470482
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
471483
}
472-
pins[PIN_INDEX_PW1].update(buffer, ISO7816.OFFSET_CDATA, (byte) length);
473-
pinLength[PIN_INDEX_PW1] = (byte) length;
484+
updatePIN(PIN_INDEX_PW1, buffer, ISO7816.OFFSET_CDATA, (byte) length);
474485
} else {
475486
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
476487
}
@@ -779,8 +790,7 @@ private void putData(APDU apdu) {
779790
if (length > MAX_PIN_LENGTH || (length != (byte) 0 && length < (byte) 8)) {
780791
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
781792
}
782-
pinLength[PIN_INDEX_RC] = buffer[0];
783-
pins[PIN_INDEX_RC].update(buffer, (short) 1, buffer[0]);
793+
updatePIN(PIN_INDEX_RC, buffer, (short) 1, buffer[0]);
784794
break;
785795

786796
default:

javatest/net/ss3t/javacard/SimulatedCard/SimulatedCard.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

javatest/net/ss3t/javacard/gpg/simulated/GpgCryptoTestSimulated.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

javatest/net/ss3t/javacard/gpg/simulated/GpgDataTestSimulated.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

javatest/net/ss3t/javacard/gpg/simulated/GpgPINTestSimulated.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

javatest/net/ss3t/javacard/gpg/simulated/GpgTestSimulated.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)