From 930515e496eea3e7c012ef26ffb072672f27b195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=C3=ADn=20Dufka?= Date: Sun, 24 Sep 2023 19:27:32 +0200 Subject: [PATCH] feat: add an instruction for querying group key --- README.md | 1 + applet/src/main/java/jcfrost/Consts.java | 1 + applet/src/main/java/jcfrost/JCFROST.java | 9 +++++++++ applet/src/test/java/tests/AppletTest.java | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 1d486dc..adba77b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/applet/src/main/java/jcfrost/Consts.java b/applet/src/main/java/jcfrost/Consts.java index 1c5c338..c5fa6fe 100644 --- a/applet/src/main/java/jcfrost/Consts.java +++ b/applet/src/main/java/jcfrost/Consts.java @@ -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; diff --git a/applet/src/main/java/jcfrost/JCFROST.java b/applet/src/main/java/jcfrost/JCFROST.java index 179bb7f..3b115ee 100755 --- a/applet/src/main/java/jcfrost/JCFROST.java +++ b/applet/src/main/java/jcfrost/JCFROST.java @@ -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); } @@ -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); + } } diff --git a/applet/src/test/java/tests/AppletTest.java b/applet/src/test/java/tests/AppletTest.java index fb746cb..16f0eae 100755 --- a/applet/src/test/java/tests/AppletTest.java +++ b/applet/src/test/java/tests/AppletTest.java @@ -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(); @@ -79,6 +84,7 @@ public void testSetup() throws Exception { ); Assert.assertArrayEquals(responseAPDU.getData(), expected); } + Assert.assertArrayEquals(tv.groupKey(), groupKey(cm).getData()); reset(cm); }