Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e0f11f71c | ||
|
|
64aece4837 |
@@ -24,23 +24,14 @@ public class NFCCardChannel implements CardChannel {
|
||||
public APDUResponse send(APDUCommand cmd) throws IOException {
|
||||
byte[] apdu = cmd.serialize();
|
||||
Log.d(TAG, String.format("COMMAND CLA: %02X INS: %02X P1: %02X P2: %02X LC: %02X", cmd.getCla(), cmd.getIns(), cmd.getP1(), cmd.getP2(), cmd.getData().length));
|
||||
|
||||
try {
|
||||
byte[] resp = this.isoDep.transceive(apdu);
|
||||
APDUResponse response = new APDUResponse(resp);
|
||||
Log.d(TAG, String.format("RESPONSE LEN: %02X, SW: %04X %n-----------------------", response.getData().length, response.getSw()));
|
||||
return response;
|
||||
} catch(SecurityException e) {
|
||||
throw new IOException("Tag disconnected", e);
|
||||
}
|
||||
byte[] resp = this.isoDep.transceive(apdu);
|
||||
APDUResponse response = new APDUResponse(resp);
|
||||
Log.d(TAG, String.format("RESPONSE LEN: %02X, SW: %04X %n-----------------------", response.getData().length, response.getSw()));
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
return this.isoDep.isConnected();
|
||||
} catch(SecurityException e) {
|
||||
return false;
|
||||
}
|
||||
return this.isoDep.isConnected();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,7 @@ public class NFCCardManager extends Thread implements NfcAdapter.ReaderCallback
|
||||
* @return if connected, false otherwise
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
return isoDep != null && isoDep.isConnected();
|
||||
} catch (SecurityException e) {
|
||||
return false;
|
||||
}
|
||||
return isoDep != null && isoDep.isConnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +58,7 @@ public class NFCCardManager extends Thread implements NfcAdapter.ReaderCallback
|
||||
isoDep = IsoDep.get(tag);
|
||||
isoDep.connect();
|
||||
isoDep.setTimeout(120000);
|
||||
} catch (IOException | SecurityException e) {
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "error connecting to tag");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ public class KeycardCommandSet {
|
||||
* @throws IOException communication error
|
||||
*/
|
||||
public APDUResponse sign(byte[] data, int p1) throws IOException {
|
||||
APDUCommand sign = secureChannel.protectedCommand(0x80, INS_SIGN, p1, 0x01, data);
|
||||
APDUCommand sign = secureChannel.protectedCommand(0x80, INS_SIGN, p1, 0x00, data);
|
||||
return secureChannel.transmit(apduChannel, sign);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ public class RecoverableSignature {
|
||||
private boolean compressed;
|
||||
|
||||
public static final byte TLV_SIGNATURE_TEMPLATE = (byte) 0xA0;
|
||||
public static final byte TLV_RAW_SIGNATURE = (byte) 0x80;
|
||||
public static final byte TLV_ECDSA_TEMPLATE = (byte) 0x30;
|
||||
|
||||
private static final X9ECParameters CURVE_PARAMS = CustomNamedCurves.getByName("secp256k1");
|
||||
@@ -42,19 +41,6 @@ public class RecoverableSignature {
|
||||
*/
|
||||
public RecoverableSignature(byte[] hash, byte[] tlvData) {
|
||||
TinyBERTLV tlv = new TinyBERTLV(tlvData);
|
||||
int tag = tlv.readTag();
|
||||
tlv.unreadLastTag();
|
||||
|
||||
if (tag == TLV_RAW_SIGNATURE) {
|
||||
initFromRawSignature(hash, tlv.readPrimitive(tag));
|
||||
} else if (tag == TLV_SIGNATURE_TEMPLATE) {
|
||||
initFromLegacy(hash, tlv);
|
||||
} else {
|
||||
throw new IllegalArgumentException("invalid tlv");
|
||||
}
|
||||
}
|
||||
|
||||
private void initFromLegacy(byte[] hash, TinyBERTLV tlv) {
|
||||
tlv.enterConstructed(TLV_SIGNATURE_TEMPLATE);
|
||||
this.publicKey = tlv.readPrimitive(ApplicationInfo.TLV_PUB_KEY);
|
||||
tlv.enterConstructed(TLV_ECDSA_TEMPLATE);
|
||||
@@ -65,14 +51,6 @@ public class RecoverableSignature {
|
||||
calculateRecID(hash);
|
||||
}
|
||||
|
||||
private void initFromRawSignature(byte[] hash, byte[] signature) {
|
||||
this.r = Arrays.copyOfRange(signature, 0, 32);
|
||||
this.s = Arrays.copyOfRange(signature, 32, 64);
|
||||
this.recId = signature[64];
|
||||
this.compressed = false;
|
||||
this.publicKey = recoverFromSignature(this.recId, hash, this.r, this.s, this.compressed);
|
||||
}
|
||||
|
||||
public RecoverableSignature(byte[] publicKey, boolean compressed, byte[] r, byte[] s, int recId) {
|
||||
this.publicKey = publicKey;
|
||||
this.r = r;
|
||||
|
||||
Reference in New Issue
Block a user