From 0ca7cbb45eab4141c74fa6b2c111a3c4d285f57d Mon Sep 17 00:00:00 2001 From: Rylie Pavlik Date: Fri, 15 Dec 2023 16:27:23 -0600 Subject: [PATCH] turn back on Feitian workaround, with fix to save/restore INS --- .../mysmartlogon/gidsApplet/GidsApplet.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/com/mysmartlogon/gidsApplet/GidsApplet.java b/src/com/mysmartlogon/gidsApplet/GidsApplet.java index a02e4a8..050e9b8 100644 --- a/src/com/mysmartlogon/gidsApplet/GidsApplet.java +++ b/src/com/mysmartlogon/gidsApplet/GidsApplet.java @@ -79,6 +79,8 @@ public class GidsApplet extends Applet { public static final short LENGTH_RSA_3072 = (short) 3072; public static final short LENGTH_RSA_4096 = (short) 4096; + public static final boolean CONFIG_USE_FEITIAN_WORKAROUND = true; + private GidsPINManager pinManager = null; @@ -439,15 +441,21 @@ public void processGenerateAsymmetricKeypair(APDU apdu) throws ISOException { } kp.genKeyPair(); - // special Feitian workaround for A40CR and A22CR cards - // but it breaks J3H145 :( - // - // RSAPrivateCrtKey priKey = (RSAPrivateCrtKey) kp.getPrivate(); - // short pLen = priKey.getP(buf, (short) 0); - // priKey.setP(buf, (short) 0, pLen); - // short qLen = priKey.getQ(buf, (short) 0); - // priKey.setQ(buf, (short) 0, qLen); - // end of workaround + if (CONFIG_USE_FEITIAN_WORKAROUND) { + // special Feitian workaround for A40CR and A22CR cards + // but it breaks J3H145 :( + // using p1 for temp since we aren't using it anymore + p1 = buf[ISO7816.OFFSET_INS]; + // TODO do we also need to back up and restore Le? + + RSAPrivateCrtKey priKey = (RSAPrivateCrtKey) kp.getPrivate(); + short pLen = priKey.getP(buf, (short) 0); + priKey.setP(buf, (short) 0, pLen); + short qLen = priKey.getQ(buf, (short) 0); + priKey.setQ(buf, (short) 0, qLen); + + buf[ISO7816.OFFSET_INS] = p1; + } } catch(CryptoException e) { if(e.getReason() == CryptoException.NO_SUCH_ALGORITHM) {