diff options
Diffstat (limited to 'OpenKeychain/src')
22 files changed, 168 insertions, 98 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java index 08b7316aa..db0a9b137 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedKeyRing.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.pgp; import org.spongycastle.openpgp.PGPKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.util.IterableIterator; import java.io.IOException; @@ -56,11 +57,11 @@ public abstract class CanonicalizedKeyRing extends KeyRing { return getRing().getPublicKey().getFingerprint(); } - public String getPrimaryUserId() throws PgpGeneralException { + public String getPrimaryUserId() throws PgpKeyNotFoundException { return getPublicKey().getPrimaryUserId(); } - public String getPrimaryUserIdWithFallback() throws PgpGeneralException { + public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { return getPublicKey().getPrimaryUserIdWithFallback(); } @@ -87,24 +88,24 @@ public abstract class CanonicalizedKeyRing extends KeyRing { return creationDate.after(now) || (expiryDate != null && expiryDate.before(now)); } - public boolean canCertify() throws PgpGeneralException { + public boolean canCertify() throws PgpKeyNotFoundException { return getRing().getPublicKey().isEncryptionKey(); } - public long getEncryptId() throws PgpGeneralException { + public long getEncryptId() throws PgpKeyNotFoundException { for(CanonicalizedPublicKey key : publicKeyIterator()) { if (key.canEncrypt() && key.isValid()) { return key.getKeyId(); } } - throw new PgpGeneralException("No valid encryption key found!"); + throw new PgpKeyNotFoundException("No valid encryption key found!"); } - public boolean hasEncrypt() throws PgpGeneralException { + public boolean hasEncrypt() throws PgpKeyNotFoundException { try { getEncryptId(); return true; - } catch(PgpGeneralException e) { + } catch(PgpKeyNotFoundException e) { return false; } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java index 77c967c65..85ef3eaa4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java @@ -21,7 +21,7 @@ package org.sufficientlysecure.keychain.pgp; import org.spongycastle.openpgp.PGPObjectFactory; import org.spongycastle.openpgp.PGPPublicKey; import org.spongycastle.openpgp.PGPPublicKeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.util.IterableIterator; import java.io.IOException; @@ -61,16 +61,16 @@ public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing { } /** Getter that returns the subkey that should be used for signing. */ - CanonicalizedPublicKey getEncryptionSubKey() throws PgpGeneralException { + CanonicalizedPublicKey getEncryptionSubKey() throws PgpKeyNotFoundException { PGPPublicKey key = getRing().getPublicKey(getEncryptId()); if(key != null) { CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key); if(!cKey.canEncrypt()) { - throw new PgpGeneralException("key error"); + throw new PgpKeyNotFoundException("key error"); } return cKey; } - throw new PgpGeneralException("no encryption key available"); + throw new PgpKeyNotFoundException("no encryption key available"); } public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index 595f37872..a65759a3b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -41,6 +41,7 @@ import org.spongycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.Log; @@ -254,9 +255,11 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { spGen.setSignatureCreationTime(false, nfcCreationTimestamp); signatureGenerator.setHashedSubpackets(spGen.generate()); return signatureGenerator; - } catch (PGPException e) { + } catch (PgpKeyNotFoundException e) { // TODO: simply throw PGPException! throw new PgpGeneralException("Error initializing signature!", e); + } catch (PGPException e) { + throw new PgpGeneralException("Error initializing signature!", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java index b682378e9..26375219b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/KeyRing.java @@ -20,7 +20,7 @@ package org.sufficientlysecure.keychain.pgp; import android.text.TextUtils; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -38,25 +38,25 @@ import java.util.regex.Pattern; */ public abstract class KeyRing { - abstract public long getMasterKeyId() throws PgpGeneralException; + abstract public long getMasterKeyId() throws PgpKeyNotFoundException; - abstract public String getPrimaryUserId() throws PgpGeneralException; + abstract public String getPrimaryUserId() throws PgpKeyNotFoundException; - abstract public String getPrimaryUserIdWithFallback() throws PgpGeneralException; + abstract public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException; - public String[] getSplitPrimaryUserIdWithFallback() throws PgpGeneralException { + public String[] getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { return splitUserId(getPrimaryUserIdWithFallback()); } - abstract public boolean isRevoked() throws PgpGeneralException; + abstract public boolean isRevoked() throws PgpKeyNotFoundException; - abstract public boolean canCertify() throws PgpGeneralException; + abstract public boolean canCertify() throws PgpKeyNotFoundException; - abstract public long getEncryptId() throws PgpGeneralException; + abstract public long getEncryptId() throws PgpKeyNotFoundException; - abstract public boolean hasEncrypt() throws PgpGeneralException; + abstract public boolean hasEncrypt() throws PgpKeyNotFoundException; - abstract public int getVerified() throws PgpGeneralException; + abstract public int getVerified() throws PgpKeyNotFoundException; private static final Pattern USER_ID_PATTERN = Pattern.compile("^(.*?)(?: \\((.*)\\))?(?: <(.*)>)?$"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java index bd7606194..aa324c7ed 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.pgp; import org.openintents.openpgp.OpenPgpSignatureResult; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; @@ -96,7 +97,7 @@ public class OpenPgpSignatureResultBuilder { setKeyId(signingRing.getMasterKeyId()); try { setPrimaryUserId(signingRing.getPrimaryUserIdWithFallback()); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.d(Constants.TAG, "No primary user id in keyring with master key id " + signingRing.getMasterKeyId()); } setSignatureKeyCertified(signingRing.getVerified() > 0); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java index 416dbce7c..6ffa30fe1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java @@ -35,6 +35,7 @@ import org.spongycastle.util.encoders.Hex; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.results.OperationResult.LogType; @@ -392,7 +393,7 @@ public class PgpSignEncrypt { cPk.addMethod(key.getPubKeyEncryptionGenerator()); log.add(LogType.MSG_SE_KEY_OK, indent + 1, KeyFormattingUtils.convertKeyIdToHex(id)); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { log.add(LogType.MSG_SE_KEY_WARN, indent + 1, KeyFormattingUtils.convertKeyIdToHex(id)); } catch (ProviderHelper.NotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/exception/PgpKeyNotFoundException.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/exception/PgpKeyNotFoundException.java new file mode 100644 index 000000000..21a7c0cf0 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/exception/PgpKeyNotFoundException.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2012-2014 Dominik Schürmann <dominik@dominikschuermann.de> + * Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org> + * + * 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.pgp.exception; + +public class PgpKeyNotFoundException extends Exception { + static final long serialVersionUID = 0xf812773342L; + + public PgpKeyNotFoundException(String message) { + super(message); + } + public PgpKeyNotFoundException(String message, Throwable cause) { + super(message, cause); + } + public PgpKeyNotFoundException(Throwable cause) { + super(cause); + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java index 5a3770f2d..7c9ef719e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java @@ -24,7 +24,7 @@ import android.net.Uri; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.Keys; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; @@ -57,13 +57,13 @@ public class CachedPublicKeyRing extends KeyRing { } @Override - public long getMasterKeyId() throws PgpGeneralException { + public long getMasterKeyId() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER); return (Long) data; } catch (ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } @@ -71,7 +71,7 @@ public class CachedPublicKeyRing extends KeyRing { * Find the master key id related to a given query. The id will either be extracted from the * query, which should work for all specific /key_rings/ queries, or will be queried if it can't. */ - public long extractOrGetMasterKeyId() throws PgpGeneralException { + public long extractOrGetMasterKeyId() throws PgpKeyNotFoundException { // try extracting from the uri first String firstSegment = mUri.getPathSegments().get(1); if (!firstSegment.equals("find")) try { @@ -83,70 +83,70 @@ public class CachedPublicKeyRing extends KeyRing { return getMasterKeyId(); } - public byte[] getFingerprint() throws PgpGeneralException { + public byte[] getFingerprint() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); return (byte[]) data; } catch (ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } @Override - public String getPrimaryUserId() throws PgpGeneralException { + public String getPrimaryUserId() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.USER_ID, ProviderHelper.FIELD_TYPE_STRING); return (String) data; } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } - public String getPrimaryUserIdWithFallback() throws PgpGeneralException { + public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException { return getPrimaryUserId(); } @Override - public boolean isRevoked() throws PgpGeneralException { + public boolean isRevoked() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.IS_REVOKED, ProviderHelper.FIELD_TYPE_INTEGER); return (Long) data > 0; } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } @Override - public boolean canCertify() throws PgpGeneralException { + public boolean canCertify() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.HAS_CERTIFY, ProviderHelper.FIELD_TYPE_NULL); return !((Boolean) data); } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } @Override - public long getEncryptId() throws PgpGeneralException { + public long getEncryptId() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeyRings.HAS_ENCRYPT, ProviderHelper.FIELD_TYPE_INTEGER); return (Long) data; } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } @Override - public boolean hasEncrypt() throws PgpGeneralException { + public boolean hasEncrypt() throws PgpKeyNotFoundException { return getEncryptId() != 0; } @@ -156,41 +156,41 @@ public class CachedPublicKeyRing extends KeyRing { * revoked, or expired), hence only works on keyrings where a secret key is available! * */ - public long getSecretSignId() throws PgpGeneralException { + public long getSecretSignId() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeyRings.HAS_SIGN, ProviderHelper.FIELD_TYPE_INTEGER); return (Long) data; } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } @Override - public int getVerified() throws PgpGeneralException { + public int getVerified() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.VERIFIED, ProviderHelper.FIELD_TYPE_INTEGER); return (Integer) data; } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } - public boolean hasAnySecret() throws PgpGeneralException { + public boolean hasAnySecret() throws PgpKeyNotFoundException { try { Object data = mProviderHelper.getGenericData(mUri, KeychainContract.KeyRings.HAS_ANY_SECRET, ProviderHelper.FIELD_TYPE_INTEGER); return (Long) data > 0; } catch(ProviderHelper.NotFoundException e) { - throw new PgpGeneralException(e); + throw new PgpKeyNotFoundException(e); } } - private Cursor getSubkeys() throws PgpGeneralException { + private Cursor getSubkeys() throws PgpKeyNotFoundException { Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index b650147cf..b78ab8a37 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -31,6 +31,7 @@ import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.util.OpenPgpApi; import org.spongycastle.util.encoders.Hex; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.ui.NfcActivity; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; @@ -272,9 +273,16 @@ public class OpenPgpService extends RemoteService { InputData inputData = new InputData(is, inputLength); // Find the appropriate subkey to sign with - CachedPublicKeyRing signingRing = - new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId()); - final long sigSubKeyId = signingRing.getSecretSignId(); + long sigSubKeyId; + try { + CachedPublicKeyRing signingRing = + new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId()); + sigSubKeyId = signingRing.getSecretSignId(); + } catch (PgpKeyNotFoundException e) { + // secret key that is set for this account is deleted? + // show account config again! + return getCreateAccountIntent(data, getAccountName(data)); + } // get passphrase from cache, if key has "no" passphrase, this returns an empty String String passphrase; @@ -285,8 +293,7 @@ public class OpenPgpService extends RemoteService { passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), accSettings.getKeyId(), sigSubKeyId); } catch (PassphraseCacheService.KeyNotFoundException e) { - // secret key that is set for this account is deleted? - // show account config again! + // should happen earlier, but return again here if it happens return getCreateAccountIntent(data, getAccountName(data)); } } @@ -403,9 +410,16 @@ public class OpenPgpService extends RemoteService { if (sign) { // Find the appropriate subkey to sign with - CachedPublicKeyRing signingRing = - new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId()); - final long sigSubKeyId = signingRing.getSecretSignId(); + long sigSubKeyId; + try { + CachedPublicKeyRing signingRing = + new ProviderHelper(this).getCachedPublicKeyRing(accSettings.getKeyId()); + sigSubKeyId = signingRing.getSecretSignId(); + } catch (PgpKeyNotFoundException e) { + // secret key that is set for this account is deleted? + // show account config again! + return getCreateAccountIntent(data, getAccountName(data)); + } String passphrase; if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RemoteServiceActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RemoteServiceActivity.java index ed5e1f4cc..d7b723eb0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RemoteServiceActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RemoteServiceActivity.java @@ -31,7 +31,6 @@ import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; import android.view.View; import android.widget.TextView; -import android.widget.Toast; import org.openintents.openpgp.util.OpenPgpApi; import org.sufficientlysecure.keychain.Constants; @@ -42,6 +41,7 @@ import org.sufficientlysecure.keychain.remote.AccountSettings; import org.sufficientlysecure.keychain.remote.AppSettings; import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment; import org.sufficientlysecure.keychain.ui.util.ActionBarHelper; +import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; @@ -176,10 +176,9 @@ public class RemoteServiceActivity extends ActionBarActivity { public void onClick(View v) { // Save - // user needs to select a key! - if (mAccSettingsFragment.getAccSettings().getKeyId() == Constants.key.none) { - // TODO - Toast.makeText(RemoteServiceActivity.this, getString(R.string.api_register_error_select_key), Toast.LENGTH_LONG).show(); + // user needs to select a key if it has explicitly requested (None is only allowed for new accounts) + if (mUpdateExistingAccount && mAccSettingsFragment.getAccSettings().getKeyId() == Constants.key.none) { + Notify.showNotify(RemoteServiceActivity.this, getString(R.string.api_register_error_select_key), Notify.Style.ERROR); } else { if (mUpdateExistingAccount) { Uri baseUri = KeychainContract.ApiAccounts.buildBaseUri(packageName); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index b9c42db3f..90091ce35 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -30,6 +30,7 @@ import android.os.RemoteException; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.PgpCertifyOperation; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.service.results.CertifyResult; import org.sufficientlysecure.keychain.util.FileHelper; @@ -719,7 +720,7 @@ public class KeychainIntentService extends IntentService implements Progressable builder.setNfcState(nfcHash, nfcTimestamp); } - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { // encrypt-only // TODO Just silently drop the requested signature? Shouldn't we throw here? } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 9638fb7bf..97fb7e7b4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -39,11 +39,11 @@ import android.support.v4.util.LongSparseArray; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.util.Preferences; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; import org.sufficientlysecure.keychain.util.Log; import java.util.Date; @@ -239,9 +239,9 @@ public class PassphraseCacheService extends Service { case PASSPHRASE_EMPTY: return ""; case UNAVAILABLE: - throw new NotFoundException("secret key for this subkey is not available"); + throw new ProviderHelper.NotFoundException("secret key for this subkey is not available"); case GNU_DUMMY: - throw new NotFoundException("secret key for stripped subkey is not available"); + throw new ProviderHelper.NotFoundException("secret key for stripped subkey is not available"); } // get cached passphrase diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java index 57c2cac5c..dce86abd2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -40,6 +40,7 @@ import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.ui.util.ActionBarHelper; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; @@ -226,10 +227,10 @@ public class EditKeyFragment extends LoaderFragment implements mSaveKeyringParcel = new SaveKeyringParcel(masterKeyId, keyRing.getFingerprint()); mPrimaryUserId = keyRing.getPrimaryUserIdWithFallback(); - } catch (NotFoundException e) { + } catch (PgpKeyNotFoundException e) { finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND); return; - } catch (PgpGeneralException e) { + } catch (NotFoundException e) { finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND); return; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java index 54877f676..2d1b66daa 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java @@ -29,6 +29,7 @@ import com.tokenautocomplete.TokenCompleteTextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; @@ -139,7 +140,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi setSignatureKeyId(keyring.getMasterKeyId()); mSign.setSelectedKeyId(mEncryptInterface.getSignatureKey()); } - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } } @@ -151,7 +152,7 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(preselectedId)); mEncryptKeyView.addObject(mEncryptKeyView.new EncryptionKey(ring)); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java index ddfbac03c..34589c8e7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java @@ -45,6 +45,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; @@ -115,7 +116,7 @@ public class MultiCertifyKeyFragment extends LoaderFragment if (key.canCertify()) { mCertifyKeySpinner.setSelectedKeyId(certifyKeyId); } - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "certify certify check failed", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index 4bfca9e1d..b9761fbf3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -45,6 +45,7 @@ import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; @@ -151,11 +152,11 @@ public class PassphraseDialogActivity extends FragmentActivity { // the catch clause doesn't return. try { userId = mSecretRing.getPrimaryUserIdWithFallback(); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { userId = null; } - /* Get key type for message */ + /* Get key type for message */ // find a master key id for our key long masterKeyId = new ProviderHelper(activity).getMasterKeyId(mSubKeyId); CachedPublicKeyRing keyRing = new ProviderHelper(activity).getCachedPublicKeyRing(masterKeyId); @@ -312,7 +313,7 @@ public class PassphraseDialogActivity extends FragmentActivity { PassphraseCacheService.addCachedPassphrase(getActivity(), mSecretRing.getMasterKeyId(), mSubKeyId, passphrase, mSecretRing.getPrimaryUserIdWithFallback()); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "adding of a passphrase failed", e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index b0e641778..34c08a6c7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -38,6 +38,7 @@ import android.widget.TextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.pgp.WrappedSignature; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; @@ -185,7 +186,7 @@ public class ViewCertActivity extends ActionBarActivity KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); startActivity(viewIntent); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { // TODO notify user of this, maybe offer download? Log.e(Constants.TAG, "key not found!", e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java index 2d7bb07cf..7623f9a7b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyMainFragment.java @@ -36,6 +36,7 @@ import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract; @@ -308,7 +309,7 @@ public class ViewKeyMainFragment extends LoaderFragment implements } // used instead of startActivity set actionbar based on callingPackage startActivityForResult(intent, 0); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 43f869f02..8560bccc0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -48,6 +48,7 @@ import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; @@ -145,7 +146,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // the catch clause doesn't return. try { userId = mSecretRing.getPrimaryUserIdWithFallback(); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { userId = null; } @@ -308,7 +309,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor PassphraseCacheService.addCachedPassphrase(getActivity(), mSecretRing.getMasterKeyId(), mSubKeyId, passphrase, mSecretRing.getPrimaryUserIdWithFallback()); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "adding of a passphrase failed", e); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java index 08599333a..e03a14989 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/EncryptKeyCompletionView.java @@ -42,6 +42,7 @@ import com.tokenautocomplete.TokenCompleteTextView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.ContactHelper; import org.sufficientlysecure.keychain.pgp.KeyRing; @@ -198,7 +199,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView { } - public EncryptionKey(CachedPublicKeyRing ring) throws PgpGeneralException { + public EncryptionKey(CachedPublicKeyRing ring) throws PgpKeyNotFoundException { this(ring.getPrimaryUserId(), ring.extractOrGetMasterKeyId(), KeyFormattingUtils.convertFingerprintToHex(ring.getFingerprint())); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ExportHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ExportHelper.java index 3c100e272..649a74641 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ExportHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ExportHelper.java @@ -30,6 +30,7 @@ import android.widget.Toast; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; @@ -57,7 +58,7 @@ public class ExportHelper { DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, new long[]{ masterKeyId }); deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog"); - } catch (PgpGeneralException e) { + } catch (PgpKeyNotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } } diff --git a/OpenKeychain/src/main/res/layout/api_remote_create_account.xml b/OpenKeychain/src/main/res/layout/api_remote_create_account.xml index 3aee9094f..a6a39b1ad 100644 --- a/OpenKeychain/src/main/res/layout/api_remote_create_account.xml +++ b/OpenKeychain/src/main/res/layout/api_remote_create_account.xml @@ -1,29 +1,37 @@ <?xml version="1.0" encoding="utf-8"?> -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="match_parent" + android:orientation="vertical"> - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="16dp" - android:orientation="vertical"> + <include layout="@layout/notify_area" /> - <TextView - android:id="@+id/api_remote_create_account_text" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:paddingBottom="3dip" - android:text="@string/api_create_account_text" - android:textAppearance="?android:attr/textAppearanceMedium" /> + <ScrollView + android:layout_width="match_parent" + android:layout_height="wrap_content"> - <fragment - android:id="@+id/api_account_settings_fragment" - android:name="org.sufficientlysecure.keychain.remote.ui.AccountSettingsFragment" + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - tools:layout="@layout/api_app_settings_fragment" /> + android:padding="16dp" + android:orientation="vertical"> + + <TextView + android:id="@+id/api_remote_create_account_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingBottom="3dip" + android:text="@string/api_create_account_text" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + <fragment + android:id="@+id/api_account_settings_fragment" + android:name="org.sufficientlysecure.keychain.remote.ui.AccountSettingsFragment" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:layout="@layout/api_app_settings_fragment" /> - </LinearLayout> -</ScrollView> + </LinearLayout> + </ScrollView> +</LinearLayout>
\ No newline at end of file |