save flags from checkboxes

This commit is contained in:
Ashley Hughes 2014-02-03 01:15:29 +00:00
parent fd308a671d
commit 089a70fe32
2 changed files with 18 additions and 30 deletions

View File

@ -237,8 +237,8 @@ public class PgpKeyOperation {
updateProgress(R.string.progress_preparing_master_key, 10, 100);
int usageId = keysUsages.get(0);
boolean canSign = (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
boolean canEncrypt = (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
boolean canSign = (usageId & KeyFlags.SIGN_DATA) > 0;
boolean canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0;
String mainUserId = userIds.get(0);
@ -287,11 +287,7 @@ public class PgpKeyOperation {
PGPSignatureSubpacketGenerator hashedPacketsGen = new PGPSignatureSubpacketGenerator();
PGPSignatureSubpacketGenerator unhashedPacketsGen = new PGPSignatureSubpacketGenerator();
int keyFlags = KeyFlags.CERTIFY_OTHER | KeyFlags.SIGN_DATA;
if (canEncrypt) {
keyFlags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
}
hashedPacketsGen.setKeyFlags(true, keyFlags);
hashedPacketsGen.setKeyFlags(true, usageId);
hashedPacketsGen.setPreferredSymmetricAlgorithms(true, PREFERRED_SYMMETRIC_ALGORITHMS);
hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS);
@ -349,14 +345,11 @@ public class PgpKeyOperation {
hashedPacketsGen = new PGPSignatureSubpacketGenerator();
unhashedPacketsGen = new PGPSignatureSubpacketGenerator();
keyFlags = 0;
usageId = keysUsages.get(i);
canSign = (usageId == Id.choice.usage.sign_only || usageId == Id.choice.usage.sign_and_encrypt);
canEncrypt = (usageId == Id.choice.usage.encrypt_only || usageId == Id.choice.usage.sign_and_encrypt);
canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this
canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0;
if (canSign) {
Date todayDate = new Date(); //both sig times the same
keyFlags |= KeyFlags.SIGN_DATA;
// cross-certify signing keys
hashedPacketsGen.setSignatureCreationTime(false, todayDate); //set outer creation time
PGPSignatureSubpacketGenerator subHashedPacketsGen = new PGPSignatureSubpacketGenerator();
@ -371,10 +364,7 @@ public class PgpKeyOperation {
subPublicKey);
unhashedPacketsGen.setEmbeddedSignature(false, certification);
}
if (canEncrypt) {
keyFlags |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
}
hashedPacketsGen.setKeyFlags(false, keyFlags);
hashedPacketsGen.setKeyFlags(false, usageId);
if (keysExpiryDates.get(i) != null) {
GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

View File

@ -23,6 +23,7 @@ import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Vector;
import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPSecretKey;
import org.sufficientlysecure.keychain.Id;
@ -183,12 +184,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
mLabelUsage2.setVisibility(View.INVISIBLE);
}
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getContext(),
android.R.layout.simple_spinner_item, choices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//mUsage.setAdapter(adapter);
// Set value in choice dropdown to key
int selectId = 0;
if (key.isMasterKey())
mChkCertify.setChecked(PgpKeyHelper.isCertificationKey(key));
@ -197,13 +192,6 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
mChkAuthenticate.setChecked(PgpKeyHelper.isAuthenticationKey(key));
// TODO: use usage argument?
for (int i = 0; i < choices.size(); ++i) {
if (choices.get(i).getId() == selectId) {
//mUsage.setSelection(i);
break;
}
}
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
cal.setTime(PgpKeyHelper.getCreationDate(key));
mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime()));
@ -250,7 +238,17 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
}
public int getUsage() {
return 1; //((Choice) mUsage.getSelectedItem()).getId();
int result = 0; // TODO: preserve other flags
if (mChkCertify.isChecked())
result |= KeyFlags.CERTIFY_OTHER;
if (mChkSign.isChecked()) //TODO: fix what happens when we remove sign flag from master - should still be able to certify
result |= KeyFlags.SIGN_DATA;
if (mChkEncrypt.isChecked())
result |= KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE;
if (mChkAuthenticate.isChecked())
result |= KeyFlags.AUTHENTICATION;
return result;
}
}