intent to create key with default keyring

This commit is contained in:
Dominik 2012-04-14 15:25:33 +02:00
parent 4eebeede2b
commit 30b6cc60f2
12 changed files with 210 additions and 153 deletions

View File

@ -78,6 +78,7 @@
android:uiOptions="splitActionBarWhenNarrow" android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="stateHidden" > android:windowSoftInputMode="stateHidden" >
<intent-filter> <intent-filter>
<action android:name="org.apg.intent.CREATE_KEY" />
<action android:name="org.apg.intent.EDIT_KEY" /> <action android:name="org.apg.intent.EDIT_KEY" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />

Binary file not shown.

View File

@ -28,6 +28,7 @@
<string name="title_authentication">Passphrase</string> <string name="title_authentication">Passphrase</string>
<string name="title_createKey">Create Key</string> <string name="title_createKey">Create Key</string>
<string name="title_editKey">Edit Key</string> <string name="title_editKey">Edit Key</string>
<string name="title_createKey">Create Key</string>
<string name="title_preferences">Preferences</string> <string name="title_preferences">Preferences</string>
<string name="title_keyServerPreference">Key Server Preference</string> <string name="title_keyServerPreference">Key Server Preference</string>
<string name="title_changePassPhrase">Change Passphrase</string> <string name="title_changePassPhrase">Change Passphrase</string>

View File

