Skip to content

Commit

Permalink
feat: add an instruction for querying group key
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Sep 24, 2023
1 parent 9888920 commit 930515e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ The applet responds to the following APDUs.
| `COMMITMENT` | 0x00 | 0x03 | `idx` | 0x00 | hiding commitment + binding commitment of party `idx` |
| `SIGN` | 0x00 | 0x04 | msg length | 0x00 | message |
| `RESET` | 0x00 | 0x05 | 0x00 | 0x00 | --- |
| `GROUP_KEY` | 0x00 | 0x06 | 0x00 | 0x00 | --- |

The applet expects that commitments supplied by the `COMMITMENT` instruction are ordered by party `idx`, including the card's commitments.
1 change: 1 addition & 0 deletions applet/src/main/java/jcfrost/Consts.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Consts {
public static final byte INS_SIGN = (byte) 0x04;

public static final byte INS_RESET = (byte) 0x05;
public static final byte INS_GROUP_KEY = (byte) 0x06;

public final static short E_ALREADY_INITIALIZED = (short) 0xee00;
public final static short E_UNINITIALIZED = (short) 0xee01;
Expand Down
9 changes: 9 additions & 0 deletions applet/src/main/java/jcfrost/JCFROST.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public void process(APDU apdu) {
reset(apdu);
break;

case Consts.INS_GROUP_KEY:
getGroupKey(apdu);
break;

default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
Expand Down Expand Up @@ -167,4 +171,9 @@ private void reset(APDU apdu) {
frost.reset();
apdu.setOutgoing();
}

private void getGroupKey(APDU apdu) {
short len = groupPublic.encode(apdu.getBuffer(), (short) 0, true);
apdu.setOutgoingAndSend((short) 0, len);
}
}
6 changes: 6 additions & 0 deletions applet/src/test/java/tests/AppletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public ResponseAPDU reset(CardManager cm) throws CardException {
return cm.transmit(cmd);
}

public ResponseAPDU groupKey(CardManager cm) throws CardException {
final CommandAPDU cmd = new CommandAPDU(Consts.CLA_JCFROST, Consts.INS_GROUP_KEY, 0, 0);
return cm.transmit(cmd);
}

@Test
public void testSetup() throws Exception {
CardManager cm = connect();
Expand All @@ -79,6 +84,7 @@ public void testSetup() throws Exception {
);
Assert.assertArrayEquals(responseAPDU.getData(), expected);
}
Assert.assertArrayEquals(tv.groupKey(), groupKey(cm).getData());
reset(cm);
}

Expand Down

0 comments on commit 930515e

Please sign in to comment.