mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-17 07:30:14 -05:00
change how new default keys are passed back, fix showing their usage flags
This commit is contained in:
parent
bb2fb786a8
commit
47b23a90d5
@ -26,6 +26,7 @@ import android.os.Message;
|
|||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
|
import org.spongycastle.bcpg.sig.KeyFlags;
|
||||||
import org.spongycastle.openpgp.*;
|
import org.spongycastle.openpgp.*;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.Id;
|
import org.sufficientlysecure.keychain.Id;
|
||||||
@ -145,7 +146,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
*/
|
*/
|
||||||
// keys
|
// keys
|
||||||
public static final String RESULT_NEW_KEY = "new_key";
|
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
|
// encrypt
|
||||||
public static final String RESULT_SIGNATURE_BYTES = "signature_data";
|
public static final String RESULT_SIGNATURE_BYTES = "signature_data";
|
||||||
@ -563,6 +564,8 @@ public class KeychainIntentService extends IntentService
|
|||||||
try {
|
try {
|
||||||
/* Input */
|
/* Input */
|
||||||
String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
|
String passphrase = data.getString(GENERATE_KEY_SYMMETRIC_PASSPHRASE);
|
||||||
|
ArrayList<PGPSecretKey> newKeys = new ArrayList<PGPSecretKey>();
|
||||||
|
ArrayList<Integer> keyUsageList = new ArrayList<Integer>();
|
||||||
|
|
||||||
/* Operation */
|
/* Operation */
|
||||||
int keysTotal = 2;
|
int keysTotal = 2;
|
||||||
@ -576,11 +579,15 @@ public class KeychainIntentService extends IntentService
|
|||||||
|
|
||||||
PGPSecretKey masterKey = keyOperations.createKey(Id.choice.algorithm.rsa,
|
PGPSecretKey masterKey = keyOperations.createKey(Id.choice.algorithm.rsa,
|
||||||
4096, passphrase, true);
|
4096, passphrase, true);
|
||||||
|
newKeys.add(masterKey);
|
||||||
|
keyUsageList.add(KeyFlags.CERTIFY_OTHER);
|
||||||
keysCreated++;
|
keysCreated++;
|
||||||
setProgress(keysCreated, keysTotal);
|
setProgress(keysCreated, keysTotal);
|
||||||
|
|
||||||
PGPSecretKey subKey = keyOperations.createKey(Id.choice.algorithm.rsa,
|
PGPSecretKey subKey = keyOperations.createKey(Id.choice.algorithm.rsa,
|
||||||
4096, passphrase, false);
|
4096, passphrase, false);
|
||||||
|
newKeys.add(subKey);
|
||||||
|
keyUsageList.add(KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
|
||||||
keysCreated++;
|
keysCreated++;
|
||||||
setProgress(keysCreated, keysTotal);
|
setProgress(keysCreated, keysTotal);
|
||||||
|
|
||||||
@ -588,11 +595,11 @@ public class KeychainIntentService extends IntentService
|
|||||||
// for sign
|
// for sign
|
||||||
|
|
||||||
/* Output */
|
/* Output */
|
||||||
|
|
||||||
Bundle resultData = new Bundle();
|
Bundle resultData = new Bundle();
|
||||||
resultData.putByteArray(RESULT_NEW_KEY,
|
resultData.putByteArray(RESULT_NEW_KEY,
|
||||||
PgpConversionHelper.PGPSecretKeyToBytes(masterKey));
|
PgpConversionHelper.PGPSecretKeyArrayListToBytes(newKeys));
|
||||||
resultData.putByteArray(RESULT_NEW_KEY2,
|
resultData.putIntegerArrayList(RESULT_KEY_USAGES, keyUsageList);
|
||||||
PgpConversionHelper.PGPSecretKeyToBytes(subKey));
|
|
||||||
|
|
||||||
OtherHelper.logDebugBundle(resultData, "resultData");
|
OtherHelper.logDebugBundle(resultData, "resultData");
|
||||||
|
|
||||||
|
@ -235,22 +235,20 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
|
|||||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
// get new key from data bundle returned from service
|
// get new key from data bundle returned from service
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
PGPSecretKey masterKey = PgpConversionHelper
|
|
||||||
.BytesToPGPSecretKey(data
|
ArrayList<PGPSecretKey> newKeys =
|
||||||
|
PgpConversionHelper.BytesToPGPSecretKeyList(data
|
||||||
.getByteArray(KeychainIntentService.RESULT_NEW_KEY));
|
.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
|
ArrayList<Integer> keyUsageFlags = data.getIntegerArrayList(
|
||||||
//key pair. Because we are not generating hashed packets there...
|
KeychainIntentService.RESULT_KEY_USAGES);
|
||||||
// add master key
|
|
||||||
mKeys.add(masterKey);
|
|
||||||
mKeysUsages.add(KeyFlags.CERTIFY_OTHER);
|
|
||||||
|
|
||||||
// add sub key
|
if (newKeys.size() == keyUsageFlags.size()) {
|
||||||
mKeys.add(subKey);
|
for (int i = 0; i < newKeys.size(); ++i) {
|
||||||
mKeysUsages.add(KeyFlags.ENCRYPT_COMMS + KeyFlags.ENCRYPT_STORAGE);
|
mKeys.add(newKeys.get(i));
|
||||||
|
mKeysUsages.add(keyUsageFlags.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buildLayout(true);
|
buildLayout(true);
|
||||||
}
|
}
|
||||||
|
@ -252,11 +252,11 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
|||||||
mIsNewKey = isNewKey;
|
mIsNewKey = isNewKey;
|
||||||
if (isNewKey) {
|
if (isNewKey) {
|
||||||
mUsage = usage;
|
mUsage = usage;
|
||||||
mChkCertify.setChecked((usage &= KeyFlags.CERTIFY_OTHER) == KeyFlags.CERTIFY_OTHER);
|
mChkCertify.setChecked((usage & KeyFlags.CERTIFY_OTHER) == KeyFlags.CERTIFY_OTHER);
|
||||||
mChkSign.setChecked((usage &= KeyFlags.SIGN_DATA) == KeyFlags.SIGN_DATA);
|
mChkSign.setChecked((usage & KeyFlags.SIGN_DATA) == KeyFlags.SIGN_DATA);
|
||||||
mChkEncrypt.setChecked(((usage &= KeyFlags.ENCRYPT_COMMS) == KeyFlags.ENCRYPT_COMMS) ||
|
mChkEncrypt.setChecked(((usage & KeyFlags.ENCRYPT_COMMS) == KeyFlags.ENCRYPT_COMMS) ||
|
||||||
((usage &= KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE));
|
((usage & KeyFlags.ENCRYPT_STORAGE) == KeyFlags.ENCRYPT_STORAGE));
|
||||||
mChkAuthenticate.setChecked((usage &= KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
|
mChkAuthenticate.setChecked((usage & KeyFlags.AUTHENTICATION) == KeyFlags.AUTHENTICATION);
|
||||||
} else {
|
} else {
|
||||||
mUsage = PgpKeyHelper.getKeyUsage(key);
|
mUsage = PgpKeyHelper.getKeyUsage(key);
|
||||||
mOriginalUsage = mUsage;
|
mOriginalUsage = mUsage;
|
||||||
|
Loading…
Reference in New Issue
Block a user