pass (encryption) key id from Decrypt*Fragment to NfcActivity
This commit is contained in:
@@ -216,7 +216,7 @@ public class DecryptFilesFragment extends DecryptFragment {
|
||||
startPassphraseDialog(Constants.key.symmetric);
|
||||
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
|
||||
DecryptVerifyResult.RESULT_PENDING_NFC) {
|
||||
startNfcDecrypt(pgpResult.getNfcPassphrase(), pgpResult.getNfcEncryptedSessionKey());
|
||||
startNfcDecrypt(pgpResult.getNfcSubKeyId(), pgpResult.getNfcPassphrase(), pgpResult.getNfcEncryptedSessionKey());
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled pending result!");
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class DecryptFilesFragment extends DecryptFragment {
|
||||
startPassphraseDialog(Constants.key.symmetric);
|
||||
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
|
||||
DecryptVerifyResult.RESULT_PENDING_NFC) {
|
||||
startNfcDecrypt(pgpResult.getNfcPassphrase(), pgpResult.getNfcEncryptedSessionKey());
|
||||
startNfcDecrypt(pgpResult.getNfcSubKeyId(), pgpResult.getNfcPassphrase(), pgpResult.getNfcEncryptedSessionKey());
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled pending result!");
|
||||
}
|
||||
|
||||
@@ -89,11 +89,12 @@ public abstract class DecryptFragment extends Fragment {
|
||||
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||
}
|
||||
|
||||
protected void startNfcDecrypt(String pin, byte[] encryptedSessionKey) {
|
||||
protected void startNfcDecrypt(long subKeyId, String pin, byte[] encryptedSessionKey) {
|
||||
// build PendingIntent for Yubikey NFC operations
|
||||
Intent intent = new Intent(getActivity(), NfcActivity.class);
|
||||
intent.setAction(NfcActivity.ACTION_DECRYPT_SESSION_KEY);
|
||||
intent.putExtra(NfcActivity.EXTRA_DATA, new Intent()); // not used, only relevant to OpenPgpService
|
||||
intent.putExtra(NfcActivity.EXTRA_KEY_ID, subKeyId);
|
||||
intent.putExtra(NfcActivity.EXTRA_PIN, pin);
|
||||
|
||||
intent.putExtra(NfcActivity.EXTRA_NFC_ENC_SESSION_KEY, encryptedSessionKey);
|
||||
|
||||
@@ -172,7 +172,7 @@ public class DecryptTextFragment extends DecryptFragment {
|
||||
startPassphraseDialog(Constants.key.symmetric);
|
||||
} else if ((pgpResult.getResult() & DecryptVerifyResult.RESULT_PENDING_NFC) ==
|
||||
DecryptVerifyResult.RESULT_PENDING_NFC) {
|
||||
startNfcDecrypt(pgpResult.getNfcPassphrase(), pgpResult.getNfcEncryptedSessionKey());
|
||||
startNfcDecrypt(pgpResult.getNfcSubKeyId(), pgpResult.getNfcPassphrase(), pgpResult.getNfcEncryptedSessionKey());
|
||||
} else {
|
||||
throw new RuntimeException("Unhandled pending result!");
|
||||
}
|
||||
|
||||
@@ -205,19 +205,6 @@ public class NfcActivity extends ActionBarActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we were supplied with a key id for checking, do so
|
||||
if (mKeyId != null) {
|
||||
// We always check the master key id
|
||||
long keyId = nfcGetKeyId(mIsoDep, 0);
|
||||
// If it's wrong, just cancel
|
||||
if (keyId != mKeyId) {
|
||||
toast("NFC Tag has wrong key id!");
|
||||
setResult(RESULT_CANCELED, mServiceIntent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Command APDU for VERIFY command (page 32)
|
||||
String login =
|
||||
"00" // CLA
|
||||
@@ -234,6 +221,20 @@ public class NfcActivity extends ActionBarActivity {
|
||||
}
|
||||
|
||||
if (ACTION_SIGN_HASH.equals(mAction)) {
|
||||
|
||||
// If we were supplied with a key id for checking, do so
|
||||
if (mKeyId != null) {
|
||||
// For signing, we check the master key
|
||||
long keyId = nfcGetKeyId(mIsoDep, 0);
|
||||
// If it's wrong, just cancel
|
||||
if (keyId != mKeyId) {
|
||||
toast("NFC Tag has wrong signing key id!");
|
||||
setResult(RESULT_CANCELED, mServiceIntent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// returns signed hash
|
||||
byte[] signedHash = nfcCalculateSignature(mHashToSign, mHashAlgo);
|
||||
|
||||
@@ -252,6 +253,20 @@ public class NfcActivity extends ActionBarActivity {
|
||||
finish();
|
||||
|
||||
} else if (ACTION_DECRYPT_SESSION_KEY.equals(mAction)) {
|
||||
|
||||
// If we were supplied with a key id for checking, do so
|
||||
if (mKeyId != null) {
|
||||
// For decryption, we check the confidentiality key
|
||||
long keyId = nfcGetKeyId(mIsoDep, 1);
|
||||
// If it's wrong, just cancel
|
||||
if (keyId != mKeyId) {
|
||||
toast("NFC Tag has wrong encryption key id!");
|
||||
setResult(RESULT_CANCELED, mServiceIntent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] decryptedSessionKey = nfcDecryptSessionKey(mEncryptedSessionKey);
|
||||
|
||||
// give data through for new service call
|
||||
|
||||
Reference in New Issue
Block a user