Skip to content

Commit

Permalink
Added result code to communicateSecure
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauris Kaplinski committed Jul 17, 2024
1 parent b3d12a4 commit b333619
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions id-card-lib/src/main/java/ee/ria/DigiDoc/idcard/NFC.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public Result communicateSecure(byte[] cmd, byte[] data) {
Timber.log(Log.DEBUG, "APDU: %s", Hex.toHexString(APDU));
response = card.transceive(APDU);
Timber.log(Log.DEBUG, "RESPONSE: %s", Hex.toHexString(response));
int code = (((int) response[response.length - 2] & 0xff) << 8) | ((int) response[response.length - 1] & 0xff);
if (response.length > 2) {
TLV tlv = new TLV(response, 0, response.length - 2);
Timber.log(Log.DEBUG, "TLV:%x %s", tlv.tag, Hex.toHexString(tlv.data, tlv.start, tlv.end - tlv.start));
Expand All @@ -212,15 +213,15 @@ public Result communicateSecure(byte[] cmd, byte[] data) {
byte[] decrypted = encryptDecryptData(Arrays.copyOfRange(tlv_enc.data, tlv_enc.start + 1, tlv_enc.end), Cipher.DECRYPT_MODE);
int indexOfTerminator = Hex.toHexString(decrypted).lastIndexOf("80") / 2;
byte[] pruned = Arrays.copyOf(decrypted, indexOfTerminator);
return new Result(0x9000, pruned);
return new Result(code, pruned);
} else {
TLV tlv_res = tlv;
Timber.log(Log.DEBUG, "RES:%x %s", tlv_res.tag, Hex.toHexString(tlv_res.data, tlv_res.start, tlv_res.end - tlv_res.start));
TLV tlv_mac = new TLV(tlv.data, tlv_res.end, response.length - 2);
Timber.log(Log.DEBUG, "MAC:%x %s", tlv_mac.tag, Hex.toHexString(tlv_mac.data, tlv_mac.start, tlv_mac.end - tlv_mac.start));
}
}
return new Result(response);
return new Result(code, response);
} catch (RuntimeException e) {
Timber.log(Log.ERROR, "Exception in app with NFC: %s", e.getMessage());
} catch (Exception exc) {
Expand Down

0 comments on commit b333619

Please sign in to comment.