mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22: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:text="dominik@dominikschuermann.de"
|
||||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
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
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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);
|
mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message);
|
||||||
mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
|
mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
|
||||||
mEncryptUserId = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
|
mEncryptUserId = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
|
||||||
mSignUserId = (EditText) findViewById(R.id.crypto_provider_demo_sign_user_id);
|
|
||||||
|
|
||||||
selectCryptoProvider();
|
selectCryptoProvider();
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@
|
|||||||
<!-- Remote API internal intents -->
|
<!-- Remote API internal intents -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.sufficientlysecure.keychain.remote_api.ServiceActivity"
|
android:name="org.sufficientlysecure.keychain.remote_api.CryptoServiceActivity"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:process=":crypto" >
|
android:process=":crypto" >
|
||||||
|
@ -120,7 +120,7 @@ public class OtherHelper {
|
|||||||
public static void checkPackagePermissionForActions(Activity activity, String pkgName,
|
public static void checkPackagePermissionForActions(Activity activity, String pkgName,
|
||||||
String permName, String action, String[] restrictedActions) {
|
String permName, String action, String[] restrictedActions) {
|
||||||
if (action != null) {
|
if (action != null) {
|
||||||
PackageManager pkgManager = activity.getPackageManager();
|
// PackageManager pkgManager = activity.getPackageManager();
|
||||||
|
|
||||||
// for (int i = 0; i < restrictedActions.length; i++) {
|
// for (int i = 0; i < restrictedActions.length; i++) {
|
||||||
// if (restrictedActions[i].equals(action)) {
|
// if (restrictedActions[i].equals(action)) {
|
||||||
|
@ -718,9 +718,9 @@ public class ProviderHelper {
|
|||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<String> getCryptoConsumers(Context context) {
|
public static ArrayList<String> getRegisteredApiApps(Context context) {
|
||||||
Cursor cursor = context.getContentResolver().query(ApiApps.CONTENT_URI, null, null,
|
Cursor cursor = context.getContentResolver().query(ApiApps.CONTENT_URI, null, null, null,
|
||||||
null, null);
|
null);
|
||||||
|
|
||||||
ArrayList<String> packageNames = new ArrayList<String>();
|
ArrayList<String> packageNames = new ArrayList<String>();
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
@ -739,9 +739,12 @@ public class ProviderHelper {
|
|||||||
return packageNames;
|
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();
|
ContentValues values = new ContentValues();
|
||||||
values.put(ApiApps.PACKAGE_NAME, packageName);
|
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);
|
context.getContentResolver().insert(ApiApps.CONTENT_URI, values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,9 @@ public class CryptoService extends Service {
|
|||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
// return different binder for connections from internal service activity
|
// return different binder for connections from internal service activity
|
||||||
if (ACTION_SERVICE_ACTIVITY.equals(intent.getAction())) {
|
if (ACTION_SERVICE_ACTIVITY.equals(intent.getAction())) {
|
||||||
String callingPackageName = intent.getPackage();
|
|
||||||
|
|
||||||
// this binder can only be used from OpenPGP Keychain
|
// this binder can only be used from OpenPGP Keychain
|
||||||
if (callingPackageName.equals(Constants.PACKAGE_NAME)) {
|
if (isCallerAllowed(true)) {
|
||||||
return mBinderServiceActivity;
|
return mBinderServiceActivity;
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "This binder can only be used from " + Constants.PACKAGE_NAME);
|
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
|
// start passphrase dialog
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
extras.putLong(ServiceActivity.EXTRA_SECRET_KEY_ID, secretKeyId);
|
extras.putLong(CryptoServiceActivity.EXTRA_SECRET_KEY_ID, secretKeyId);
|
||||||
pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_CACHE_PASSPHRASE, extras);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (signedOnly) {
|
// if (signedOnly) {
|
||||||
@ -267,7 +266,7 @@ public class CryptoService extends Service {
|
|||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// resume threads
|
// resume threads
|
||||||
if (isPackageAllowed(packageName)) {
|
if (isPackageAllowed(packageName, false)) {
|
||||||
mThreadPool.resume();
|
mThreadPool.resume();
|
||||||
} else {
|
} else {
|
||||||
// TODO: should not happen?
|
// TODO: should not happen?
|
||||||
@ -287,7 +286,7 @@ public class CryptoService extends Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private void checkAndEnqueue(Runnable r) {
|
private void checkAndEnqueue(Runnable r) {
|
||||||
if (isCallerAllowed()) {
|
if (isCallerAllowed(false)) {
|
||||||
mThreadPool.execute(r);
|
mThreadPool.execute(r);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "Enqueued runnable…");
|
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!");
|
Log.e(Constants.TAG, "Not allowed to use service! Starting activity for registration!");
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
// TODO: currently simply uses first entry
|
// TODO: currently simply uses first entry
|
||||||
extras.putString(ServiceActivity.EXTRA_PACKAGE_NAME, callingPackages[0]);
|
extras.putString(CryptoServiceActivity.EXTRA_PACKAGE_NAME, callingPackages[0]);
|
||||||
pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_REGISTER, extras);
|
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_REGISTER, extras);
|
||||||
|
|
||||||
mThreadPool.execute(r);
|
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
|
* 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.
|
* 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
|
* @return true if process is allowed to use this service
|
||||||
*/
|
*/
|
||||||
private boolean isCallerAllowed() {
|
private boolean isCallerAllowed(boolean allowOnlySelf) {
|
||||||
String[] callingPackages = getPackageManager().getPackagesForUid(Binder.getCallingUid());
|
String[] callingPackages = getPackageManager().getPackagesForUid(Binder.getCallingUid());
|
||||||
|
|
||||||
// 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];
|
||||||
|
|
||||||
if (isPackageAllowed(currentPkg)) {
|
if (isPackageAllowed(currentPkg, allowOnlySelf)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,14 +330,22 @@ public class CryptoService extends Service {
|
|||||||
return false;
|
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);
|
Log.d(Constants.TAG, "packageName: " + packageName);
|
||||||
|
|
||||||
ArrayList<String> allowedPkgs = ProviderHelper.getCryptoConsumers(mContext);
|
ArrayList<String> allowedPkgs = ProviderHelper.getRegisteredApiApps(mContext);
|
||||||
Log.d(Constants.TAG, "allowed: " + allowedPkgs);
|
Log.d(Constants.TAG, "allowed: " + allowedPkgs);
|
||||||
|
|
||||||
// check if package is allowed to use our service
|
// 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);
|
Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -353,7 +362,7 @@ public class CryptoService extends Service {
|
|||||||
mThreadPool.pause();
|
mThreadPool.pause();
|
||||||
|
|
||||||
Log.d(Constants.TAG, "starting activity...");
|
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.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.setAction(action);
|
intent.setAction(action);
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
|
@ -43,7 +43,7 @@ import android.widget.Toast;
|
|||||||
import com.actionbarsherlock.app.ActionBar;
|
import com.actionbarsherlock.app.ActionBar;
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
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_REGISTER = "org.sufficientlysecure.keychain.remote_api.REGISTER";
|
||||||
public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.remote_api.CRYPTO_CACHE_PASSPHRASE";
|
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");
|
Log.d(Constants.TAG, "not bound yet");
|
||||||
|
|
||||||
Intent serviceIntent = new Intent();
|
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);
|
bindService(serviceIntent, mServiceActivityConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -151,11 +152,13 @@ public class ServiceActivity extends SherlockFragmentActivity {
|
|||||||
// Allow
|
// Allow
|
||||||
|
|
||||||
if (settingsFragment.getSecretKeyId() == Id.key.none) {
|
if (settingsFragment.getSecretKeyId() == Id.key.none) {
|
||||||
Toast.makeText(ServiceActivity.this,
|
Toast.makeText(CryptoServiceActivity.this,
|
||||||
R.string.api_register_error_select_key, Toast.LENGTH_LONG)
|
R.string.api_register_error_select_key, Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
ProviderHelper.addCryptoConsumer(ServiceActivity.this, packageName);
|
ProviderHelper.addCryptoConsumer(CryptoServiceActivity.this,
|
||||||
|
packageName, settingsFragment.getSecretKeyId(),
|
||||||
|
settingsFragment.isAsciiArmor());
|
||||||
// Intent data = new Intent();
|
// Intent data = new Intent();
|
||||||
|
|
||||||
try {
|
try {
|
Loading…
Reference in New Issue
Block a user