Check subkey id instead of masterkey id on security token operations
Rename ambiguous getMasterKeyFingerprint -> getKeyFingerprint
This commit is contained in:
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.securitytoken;
|
package org.sufficientlysecure.keychain.securitytoken;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.bouncycastle.bcpg.HashAlgorithmTags;
|
import org.bouncycastle.bcpg.HashAlgorithmTags;
|
||||||
import org.bouncycastle.util.Arrays;
|
import org.bouncycastle.util.Arrays;
|
||||||
import org.bouncycastle.util.encoders.Hex;
|
import org.bouncycastle.util.encoders.Hex;
|
||||||
@@ -131,13 +133,13 @@ public class SecurityTokenHelper {
|
|||||||
private boolean isSlotEmpty(KeyType keyType) throws IOException {
|
private boolean isSlotEmpty(KeyType keyType) throws IOException {
|
||||||
// Note: special case: This should not happen, but happens with
|
// Note: special case: This should not happen, but happens with
|
||||||
// https://github.com/FluffyKaon/OpenPGP-Card, thus for now assume true
|
// https://github.com/FluffyKaon/OpenPGP-Card, thus for now assume true
|
||||||
if (getMasterKeyFingerprint(keyType) == null) return true;
|
if (getKeyFingerprint(keyType) == null) return true;
|
||||||
|
|
||||||
return keyMatchesFingerPrint(keyType, BLANK_FINGERPRINT);
|
return keyMatchesFingerPrint(keyType, BLANK_FINGERPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean keyMatchesFingerPrint(KeyType keyType, byte[] fingerprint) throws IOException {
|
public boolean keyMatchesFingerPrint(KeyType keyType, byte[] fingerprint) throws IOException {
|
||||||
return java.util.Arrays.equals(getMasterKeyFingerprint(keyType), fingerprint);
|
return java.util.Arrays.equals(getKeyFingerprint(keyType), fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -723,10 +725,10 @@ public class SecurityTokenHelper {
|
|||||||
* Return the fingerprint from application specific data stored on tag, or
|
* Return the fingerprint from application specific data stored on tag, or
|
||||||
* null if it doesn't exist.
|
* null if it doesn't exist.
|
||||||
*
|
*
|
||||||
* @param keyType key.operatio type
|
* @param keyType key type
|
||||||
* @return The fingerprint of the requested key, or null if not found.
|
* @return The fingerprint of the requested key, or null if not found.
|
||||||
*/
|
*/
|
||||||
public byte[] getMasterKeyFingerprint(KeyType keyType) throws IOException {
|
public byte[] getKeyFingerprint(@NonNull KeyType keyType) throws IOException {
|
||||||
byte[] data = getFingerprints();
|
byte[] data = getFingerprints();
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -186,9 +186,9 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
|||||||
switch (mRequiredInput.mType) {
|
switch (mRequiredInput.mType) {
|
||||||
case SECURITY_TOKEN_DECRYPT: {
|
case SECURITY_TOKEN_DECRYPT: {
|
||||||
long tokenKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(
|
long tokenKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(
|
||||||
mSecurityTokenHelper.getMasterKeyFingerprint(KeyType.SIGN));
|
mSecurityTokenHelper.getKeyFingerprint(KeyType.ENCRYPT));
|
||||||
|
|
||||||
if (tokenKeyId != mRequiredInput.getMasterKeyId()) {
|
if (tokenKeyId != mRequiredInput.getSubKeyId()) {
|
||||||
throw new IOException(getString(R.string.error_wrong_security_token));
|
throw new IOException(getString(R.string.error_wrong_security_token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,9 +201,9 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenNfcActivity
|
|||||||
}
|
}
|
||||||
case SECURITY_TOKEN_SIGN: {
|
case SECURITY_TOKEN_SIGN: {
|
||||||
long tokenKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(
|
long tokenKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(
|
||||||
mSecurityTokenHelper.getMasterKeyFingerprint(KeyType.SIGN));
|
mSecurityTokenHelper.getKeyFingerprint(KeyType.SIGN));
|
||||||
|
|
||||||
if (tokenKeyId != mRequiredInput.getMasterKeyId()) {
|
if (tokenKeyId != mRequiredInput.getSubKeyId()) {
|
||||||
throw new IOException(getString(R.string.error_wrong_security_token));
|
throw new IOException(getString(R.string.error_wrong_security_token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user