reduce number of token roundtrips used to obtain SecurityTokenInfo
This commit is contained in:
@@ -27,7 +27,6 @@ class OpenPgpCapabilities {
|
||||
private final static int MASK_KEY_IMPORT = 1 << 5;
|
||||
private final static int MASK_ATTRIBUTES_CHANGABLE = 1 << 2;
|
||||
|
||||
private boolean mPw1ValidForMultipleSignatures;
|
||||
private byte[] mAid;
|
||||
private byte[] mHistoricalBytes;
|
||||
|
||||
@@ -40,6 +39,8 @@ class OpenPgpCapabilities {
|
||||
private int mMaxRspLen;
|
||||
|
||||
private Map<KeyType, KeyFormat> mKeyFormats;
|
||||
private byte[] mFingerprints;
|
||||
private byte[] mPwStatusBytes;
|
||||
|
||||
OpenPgpCapabilities(byte[] data) throws IOException {
|
||||
mKeyFormats = new HashMap<>();
|
||||
@@ -76,7 +77,10 @@ class OpenPgpCapabilities {
|
||||
mKeyFormats.put(KeyType.AUTH, KeyFormat.fromBytes(tlv.mV));
|
||||
break;
|
||||
case 0xC4:
|
||||
mPw1ValidForMultipleSignatures = tlv.mV[0] == 1;
|
||||
mPwStatusBytes = tlv.mV;
|
||||
break;
|
||||
case 0xC5:
|
||||
mFingerprints = tlv.mV;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +102,10 @@ class OpenPgpCapabilities {
|
||||
mKeyFormats.put(KeyType.AUTH, KeyFormat.fromBytes(tlv.mV));
|
||||
break;
|
||||
case 0xC4:
|
||||
mPw1ValidForMultipleSignatures = tlv.mV[0] == 1;
|
||||
mPwStatusBytes = tlv.mV;
|
||||
break;
|
||||
case 0xC5:
|
||||
mFingerprints = tlv.mV;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -115,14 +122,18 @@ class OpenPgpCapabilities {
|
||||
mMaxRspLen = (v[8] << 8) + v[9];
|
||||
}
|
||||
|
||||
boolean isPw1ValidForMultipleSignatures() {
|
||||
return mPw1ValidForMultipleSignatures;
|
||||
}
|
||||
|
||||
byte[] getAid() {
|
||||
return mAid;
|
||||
}
|
||||
|
||||
byte[] getPwStatusBytes() {
|
||||
return mPwStatusBytes;
|
||||
}
|
||||
|
||||
boolean isPw1ValidForMultipleSignatures() {
|
||||
return mPwStatusBytes[0] == 1;
|
||||
}
|
||||
|
||||
byte[] getHistoricalBytes() {
|
||||
return mHistoricalBytes;
|
||||
}
|
||||
@@ -158,4 +169,8 @@ class OpenPgpCapabilities {
|
||||
KeyFormat getFormatForKeyType(KeyType keyType) {
|
||||
return mKeyFormats.get(keyType);
|
||||
}
|
||||
|
||||
public byte[] getFingerprints() {
|
||||
return mFingerprints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,29 +572,7 @@ public class SecurityTokenConnection {
|
||||
* @return The fingerprints of all subkeys in a contiguous byte array.
|
||||
*/
|
||||
public byte[] getFingerprints() throws IOException {
|
||||
CommandApdu apdu = commandFactory.createGetDataCommand(0x00, 0x6E);
|
||||
ResponseApdu response = communicate(apdu);
|
||||
|
||||
if (!response.isSuccess()) {
|
||||
throw new CardException("Failed to get fingerprints", response.getSw());
|
||||
}
|
||||
|
||||
Iso7816TLV[] tlvList = Iso7816TLV.readList(response.getData(), true);
|
||||
Iso7816TLV fingerPrintTlv = null;
|
||||
|
||||
for (Iso7816TLV tlv : tlvList) {
|
||||
Log.d(Constants.TAG, "nfcGetFingerprints() Iso7816TLV tlv data:\n" + tlv.prettyPrint());
|
||||
|
||||
Iso7816TLV matchingTlv = Iso7816TLV.findRecursive(tlv, 0xc5);
|
||||
if (matchingTlv != null) {
|
||||
fingerPrintTlv = matchingTlv;
|
||||
}
|
||||
}
|
||||
|
||||
if (fingerPrintTlv == null) {
|
||||
return null;
|
||||
}
|
||||
return fingerPrintTlv.mV;
|
||||
return mOpenPgpCapabilities.getFingerprints();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -603,11 +581,11 @@ public class SecurityTokenConnection {
|
||||
* @return Seven bytes in fixed format, plus 0x9000 status word at the end.
|
||||
*/
|
||||
private byte[] getPwStatusBytes() throws IOException {
|
||||
return getData(0x00, 0xC4);
|
||||
return mOpenPgpCapabilities.getPwStatusBytes();
|
||||
}
|
||||
|
||||
public byte[] getAid() throws IOException {
|
||||
return getData(0x00, 0x4F);
|
||||
return mOpenPgpCapabilities.getAid();
|
||||
}
|
||||
|
||||
public String getUrl() throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user