mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-04 14:32:16 -05:00
Possible to add allowed packages
This commit is contained in:
parent
1b29330f18
commit
0f3e78ebf7
@ -69,7 +69,7 @@ public class CryptoServiceConnection {
|
|||||||
|
|
||||||
Intent serviceIntent = new Intent();
|
Intent serviceIntent = new Intent();
|
||||||
serviceIntent.setAction("org.openintents.crypto.ICryptoService");
|
serviceIntent.setAction("org.openintents.crypto.ICryptoService");
|
||||||
serviceIntent.setPackage(cryptoProviderPackageName); // TODO: test
|
serviceIntent.setPackage(cryptoProviderPackageName);
|
||||||
mApplicationContext.bindService(serviceIntent, mCryptoServiceConnection,
|
mApplicationContext.bindService(serviceIntent, mCryptoServiceConnection,
|
||||||
Context.BIND_AUTO_CREATE);
|
Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
|
@ -58,8 +58,6 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
private ArrayList<String> mAllowedPackages;
|
private ArrayList<String> mAllowedPackages;
|
||||||
|
|
||||||
// RemoteCallbackList<IInterface>
|
|
||||||
|
|
||||||
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
|
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -218,12 +216,13 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(boolean success, String packageName) throws RemoteException {
|
public void register(boolean success, String packageName) throws RemoteException {
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// reload allowed packages
|
// reload allowed packages
|
||||||
mAllowedPackages = ProviderHelper.getCryptoConsumers(mContext);
|
mAllowedPackages = ProviderHelper.getCryptoConsumers(mContext);
|
||||||
|
|
||||||
// resume threads
|
// resume threads
|
||||||
if (isCallerAllowed()) {
|
if (isPackageAllowed(packageName)) {
|
||||||
mThreadPool.resume();
|
mThreadPool.resume();
|
||||||
} else {
|
} else {
|
||||||
// TODO: should not happen?
|
// TODO: should not happen?
|
||||||
@ -248,8 +247,15 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
Log.d(Constants.TAG, "Enqueued runnable…");
|
Log.d(Constants.TAG, "Enqueued runnable…");
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "Not allowed to use service! Starting register with activity!");
|
String[] callingPackages = getPackageManager()
|
||||||
pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_REGISTER, null);
|
.getPackagesForUid(Binder.getCallingUid());
|
||||||
|
|
||||||
|
Log.e(Constants.TAG, "Not allowed to use service! Starting activity for registration!");
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
// TODO: currently simply uses first entry
|
||||||
|
extras.putString(ServiceActivity.EXTRA_PACKAGE_NAME, callingPackages[0]);
|
||||||
|
pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_REGISTER, extras);
|
||||||
|
|
||||||
mThreadPool.execute(r);
|
mThreadPool.execute(r);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "Enqueued runnable…");
|
Log.d(Constants.TAG, "Enqueued runnable…");
|
||||||
@ -268,16 +274,8 @@ public class CryptoService extends Service {
|
|||||||
// is calling package allowed to use this service?
|
// is calling package allowed to use this service?
|
||||||
for (int i = 0; i < callingPackages.length; i++) {
|
for (int i = 0; i < callingPackages.length; i++) {
|
||||||
String currentPkg = callingPackages[i];
|
String currentPkg = callingPackages[i];
|
||||||
Log.d(Constants.TAG, "Caller packageName: " + currentPkg);
|
|
||||||
|
|
||||||
// check if package is allowed to use our service
|
|
||||||
if (mAllowedPackages.contains(currentPkg)) {
|
|
||||||
Log.d(Constants.TAG, "Caller is allowed! packageName: " + currentPkg);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else if (Constants.PACKAGE_NAME.equals(currentPkg)) {
|
|
||||||
Log.d(Constants.TAG, "Caller is OpenPGP Keychain! -> allowed!");
|
|
||||||
|
|
||||||
|
if (isPackageAllowed(currentPkg)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,6 +284,23 @@ public class CryptoService extends Service {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPackageAllowed(String packageName) {
|
||||||
|
Log.d(Constants.TAG, "packageName: " + packageName);
|
||||||
|
|
||||||
|
// check if package is allowed to use our service
|
||||||
|
if (mAllowedPackages.contains(packageName)) {
|
||||||
|
Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if (Constants.PACKAGE_NAME.equals(packageName)) {
|
||||||
|
Log.d(Constants.TAG, "Package is OpenPGP Keychain! -> allowed!");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void pauseQueueAndStartServiceActivity(String action, Bundle extras) {
|
private void pauseQueueAndStartServiceActivity(String action, Bundle extras) {
|
||||||
mThreadPool.pause();
|
mThreadPool.pause();
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain.crypto_provider;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.PgpMain;
|
import org.sufficientlysecure.keychain.helper.PgpMain;
|
||||||
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ public class ServiceActivity extends SherlockFragmentActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// ProviderHelper.addCryptoConsumer(RegisterActivity.this, callingPackageName);
|
ProviderHelper.addCryptoConsumer(ServiceActivity.this, packageName);
|
||||||
// Intent data = new Intent();
|
// Intent data = new Intent();
|
||||||
|
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
|
@ -222,6 +222,10 @@ public class KeychainContract {
|
|||||||
|
|
||||||
/** Use if a single item is returned */
|
/** Use if a single item is returned */
|
||||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.crypto_consumers";
|
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.crypto_consumers";
|
||||||
|
|
||||||
|
public static Uri buildIdUri(String rowId) {
|
||||||
|
return CONTENT_URI.buildUpon().appendPath(rowId).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DataStream {
|
public static class DataStream {
|
||||||
|
@ -685,6 +685,11 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
rowId = db.insertOrThrow(Tables.USER_IDS, null, values);
|
rowId = db.insertOrThrow(Tables.USER_IDS, null, values);
|
||||||
rowUri = UserIds.buildSecretUserIdsUri(Long.toString(rowId));
|
rowUri = UserIds.buildSecretUserIdsUri(Long.toString(rowId));
|
||||||
|
|
||||||
|
break;
|
||||||
|
case CRYPTO_CONSUMERS:
|
||||||
|
rowId = db.insertOrThrow(Tables.CRYPTO_CONSUMERS, null, values);
|
||||||
|
rowUri = CryptoConsumers.buildIdUri(Long.toString(rowId));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||||
|
Loading…
Reference in New Issue
Block a user