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 14:29:51 -0400
committerJoey Castillo <jose.castillo@gmail.com>2015-05-13 17:56:17 -0400
commitbc48ce4210a01fb37146d210c10fb98abc15aa17 (patch)
tree0bde985192c86043dfc705878050935c3c393ced /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
parentde2006a61f71ada64763112706b61bf51ae5f6e4 (diff)
downloadopen-keychain-bc48ce4210a01fb37146d210c10fb98abc15aa17.tar.gz
open-keychain-bc48ce4210a01fb37146d210c10fb98abc15aa17.tar.bz2
open-keychain-bc48ce4210a01fb37146d210c10fb98abc15aa17.zip
Add check for exporting two keys to same smart card slot.
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, 36 insertions, 0 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 566ffd44b..62809ca6b 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpKeyOperation.java
@@ -410,6 +410,10 @@ public class PgpKeyOperation {
return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
}
+ // Ensure we don't have multiple keys for the same slot.
+ boolean hasSign = false;
+ boolean hasEncrypt = false;
+ boolean hasAuth = false;
for(SaveKeyringParcel.SubkeyChange change : saveParcel.mChangeSubKeys) {
if (change.mMoveKeyToCard) {
// If this is a keytocard operation, see if it was completed: look for a hash
@@ -424,6 +428,38 @@ public class PgpKeyOperation {
change.mDummyDivert = serialNumber;
}
}
+
+ if (change.mMoveKeyToCard) {
+ // Pending keytocard operation. Need to make sure that we don't have multiple
+ // subkeys pending for the same slot.
+ CanonicalizedSecretKey wsK = wsKR.getSecretKey(change.mKeyId);
+
+ if ((wsK.canSign() || wsK.canCertify())) {
+ if (hasSign) {
+ log.add(LogType.MSG_MF_ERROR_DUPLICATE_KEYTOCARD_FOR_SLOT, indent + 1);
+ return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
+ } else {
+ hasSign = true;
+ }
+ } else if ((wsK.canEncrypt())) {
+ if (hasEncrypt) {
+ log.add(LogType.MSG_MF_ERROR_DUPLICATE_KEYTOCARD_FOR_SLOT, indent + 1);
+ return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
+ } else {
+ hasEncrypt = true;
+ }
+ } else if ((wsK.canAuthenticate())) {
+ if (hasAuth) {
+ log.add(LogType.MSG_MF_ERROR_DUPLICATE_KEYTOCARD_FOR_SLOT, indent + 1);
+ return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
+ } else {
+ hasAuth = true;
+ }
+ } else {
+ log.add(LogType.MSG_MF_ERROR_INVALID_FLAGS_FOR_KEYTOCARD, indent + 1);
+ return new PgpEditKeyResult(PgpEditKeyResult.RESULT_ERROR, log, null);
+ }
+ }
}
if (isDummy(masterSecretKey) || saveParcel.isRestrictedOnly()) {