mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 09:12:16 -05:00
Register works basically
This commit is contained in:
parent
dc6a709b7a
commit
1beb85acf5
@ -21,19 +21,6 @@
|
||||
android:text="dominik@dominikschuermann.de"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Sign User Id"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/crypto_provider_demo_sign_user_id"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="dominik@dominikschuermann.de"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -63,7 +63,6 @@ public class CryptoProviderDemoActivity extends Activity {
|
||||
mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message);
|
||||
mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
|
||||
mEncryptUserId = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
|
||||
mSignUserId = (EditText) findViewById(R.id.crypto_provider_demo_sign_user_id);
|
||||
|
||||
selectCryptoProvider();
|
||||
}
|
||||
@ -88,7 +87,7 @@ public class CryptoProviderDemoActivity extends Activity {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
final ICryptoCallback.Stub decryptCallback = new ICryptoCallback.Stub() {
|
||||
|
||||
@Override
|
||||
|
@ -470,7 +470,7 @@
|
||||
<!-- Remote API internal intents -->
|
||||
|
||||
<activity
|
||||
android:name="org.sufficientlysecure.keychain.remote_api.ServiceActivity"
|
||||
android:name="org.sufficientlysecure.keychain.remote_api.CryptoServiceActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/app_name"
|
||||
android:process=":crypto" >
|
||||
|
@ -120,7 +120,7 @@ public class OtherHelper {
|
||||
public static void checkPackagePermissionForActions(Activity activity, String pkgName,
|
||||
String permName, String action, String[] restrictedActions) {
|
||||
if (action != null) {
|
||||
PackageManager pkgManager = activity.getPackageManager();
|
||||
// PackageManager pkgManager = activity.getPackageManager();
|
||||
|
||||
// for (int i = 0; i < restrictedActions.length; i++) {
|
||||
// if (restrictedActions[i].equals(action)) {
|
||||
|
@ -718,9 +718,9 @@ public class ProviderHelper {
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getCryptoConsumers(Context context) {
|
||||
Cursor cursor = context.getContentResolver().query(ApiApps.CONTENT_URI, null, null,
|
||||
null, null);
|
||||
public static ArrayList<String> getRegisteredApiApps(Context context) {
|
||||
Cursor cursor = context.getContentResolver().query(ApiApps.CONTENT_URI, null, null, null,
|
||||
null);
|
||||
|
||||
ArrayList<String> packageNames = new ArrayList<String>();
|
||||
if (cursor != null) {
|
||||
@ -739,9 +739,12 @@ public class ProviderHelper {
|
||||
return packageNames;
|
||||
}
|
||||
|
||||
public static void addCryptoConsumer(Context context, String packageName) {
|
||||
public static void addCryptoConsumer(Context context, String packageName, long keyId,
|
||||
boolean asciiArmor) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ApiApps.PACKAGE_NAME, packageName);
|
||||
values.put(ApiApps.KEY_ID, keyId);
|
||||
values.put(ApiApps.ASCII_ARMOR, asciiArmor);
|
||||
context.getContentResolver().insert(ApiApps.CONTENT_URI, values);
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +76,9 @@ public class CryptoService extends Service {
|
||||
public IBinder onBind(Intent intent) {
|
||||
// return different binder for connections from internal service activity
|
||||
if (ACTION_SERVICE_ACTIVITY.equals(intent.getAction())) {
|
||||
String callingPackageName = intent.getPackage();
|
||||
|
||||
// this binder can only be used from OpenPGP Keychain
|
||||
if (callingPackageName.equals(Constants.PACKAGE_NAME)) {
|
||||
if (isCallerAllowed(true)) {
|
||||
return mBinderServiceActivity;
|
||||
} else {
|
||||
Log.e(Constants.TAG, "This binder can only be used from " + Constants.PACKAGE_NAME);
|
||||
@ -150,8 +149,8 @@ public class CryptoService extends Service {
|
||||
|
||||
// start passphrase dialog
|
||||
Bundle extras = new Bundle();
|
||||
extras.putLong(ServiceActivity.EXTRA_SECRET_KEY_ID, secretKeyId);
|
||||
pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
||||
extras.putLong(CryptoServiceActivity.EXTRA_SECRET_KEY_ID, secretKeyId);
|
||||
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
||||
}
|
||||
|
||||
// if (signedOnly) {
|
||||
@ -255,7 +254,7 @@ public class CryptoService extends Service {
|
||||
public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId)
|
||||
throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@ -267,7 +266,7 @@ public class CryptoService extends Service {
|
||||
|
||||
if (success) {
|
||||
// resume threads
|
||||
if (isPackageAllowed(packageName)) {
|
||||
if (isPackageAllowed(packageName, false)) {
|
||||
mThreadPool.resume();
|
||||
} else {
|
||||
// TODO: should not happen?
|
||||
@ -287,7 +286,7 @@ public class CryptoService extends Service {
|
||||
};
|
||||
|
||||
private void checkAndEnqueue(Runnable r) {
|
||||
if (isCallerAllowed()) {
|
||||
if (isCallerAllowed(false)) {
|
||||
mThreadPool.execute(r);
|
||||
|
||||
Log.d(Constants.TAG, "Enqueued runnable…");
|
||||
@ -298,8 +297,8 @@ public class CryptoService extends Service {
|
||||
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);
|
||||
extras.putString(CryptoServiceActivity.EXTRA_PACKAGE_NAME, callingPackages[0]);
|
||||
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_REGISTER, extras);
|
||||
|
||||
mThreadPool.execute(r);
|
||||
|
||||
@ -311,16 +310,18 @@ public class CryptoService extends Service {
|
||||
* Checks if process that binds to this service (i.e. the package name corresponding to the
|
||||
* process) is in the list of allowed package names.
|
||||
*
|
||||
* @param allowOnlySelf
|
||||
* allow only Keychain app itself
|
||||
* @return true if process is allowed to use this service
|
||||
*/
|
||||
private boolean isCallerAllowed() {
|
||||
private boolean isCallerAllowed(boolean allowOnlySelf) {
|
||||
String[] callingPackages = getPackageManager().getPackagesForUid(Binder.getCallingUid());
|
||||
|
||||
// is calling package allowed to use this service?
|
||||
for (int i = 0; i < callingPackages.length; i++) {
|
||||
String currentPkg = callingPackages[i];
|
||||
|
||||
if (isPackageAllowed(currentPkg)) {
|
||||
if (isPackageAllowed(currentPkg, allowOnlySelf)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -329,14 +330,22 @@ public class CryptoService extends Service {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isPackageAllowed(String packageName) {
|
||||
/**
|
||||
* Checks if packageName is a registered app for the API.
|
||||
*
|
||||
* @param packageName
|
||||
* @param allowOnlySelf
|
||||
* allow only Keychain app itself
|
||||
* @return
|
||||
*/
|
||||
private boolean isPackageAllowed(String packageName, boolean allowOnlySelf) {
|
||||
Log.d(Constants.TAG, "packageName: " + packageName);
|
||||
|
||||
ArrayList<String> allowedPkgs = ProviderHelper.getCryptoConsumers(mContext);
|
||||
ArrayList<String> allowedPkgs = ProviderHelper.getRegisteredApiApps(mContext);
|
||||
Log.d(Constants.TAG, "allowed: " + allowedPkgs);
|
||||
|
||||
// check if package is allowed to use our service
|
||||
if (allowedPkgs.contains(packageName)) {
|
||||
if (allowedPkgs.contains(packageName) && (!allowOnlySelf)) {
|
||||
Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
|
||||
|
||||
return true;
|
||||
@ -353,7 +362,7 @@ public class CryptoService extends Service {
|
||||
mThreadPool.pause();
|
||||
|
||||
Log.d(Constants.TAG, "starting activity...");
|
||||
Intent intent = new Intent(getBaseContext(), ServiceActivity.class);
|
||||
Intent intent = new Intent(getBaseContext(), CryptoServiceActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.setAction(action);
|
||||
if (extras != null) {
|
||||
|
@ -43,7 +43,7 @@ import android.widget.Toast;
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
|
||||
public class ServiceActivity extends SherlockFragmentActivity {
|
||||
public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
|
||||
public static final String ACTION_REGISTER = "org.sufficientlysecure.keychain.remote_api.REGISTER";
|
||||
public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.remote_api.CRYPTO_CACHE_PASSPHRASE";
|
||||
@ -82,7 +82,8 @@ public class ServiceActivity extends SherlockFragmentActivity {
|
||||
Log.d(Constants.TAG, "not bound yet");
|
||||
|
||||
Intent serviceIntent = new Intent();
|
||||
serviceIntent.setAction("org.openintents.crypto.ICryptoService");
|
||||
serviceIntent
|
||||
.setAction("org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback");
|
||||
bindService(serviceIntent, mServiceActivityConnection, Context.BIND_AUTO_CREATE);
|
||||
|
||||
return true;
|
||||
@ -151,11 +152,13 @@ public class ServiceActivity extends SherlockFragmentActivity {
|
||||
// Allow
|
||||
|
||||
if (settingsFragment.getSecretKeyId() == Id.key.none) {
|
||||
Toast.makeText(ServiceActivity.this,
|
||||
Toast.makeText(CryptoServiceActivity.this,
|
||||
R.string.api_register_error_select_key, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
ProviderHelper.addCryptoConsumer(ServiceActivity.this, packageName);
|
||||
ProviderHelper.addCryptoConsumer(CryptoServiceActivity.this,
|
||||
packageName, settingsFragment.getSecretKeyId(),
|
||||
settingsFragment.isAsciiArmor());
|
||||
// Intent data = new Intent();
|
||||
|
||||
try {
|
Loading…
Reference in New Issue
Block a user