aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-04-01 13:31:57 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2014-04-01 13:31:57 +0200
commitb020f950e149368bd1d6413b2644b4c0e6f4bf31 (patch)
tree2542126973c12f78864bf57b9c06461e7fcc6a6b /OpenPGP-Keychain/src
parent6a617e0bf85ba6e7a3616b3942a143aae2ac87c1 (diff)
parent9283205ea8a0dfb57320ec0387bc9c9f89f03dc2 (diff)
downloadopen-keychain-b020f950e149368bd1d6413b2644b4c0e6f4bf31.tar.gz
open-keychain-b020f950e149368bd1d6413b2644b4c0e6f4bf31.tar.bz2
open-keychain-b020f950e149368bd1d6413b2644b4c0e6f4bf31.zip
Merge branch 'master' of github.com:openpgp-keychain/openpgp-keychain
Diffstat (limited to 'OpenPGP-Keychain/src')
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java24
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java31
-rw-r--r--OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java10
-rw-r--r--OpenPGP-Keychain/src/main/res/values/strings.xml1
4 files changed, 40 insertions, 26 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
index 7ac1747b7..f616f7300 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
@@ -26,6 +26,7 @@ import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
+import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.openpgp.*;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
@@ -145,7 +146,7 @@ public class KeychainIntentService extends IntentService
*/
// keys
public static final String RESULT_NEW_KEY = "new_key";
- public static final String RESULT_NEW_KEY2 = "new_key2";
+ public static final String RESULT_KEY_USAGES = "new_key_usages";
// encrypt
public static final String RESULT_SIGNATURE_BYTES = "signature_data";
@@ -563,9 +564,11 @@ public class KeychainIntentService extends IntentService
try {
/* Input */
String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
+ ArrayList<PGPSecretKey> newKeys = new ArrayList<PGPSecretKey>();
+ ArrayList<Integer> keyUsageList = new ArrayList<Integer>();
/* Operation */
- int keysTotal = 2;
+ int keysTotal = 3;
int keysCreated = 0;
setProgress(
getApplicationContext().getResources().
@@ -576,11 +579,22 @@ public class KeychainIntentService extends IntentService
PGPSecretKey masterKey = keyOperations.createKey(Id.choice.algorithm.rsa,
4096, passphrase, true);
+ newKeys.add(masterKey);
+ keyUsageList.add(KeyFlags.CERTIFY_OTHER);
keysCreated++;
setProgress(keysCreated, keysTotal);
PGPSecretKey subKey = keyOperations.createKey(Id.choice.algorithm.rsa,
4096, passphrase, false);
+ newKeys.add(subKey);
+ keyUsageList.add(KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
+ keysCreated++;
+ setProgress(keysCreated, keysTotal);
+
+ subKey = keyOperations.createKey(Id.choice.algorithm.rsa,
+ 4096, passphrase, false);
+ newKeys.add(subKey);
+ keyUsageList.add(KeyFlags.SIGN_DATA);
keysCreated++;
setProgress(keysCreated, keysTotal);
@@ -588,11 +602,11 @@ public class KeychainIntentService extends IntentService
// for sign
/* Output */
+
Bundle resultData = new Bundle();
resultData.putByteArray(RESULT_NEW_KEY,
- PgpConversionHelper.PGPSecretKeyToBytes(masterKey));
- resultData.putByteArray(RESULT_NEW_KEY2,
- PgpConversionHelper.PGPSecretKeyToBytes(subKey));
+ PgpConversionHelper.PGPSecretKeyArrayListToBytes(newKeys));
+ resultData.putIntegerArrayList(RESULT_KEY_USAGES, keyUsageList);
OtherHelper.logDebugBundle(resultData, "resultData");
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
index b7fffc7ff..9df84065f 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyActivity.java
@@ -42,6 +42,8 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.beardedhen.androidbootstrap.BootstrapButton;
+import com.devspark.appmsg.AppMsg;
+
import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.sufficientlysecure.keychain.Constants;
@@ -105,7 +107,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
private boolean mIsPassPhraseSet;
private boolean mNeedsSaving;
private boolean mIsBrandNewKeyring = false;
- private MenuItem mSaveButton;
private BootstrapButton mChangePassphrase;
@@ -235,22 +236,20 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
// get new key from data bundle returned from service
Bundle data = message.getData();
- PGPSecretKey masterKey = PgpConversionHelper
- .BytesToPGPSecretKey(data
+
+ ArrayList<PGPSecretKey> newKeys =
+ PgpConversionHelper.BytesToPGPSecretKeyList(data
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
- PGPSecretKey subKey = PgpConversionHelper
- .BytesToPGPSecretKey(data
- .getByteArray(KeychainIntentService.RESULT_NEW_KEY2));
- //We must set the key flags here as they are not set when we make the
- //key pair. Because we are not generating hashed packets there...
- // add master key
- mKeys.add(masterKey);
- mKeysUsages.add(KeyFlags.CERTIFY_OTHER);
+ ArrayList<Integer> keyUsageFlags = data.getIntegerArrayList(
+ KeychainIntentService.RESULT_KEY_USAGES);
- // add sub key
- mKeys.add(subKey);
- mKeysUsages.add(KeyFlags.ENCRYPT_COMMS + KeyFlags.ENCRYPT_STORAGE);
+ if (newKeys.size() == keyUsageFlags.size()) {
+ for (int i = 0; i < newKeys.size(); ++i) {
+ mKeys.add(newKeys.get(i));
+ mKeysUsages.add(keyUsageFlags.get(i));
+ }
+ }
buildLayout(true);
}
@@ -325,8 +324,6 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.key_edit, menu);
- mSaveButton = menu.findItem(R.id.menu_key_edit_save);
- mSaveButton.setEnabled(needsSaving());
//totally get rid of some actions for new keys
if (mDataUri == null) {
MenuItem mButton = menu.findItem(R.id.menu_key_edit_export_file);
@@ -571,6 +568,8 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
Toast.makeText(this, getString(R.string.error_message, e.getMessage()),
Toast.LENGTH_SHORT).show();
}
+ } else {
+ AppMsg.makeText(this, R.string.error_change_something_first, AppMsg.STYLE_ALERT).show();
}
}
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java
index 0dfc6dc5e..038f8507e 100644
--- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java
+++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeyEditor.java
@@ -252,11 +252,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
mIsNewKey = isNewKey;
if (isNewKey) {
mUsage = usage;
- mChkCertify.setChecked((usage &= KeyFlags.CERTIFY_OTHER) == KeyFlags.CERTIFY_OTHER);
- mChkSign.setChecked((usage &= KeyFlags.SIGN_DATA) == KeyFlags.SIGN_DATA);
- mChkEncrypt.setChecked(((usage &= KeyFlags.ENCRYPT_COMMS) == KeyFlags.ENCRYPT_COMMS) ||
- ((usage &= KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE));
- mChkAuthenticate.setChecked((usage &= KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
+ mChkCertify.setChecked((usage & KeyFlags.CERTIFY_OTHER) == KeyFlags.CERTIFY_OTHER);
+ mChkSign.setChecked((usage & KeyFlags.SIGN_DATA) == KeyFlags.SIGN_DATA);
+ mChkEncrypt.setChecked(((usage & KeyFlags.ENCRYPT_COMMS) == KeyFlags.ENCRYPT_COMMS) ||
+ ((usage & KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE));
+ mChkAuthenticate.setChecked((usage & KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
} else {
mUsage = PgpKeyHelper.getKeyUsage(key);
mOriginalUsage = mUsage;
diff --git a/OpenPGP-Keychain/src/main/res/values/strings.xml b/OpenPGP-Keychain/src/main/res/values/strings.xml
index 8ae43c8ea..bb6db01d8 100644
--- a/OpenPGP-Keychain/src/main/res/values/strings.xml
+++ b/OpenPGP-Keychain/src/main/res/values/strings.xml
@@ -325,6 +325,7 @@
<item quantity="one">part of the loaded file is a valid OpenPGP object but not a OpenPGP key</item>
<item quantity="other">parts of the loaded file are valid OpenPGP objects but not OpenPGP keys</item>
</plurals>
+ <string name="error_change_something_first">You must make changes to the keyring before you can save it</string>
<!-- progress dialogs, usually ending in '…' -->
<string name="progress_done">Done.</string>