Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turn back on Feitian workaround, with fix to save/restore INS #23

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/com/mysmartlogon/gidsApplet/GidsApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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) {
Expand Down