Fix crashes with Fluffys PGP applet

This commit is contained in:
Dominik Schürmann
2015-08-22 03:13:04 +02:00
parent 1d0e9bf60a
commit 08e25747da
4 changed files with 32 additions and 20 deletions

View File

@@ -206,7 +206,7 @@ public class PgpSecurityConstants {
* TODO: Ed25519 * TODO: Ed25519
* CITE: zooko's hash function table CITE: distinguishers on SHA-256 * CITE: zooko's hash function table CITE: distinguishers on SHA-256
*/ */
public static final int DEFAULT_HASH_ALGORITHM = HashAlgorithmTags.SHA512; public static final int DEFAULT_HASH_ALGORITHM = HashAlgorithmTags.SHA256;
public interface OpenKeychainHashAlgorithmTags extends HashAlgorithmTags { public interface OpenKeychainHashAlgorithmTags extends HashAlgorithmTags {
int USE_DEFAULT = -1; int USE_DEFAULT = -1;

View File

@@ -187,15 +187,17 @@ public class CreateKeyActivity extends BaseNfcActivity {
} }
private boolean containsKeys(byte[] scannedFingerprints) { private boolean containsKeys(byte[] scannedFingerprints) {
if (scannedFingerprints == null) {
return false;
}
// If all fingerprint bytes are 0, the card contains no keys. // If all fingerprint bytes are 0, the card contains no keys.
boolean cardContainsKeys = false;
for (byte b : scannedFingerprints) { for (byte b : scannedFingerprints) {
if (b != 0) { if (b != 0) {
cardContainsKeys = true; return true;
break;
} }
} }
return cardContainsKeys; return false;
} }
@Override @Override

View File

@@ -294,9 +294,11 @@ public class NfcOperationActivity extends BaseNfcActivity {
private boolean shouldPutKey(byte[] fingerprint, int idx) throws IOException { private boolean shouldPutKey(byte[] fingerprint, int idx) throws IOException {
byte[] cardFingerprint = nfcGetFingerprint(idx); byte[] cardFingerprint = nfcGetFingerprint(idx);
// Slot is empty, or contains this key already. PUT KEY operation is safe // Slot is empty, or contains this key already. PUT KEY operation is safe
if (Arrays.equals(cardFingerprint, BLANK_FINGERPRINT) || if (cardFingerprint == null ||
Arrays.equals(cardFingerprint, fingerprint)) { Arrays.equals(cardFingerprint, BLANK_FINGERPRINT) ||
Arrays.equals(cardFingerprint, fingerprint)) {
return true; return true;
} }

View File

@@ -147,8 +147,6 @@ public abstract class BaseNfcActivity extends BaseActivity {
protected Exception doInBackground(Void... params) { protected Exception doInBackground(Void... params) {
try { try {
handleTagDiscoveredIntent(intent); handleTagDiscoveredIntent(intent);
} catch (CardException e) {
return e;
} catch (IOException e) { } catch (IOException e) {
return e; return e;
} }
@@ -406,6 +404,10 @@ public abstract class BaseNfcActivity extends BaseActivity {
// Connect to the detected tag, setting a couple of settings // Connect to the detected tag, setting a couple of settings
mIsoDep = IsoDep.get(detectedTag); mIsoDep = IsoDep.get(detectedTag);
if (mIsoDep == null) {
// TODO: better exception?
throw new IOException("Tag does not support ISO-DEP (ISO 14443-4)!");
}
mIsoDep.setTimeout(TIMEOUT); // timeout is set to 100 seconds to avoid cancellation during calculation mIsoDep.setTimeout(TIMEOUT); // timeout is set to 100 seconds to avoid cancellation during calculation
mIsoDep.connect(); mIsoDep.connect();
@@ -496,6 +498,9 @@ public abstract class BaseNfcActivity extends BaseActivity {
*/ */
public byte[] nfcGetFingerprint(int idx) throws IOException { public byte[] nfcGetFingerprint(int idx) throws IOException {
byte[] data = nfcGetFingerprints(); byte[] data = nfcGetFingerprints();
if (data == null) {
return null;
}
// return the master key fingerprint // return the master key fingerprint
ByteBuffer fpbuf = ByteBuffer.wrap(data); ByteBuffer fpbuf = ByteBuffer.wrap(data);
@@ -507,14 +512,11 @@ public abstract class BaseNfcActivity extends BaseActivity {
} }
public byte[] nfcGetAid() throws IOException { public byte[] nfcGetAid() throws IOException {
String info = "00CA004F00"; String info = "00CA004F00";
return mIsoDep.transceive(Hex.decode(info)); return mIsoDep.transceive(Hex.decode(info));
} }
public String nfcGetUserId() throws IOException { public String nfcGetUserId() throws IOException {
String info = "00CA006500"; String info = "00CA006500";
return nfcGetHolderName(nfcCommunicate(info)); return nfcGetHolderName(nfcCommunicate(info));
} }
@@ -952,14 +954,20 @@ public abstract class BaseNfcActivity extends BaseActivity {
} }
public String nfcGetHolderName(String name) { public String nfcGetHolderName(String name) {
String slength; try {
int ilength; String slength;
name = name.substring(6); int ilength;
slength = name.substring(0, 2); name = name.substring(6);
ilength = Integer.parseInt(slength, 16) * 2; slength = name.substring(0, 2);
name = name.substring(2, ilength + 2); ilength = Integer.parseInt(slength, 16) * 2;
name = (new String(Hex.decode(name))).replace('<', ' '); name = name.substring(2, ilength + 2);
return (name); name = (new String(Hex.decode(name))).replace('<', ' ');
return name;
} catch (IndexOutOfBoundsException e) {
Log.e(Constants.TAG, "couldn't get holder name", e);
// try-catch for https://github.com/FluffyKaon/OpenPGP-Card
return "";
}
} }
private String nfcGetDataField(String output) { private String nfcGetDataField(String output) {