@ -109,24 +109,27 @@ import java.util.Vector;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class Apg { public class Apg {
private static final String mApgPackageName = "org.apg"; private static final String PACKAGE_NAME = "org.apg";
private static final String INTENT_PREFIX = "org.apg.intent.";
public static class Intent { public static class Intent {
public static final String DECRYPT = "org.apg.intent.DECRYPT"; public static final String DECRYPT = INTENT_PREFIX + "DECRYPT";
public static final String ENCRYPT = "org.apg.intent.ENCRYPT"; public static final String ENCRYPT = INTENT_PREFIX + "ENCRYPT";
public static final String DECRYPT_FILE = "org.apg.intent.DECRYPT_FILE"; public static final String DECRYPT_FILE = INTENT_PREFIX + "DECRYPT_FILE";
public static final String ENCRYPT_FILE = "org.apg.intent.ENCRYPT_FILE"; public static final String ENCRYPT_FILE = INTENT_PREFIX + "ENCRYPT_FILE";
public static final String DECRYPT_AND_RETURN = "org.apg.intent.DECRYPT_AND_RETURN"; public static final String DECRYPT_AND_RETURN = INTENT_PREFIX + "DECRYPT_AND_RETURN";
public static final String ENCRYPT_AND_RETURN = "org.apg.intent.ENCRYPT_AND_RETURN"; public static final String ENCRYPT_AND_RETURN = INTENT_PREFIX + "ENCRYPT_AND_RETURN";
public static final String SELECT_PUBLIC_KEYS = "org.apg.intent.SELECT_PUBLIC_KEYS"; public static final String SELECT_PUBLIC_KEYS = INTENT_PREFIX + "SELECT_PUBLIC_KEYS";
public static final String SELECT_SECRET_KEY = "org.apg.intent.SELECT_SECRET_KEY"; public static final String SELECT_SECRET_KEY = INTENT_PREFIX + "SELECT_SECRET_KEY";
public static final String IMPORT = "org.apg.intent.IMPORT"; public static final String IMPORT = INTENT_PREFIX + "IMPORT";
public static final String LOOK_UP_KEY_ID = "org.apg.intent.LOOK_UP_KEY_ID"; public static final String LOOK_UP_KEY_ID = INTENT_PREFIX + "LOOK_UP_KEY_ID";
public static final String LOOK_UP_KEY_ID_AND_RETURN = "org.apg.intent.LOOK_UP_KEY_ID_AND_RETURN"; public static final String LOOK_UP_KEY_ID_AND_RETURN = INTENT_PREFIX
public static final String GENERATE_SIGNATURE = "org.apg.intent.GENERATE_SIGNATURE"; + "LOOK_UP_KEY_ID_AND_RETURN";
public static final String EXPORT_KEY_TO_SERVER = "org.apg.intent.EXPORT_KEY_TO_SERVER"; public static final String GENERATE_SIGNATURE = INTENT_PREFIX + "GENERATE_SIGNATURE";
public static final String IMPORT_FROM_QR_CODE = "org.apg.intent.IMPORT_FROM_QR_CODE"; public static final String EXPORT_KEY_TO_SERVER = INTENT_PREFIX + "EXPORT_KEY_TO_SERVER";
public static final String EDIT_KEY = "org.apg.intent.EDIT_KEY"; public static final String IMPORT_FROM_QR_CODE = INTENT_PREFIX + "IMPORT_FROM_QR_CODE";
public static final String CREATE_KEY = INTENT_PREFIX + "CREATE_KEY";
public static final String EDIT_KEY = INTENT_PREFIX + "EDIT_KEY";
} }
public static final String EXTRA_TEXT = "text"; public static final String EXTRA_TEXT = "text";
@ -157,6 +160,7 @@ public class Apg {
public static final String EXTRA_KEY_SERVERS = "keyServers"; public static final String EXTRA_KEY_SERVERS = "keyServers";
public static final String EXTRA_EXPECTED_FINGERPRINT = "expectedFingerprint"; public static final String EXTRA_EXPECTED_FINGERPRINT = "expectedFingerprint";
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase"; public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
public static final String AUTHORITY = DataProvider.AUTHORITY; public static final String AUTHORITY = DataProvider.AUTHORITY;
@ -2187,7 +2191,7 @@ public class Apg {
public static boolean isReleaseVersion(Context context) { public static boolean isReleaseVersion(Context context) {
try { try {
PackageInfo pi = context.getPackageManager().getPackageInfo(mApgPackageName, 0); PackageInfo pi = context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
if (pi.versionCode % 100 == 99) { if (pi.versionCode % 100 == 99) {
return true; return true;
} else { } else {
@ -2204,7 +2208,7 @@ public class Apg {
return VERSION; return VERSION;
} }
try { try {
PackageInfo pi = context.getPackageManager().getPackageInfo(mApgPackageName, 0); PackageInfo pi = context.getPackageManager().getPackageInfo(PACKAGE_NAME, 0);
VERSION = pi.versionName; VERSION = pi.versionName;
return VERSION; return VERSION;
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {

View File

@ -40,8 +40,10 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
@ -52,6 +54,8 @@ import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException; import java.security.NoSuchProviderException;
import java.security.SignatureException; import java.security.SignatureException;
@ -59,6 +63,7 @@ import java.util.Vector;
public class EditKeyActivity extends BaseActivity { public class EditKeyActivity extends BaseActivity {
private Intent mIntent = null; private Intent mIntent = null;
private ActionBar mActionBar;
private PGPSecretKeyRing mKeyRing = null; private PGPSecretKeyRing mKeyRing = null;
@ -109,60 +114,119 @@ public class EditKeyActivity extends BaseActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.edit_key); setContentView(R.layout.edit_key);
mActionBar = getSupportActionBar();
// find views
mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase);
mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase);
Vector<String> userIds = new Vector<String>(); Vector<String> userIds = new Vector<String>();
Vector<PGPSecretKey> keys = new Vector<PGPSecretKey>(); Vector<PGPSecretKey> keys = new Vector<PGPSecretKey>();
Vector<Integer> keysUsages = new Vector<Integer>();
Intent intent = getIntent();
long keyId = 0;
if (intent.getExtras() != null) {
keyId = intent.getExtras().getLong(Apg.EXTRA_KEY_ID);
}
if (keyId != 0) {
PGPSecretKey masterKey = null;
mKeyRing = Apg.getSecretKeyRing(keyId);
if (mKeyRing != null) {
masterKey = Apg.getMasterKey(mKeyRing);
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(mKeyRing.getSecretKeys())) {
keys.add(key);
}
}
if (masterKey != null) {
for (String userId : new IterableIterator<String>(masterKey.getUserIDs())) {
userIds.add(userId);
}
}
}
// Catch Intents opened from other apps // Catch Intents opened from other apps
mIntent = getIntent(); mIntent = getIntent();
if (Apg.Intent.EDIT_KEY.equals(mIntent.getAction())) { Bundle extras = mIntent.getExtras();
Bundle extras = mIntent.getExtras(); if (Apg.Intent.CREATE_KEY.equals(mIntent.getAction())) {
if (extras == null) {
extras = new Bundle(); mActionBar.setTitle(R.string.title_createKey);
mCurrentPassPhrase = "";
if (extras != null) {
// disable home button on actionbar because this activity is run from another app
mActionBar.setDisplayShowTitleEnabled(true);
mActionBar.setDisplayHomeAsUpEnabled(false);
mActionBar.setHomeButtonEnabled(false);
// if userId is given, prefill the fields
if (extras.containsKey(Apg.EXTRA_USER_IDS)) {
Log.d(Constants.TAG, "UserIds are given!");
userIds.add(extras.getString(Apg.EXTRA_USER_IDS));
}
// if no passphrase is given
if (extras.containsKey(Apg.EXTRA_NO_PASSPHRASE)) {
boolean noPassphrase = extras.getBoolean(Apg.EXTRA_NO_PASSPHRASE);
if (noPassphrase) {
// check "no passphrase" checkbox and remove button
mNoPassphrase.setChecked(true);
mChangePassPhrase.setVisibility(View.GONE);
}
}
// generate key
if (extras.containsKey(Apg.EXTRA_GENERATE_DEFAULT_KEYS)) {
boolean generateDefaultKeys = extras
.getBoolean(Apg.EXTRA_GENERATE_DEFAULT_KEYS);
if (generateDefaultKeys) {
// generate a RSA 2048 key for encryption and signing!
try {
PGPSecretKey masterKey = Apg.createKey(this, Id.choice.algorithm.rsa,
2048, mCurrentPassPhrase, null);
// add new masterKey to keys array, which is then added to view
keys.add(masterKey);
keysUsages.add(Id.choice.usage.sign_only);
PGPSecretKey subKey = Apg.createKey(this, Id.choice.algorithm.rsa,
2048, mCurrentPassPhrase, masterKey);
keys.add(subKey);
keysUsages.add(Id.choice.usage.encrypt_only);
// define usage of this key
} catch (Exception e) {
Log.e(Constants.TAG, "Creating initial key failed: +" + e);
}
}
}
}
} else if (Apg.Intent.EDIT_KEY.equals(mIntent.getAction())) {
mActionBar.setTitle(R.string.title_editKey);
mCurrentPassPhrase = Apg.getEditPassPhrase();
if (mCurrentPassPhrase == null) {
mCurrentPassPhrase = "";
} }
// disable home button on actionbar because this activity is run from another app if (mCurrentPassPhrase.equals("")) {
final ActionBar actionBar = getSupportActionBar(); // check "no passphrase" checkbox and remove button
actionBar.setDisplayShowTitleEnabled(true); mNoPassphrase.setChecked(true);
actionBar.setDisplayHomeAsUpEnabled(false); mChangePassPhrase.setVisibility(View.GONE);
actionBar.setHomeButtonEnabled(false);
// if userId is given, prefill the fields
if (extras.containsKey(Apg.EXTRA_USER_IDS)) {
userIds.add(extras.getString(Apg.EXTRA_USER_IDS));
} }
// if userId is given, prefill the fields if (extras != null) {
if (extras.containsKey(Apg.EXTRA_NO_PASSPHRASE)) {
boolean noPassphrase = extras.getBoolean(Apg.EXTRA_NO_PASSPHRASE); if (extras.containsKey(Apg.EXTRA_KEY_ID)) {
if (noPassphrase) { long keyId = mIntent.getExtras().getLong(Apg.EXTRA_KEY_ID);
mCurrentPassPhrase = "";
if (keyId != 0) {
PGPSecretKey masterKey = null;
mKeyRing = Apg.getSecretKeyRing(keyId);
if (mKeyRing != null) {
masterKey = Apg.getMasterKey(mKeyRing);
for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(
mKeyRing.getSecretKeys())) {
keys.add(key);
keysUsages.add(-1); // get usage when view is created
}
}
if (masterKey != null) {
for (String userId : new IterableIterator<String>(
masterKey.getUserIDs())) {
userIds.add(userId);
}
}
}
} }
} }
} }
mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase);
mChangePassPhrase.setOnClickListener(new OnClickListener() { mChangePassPhrase.setOnClickListener(new OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
showDialog(Id.dialog.new_pass_phrase); showDialog(Id.dialog.new_pass_phrase);
@ -170,7 +234,6 @@ public class EditKeyActivity extends BaseActivity {
}); });
// disable passphrase when no passphrase checkobox is checked! // disable passphrase when no passphrase checkobox is checked!
mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase);
mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() { mNoPassphrase.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
@ -197,20 +260,9 @@ public class EditKeyActivity extends BaseActivity {
container.addView(mUserIds); container.addView(mUserIds);
mKeys = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false); mKeys = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
mKeys.setType(Id.type.key); mKeys.setType(Id.type.key);
mKeys.setKeys(keys); mKeys.setKeys(keys, keysUsages);
container.addView(mKeys); container.addView(mKeys);
mCurrentPassPhrase = Apg.getEditPassPhrase();
if (mCurrentPassPhrase == null) {
mCurrentPassPhrase = "";
}
if (mCurrentPassPhrase.equals("")) {
// check "no passphrase" checkbox and remove button
mNoPassphrase.setChecked(true);
mChangePassPhrase.setVisibility(View.GONE);
}
updatePassPhraseButtonText(); updatePassPhraseButtonText();
} }

View File

@ -164,13 +164,13 @@ public class SecretKeyListActivity extends KeyListActivity implements OnChildCli
private void createKey() { private void createKey() {
Apg.setEditPassPhrase(""); Apg.setEditPassPhrase("");
Intent intent = new Intent(this, EditKeyActivity.class); Intent intent = new Intent(Apg.Intent.CREATE_KEY);
startActivityForResult(intent, Id.message.create_key); startActivityForResult(intent, Id.message.create_key);
} }
private void editKey() { private void editKey() {
long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem); long keyId = ((KeyListAdapter) mList.getExpandableListAdapter()).getGroupId(mSelectedItem);
Intent intent = new Intent(this, EditKeyActivity.class); Intent intent = new Intent(Apg.Intent.EDIT_KEY);
intent.putExtra(Apg.EXTRA_KEY_ID, keyId); intent.putExtra(Apg.EXTRA_KEY_ID, keyId);
startActivityForResult(intent, Id.message.edit_key); startActivityForResult(intent, Id.message.edit_key);
} }

View File

@ -59,13 +59,12 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
Button mExpiryDateButton; Button mExpiryDateButton;
GregorianCalendar mExpiryDate; GregorianCalendar mExpiryDate;
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth); setExpiryDate(date);
setExpiryDate(date); }
} };
};
public KeyEditor(Context context) { public KeyEditor(Context context) {
super(context); super(context);
@ -86,16 +85,14 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
mExpiryDateButton = (Button) findViewById(R.id.expiry); mExpiryDateButton = (Button) findViewById(R.id.expiry);
mUsage = (Spinner) findViewById(R.id.usage); mUsage = (Spinner) findViewById(R.id.usage);
Choice choices[] = { Choice choices[] = {
new Choice(Id.choice.usage.sign_only, new Choice(Id.choice.usage.sign_only, getResources().getString(
getResources().getString(R.string.choice_signOnly)), R.string.choice_signOnly)),
new Choice(Id.choice.usage.encrypt_only, new Choice(Id.choice.usage.encrypt_only, getResources().getString(
getResources().getString(R.string.choice_encryptOnly)), R.string.choice_encryptOnly)),
new Choice(Id.choice.usage.sign_and_encrypt, new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString(
getResources().getString(R.string.choice_signAndEncrypt)), R.string.choice_signAndEncrypt)), };
}; ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
ArrayAdapter<Choice> adapter = android.R.layout.simple_spinner_item, choices);
new ArrayAdapter<Choice>(getContext(),
android.R.layout.simple_spinner_item, choices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mUsage.setAdapter(adapter); mUsage.setAdapter(adapter);
@ -111,15 +108,12 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
date = new GregorianCalendar(); date = new GregorianCalendar();
} }
DatePickerDialog dialog = DatePickerDialog dialog = new DatePickerDialog(getContext(),
new DatePickerDialog(getContext(), mExpiryDateSetListener, mExpiryDateSetListener, date.get(Calendar.YEAR), date.get(Calendar.MONTH),
date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_MONTH));
date.get(Calendar.MONTH),
date.get(Calendar.DAY_OF_MONTH));
dialog.setCancelable(true); dialog.setCancelable(true);
dialog.setButton(Dialog.BUTTON_NEGATIVE, dialog.setButton(Dialog.BUTTON_NEGATIVE, getContext()
getContext().getString(R.string.btn_noDate), .getString(R.string.btn_noDate), new DialogInterface.OnClickListener() {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
setExpiryDate(null); setExpiryDate(null);
} }
@ -131,7 +125,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
super.onFinishInflate(); super.onFinishInflate();
} }
public void setValue(PGPSecretKey key, boolean isMasterKey) { public void setValue(PGPSecretKey key, boolean isMasterKey, int usage) {
mKey = key; mKey = key;
mIsMasterKey = isMasterKey; mIsMasterKey = isMasterKey;
@ -147,24 +141,24 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
Vector<Choice> choices = new Vector<Choice>(); Vector<Choice> choices = new Vector<Choice>();
boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT); boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT);
if (!isElGamalKey) { if (!isElGamalKey) {
choices.add(new Choice(Id.choice.usage.sign_only, choices.add(new Choice(Id.choice.usage.sign_only, getResources().getString(
getResources().getString(R.string.choice_signOnly))); R.string.choice_signOnly)));
} }
if (!mIsMasterKey) { if (!mIsMasterKey) {
choices.add(new Choice(Id.choice.usage.encrypt_only, choices.add(new Choice(Id.choice.usage.encrypt_only, getResources().getString(
getResources().getString(R.string.choice_encryptOnly))); R.string.choice_encryptOnly)));
} }
if (!isElGamalKey) { if (!isElGamalKey) {
choices.add(new Choice(Id.choice.usage.sign_and_encrypt, choices.add(new Choice(Id.choice.usage.sign_and_encrypt, getResources().getString(
getResources().getString(R.string.choice_signAndEncrypt))); R.string.choice_signAndEncrypt)));
} }
ArrayAdapter<Choice> adapter = ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
new ArrayAdapter<Choice>(getContext(), android.R.layout.simple_spinner_item, choices);
android.R.layout.simple_spinner_item, choices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mUsage.setAdapter(adapter); mUsage.setAdapter(adapter);
// Set value in choice dropdown to key
int selectId = 0; int selectId = 0;
if (Apg.isEncryptionKey(key)) { if (Apg.isEncryptionKey(key)) {
if (Apg.isSigningKey(key)) { if (Apg.isSigningKey(key)) {
@ -173,7 +167,13 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
selectId = Id.choice.usage.encrypt_only; selectId = Id.choice.usage.encrypt_only;
} }
} else { } else {
selectId = Id.choice.usage.sign_only; // set usage if it is predefined
if (usage != -1) {
selectId = usage;
} else {
selectId = Id.choice.usage.sign_only;
}
} }
for (int i = 0; i < choices.size(); ++i) { for (int i = 0; i < choices.size(); ++i) {
@ -194,6 +194,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
cal.setTime(Apg.getExpiryDate(key)); cal.setTime(Apg.getExpiryDate(key));
setExpiryDate(cal); setExpiryDate(cal);
} }
} }
public PGPSecretKey getValue() { public PGPSecretKey getValue() {
@ -201,7 +202,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
} }
public void onClick(View v) { public void onClick(View v) {
final ViewGroup parent = (ViewGroup)getParent(); final ViewGroup parent = (ViewGroup) getParent();
if (v == mDeleteButton) { if (v == mDeleteButton) {
parent.removeView(this); parent.removeView(this);
if (mEditorListener != null) { if (mEditorListener != null) {
@ -230,4 +231,5 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
public int getUsage() { public int getUsage() {
return ((Choice) mUsage.getSelectedItem()).getId(); return ((Choice) mUsage.getSelectedItem()).getId();
} }
} }

View File

@ -93,7 +93,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
mEditors, false); mEditors, false);
view.setEditorListener(SectionView.this); view.setEditorListener(SectionView.this);
boolean isMasterKey = (mEditors.getChildCount() == 0); boolean isMasterKey = (mEditors.getChildCount() == 0);
view.setValue(mNewKey, isMasterKey); view.setValue(mNewKey, isMasterKey, -1);
mEditors.addView(view); mEditors.addView(view);
SectionView.this.updateEditorsVisible(); SectionView.this.updateEditorsVisible();
} }
@ -260,42 +260,26 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
this.updateEditorsVisible(); this.updateEditorsVisible();
} }
public void setKeys(Vector<PGPSecretKey> list) { public void setKeys(Vector<PGPSecretKey> list, Vector<Integer> usages) {
if (mType != Id.type.key) { if (mType != Id.type.key) {
return; return;
} }
mEditors.removeAllViews(); mEditors.removeAllViews();
for (PGPSecretKey key : list) {
// go through all keys and set view based on them
for (int i = 0; i < list.size(); i++) {
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors, KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors,
false); false);
view.setEditorListener(this); view.setEditorListener(this);
boolean isMasterKey = (mEditors.getChildCount() == 0); boolean isMasterKey = (mEditors.getChildCount() == 0);
view.setValue(key, isMasterKey); view.setValue(list.get(i), isMasterKey, usages.get(i));
mEditors.addView(view); mEditors.addView(view);
} }
this.updateEditorsVisible(); this.updateEditorsVisible();
} }
// TODO !!!
public void createInitialKey() {
mEditors.removeAllViews();
// create initial key
// PGPSecretKey key = new PGPSecretKey();
// for (PGPSecretKey key : list) {
KeyEditor view = (KeyEditor) mInflater.inflate(R.layout.edit_key_key_item, mEditors, false);
view.setEditorListener(this);
boolean isMasterKey = (mEditors.getChildCount() == 0);
// view.setValue(key, isMasterKey);
mEditors.addView(view);
// }
this.updateEditorsVisible();
}
private void createKey() { private void createKey() {
mProgressDialog = new ProgressDialog(getContext()); mProgressDialog = new ProgressDialog(getContext());
mProgressDialog.setMessage(getContext().getString(R.string.progress_generating)); mProgressDialog.setMessage(getContext().getString(R.string.progress_generating));

View File

@ -0,0 +1,6 @@
package org.apg.util;
public class Constants {
public static final String TAG = "APG";
}

View File

@ -56,7 +56,7 @@ public class IntentDemoActivity extends Activity {
public void intentDemoCreateNewKeyOnClick(View view) { public void intentDemoCreateNewKeyOnClick(View view) {
// mApgIntentHelper.createNewKey(); // mApgIntentHelper.createNewKey();
mApgIntentHelper.createNewKey("dom <+491716581452@cryptocall.org>"); mApgIntentHelper.createNewKey("test <+491716581452@cryptocall.org>", true, true);
} }
public void intentDemoSelectSecretKeyOnClick(View view) { public void intentDemoSelectSecretKeyOnClick(View view) {

View File

@ -26,6 +26,7 @@ import android.content.ContentUris;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
public class ApgIntentHelper { public class ApgIntentHelper {
@ -42,14 +43,17 @@ public class ApgIntentHelper {
* value to specify prefilled values for user that should be created * value to specify prefilled values for user that should be created
* @return true when activity was found and executed successfully * @return true when activity was found and executed successfully
*/ */
public boolean createNewKey(String userIds) { public boolean createNewKey(String userIds, boolean noPassphrase, boolean generateDefaultKeys) {
Intent intent = new Intent(Constants.Intent.EDIT_KEY); Intent intent = new Intent(Constants.Intent.CREATE_KEY);
if (userIds != null) { if (userIds != null) {
intent.putExtra(Constants.EXTRA_USER_IDS, userIds); intent.putExtra(Constants.EXTRA_USER_IDS, userIds);
} }
intent.putExtra(Constants.EXTRA_NO_PASSPHRASE, noPassphrase);
intent.putExtra(Constants.EXTRA_GENERATE_DEFAULT_KEYS, generateDefaultKeys);
intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION); intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION);
try { try {
activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY); activity.startActivityForResult(intent, Constants.CREATE_KEY);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -63,7 +67,7 @@ public class ApgIntentHelper {
* @return true when activity was found and executed successfully * @return true when activity was found and executed successfully
*/ */
public boolean createNewKey() { public boolean createNewKey() {
return createNewKey(null); return createNewKey(null, false, false);
} }
/** /**
@ -77,7 +81,7 @@ public class ApgIntentHelper {
intent.putExtra(Constants.EXTRA_KEY_ID, keyId); intent.putExtra(Constants.EXTRA_KEY_ID, keyId);
intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION); intent.putExtra(Constants.EXTRA_INTENT_VERSION, Constants.INTENT_VERSION);
try { try {
activity.startActivityForResult(intent, Constants.CREATE_NEW_KEY); activity.startActivityForResult(intent, Constants.EDIT_KEY);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();

View File

@ -36,20 +36,19 @@ public class Constants {
public static final Uri CONTENT_URI_PUBLIC_KEY_RING_BY_EMAILS = Uri.parse("content://" public static final Uri CONTENT_URI_PUBLIC_KEY_RING_BY_EMAILS = Uri.parse("content://"
+ AUTHORITY + "/key_rings/public/emails/"); + AUTHORITY + "/key_rings/public/emails/");
public static final String APG_INTENT_PREFIX = "org.apg.intent.";
public static class Intent { public static class Intent {
public static final String DECRYPT = APG_PACKAGE_NAME + ".intent.DECRYPT"; public static final String DECRYPT = APG_INTENT_PREFIX + "DECRYPT";
public static final String ENCRYPT = APG_PACKAGE_NAME + ".intent.ENCRYPT"; public static final String ENCRYPT = APG_INTENT_PREFIX + "ENCRYPT";
public static final String DECRYPT_FILE = APG_PACKAGE_NAME + ".intent.DECRYPT_FILE"; public static final String DECRYPT_FILE = APG_INTENT_PREFIX + "DECRYPT_FILE";
public static final String ENCRYPT_FILE = APG_PACKAGE_NAME + ".intent.ENCRYPT_FILE"; public static final String ENCRYPT_FILE = APG_INTENT_PREFIX + "ENCRYPT_FILE";
public static final String DECRYPT_AND_RETURN = APG_PACKAGE_NAME public static final String DECRYPT_AND_RETURN = APG_INTENT_PREFIX + "DECRYPT_AND_RETURN";
+ ".intent.DECRYPT_AND_RETURN"; public static final String ENCRYPT_AND_RETURN = APG_INTENT_PREFIX + "ENCRYPT_AND_RETURN";
public static final String ENCRYPT_AND_RETURN = APG_PACKAGE_NAME public static final String SELECT_PUBLIC_KEYS = APG_INTENT_PREFIX + "SELECT_PUBLIC_KEYS";
+ ".intent.ENCRYPT_AND_RETURN"; public static final String SELECT_SECRET_KEY = APG_INTENT_PREFIX + "SELECT_SECRET_KEY";
public static final String SELECT_PUBLIC_KEYS = APG_PACKAGE_NAME public static final String CREATE_KEY = APG_INTENT_PREFIX + "CREATE_KEY";
+ ".intent.SELECT_PUBLIC_KEYS"; public static final String EDIT_KEY = APG_INTENT_PREFIX + "EDIT_KEY";
public static final String SELECT_SECRET_KEY = APG_PACKAGE_NAME
+ ".intent.SELECT_SECRET_KEY";
public static final String EDIT_KEY = APG_PACKAGE_NAME + ".intent.EDIT_KEY";
} }
public static final String EXTRA_TEXT = "text"; public static final String EXTRA_TEXT = "text";
@ -68,6 +67,8 @@ public class Constants {
public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds"; public static final String EXTRA_ENCRYPTION_KEY_IDS = "encryptionKeyIds";
public static final String EXTRA_SELECTION = "selection"; public static final String EXTRA_SELECTION = "selection";
public static final String EXTRA_MESSAGE = "message"; public static final String EXTRA_MESSAGE = "message";
public static final String EXTRA_NO_PASSPHRASE = "noPassphrase";
public static final String EXTRA_GENERATE_DEFAULT_KEYS = "generateDefaultKeys";
public static final String EXTRA_INTENT_VERSION = "intentVersion"; public static final String EXTRA_INTENT_VERSION = "intentVersion";
public static final String INTENT_VERSION = "1"; public static final String INTENT_VERSION = "1";
@ -76,7 +77,9 @@ public class Constants {
public static final int ENCRYPT_MESSAGE = 0x21070002; public static final int ENCRYPT_MESSAGE = 0x21070002;
public static final int SELECT_PUBLIC_KEYS = 0x21070003; public static final int SELECT_PUBLIC_KEYS = 0x21070003;
public static final int SELECT_SECRET_KEY = 0x21070004; public static final int SELECT_SECRET_KEY = 0x21070004;
public static final int CREATE_NEW_KEY = 0x21070005; public static final int CREATE_KEY = 0x21070005;
public static final int EDIT_KEY = 0x21070006;
// public static Pattern PGP_MESSAGE = Pattern.compile( // public static Pattern PGP_MESSAGE = Pattern.compile(
// ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); // ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL);