diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2015-05-06 13:08:03 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2015-05-12 14:44:26 -0400 |
commit | 76241e90ad440bedaf40f148ba0584e06064096a (patch) | |
tree | feee753bb557be2f4a589126097c8942525b8b2e /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations | |
parent | 5c44f8400970de5943fd6c5e804dfa394f3deb01 (diff) | |
download | open-keychain-76241e90ad440bedaf40f148ba0584e06064096a.tar.gz open-keychain-76241e90ad440bedaf40f148ba0584e06064096a.tar.bz2 open-keychain-76241e90ad440bedaf40f148ba0584e06064096a.zip |
Adding NFC Key to Card operation, accessible from Edit Key activity.
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations')
2 files changed, 107 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/NfcKeyToCardOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/NfcKeyToCardOperation.java new file mode 100644 index 000000000..95937a233 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/NfcKeyToCardOperation.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2015 Joey Castillo <joey@joeycastillo.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.operations; + +import android.content.Context; + +import org.sufficientlysecure.keychain.operations.results.NfcKeyToCardResult; +import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; +import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; +import org.sufficientlysecure.keychain.pgp.Progressable; +import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; + +public class NfcKeyToCardOperation extends BaseOperation { + public NfcKeyToCardOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { + super(context, providerHelper, progressable); + } + + public NfcKeyToCardResult execute(long subKeyId) { + OperationResult.OperationLog log = new OperationResult.OperationLog(); + int indent = 0; + long masterKeyId; + + try { + // fetch the indicated master key id + masterKeyId = mProviderHelper.getMasterKeyId(subKeyId); + CanonicalizedSecretKeyRing keyRing = + mProviderHelper.getCanonicalizedSecretKeyRing(masterKeyId); + + log.add(OperationResult.LogType.MSG_KC_SECRET, indent); + + // fetch the specific subkey + CanonicalizedSecretKey subKey = keyRing.getSecretKey(subKeyId); + + switch (subKey.getSecretKeyType()) { + case DIVERT_TO_CARD: + case GNU_DUMMY: { + throw new AssertionError( + "Cannot export GNU_DUMMY/DIVERT_TO_CARD key to a smart card!" + + " This is a programming error!"); + } + + case PIN: + case PATTERN: + case PASSPHRASE: { + log.add(OperationResult.LogType.MSG_PSE_PENDING_NFC, indent); + return new NfcKeyToCardResult(log, RequiredInputParcel + .createNfcKeyToCardOperation(masterKeyId, subKeyId)); + } + + default: { + throw new AssertionError("Unhandled SecretKeyType! (should not happen)"); + } + + } + } catch (ProviderHelper.NotFoundException e) { + log.add(OperationResult.LogType.MSG_PSE_ERROR_UNLOCK, indent); + return new NfcKeyToCardResult(NfcKeyToCardResult.RESULT_ERROR, log); + } + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/NfcKeyToCardResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/NfcKeyToCardResult.java new file mode 100644 index 000000000..c4bd3986c --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/NfcKeyToCardResult.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 Joey Castillo <joey@joeycastillo.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.operations.results; + +import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; + +public class NfcKeyToCardResult extends InputPendingResult { + public NfcKeyToCardResult(int result, OperationLog log) { + super(result, log); + } + + public NfcKeyToCardResult(OperationLog log, RequiredInputParcel requiredInput) { + super(log, requiredInput); + } +} |