From 28b9068ae03b6c17b247a1d2fdf9b20d8a11a274 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Wed, 13 May 2015 06:01:42 -0400 Subject: Adding keytocard flag to SubkeyChange: UI sets this flag to initiate keytocard; operation unsets it and fills in dummyDivert to finish it. --- .../keychain/pgp/PgpKeyOperation.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp') 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); } -- cgit v1.2.3