aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
diff options
context:
space:
mode:
authorJoey Castillo <jose.castillo@gmail.com>2015-05-13 06:01:42 -0400
committerJoey Castillo <jose.castillo@gmail.com>2015-05-13 14:36:34 -0400
commit28b9068ae03b6c17b247a1d2fdf9b20d8a11a274 (patch)
tree821b50d623d5aea38c17bf396cf281b8ef217bf1 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
parentd21fb7733697a8f947604dbd1d6c608f5b2a21d5 (diff)
downloadopen-keychain-28b9068ae03b6c17b247a1d2fdf9b20d8a11a274.tar.gz
open-keychain-28b9068ae03b6c17b247a1d2fdf9b20d8a11a274.tar.bz2
open-keychain-28b9068ae03b6c17b247a1d2fdf9b20d8a11a274.zip
Adding keytocard flag to SubkeyChange: UI sets this flag to initiate keytocard; operation unsets it and fills in dummyDivert to finish it.
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java36
1 files changed, 18 insertions, 18 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
index 93c479d5e..b6e978f48 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
@@ -412,7 +412,7 @@ public class PgpKeyOperation {
}
for(SaveKeyringParcel.SubkeyChange change : saveParcel.mChangeSubKeys) {
- if (change.mDummyDivert != null && change.mDummyDivert.length == 0) {
+ if (change.mMoveKeyToCard) {
// If this is a keytocard operation, see if it was completed: look for a hash
// matching the given subkey ID in cryptoData.
byte[] subKeyId = new byte[8];
@@ -421,6 +421,7 @@ public class PgpKeyOperation {
byte[] serialNumber = cryptoInput.getCryptoData().get(buf);
if (serialNumber != null) {
+ change.mMoveKeyToCard = false;
change.mDummyDivert = serialNumber;
}
}
@@ -776,28 +777,27 @@ public class PgpKeyOperation {
// no really, it is. this operation irrevocably removes the private key data from the key
sKey = PGPSecretKey.constructGnuDummyKey(sKey.getPublicKey());
sKR = PGPSecretKeyRing.insertSecretKey(sKR, sKey);
- } else if (change.mDummyDivert != null) {
- if (change.mDummyDivert.length == 0) {
- // If serial number is 0 length, we're moving the key to a card.
- if (checkSmartCardCompatibility(sKey, log, indent + 1)) {
- log.add(LogType.MSG_MF_KEYTOCARD_START, indent + 1,
- KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
- nfcKeyToCardOps.addSubkey(change.mKeyId);
- } else {
- return new PgpEditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
- }
- } else if (change.mDummyDivert.length == 16) {
- // If serial number is 16 bytes long, we're associating the key with a card.
- log.add(LogType.MSG_MF_KEYTOCARD_FINISH, indent + 1,
- KeyFormattingUtils.convertKeyIdToHex(change.mKeyId),
- Hex.toHexString(change.mDummyDivert, 8, 6));
- sKey = PGPSecretKey.constructGnuDummyKey(sKey.getPublicKey(), change.mDummyDivert);
- sKR = PGPSecretKeyRing.insertSecretKey(sKR, sKey);
+ } else if (change.mMoveKeyToCard) {
+ if (checkSmartCardCompatibility(sKey, log, indent + 1)) {
+ log.add(LogType.MSG_MF_KEYTOCARD_START, indent + 1,
+ KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
+ nfcKeyToCardOps.addSubkey(change.mKeyId);
} else {
+ // Appropriate log message already set by checkSmartCardCompatibility
+ return new PgpEditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
+ }
+ } else if (change.mDummyDivert != null) {
+ // NOTE: Does this code get executed? Or always handled in internalRestricted?
+ if (change.mDummyDivert.length != 16) {
log.add(LogType.MSG_MF_ERROR_DIVERT_SERIAL,
indent + 1, KeyFormattingUtils.convertKeyIdToHex(change.mKeyId));
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
}
+ log.add(LogType.MSG_MF_KEYTOCARD_FINISH, indent + 1,
+ KeyFormattingUtils.convertKeyIdToHex(change.mKeyId),
+ Hex.toHexString(change.mDummyDivert, 8, 6));
+ sKey = PGPSecretKey.constructGnuDummyKey(sKey.getPublicKey(), change.mDummyDivert);
+ sKR = PGPSecretKeyRing.insertSecretKey(sKR, sKey);
}