More work on crypto consumers

This commit is contained in:
Dominik Schürmann 2013-07-01 23:19:53 +02:00
parent 36cc814e84
commit 202ccc2c36
14 changed files with 205 additions and 17 deletions

View File

@ -20,10 +20,12 @@ import org.openintents.crypto.CryptoSignatureResult;
import org.openintents.crypto.CryptoError;
interface ICryptoCallback {
oneway void onEncryptSignSuccess(in byte[] outputBytes);
oneway void onDecryptVerifySuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult);
/**
* CryptoSignatureResult is only returned if the Callback was used from decryptAndVerify
*
*/
oneway void onSuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult);
oneway void onError(in CryptoError error);

View File

@ -71,6 +71,12 @@ interface ICryptoService {
* @param callback
* Callback where to return results
*/
oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback);
oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback);
/**
* Opens setup using default parameters
*
*/
oneway void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId);
}

View File

@ -71,17 +71,28 @@ public class CryptoProviderDemoActivity extends Activity {
/**
* Callback from remote crypto service
*/
final ICryptoCallback.Stub callback = new ICryptoCallback.Stub() {
final ICryptoCallback.Stub encryptCallback = new ICryptoCallback.Stub() {
@Override
public void onEncryptSignSuccess(byte[] outputBytes) throws RemoteException {
public void onSuccess(byte[] outputBytes, CryptoSignatureResult signatureResult)
throws RemoteException {
Log.d(Constants.TAG, "onEncryptSignSuccess");
// TODO
}
@Override
public void onDecryptVerifySuccess(byte[] outputBytes, CryptoSignatureResult signatureResult)
public void onError(CryptoError error) throws RemoteException {
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
}
};
final ICryptoCallback.Stub decryptCallback = new ICryptoCallback.Stub() {
@Override
public void onSuccess(byte[] outputBytes, CryptoSignatureResult signatureResult)
throws RemoteException {
Log.d(Constants.TAG, "onDecryptVerifySuccess");
@ -101,7 +112,7 @@ public class CryptoProviderDemoActivity extends Activity {
try {
mCryptoServiceConnection.getService().encrypt(inputBytes,
new String[] { mEncryptUserId.getText().toString() }, callback);
new String[] { mEncryptUserId.getText().toString() }, encryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}
@ -112,7 +123,7 @@ public class CryptoProviderDemoActivity extends Activity {
try {
mCryptoServiceConnection.getService().sign(inputBytes,
mSignUserId.getText().toString(), callback);
mSignUserId.getText().toString(), encryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}
@ -124,7 +135,7 @@ public class CryptoProviderDemoActivity extends Activity {
try {
mCryptoServiceConnection.getService().encryptAndSign(inputBytes,
new String[] { mEncryptUserId.getText().toString() },
mSignUserId.getText().toString(), callback);
mSignUserId.getText().toString(), encryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}
@ -134,7 +145,7 @@ public class CryptoProviderDemoActivity extends Activity {
byte[] inputBytes = mCiphertext.getText().toString().getBytes();
try {
mCryptoServiceConnection.getService().decryptAndVerify(inputBytes, callback);
mCryptoServiceConnection.getService().decryptAndVerify(inputBytes, decryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}

View File

@ -298,6 +298,10 @@
android:name=".ui.PreferencesActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/title_preferences" />
<activity
android:name=".ui.CryptoConsumersActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/title_crypto_consumers" />
<activity
android:name=".ui.PreferencesKeyServerActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"

View File

@ -4,7 +4,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.1'
classpath 'com.android.tools.build:gradle:0.4.+'
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/crypto_consumers_list_fragment"
android:name="org.sufficientlysecure.keychain.ui.CryptoConsumersFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -31,6 +31,7 @@
<string name="title_editKey">Edit Keyring</string>
<string name="title_createKey">Create Keyring</string>
<string name="title_preferences">Preferences</string>
<string name="title_crypto_consumers">Crypto Consumers</string>
<string name="title_keyServerPreference">Key Server Preference</string>
<string name="title_changePassPhrase">Change Passphrase</string>
<string name="title_setPassPhrase">Set Passphrase</string>
@ -89,6 +90,7 @@
<string name="menu_managePublicKeys">Manage Public Keyrings</string>
<string name="menu_manageSecretKeys">Manage Secret Keyrings</string>
<string name="menu_preferences">Settings</string>
<string name="menu_crypto_consumers">Crypto Consumers</string>
<string name="menu_importFromFile">Import from file</string>
<string name="menu_importFromQrCode">Import from QR Code</string>
<string name="menu_importFromNfc">Import from NFC</string>

View File

@ -20,10 +20,12 @@ import org.openintents.crypto.CryptoSignatureResult;
import org.openintents.crypto.CryptoError;
interface ICryptoCallback {
oneway void onEncryptSignSuccess(in byte[] outputBytes);
oneway void onDecryptVerifySuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult);
/**
* CryptoSignatureResult is only returned if the Callback was used from decryptAndVerify
*
*/
oneway void onSuccess(in byte[] outputBytes, in CryptoSignatureResult signatureResult);
oneway void onError(in CryptoError error);

View File

@ -71,6 +71,12 @@ interface ICryptoService {
* @param callback
* Callback where to return results
*/
oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback);
oneway void decryptAndVerify(in byte[] inputBytes, in ICryptoCallback callback);
/**
* Opens setup using default parameters
*
*/
oneway void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId);
}

View File

@ -62,6 +62,7 @@ public final class Id {
public static final int import_from_file = 0x21070020;
public static final int import_from_qr_code = 0x21070021;
public static final int import_from_nfc = 0x21070022;
public static final int crypto_consumers = 0x21070023;
}
}

View File

@ -184,7 +184,7 @@ public class CryptoService extends Service {
signatureSuccess, signatureUnknown);
// return over handler on client side
callback.onDecryptVerifySuccess(outputBytes, sigResult);
callback.onSuccess(outputBytes, sigResult);
} catch (Exception e) {
Log.e(Constants.TAG, "KeychainService, Exception!", e);
@ -250,6 +250,13 @@ public class CryptoService extends Service {
checkAndEnqueue(r);
}
@Override
public void setup(boolean asciiArmor, boolean newKeyring, String newKeyringUserId)
throws RemoteException {
// TODO Auto-generated method stub
}
};
private final IServiceActivityCallback.Stub mBinderServiceActivity = new IServiceActivityCallback.Stub() {

View File

@ -0,0 +1,43 @@
package org.sufficientlysecure.keychain.ui;
import org.sufficientlysecure.keychain.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import android.content.Intent;
import android.os.Bundle;
public class CryptoConsumersActivity extends SherlockFragmentActivity {
private ActionBar mActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActionBar = getSupportActionBar();
setContentView(R.layout.crypto_consumers_activity);
mActionBar.setDisplayShowTitleEnabled(true);
mActionBar.setDisplayHomeAsUpEnabled(true);
}
/**
* Menu Options
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in Action Bar clicked; go home
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@ -0,0 +1,85 @@
package org.sufficientlysecure.keychain.ui;
import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumers;
import org.sufficientlysecure.keychain.util.Log;
import com.actionbarsherlock.app.SherlockListFragment;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.widget.ListView;
public class CryptoConsumersFragment extends SherlockListFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
// This is the Adapter being used to display the list's data.
SimpleCursorAdapter mAdapter;
// If non-null, this is the current filter the user has provided.
String mCurFilter;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Give some text to display if there is no data. In a real
// application this would come from a resource.
setEmptyText("TODO no crypto consumers");
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2,
null, new String[] { CryptoConsumers.PACKAGE_NAME, CryptoConsumers.PACKAGE_NAME },
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
setListAdapter(mAdapter);
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Insert desired behavior here.
Log.i("FragmentComplexList", "Item clicked: " + id);
}
// These are the Contacts rows that we will retrieve.
static final String[] CONSUMERS_SUMMARY_PROJECTION = new String[] { CryptoConsumers._ID,
CryptoConsumers.PACKAGE_NAME };
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// This is called when a new Loader needs to be created. This
// sample only has one Loader, so we don't care about the ID.
// First, pick the base URI to use depending on whether we are
// currently filtering.
Uri baseUri = CryptoConsumers.CONTENT_URI;
// Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed.
return new CursorLoader(getActivity(), baseUri, CONSUMERS_SUMMARY_PROJECTION, null, null,
CryptoConsumers.PACKAGE_NAME + " COLLATE LOCALIZED ASC");
}
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// Swap the new cursor in. (The framework will take care of closing the
// old cursor once we return.)
mAdapter.swapCursor(data);
}
public void onLoaderReset(Loader<Cursor> loader) {
// This is called when the last Cursor provided to onLoadFinished()
// above is about to be closed. We need to make sure we are no
// longer using it.
mAdapter.swapCursor(null);
}
}

View File

@ -80,6 +80,9 @@ public class MainActivity extends SherlockActivity {
menu.add(0, Id.menu.option.preferences, 0, R.string.menu_preferences)
.setIcon(R.drawable.ic_menu_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, Id.menu.option.crypto_consumers, 0, R.string.menu_crypto_consumers)
.setIcon(R.drawable.ic_menu_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@ -91,6 +94,10 @@ public class MainActivity extends SherlockActivity {
startActivity(new Intent(this, PreferencesActivity.class));
return true;
case Id.menu.option.crypto_consumers:
startActivity(new Intent(this, CryptoConsumersActivity.class));
return true;
default:
break;