Skip to content

Commit

Permalink
Add support for vsmartcard/vpcd integration, fix up stuff for PivApplet
Browse files Browse the repository at this point in the history
  • Loading branch information
arekinath committed May 12, 2020
1 parent a47a980 commit 5574374
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ else if (applet == null) {
applet.process(apdu);
Util.setShort(theSW, (short) 0, (short) 0x9000);
} catch (Throwable e) {
e.printStackTrace(System.out);
Util.setShort(theSW, (short) 0, ISO7816.SW_UNKNOWN);
if (e instanceof CardException) {
Util.setShort(theSW, (short) 0, ((CardException) e).getReason());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void init(Key theKey, byte theMode) throws CryptoException {
}
KeyWithParameters key = (KeyWithParameters) theKey;
engine.init(theMode == MODE_ENCRYPT, key.getParameters());
buffer = JCSystem.makeTransientByteArray((short) engine.getInputBlockSize(), JCSystem.CLEAR_ON_DESELECT);
buffer = JCSystem.makeTransientByteArray((short)(engine.getInputBlockSize() + 1), JCSystem.CLEAR_ON_DESELECT);
bufferPos = 0;
isInitialized = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/licel/jcardsim/framework/APDUProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public class APDUProxy {
// buffer size
private static final short BUFFER_SIZE = 260;
private static final short BUFFER_SIZE = 261;
// buffer size (extended APDU) + (CLA,INS,P1,P2,0,Lc_Hi,Lc_Low,CData,Le_Hi,Le_Lo)
private static final int BUFFER_EXTENDED_SIZE = Short.MAX_VALUE + 10;
// input block size, for T0 protocol = 1
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/com/licel/jcardsim/remote/VSmartCard.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*
<<<<<<< HEAD
* Copyright 2018 Joyent, Inc
* Copyright 2020 The University of Queensland
=======
>>>>>>> 5389ece... Add support for vsmartcard/vpcd integration, fix up stuff for PivApplet
* Copyright 2013 Licel LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -111,7 +114,25 @@ public IOThread(Simulator sim, VSmartCardTCPProtocol driverProtocol) {
this.sim = sim;
this.driverProtocol = driverProtocol;
isRunning = true;
}

private void hexDump(byte[] apdu) {
for (int i = 0; i < apdu.length; i += 8) {
System.out.printf("%04X: ", i);
for (int j = i; j < i + 4; ++j) {
if (j >= apdu.length)
break;
System.out.printf("%02X ", apdu[j]);
}
System.out.printf(" ");
for (int j = i + 4; j < i + 8; ++j) {
if (j >= apdu.length)
break;
System.out.printf("%02X ", apdu[j]);
}
System.out.printf("\n");
}
}

@Override
public void run() {
Expand All @@ -128,11 +149,17 @@ public void run() {
break;
case VSmartCardTCPProtocol.APDU:
final byte[] apdu = driverProtocol.readData();
System.out.println("== APDU");
hexDump(apdu);
final byte[] reply = CardManager.dispatchApdu(sim, apdu);
System.out.println("== Reply APDU");
hexDump(reply);
driverProtocol.writeData(reply);
break;
}
} catch (Exception e) {}
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
}
Expand Down

0 comments on commit 5574374

Please sign in to comment.