mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-16 22:05:05 -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);
|
|
||||||
|
|
||||||
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
// Create a new Messenger for the communication back
|
||||||
new long[]{ masterKeyId });
|
Messenger messenger = new Messenger(deleteHandler);
|
||||||
deleteKeyDialog.show(mActivity.getSupportFragmentManager(), "deleteKeyDialog");
|
DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
|
||||||
|
new long[]{ masterKeyId });
|
||||||
|
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,
|
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(encData.getKeyID()))
|
// get master key id for this encryption key id
|
||||||
);
|
long masterKeyId = 0;
|
||||||
|
try {
|
||||||
|
masterKeyId = ProviderHelper.getMasterKeyId(mContext,
|
||||||
|
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,17 +168,23 @@ 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);
|
||||||
return null;
|
} catch (NotFoundException e) {
|
||||||
|
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);
|
||||||
return null;
|
} catch (NotFoundException notFound) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), data.getData());
|
try {
|
||||||
mSelectKeyFragment.selectKey(masterKeyId);
|
long masterKeyId = ProviderHelper.getMasterKeyId(getActivity(), data.getData());
|
||||||
|
mSelectKeyFragment.selectKey(masterKeyId);
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -171,11 +171,12 @@ 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) {
|
||||||
masterKeyId = ProviderHelper.getMasterKeyId(this,
|
try {
|
||||||
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId)));
|
masterKeyId = ProviderHelper.getMasterKeyId(this,
|
||||||
// Failure
|
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId)));
|
||||||
if(masterKeyId == 0)
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, "getCachedPassphraseImpl() for masterKeyId " + masterKeyId);
|
Log.d(TAG, "getCachedPassphraseImpl() for masterKeyId " + masterKeyId);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
// get master key id using row id
|
try {
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
// get master key id using row id
|
||||||
finallyEdit(masterKeyId);
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, mDataUri);
|
||||||
|
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) {
|
||||||
long id = ProviderHelper.getMasterKeyId(getActivity(),
|
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
|
|
||||||
);
|
|
||||||
// TODO check for available encrypt keys... is this even relevant?
|
// TODO check for available encrypt keys... is this even relevant?
|
||||||
goodIds.add(id);
|
try {
|
||||||
|
long id = ProviderHelper.getMasterKeyId(getActivity(),
|
||||||
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(preselectedEncryptionKeyIds[i]))
|
||||||
|
);
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
long signerMasterKeyId = ProviderHelper.getMasterKeyId(this,
|
try {
|
||||||
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mSignerKeyId))
|
long signerMasterKeyId = ProviderHelper.getMasterKeyId(this,
|
||||||
);
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(mSignerKeyId))
|
||||||
// TODO notify user of this, maybe offer download?
|
);
|
||||||
if (mSignerKeyId == 0L)
|
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
|
||||||
return true;
|
Long.toString(signerMasterKeyId))
|
||||||
viewIntent.setData(KeyRings.buildGenericKeyRingUri(
|
);
|
||||||
Long.toString(signerMasterKeyId))
|
startActivity(viewIntent);
|
||||||
);
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
startActivity(viewIntent);
|
// 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,27 +200,36 @@ public class ViewKeyActivity extends ActionBarActivity {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// get public keyring as ascii armored string
|
// get public keyring as ascii armored string
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
try {
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
this, new long[]{masterKeyId});
|
|
||||||
|
|
||||||
content = keyringArmored.get(0);
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||||
|
this, new long[]{masterKeyId});
|
||||||
|
|
||||||
// Android will fail with android.os.TransactionTooLargeException if key is too big
|
content = keyringArmored.get(0);
|
||||||
// see http://www.lonestarprod.com/?p=34
|
|
||||||
if (content.length() >= 86389) {
|
// Android will fail with android.os.TransactionTooLargeException if key is too big
|
||||||
Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing,
|
// see http://www.lonestarprod.com/?p=34
|
||||||
Toast.LENGTH_LONG).show();
|
if (content.length() >= 86389) {
|
||||||
return;
|
Toast.makeText(getApplicationContext(), R.string.key_too_big_for_sharing,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// let user choose application
|
if (content != null) {
|
||||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
// let user choose application
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||||
sendIntent.setType("text/plain");
|
sendIntent.putExtra(Intent.EXTRA_TEXT, content);
|
||||||
startActivity(Intent.createChooser(sendIntent,
|
sendIntent.setType("text/plain");
|
||||||
getResources().getText(R.string.action_share_key_with)));
|
startActivity(Intent.createChooser(sendIntent,
|
||||||
|
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
|
||||||
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
try {
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
long masterKeyId = ProviderHelper.getMasterKeyId(this, dataUri);
|
||||||
this, new long[]{masterKeyId});
|
|
||||||
|
|
||||||
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
ArrayList<String> keyringArmored = ProviderHelper.getKeyRingsAsArmoredString(
|
||||||
Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
|
this, new long[]{masterKeyId});
|
||||||
.show();
|
|
||||||
|
ClipboardReflection.copyToClipboard(this, keyringArmored.get(0));
|
||||||
|
Toast.makeText(getApplicationContext(), R.string.key_copied_to_clipboard, Toast.LENGTH_LONG)
|
||||||
|
.show();
|
||||||
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
|
Log.e(Constants.TAG, "key not found!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shareNfc() {
|
private void shareNfc() {
|
||||||
|
@ -328,14 +328,18 @@ 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
|
||||||
long keyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
try {
|
||||||
|
long keyId = ProviderHelper.getMasterKeyId(getActivity(), dataUri);
|
||||||
|
|
||||||
long[] encryptionKeyIds = new long[]{ keyId };
|
long[] encryptionKeyIds = new long[]{ keyId };
|
||||||
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
Intent intent = new Intent(getActivity(), EncryptActivity.class);
|
||||||
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
|
||||||
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