mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 04:22:18 -05:00
Use NotFoundException in more places
This commit is contained in:
parent
d81de8509b
commit
8ab9a0a2d0
@ -238,19 +238,19 @@ public class PgpDecryptVerify {
|
|||||||
|
|
||||||
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
|
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
|
||||||
|
|
||||||
// get master key id for this encryption key id
|
|
||||||
long masterKeyId = 0;
|
long masterKeyId = 0;
|
||||||
|
PGPSecretKeyRing secretKeyRing = null;
|
||||||
try {
|
try {
|
||||||
|
// get master key id for this encryption key id
|
||||||
masterKeyId = ProviderHelper.getMasterKeyId(mContext,
|
masterKeyId = ProviderHelper.getMasterKeyId(mContext,
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(encData.getKeyID()))
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(encData.getKeyID()))
|
||||||
);
|
);
|
||||||
|
// get actual keyring object based on master key id
|
||||||
|
secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, masterKeyId);
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Log.e(Constants.TAG, "key not found!", e);
|
|
||||||
// continue with the next packet in the while loop
|
// continue with the next packet in the while loop
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// get actual keyring object based on master key id
|
|
||||||
PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, masterKeyId);
|
|
||||||
if (secretKeyRing == null) {
|
if (secretKeyRing == null) {
|
||||||
// continue with the next packet in the while loop
|
// continue with the next packet in the while loop
|
||||||
continue;
|
continue;
|
||||||
@ -390,8 +390,14 @@ public class PgpDecryptVerify {
|
|||||||
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
PGPOnePassSignatureList sigList = (PGPOnePassSignatureList) dataChunk;
|
||||||
for (int i = 0; i < sigList.size(); ++i) {
|
for (int i = 0; i < sigList.size(); ++i) {
|
||||||
signature = sigList.get(i);
|
signature = sigList.get(i);
|
||||||
signatureKey = ProviderHelper
|
|
||||||
.getPGPPublicKeyRingWithKeyId(mContext, signature.getKeyID()).getPublicKey();
|
// TODO: rework this code, seems wonky!
|
||||||
|
try {
|
||||||
|
signatureKey = ProviderHelper
|
||||||
|
.getPGPPublicKeyRingWithKeyId(mContext, signature.getKeyID()).getPublicKey();
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.d(Constants.TAG, "key not found!");
|
||||||
|
}
|
||||||
if (signatureKeyId == 0) {
|
if (signatureKeyId == 0) {
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
}
|
}
|
||||||
@ -401,10 +407,12 @@ public class PgpDecryptVerify {
|
|||||||
signatureIndex = i;
|
signatureIndex = i;
|
||||||
signatureKeyId = signature.getKeyID();
|
signatureKeyId = signature.getKeyID();
|
||||||
String userId = null;
|
String userId = null;
|
||||||
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(
|
try {
|
||||||
mContext, signatureKeyId);
|
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(
|
||||||
if (signKeyRing != null) {
|
mContext, signatureKeyId);
|
||||||
userId = PgpKeyHelper.getMainUserId(signKeyRing.getPublicKey());
|
userId = PgpKeyHelper.getMainUserId(signKeyRing.getPublicKey());
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.d(Constants.TAG, "key not found!");
|
||||||
}
|
}
|
||||||
signatureResult.setUserId(userId);
|
signatureResult.setUserId(userId);
|
||||||
break;
|
break;
|
||||||
@ -598,7 +606,11 @@ public class PgpDecryptVerify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this one can't fail now (yay database constraints)
|
// this one can't fail now (yay database constraints)
|
||||||
signatureKey = ProviderHelper.getPGPPublicKeyRing(mContext, (Long) data.get(KeyRings.MASTER_KEY_ID)).getPublicKey();
|
try {
|
||||||
|
signatureKey = ProviderHelper.getPGPPublicKeyRing(mContext, (Long) data.get(KeyRings.MASTER_KEY_ID)).getPublicKey();
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
signatureResult.setUserId((String) data.get(KeyRings.USER_ID));
|
signatureResult.setUserId((String) data.get(KeyRings.USER_ID));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -664,11 +676,13 @@ public class PgpDecryptVerify {
|
|||||||
long signatureKeyId = signature.getKeyID();
|
long signatureKeyId = signature.getKeyID();
|
||||||
boolean validKeyBinding = false;
|
boolean validKeyBinding = false;
|
||||||
|
|
||||||
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(context,
|
|
||||||
signatureKeyId);
|
|
||||||
PGPPublicKey mKey = null;
|
PGPPublicKey mKey = null;
|
||||||
if (signKeyRing != null) {
|
try {
|
||||||
|
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingWithKeyId(context,
|
||||||
|
signatureKeyId);
|
||||||
mKey = signKeyRing.getPublicKey();
|
mKey = signKeyRing.getPublicKey();
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.d(Constants.TAG, "key not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signature.getKeyID() != mKey.getKeyID()) {
|
if (signature.getKeyID() != mKey.getKeyID()) {
|
||||||
|
@ -194,11 +194,14 @@ public class PgpImportExport {
|
|||||||
arOutStream.setHeader("Version", PgpHelper.getFullVersion(mContext));
|
arOutStream.setHeader("Version", PgpHelper.getFullVersion(mContext));
|
||||||
|
|
||||||
updateProgress(progress * 100 / masterKeyIdsSize, 100);
|
updateProgress(progress * 100 / masterKeyIdsSize, 100);
|
||||||
PGPPublicKeyRing publicKeyRing =
|
|
||||||
ProviderHelper.getPGPPublicKeyRing(mContext, pubKeyMasterId);
|
|
||||||
|
|
||||||
if (publicKeyRing != null) {
|
try {
|
||||||
|
PGPPublicKeyRing publicKeyRing = ProviderHelper.getPGPPublicKeyRing(mContext, pubKeyMasterId);
|
||||||
|
|
||||||
publicKeyRing.encode(arOutStream);
|
publicKeyRing.encode(arOutStream);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
// TODO: inform user?
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mKeychainServiceListener.hasServiceStopped()) {
|
if (mKeychainServiceListener.hasServiceStopped()) {
|
||||||
@ -217,12 +220,15 @@ public class PgpImportExport {
|
|||||||
arOutStream.setHeader("Version", PgpHelper.getFullVersion(mContext));
|
arOutStream.setHeader("Version", PgpHelper.getFullVersion(mContext));
|
||||||
|
|
||||||
updateProgress(progress * 100 / masterKeyIdsSize, 100);
|
updateProgress(progress * 100 / masterKeyIdsSize, 100);
|
||||||
PGPSecretKeyRing secretKeyRing =
|
|
||||||
ProviderHelper.getPGPSecretKeyRing(mContext, secretKeyMasterId);
|
|
||||||
|
|
||||||
if (secretKeyRing != null) {
|
try {
|
||||||
|
PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, secretKeyMasterId);
|
||||||
secretKeyRing.encode(arOutStream);
|
secretKeyRing.encode(arOutStream);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
// TODO: inform user?
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mKeychainServiceListener.hasServiceStopped()) {
|
if (mKeychainServiceListener.hasServiceStopped()) {
|
||||||
arOutStream.close();
|
arOutStream.close();
|
||||||
return null;
|
return null;
|
||||||
|
@ -201,9 +201,12 @@ public class PgpKeyHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PGPPublicKey getEncryptPublicKey(Context context, long masterKeyId) {
|
public static PGPPublicKey getEncryptPublicKey(Context context, long masterKeyId) {
|
||||||
PGPPublicKeyRing keyRing = ProviderHelper.getPGPPublicKeyRing(context, masterKeyId);
|
PGPPublicKeyRing keyRing = null;
|
||||||
if (keyRing == null) {
|
try {
|
||||||
Log.e(Constants.TAG, "keyRing is null!");
|
keyRing = ProviderHelper.getPGPPublicKeyRing(context, masterKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
// TODO: throw exception here!
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Vector<PGPPublicKey> encryptKeys = getUsableEncryptKeys(keyRing);
|
Vector<PGPPublicKey> encryptKeys = getUsableEncryptKeys(keyRing);
|
||||||
@ -215,8 +218,12 @@ public class PgpKeyHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PGPSecretKey getCertificationKey(Context context, long masterKeyId) {
|
public static PGPSecretKey getCertificationKey(Context context, long masterKeyId) {
|
||||||
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
PGPSecretKeyRing keyRing = null;
|
||||||
if (keyRing == null) {
|
try {
|
||||||
|
keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
// TODO: throw exception here!
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Vector<PGPSecretKey> signingKeys = getUsableCertificationKeys(keyRing);
|
Vector<PGPSecretKey> signingKeys = getUsableCertificationKeys(keyRing);
|
||||||
@ -227,8 +234,12 @@ public class PgpKeyHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PGPSecretKey getSigningKey(Context context, long masterKeyId) {
|
public static PGPSecretKey getSigningKey(Context context, long masterKeyId) {
|
||||||
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
PGPSecretKeyRing keyRing = null;
|
||||||
if (keyRing == null) {
|
try {
|
||||||
|
keyRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
// TODO: throw exception here!
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Vector<PGPSecretKey> signingKeys = getUsableSigningKeys(keyRing);
|
Vector<PGPSecretKey> signingKeys = getUsableSigningKeys(keyRing);
|
||||||
|
@ -235,7 +235,11 @@ public class PgpSignEncrypt {
|
|||||||
PGPSecretKeyRing signingKeyRing = null;
|
PGPSecretKeyRing signingKeyRing = null;
|
||||||
PGPPrivateKey signaturePrivateKey = null;
|
PGPPrivateKey signaturePrivateKey = null;
|
||||||
if (enableSignature) {
|
if (enableSignature) {
|
||||||
signingKeyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId);
|
try {
|
||||||
|
signingKeyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
||||||
|
}
|
||||||
signingKey = PgpKeyHelper.getSigningKey(mContext, mSignatureKeyId);
|
signingKey = PgpKeyHelper.getSigningKey(mContext, mSignatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
||||||
@ -464,8 +468,12 @@ public class PgpSignEncrypt {
|
|||||||
throw new PgpGeneralException(mContext.getString(R.string.error_no_signature_key));
|
throw new PgpGeneralException(mContext.getString(R.string.error_no_signature_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
PGPSecretKeyRing signingKeyRing =
|
PGPSecretKeyRing signingKeyRing;
|
||||||
ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId);
|
try {
|
||||||
|
signingKeyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(mContext, mSignatureKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
||||||
|
}
|
||||||
PGPSecretKey signingKey = PgpKeyHelper.getSigningKey(mContext, mSignatureKeyId);
|
PGPSecretKey signingKey = PgpKeyHelper.getSigningKey(mContext, mSignatureKeyId);
|
||||||
if (signingKey == null) {
|
if (signingKey == null) {
|
||||||
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
throw new PgpGeneralException(mContext.getString(R.string.error_signature_failed));
|
||||||
|
@ -159,39 +159,35 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) {
|
|
||||||
|
public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) throws NotFoundException {
|
||||||
Map<Long, PGPKeyRing> result = getPGPKeyRings(context, queryUri);
|
Map<Long, PGPKeyRing> result = getPGPKeyRings(context, queryUri);
|
||||||
if(result.isEmpty())
|
if(result.isEmpty()) {
|
||||||
return null;
|
throw new NotFoundException("PGPKeyRing object not found!");
|
||||||
return result.values().iterator().next();
|
} else {
|
||||||
|
return result.values().iterator().next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PGPPublicKeyRing getPGPPublicKeyRingWithKeyId(Context context, long keyId) {
|
public static PGPPublicKeyRing getPGPPublicKeyRingWithKeyId(Context context, long keyId)
|
||||||
|
throws NotFoundException {
|
||||||
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
||||||
long masterKeyId;
|
long masterKeyId = getMasterKeyId(context, uri);
|
||||||
try {
|
return getPGPPublicKeyRing(context, masterKeyId);
|
||||||
masterKeyId = getMasterKeyId(context, uri);
|
|
||||||
return getPGPPublicKeyRing(context, masterKeyId);
|
|
||||||
} catch (NotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public static PGPSecretKeyRing getPGPSecretKeyRingWithKeyId(Context context, long keyId) {
|
|
||||||
|
public static PGPSecretKeyRing getPGPSecretKeyRingWithKeyId(Context context, long keyId)
|
||||||
|
throws NotFoundException {
|
||||||
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
||||||
long masterKeyId;
|
long masterKeyId = getMasterKeyId(context, uri);
|
||||||
try {
|
return getPGPSecretKeyRing(context, masterKeyId);
|
||||||
masterKeyId = getMasterKeyId(context, uri);
|
|
||||||
return getPGPSecretKeyRing(context, masterKeyId);
|
|
||||||
} catch (NotFoundException notFound) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the actual PGPPublicKeyRing object from the database blob based on the masterKeyId
|
* Retrieves the actual PGPPublicKeyRing object from the database blob based on the masterKeyId
|
||||||
*/
|
*/
|
||||||
public static PGPPublicKeyRing getPGPPublicKeyRing(Context context,
|
public static PGPPublicKeyRing getPGPPublicKeyRing(Context context,
|
||||||
long masterKeyId) {
|
long masterKeyId) throws NotFoundException {
|
||||||
Uri queryUri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId));
|
Uri queryUri = KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId));
|
||||||
return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
|
return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
|
||||||
}
|
}
|
||||||
@ -200,7 +196,7 @@ public class ProviderHelper {
|
|||||||
* Retrieves the actual PGPSecretKeyRing object from the database blob based on the maserKeyId
|
* Retrieves the actual PGPSecretKeyRing object from the database blob based on the maserKeyId
|
||||||
*/
|
*/
|
||||||
public static PGPSecretKeyRing getPGPSecretKeyRing(Context context,
|
public static PGPSecretKeyRing getPGPSecretKeyRing(Context context,
|
||||||
long masterKeyId) {
|
long masterKeyId) throws NotFoundException {
|
||||||
Uri queryUri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId));
|
Uri queryUri = KeyRingData.buildSecretKeyRingUri(Long.toString(masterKeyId));
|
||||||
return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
|
return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
|
||||||
}
|
}
|
||||||
@ -214,7 +210,12 @@ public class ProviderHelper {
|
|||||||
long masterKeyId = masterKey.getKeyID();
|
long masterKeyId = masterKey.getKeyID();
|
||||||
|
|
||||||
// IF there is a secret key, preserve it!
|
// IF there is a secret key, preserve it!
|
||||||
PGPSecretKeyRing secretRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
PGPSecretKeyRing secretRing = null;
|
||||||
|
try {
|
||||||
|
secretRing = ProviderHelper.getPGPSecretKeyRing(context, masterKeyId);
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!");
|
||||||
|
}
|
||||||
|
|
||||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||||
try {
|
try {
|
||||||
|
@ -33,7 +33,6 @@ import android.os.Message;
|
|||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.support.v4.util.LongSparseArray;
|
import android.support.v4.util.LongSparseArray;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.spongycastle.openpgp.PGPException;
|
import org.spongycastle.openpgp.PGPException;
|
||||||
import org.spongycastle.openpgp.PGPPrivateKey;
|
import org.spongycastle.openpgp.PGPPrivateKey;
|
||||||
@ -48,6 +47,7 @@ import org.sufficientlysecure.keychain.helper.Preferences;
|
|||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -231,6 +231,8 @@ public class PassphraseCacheService extends Service {
|
|||||||
}
|
}
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
// silently catch
|
// silently catch
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -224,8 +224,9 @@ public class CertifyKeyActivity extends ActionBarActivity implements
|
|||||||
* handles the UI bits of the signing process on the UI thread
|
* handles the UI bits of the signing process on the UI thread
|
||||||
*/
|
*/
|
||||||
private void initiateSigning() {
|
private void initiateSigning() {
|
||||||
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRing(this, mPubKeyId);
|
try {
|
||||||
if (pubring != null) {
|
PGPPublicKeyRing pubring = ProviderHelper.getPGPPublicKeyRing(this, mPubKeyId);
|
||||||
|
|
||||||
// if we have already signed this key, dont bother doing it again
|
// if we have already signed this key, dont bother doing it again
|
||||||
boolean alreadySigned = false;
|
boolean alreadySigned = false;
|
||||||
|
|
||||||
@ -248,14 +249,14 @@ public class CertifyKeyActivity extends ActionBarActivity implements
|
|||||||
String passphrase = PassphraseCacheService.getCachedPassphrase(this, mMasterKeyId);
|
String passphrase = PassphraseCacheService.getCachedPassphrase(this, mMasterKeyId);
|
||||||
if (passphrase == null) {
|
if (passphrase == null) {
|
||||||
PassphraseDialogFragment.show(this, mMasterKeyId,
|
PassphraseDialogFragment.show(this, mMasterKeyId,
|
||||||
new Handler() {
|
new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
|
||||||
startSigning();
|
startSigning();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
// bail out; need to wait until the user has entered the passphrase before trying again
|
// bail out; need to wait until the user has entered the passphrase before trying again
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -268,6 +269,8 @@ public class CertifyKeyActivity extends ActionBarActivity implements
|
|||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,15 +300,16 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
private void finallyEdit(final long masterKeyId) {
|
private void finallyEdit(final long masterKeyId) {
|
||||||
if (masterKeyId != 0) {
|
if (masterKeyId != 0) {
|
||||||
PGPSecretKey masterKey = null;
|
PGPSecretKey masterKey = null;
|
||||||
mKeyRing = ProviderHelper.getPGPSecretKeyRing(this, masterKeyId);
|
try {
|
||||||
if (mKeyRing != null) {
|
mKeyRing = ProviderHelper.getPGPSecretKeyRing(this, masterKeyId);
|
||||||
|
|
||||||
masterKey = mKeyRing.getSecretKey();
|
masterKey = mKeyRing.getSecretKey();
|
||||||
mMasterCanSign = PgpKeyHelper.isCertificationKey(mKeyRing.getSecretKey());
|
mMasterCanSign = PgpKeyHelper.isCertificationKey(mKeyRing.getSecretKey());
|
||||||
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
|
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
|
||||||
mKeys.add(key);
|
mKeys.add(key);
|
||||||
mKeysUsages.add(-1); // get usage when view is created
|
mKeysUsages.add(-1); // get usage when view is created
|
||||||
}
|
}
|
||||||
} else {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Log.e(Constants.TAG, "Keyring not found with masterKeyId: " + masterKeyId);
|
Log.e(Constants.TAG, "Keyring not found with masterKeyId: " + masterKeyId);
|
||||||
AppMsg.makeText(this, R.string.error_no_secret_key_found, AppMsg.STYLE_ALERT).show();
|
AppMsg.makeText(this, R.string.error_no_secret_key_found, AppMsg.STYLE_ALERT).show();
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -146,17 +146,19 @@ public class EncryptAsymmetricFragment extends Fragment {
|
|||||||
private void preselectKeys(long preselectedSignatureKeyId, long[] preselectedEncryptionKeyIds) {
|
private void preselectKeys(long preselectedSignatureKeyId, long[] preselectedEncryptionKeyIds) {
|
||||||
if (preselectedSignatureKeyId != 0) {
|
if (preselectedSignatureKeyId != 0) {
|
||||||
// TODO: don't use bouncy castle objects!
|
// TODO: don't use bouncy castle objects!
|
||||||
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(getActivity(),
|
try {
|
||||||
preselectedSignatureKeyId);
|
PGPSecretKeyRing keyRing = ProviderHelper.getPGPSecretKeyRingWithKeyId(getActivity(),
|
||||||
PGPSecretKey masterKey;
|
preselectedSignatureKeyId);
|
||||||
if (keyRing != null) {
|
|
||||||
masterKey = keyRing.getSecretKey();
|
PGPSecretKey masterKey = keyRing.getSecretKey();
|
||||||
if (masterKey != null) {
|
if (masterKey != null) {
|
||||||
Vector<PGPSecretKey> signKeys = PgpKeyHelper.getUsableSigningKeys(keyRing);
|
Vector<PGPSecretKey> signKeys = PgpKeyHelper.getUsableSigningKeys(keyRing);
|
||||||
if (signKeys.size() > 0) {
|
if (signKeys.size() > 0) {
|
||||||
setSignatureKeyId(masterKey.getKeyID());
|
setSignatureKeyId(masterKey.getKeyID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +145,14 @@ public class ViewCertActivity extends ActionBarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
PGPSignature sig = PgpConversionHelper.BytesToPGPSignature(data.getBlob(INDEX_DATA));
|
PGPSignature sig = PgpConversionHelper.BytesToPGPSignature(data.getBlob(INDEX_DATA));
|
||||||
PGPKeyRing signeeRing = ProviderHelper.getPGPKeyRing(this,
|
try {
|
||||||
KeychainContract.KeyRingData.buildPublicKeyRingUri(
|
PGPKeyRing signeeRing = ProviderHelper.getPGPKeyRing(this,
|
||||||
Long.toString(data.getLong(INDEX_MASTER_KEY_ID))));
|
KeychainContract.KeyRingData.buildPublicKeyRingUri(
|
||||||
PGPKeyRing signerRing = ProviderHelper.getPGPKeyRing(this,
|
Long.toString(data.getLong(INDEX_MASTER_KEY_ID))));
|
||||||
KeychainContract.KeyRingData.buildPublicKeyRingUri(
|
PGPKeyRing signerRing = ProviderHelper.getPGPKeyRing(this,
|
||||||
Long.toString(sig.getKeyID())));
|
KeychainContract.KeyRingData.buildPublicKeyRingUri(
|
||||||
|
Long.toString(sig.getKeyID())));
|
||||||
|
|
||||||
if (signerRing != null) {
|
|
||||||
try {
|
try {
|
||||||
sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider(
|
sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider(
|
||||||
Constants.BOUNCY_CASTLE_PROVIDER_NAME), signeeRing.getPublicKey());
|
Constants.BOUNCY_CASTLE_PROVIDER_NAME), signeeRing.getPublicKey());
|
||||||
@ -170,7 +170,7 @@ public class ViewCertActivity extends ActionBarActivity
|
|||||||
mStatus.setText("error!");
|
mStatus.setText("error!");
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
||||||
}
|
}
|
||||||
} else {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
mStatus.setText("key unavailable");
|
mStatus.setText("key unavailable");
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.black));
|
mStatus.setTextColor(getResources().getColor(R.color.black));
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,9 @@ public class ViewKeyActivityJB extends ViewKeyActivity implements CreateNdefMess
|
|||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
Log.e(Constants.TAG, "Error parsing keyring", e);
|
Log.e(Constants.TAG, "Error parsing keyring", e);
|
||||||
return null;
|
return null;
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,9 +139,9 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
secretKey = null;
|
secretKey = null;
|
||||||
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
alert.setMessage(R.string.passphrase_for_symmetric_encryption);
|
||||||
} else {
|
} else {
|
||||||
secretKey = ProviderHelper.getPGPSecretKeyRing(activity, secretKeyId).getSecretKey();
|
try {
|
||||||
|
secretKey = ProviderHelper.getPGPSecretKeyRing(activity, secretKeyId).getSecretKey();
|
||||||
if (secretKey == null) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
alert.setTitle(R.string.title_key_not_found);
|
alert.setTitle(R.string.title_key_not_found);
|
||||||
alert.setMessage(getString(R.string.key_not_found, secretKeyId));
|
alert.setMessage(getString(R.string.key_not_found, secretKeyId));
|
||||||
alert.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
alert.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||||
@ -153,6 +153,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
mCanKB = false;
|
mCanKB = false;
|
||||||
return alert.create();
|
return alert.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
String userId = PgpKeyHelper.getMainUserIdSafe(activity, secretKey);
|
String userId = PgpKeyHelper.getMainUserIdSafe(activity, secretKey);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "User id: '" + userId + "'");
|
Log.d(Constants.TAG, "User id: '" + userId + "'");
|
||||||
@ -194,9 +195,13 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
sendMessageToHandler(MESSAGE_CANCEL);
|
sendMessageToHandler(MESSAGE_CANCEL);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
clickSecretKey = PgpKeyHelper.getKeyNum(ProviderHelper
|
try {
|
||||||
.getPGPSecretKeyRingWithKeyId(activity, secretKeyId),
|
clickSecretKey = PgpKeyHelper.getKeyNum(ProviderHelper
|
||||||
curKeyIndex);
|
.getPGPSecretKeyRingWithKeyId(activity, secretKeyId),
|
||||||
|
curKeyIndex);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
curKeyIndex++; // does post-increment work like C?
|
curKeyIndex++; // does post-increment work like C?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user