mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
Introduce ProviderHelper.NotFoundException, remove dead code
This commit is contained in:
parent
946c1e115c
commit
a1efb24228
@ -50,13 +50,17 @@ public class ExportHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deleteKey(Uri dataUri, Handler deleteHandler) {
|
public void deleteKey(Uri dataUri, Handler deleteHandler) {
|
||||||
// Create a new Messenger for the communication back
|
try {
|
||||||
Messenger messenger = new Messenger(deleteHandler);
|
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(mActivity, dataUri);
|
long masterKeyId = ProviderHelper.getMasterKeyId(mActivity, dataUri);
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(deleteHandler);
|
||||||
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
||||||
new long[]{ masterKeyId });
|
new long[]{ masterKeyId });
|
||||||
deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
|
deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,6 +54,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactory
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
@ -235,10 +236,19 @@ public class PgpDecryptVerify {
|
|||||||
updateProgress(R.string.progress_finding_key, currentProgress, 100);
|
updateProgress(R.string.progress_finding_key, currentProgress, 100);
|
||||||
|
|
||||||
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
|
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(mContext,
|
|
||||||
|
// get master key id for this encryption key id
|
||||||
|
long masterKeyId = 0;
|
||||||
|
try {
|
||||||
|
masterKeyId = ProviderHelper.getMasterKeyId(mContext,
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(encData.getKeyID()))
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(encData.getKeyID()))
|
||||||
);
|
);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
|
// get actual keyring object based on master key id
|
||||||
PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, masterKeyId);
|
PGPSecretKeyRing secretKeyRing = ProviderHelper.getPGPSecretKeyRing(mContext, masterKeyId);
|
||||||
|
|
||||||
if (secretKeyRing == null) {
|
if (secretKeyRing == null) {
|
||||||
throw new PgpGeneralException(mContext.getString(R.string.error_no_secret_key_found));
|
throw new PgpGeneralException(mContext.getString(R.string.error_no_secret_key_found));
|
||||||
}
|
}
|
||||||
|
@ -24,17 +24,12 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||||||
|
|
||||||
import org.spongycastle.openpgp.PGPEncryptedDataList;
|
import org.spongycastle.openpgp.PGPEncryptedDataList;
|
||||||
import org.spongycastle.openpgp.PGPObjectFactory;
|
import org.spongycastle.openpgp.PGPObjectFactory;
|
||||||
import org.spongycastle.openpgp.PGPPublicKeyEncryptedData;
|
|
||||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
|
||||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPUtil;
|
import org.spongycastle.openpgp.PGPUtil;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.NoAsymmetricEncryptionException;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
||||||
|
|
||||||
@ -43,7 +38,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class PgpHelper {
|
public class PgpHelper {
|
||||||
@ -76,52 +70,6 @@ public class PgpHelper {
|
|||||||
return "OpenPGP Keychain v" + getVersion(context);
|
return "OpenPGP Keychain v" + getVersion(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getDecryptionKeyId(Context context, InputStream inputStream)
|
|
||||||
throws PgpGeneralException, NoAsymmetricEncryptionException, IOException {
|
|
||||||
InputStream in = PGPUtil.getDecoderStream(inputStream);
|
|
||||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
|
||||||
PGPEncryptedDataList enc;
|
|
||||||
Object o = pgpF.nextObject();
|
|
||||||
|
|
||||||
// the first object might be a PGP marker packet.
|
|
||||||
if (o instanceof PGPEncryptedDataList) {
|
|
||||||
enc = (PGPEncryptedDataList) o;
|
|
||||||
} else {
|
|
||||||
enc = (PGPEncryptedDataList) pgpF.nextObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enc == null) {
|
|
||||||
throw new PgpGeneralException(context.getString(R.string.error_invalid_data));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: currently we always only look at the first known key
|
|
||||||
// find the secret key
|
|
||||||
PGPSecretKey secretKey = null;
|
|
||||||
Iterator<?> it = enc.getEncryptedDataObjects();
|
|
||||||
boolean gotAsymmetricEncryption = false;
|
|
||||||
while (it.hasNext()) {
|
|
||||||
Object obj = it.next();
|
|
||||||
if (obj instanceof PGPPublicKeyEncryptedData) {
|
|
||||||
gotAsymmetricEncryption = true;
|
|
||||||
PGPPublicKeyEncryptedData pbe = (PGPPublicKeyEncryptedData) obj;
|
|
||||||
secretKey = ProviderHelper.getPGPSecretKeyRing(context, pbe.getKeyID()).getSecretKey();
|
|
||||||
if (secretKey != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gotAsymmetricEncryption) {
|
|
||||||
throw new NoAsymmetricEncryptionException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (secretKey == null) {
|
|
||||||
return Id.key.none;
|
|
||||||
}
|
|
||||||
|
|
||||||
return secretKey.getKeyID();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getStreamContent(Context context, InputStream inStream) throws IOException {
|
public static int getStreamContent(Context context, InputStream inStream) throws IOException {
|
||||||
InputStream in = PGPUtil.getDecoderStream(inStream);
|
InputStream in = PGPUtil.getDecoderStream(inStream);
|
||||||
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
PGPObjectFactory pgpF = new PGPObjectFactory(in);
|
||||||
|
@ -64,6 +64,15 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class ProviderHelper {
|
public class ProviderHelper {
|
||||||
|
|
||||||
|
public static class NotFoundException extends Exception {
|
||||||
|
public NotFoundException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotFoundException(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we ever switch to api level 11, we can ditch this whole mess!
|
// If we ever switch to api level 11, we can ditch this whole mess!
|
||||||
public static final int FIELD_TYPE_NULL = 1;
|
public static final int FIELD_TYPE_NULL = 1;
|
||||||
// this is called integer to stay coherent with the constants in Cursor (api level 11)
|
// this is called integer to stay coherent with the constants in Cursor (api level 11)
|
||||||
@ -113,7 +122,7 @@ public class ProviderHelper {
|
|||||||
* Find the master key id related to a given query. The id will either be extracted from the
|
* 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.
|
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
||||||
*/
|
*/
|
||||||
public static long getMasterKeyId(Context context, Uri queryUri) {
|
public static long getMasterKeyId(Context context, Uri queryUri) throws NotFoundException {
|
||||||
// try extracting from the uri first
|
// try extracting from the uri first
|
||||||
String firstSegment = queryUri.getPathSegments().get(1);
|
String firstSegment = queryUri.getPathSegments().get(1);
|
||||||
if(!firstSegment.equals("find")) try {
|
if(!firstSegment.equals("find")) try {
|
||||||
@ -123,10 +132,11 @@ public class ProviderHelper {
|
|||||||
Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
|
Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
|
||||||
}
|
}
|
||||||
Object data = getGenericData(context, queryUri, KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
|
Object data = getGenericData(context, queryUri, KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
|
||||||
if(data != null)
|
if(data != null) {
|
||||||
return (Long) data;
|
return (Long) data;
|
||||||
// TODO better error handling?
|
} else {
|
||||||
return 0L;
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<Long, PGPKeyRing> getPGPKeyRings(Context context, Uri queryUri) {
|
public static Map<Long, PGPKeyRing> getPGPKeyRings(Context context, Uri queryUri) {
|
||||||
@ -158,18 +168,24 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
public static PGPPublicKeyRing getPGPPublicKeyRingWithKeyId(Context context, long keyId) {
|
public static PGPPublicKeyRing getPGPPublicKeyRingWithKeyId(Context context, long keyId) {
|
||||||
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
||||||
long masterKeyId = getMasterKeyId(context, uri);
|
long masterKeyId;
|
||||||
if(masterKeyId != 0)
|
try {
|
||||||
|
masterKeyId = getMasterKeyId(context, uri);
|
||||||
return getPGPPublicKeyRing(context, masterKeyId);
|
return getPGPPublicKeyRing(context, masterKeyId);
|
||||||
|
} catch (NotFoundException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static PGPSecretKeyRing getPGPSecretKeyRingWithKeyId(Context context, long keyId) {
|
public static PGPSecretKeyRing getPGPSecretKeyRingWithKeyId(Context context, long keyId) {
|
||||||
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
Uri uri = KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId));
|
||||||
long masterKeyId = getMasterKeyId(context, uri);
|
long masterKeyId;
|
||||||
if(masterKeyId != 0)
|
try {
|
||||||
|
masterKeyId = getMasterKeyId(context, uri);
|
||||||
return getPGPSecretKeyRing(context, masterKeyId);
|
return getPGPSecretKeyRing(context, masterKeyId);
|
||||||
|
} catch (NotFoundException notFound) {
|
||||||
return null;
|
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
|
||||||
|
@ -32,6 +32,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
@ -40,6 +41,7 @@ import org.sufficientlysecure.keychain.ui.EditKeyActivity;
|
|||||||
import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment;
|
import org.sufficientlysecure.keychain.ui.SelectSecretKeyLayoutFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.KeyValueSpinnerAdapter;
|
||||||
import org.sufficientlysecure.keychain.util.AlgorithmNames;
|
import org.sufficientlysecure.keychain.util.AlgorithmNames;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class AccountSettingsFragment extends Fragment implements
|
public class AccountSettingsFragment extends Fragment implements
|
||||||
SelectSecretKeyLayoutFragment.SelectSecretKeyCallback {
|
SelectSecretKeyLayoutFragment.SelectSecretKeyCallback {
|
||||||
@ -177,8 +179,12 @@ public class AccountSettingsFragment extends Fragment implements
|
|||||||
case REQUEST_CODE_CREATE_KEY: {
|
case REQUEST_CODE_CREATE_KEY: {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
// select newly created key
|
// select newly created key
|
||||||
|
try {
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), data.getData());
|
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), data.getData());
|
||||||
mSelectKeyFragment.selectKey(masterKeyId);
|
mSelectKeyFragment.selectKey(masterKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -171,12 +171,13 @@ public class PassphraseCacheService extends Service {
|
|||||||
// try to get master key id which is used as an identifier for cached passphrases
|
// try to get master key id which is used as an identifier for cached passphrases
|
||||||
long masterKeyId = keyId;
|
long masterKeyId = keyId;
|
||||||
if (masterKeyId != Id.key.symmetric) {
|
if (masterKeyId != Id.key.symmetric) {
|
||||||
|
try {
|
||||||
masterKeyId = ProviderHelper.getMasterKeyId(this,
|
masterKeyId = ProviderHelper.getMasterKeyId(this,
|
||||||
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId)));
|
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId)));
|
||||||
// Failure
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
if(masterKeyId == 0)
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Log.d(TAG, "getCachedPassphraseImpl() for masterKeyId " + masterKeyId);
|
Log.d(TAG, "getCachedPassphraseImpl() for masterKeyId " + masterKeyId);
|
||||||
|
|
||||||
// get cached passphrase
|
// get cached passphrase
|
||||||
|
@ -286,9 +286,13 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG, "uri: " + mDataUri);
|
Log.d(Constants.TAG, "uri: " + mDataUri);
|
||||||
|
|
||||||
|
try {
|
||||||
// get master key id using row id
|
// get master key id using row id
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||||
finallyEdit(masterKeyId);
|
finallyEdit(masterKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,11 +34,14 @@ import org.spongycastle.openpgp.PGPPublicKey;
|
|||||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||||
import org.spongycastle.openpgp.PGPSecretKey;
|
import org.spongycastle.openpgp.PGPSecretKey;
|
||||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@ -160,11 +163,15 @@ public class EncryptAsymmetricFragment extends Fragment {
|
|||||||
if (preselectedEncryptionKeyIds != null) {
|
if (preselectedEncryptionKeyIds != null) {
|
||||||
Vector<Long> goodIds = new Vector<Long>();
|
Vector<Long> goodIds = new Vector<Long>();
|
||||||
for (int i = 0; i < preselectedEncryptionKeyIds.length; ++i) {
|
for (int i = 0; i < preselectedEncryptionKeyIds.length; ++i) {
|
||||||
|
// TODO check for available encrypt keys... is this even relevant?
|
||||||
|
try {
|
||||||
long id = ProviderHelper.getMasterKeyId(getActivity(),
|
long id = ProviderHelper.getMasterKeyId(getActivity(),
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
|
||||||
);
|
);
|
||||||
// TODO check for available encrypt keys... is this even relevant?
|
|
||||||
goodIds.add(id);
|
goodIds.add(id);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (goodIds.size() > 0) {
|
if (goodIds.size() > 0) {
|
||||||
long[] keyIds = new long[goodIds.size()];
|
long[] keyIds = new long[goodIds.size()];
|
||||||
|
@ -234,17 +234,20 @@ public class ViewCertActivity extends ActionBarActivity
|
|||||||
} else {
|
} else {
|
||||||
viewIntent = new Intent(this, ViewKeyActivityJB.class);
|
viewIntent = new Intent(this, ViewKeyActivityJB.class);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
|
try {
|
||||||
long signerMasterKeyId = ProviderHelper.getMasterKeyId(this,
|
long signerMasterKeyId = ProviderHelper.getMasterKeyId(this,
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mSignerKeyId))
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mSignerKeyId))
|
||||||
);
|
);
|
||||||
// TODO notify user of this, maybe offer download?
|
|
||||||
if (mSignerKeyId == 0L)
|
|
||||||
return true;
|
|
||||||
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
|
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
|
||||||
Long.toString(signerMasterKeyId))
|
Long.toString(signerMasterKeyId))
|
||||||
);
|
);
|
||||||
startActivity(viewIntent);
|
startActivity(viewIntent);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
// TODO notify user of this, maybe offer download?
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
|
@ -43,6 +43,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
import org.sufficientlysecure.keychain.ui.adapter.TabsAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.TabsAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ShareNfcDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -184,7 +185,7 @@ public class ViewKeyActivity extends ActionBarActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void shareKey(Uri dataUri, boolean fingerprintOnly) {
|
private void shareKey(Uri dataUri, boolean fingerprintOnly) {
|
||||||
String content;
|
String content = null;
|
||||||
if (fingerprintOnly) {
|
if (fingerprintOnly) {
|
||||||
byte[] data = (byte[]) ProviderHelper.getGenericData(
|
byte[] data = (byte[]) ProviderHelper.getGenericData(
|
||||||
this, KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
|
this, KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri),
|
||||||
@ -199,7 +200,9 @@ public class ViewKeyActivity extends ActionBarActivity {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
|
try {
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
|
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||||
this, new long[]{masterKeyId});
|
this, new long[]{masterKeyId});
|
||||||
|
|
||||||
@ -212,14 +215,21 @@ public class ViewKeyActivity extends ActionBarActivity {
|
|||||||
Toast.LENGTH_LONG).show();
|
Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (content != null) {
|
||||||
// let user choose application
|
// let user choose application
|
||||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
|
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
|
||||||
sendIntent.setType("text/plain");
|
sendIntent.setType("text/plain");
|
||||||
startActivity(Intent.createChooser(sendIntent,
|
startActivity(Intent.createChooser(sendIntent,
|
||||||
getResources().getText(R.string.action_share_key_with)));
|
getResources().getText(R.string.action_share_key_with)));
|
||||||
|
} else {
|
||||||
|
Log.e(Constants.TAG, "content is null!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareKeyQrCode(Uri dataUri, boolean fingerprintOnly) {
|
private void shareKeyQrCode(Uri dataUri, boolean fingerprintOnly) {
|
||||||
@ -230,13 +240,18 @@ public class ViewKeyActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
private void copyToClipboard(Uri dataUri) {
|
private void copyToClipboard(Uri dataUri) {
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
|
try {
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
|
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||||
this, new long[]{masterKeyId});
|
this, new long[]{masterKeyId});
|
||||||
|
|
||||||
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
||||||
Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
|
Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareNfc() {
|
private void shareNfc() {
|
||||||
|
@ -328,6 +328,7 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
|
|
||||||
private void encryptToContact(Uri dataUri) {
|
private void encryptToContact(Uri dataUri) {
|
||||||
// TODO preselect from uri? should be feasible without trivial query
|
// TODO preselect from uri? should be feasible without trivial query
|
||||||
|
try {
|
||||||
long keyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
long keyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||||
|
|
||||||
long[] encryptionKeyIds = new long[]{ keyId };
|
long[] encryptionKeyIds = new long[]{ keyId };
|
||||||
@ -336,6 +337,9 @@ public class ViewKeyMainFragment extends Fragment implements
|
|||||||
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
|
||||||
// used instead of startActivity set actionbar based on callingPackage
|
// used instead of startActivity set actionbar based on callingPackage
|
||||||
startActivityForResult(intent, 0);
|
startActivityForResult(intent, 0);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void certifyKey(Uri dataUri) {
|
private void certifyKey(Uri dataUri) {
|
||||||
|
@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.QrCodeUtils;
|
import org.sufficientlysecure.keychain.util.QrCodeUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -106,7 +107,12 @@ public class ShareQrCodeDialogFragment extends DialogFragment {
|
|||||||
mText.setText(R.string.share_qr_code_dialog_start);
|
mText.setText(R.string.share_qr_code_dialog_start);
|
||||||
|
|
||||||
// TODO works, but
|
// TODO works, but
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
long masterKeyId = 0;
|
||||||
|
try {
|
||||||
|
masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||||
getActivity(), new long[] { masterKeyId });
|
getActivity(), new long[] { masterKeyId });
|
||||||
|
Loading…
Reference in New Issue
Block a user