mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-14 14:10:28 -05:00
Simple create key
This commit is contained in:
parent
c1c831e52b
commit
57f5a788fd
@ -17,8 +17,12 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
@ -29,8 +33,13 @@ import android.widget.AutoCompleteTextView;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.ContactHelper;
|
import org.sufficientlysecure.keychain.helper.ContactHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
@ -97,20 +106,65 @@ public class CreateKeyActivity extends ActionBarActivity {
|
|||||||
createButton.setOnClickListener(new View.OnClickListener() {
|
createButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
createKey();
|
createKeyCheck();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createKey() {
|
private void createKeyCheck() {
|
||||||
if (isEditTextNotEmpty(this, nameEdit)
|
if (isEditTextNotEmpty(this, nameEdit)
|
||||||
&& isEditTextNotEmpty(this, emailEdit)
|
&& isEditTextNotEmpty(this, emailEdit)
|
||||||
&& isEditTextNotEmpty(this, passphraseEdit)) {
|
&& isEditTextNotEmpty(this, passphraseEdit)) {
|
||||||
|
createKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createKey() {
|
||||||
|
Intent intent = new Intent(this, KeychainIntentService.class);
|
||||||
|
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
|
||||||
|
|
||||||
|
// Message is received after importing is done in KeychainIntentService
|
||||||
|
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
||||||
|
this,
|
||||||
|
getString(R.string.progress_importing),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL) {
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
|
super.handleMessage(message);
|
||||||
|
|
||||||
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
|
CreateKeyActivity.this.finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// fill values for this action
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
|
||||||
|
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
||||||
|
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.CERTIFY_OTHER, null));
|
||||||
|
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.SIGN_DATA, null));
|
||||||
|
parcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(Constants.choice.algorithm.rsa, 4096, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, null));
|
||||||
|
String userId = nameEdit.getText().toString() + " <" + emailEdit.getText().toString() + ">";
|
||||||
|
parcel.mAddUserIds.add(userId);
|
||||||
|
parcel.
|
||||||
|
parcel.mNewPassphrase = passphraseEdit.getText().toString();
|
||||||
|
|
||||||
|
// get selected key entries
|
||||||
|
data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel);
|
||||||
|
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
saveHandler.showProgressDialog(this);
|
||||||
|
|
||||||
|
startService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if text of given EditText is not empty. If it is empty an error is
|
* Checks if text of given EditText is not empty. If it is empty an error is
|
||||||
* set and the EditText gets the focus.
|
* set and the EditText gets the focus.
|
||||||
|
@ -93,10 +93,6 @@ public class KeyListActivity extends DrawerActivity {
|
|||||||
createKey();
|
createKey();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case R.id.menu_key_list_create_expert:
|
|
||||||
createKeyExpert();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.menu_key_list_export:
|
case R.id.menu_key_list_export:
|
||||||
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
|
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
|
||||||
return true;
|
return true;
|
||||||
@ -143,43 +139,4 @@ public class KeyListActivity extends DrawerActivity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createKeyExpert() {
|
|
||||||
Intent intent = new Intent(this, KeychainIntentService.class);
|
|
||||||
intent.setAction(KeychainIntentService.ACTION_SAVE_KEYRING);
|
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainIntentService
|
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
|
||||||
this,
|
|
||||||
getString(R.string.progress_importing),
|
|
||||||
ProgressDialog.STYLE_HORIZONTAL) {
|
|
||||||
public void handleMessage(Message message) {
|
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
|
||||||
super.handleMessage(message);
|
|
||||||
Bundle data = message.getData();
|
|
||||||
// OtherHelper.logDebugBundle(data, "message reply");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// fill values for this action
|
|
||||||
Bundle data = new Bundle();
|
|
||||||
|
|
||||||
SaveKeyringParcel parcel = new SaveKeyringParcel();
|
|
||||||
parcel.mAddSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.CERTIFY_OTHER, null));
|
|
||||||
parcel.mAddSubKeys.add(new SubkeyAdd(algorithm.rsa, 1024, KeyFlags.SIGN_DATA, null));
|
|
||||||
parcel.mAddUserIds.add("swagerinho");
|
|
||||||
parcel.mNewPassphrase = "swag";
|
|
||||||
|
|
||||||
// get selected key entries
|
|
||||||
data.putParcelable(KeychainIntentService.SAVE_KEYRING_PARCEL, parcel);
|
|
||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
|
||||||
Messenger messenger = new Messenger(saveHandler);
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
|
||||||
|
|
||||||
saveHandler.showProgressDialog(this);
|
|
||||||
|
|
||||||
startService(intent);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -26,11 +26,6 @@
|
|||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
android:title="@string/menu_create_key" />
|
android:title="@string/menu_create_key" />
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_key_list_create_expert"
|
|
||||||
app:showAsAction="never"
|
|
||||||
android:title="@string/menu_create_key_expert" />
|
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_key_list_debug_read"
|
android:id="@+id/menu_key_list_debug_read"
|
||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
|
Loading…
Reference in New Issue
Block a user