Skip to content

Commit

Permalink
Moved the secondary pin length update inside a transaction, removed t…
Browse files Browse the repository at this point in the history
…he jCardSim dependent tests until patches fixing the crypto and APDU handling are integrated.
  • Loading branch information
FluffyKaon committed Oct 19, 2013
1 parent fb934b4 commit 545da17
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 195 deletions.
30 changes: 20 additions & 10 deletions java/net/ss3t/javacard/gpg/Gpg.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ private void verify(APDU apdu) {
ISOException.throwIt((short) (SW_PIN_FAILED_00 + pins[pinOffset].getTriesRemaining()));
}

/**
* Udpate the PIN and its length in a transaction.
* @param pinId which PIN will be updated.
* @param data contains the new PIN.
* @param dataOffset first byte of the new PIN in the data array.
* @param newLength the new PIN length.
*/
private void updatePIN(short pinId, byte[] data, short dataOffset, byte newLength) {
JCSystem.beginTransaction();
pins[pinId].update(data, dataOffset, newLength);
pinLength[pinId] = newLength;
JCSystem.commitTransaction();
}

/**
* CHANGE REFERENCE DATA APDU implementation.
*/
Expand Down Expand Up @@ -426,9 +440,8 @@ private void changeReferenceData(APDU apdu) {
pinSubmitted[0] = false;
ISOException.throwIt((short) (SW_PIN_FAILED_00 + pins[pinOffset].getTriesRemaining()));
}
pins[pinOffset].update(buffer, (short) (ISO7816.OFFSET_CDATA + currentLength),
(byte) (length - currentLength));
pinLength[pinOffset] = (byte) (length - currentLength);
updatePIN(pinOffset, buffer, (short) (ISO7816.OFFSET_CDATA + currentLength),
(byte) (length - currentLength));
}

/**
Expand All @@ -455,9 +468,8 @@ private void resetRetryCounter(APDU apdu) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
if (pins[PIN_INDEX_RC].check(buffer, ISO7816.OFFSET_CDATA, rcLength)) {
pins[PIN_INDEX_PW1].update(buffer, (short) (ISO7816.OFFSET_CDATA + rcLength),
(byte) (length - rcLength));
pinLength[PIN_INDEX_PW1] = (byte) (length - rcLength);
updatePIN(PIN_INDEX_PW1, buffer, (short) (ISO7816.OFFSET_CDATA + rcLength),
(byte) (length - rcLength));
} else {
ISOException.throwIt((short) (SW_PIN_FAILED_00 + pins[PIN_INDEX_RC].getTriesRemaining()));
}
Expand All @@ -469,8 +481,7 @@ private void resetRetryCounter(APDU apdu) {
if (length < MIN_PIN1_LENGTH || length > MAX_PIN_LENGTH) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
pins[PIN_INDEX_PW1].update(buffer, ISO7816.OFFSET_CDATA, (byte) length);
pinLength[PIN_INDEX_PW1] = (byte) length;
updatePIN(PIN_INDEX_PW1, buffer, ISO7816.OFFSET_CDATA, (byte) length);
} else {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
Expand Down Expand Up @@ -779,8 +790,7 @@ private void putData(APDU apdu) {
if (length > MAX_PIN_LENGTH || (length != (byte) 0 && length < (byte) 8)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
pinLength[PIN_INDEX_RC] = buffer[0];
pins[PIN_INDEX_RC].update(buffer, (short) 1, buffer[0]);
updatePIN(PIN_INDEX_RC, buffer, (short) 1, buffer[0]);
break;

default:
Expand Down
60 changes: 0 additions & 60 deletions javatest/net/ss3t/javacard/SimulatedCard/SimulatedCard.java

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions javatest/net/ss3t/javacard/gpg/simulated/GpgDataTestSimulated.java

This file was deleted.

29 changes: 0 additions & 29 deletions javatest/net/ss3t/javacard/gpg/simulated/GpgPINTestSimulated.java

This file was deleted.

38 changes: 0 additions & 38 deletions javatest/net/ss3t/javacard/gpg/simulated/GpgTestSimulated.java

This file was deleted.

0 comments on commit 545da17

Please sign in to comment.