Fail on unknown key ids on API, Key item design consistency for API

This commit is contained in:
Dominik Schürmann 2014-10-26 00:18:45 +02:00
parent e4391c282d
commit 94693efbe5
4 changed files with 19 additions and 3 deletions

View File

@ -80,6 +80,7 @@ public class PgpSignEncrypt extends BaseOperation {
private long mAdditionalEncryptId; private long mAdditionalEncryptId;
private boolean mCleartextInput; private boolean mCleartextInput;
private String mOriginalFilename; private String mOriginalFilename;
private boolean mFailOnMissingEncryptionKeyIds;
private byte[] mNfcSignedHash = null; private byte[] mNfcSignedHash = null;
private Date mNfcCreationTimestamp = null; private Date mNfcCreationTimestamp = null;
@ -116,6 +117,7 @@ public class PgpSignEncrypt extends BaseOperation {
this.mNfcSignedHash = builder.mNfcSignedHash; this.mNfcSignedHash = builder.mNfcSignedHash;
this.mNfcCreationTimestamp = builder.mNfcCreationTimestamp; this.mNfcCreationTimestamp = builder.mNfcCreationTimestamp;
this.mOriginalFilename = builder.mOriginalFilename; this.mOriginalFilename = builder.mOriginalFilename;
this.mFailOnMissingEncryptionKeyIds = builder.mFailOnMissingEncryptionKeyIds;
} }
public static class Builder { public static class Builder {
@ -142,6 +144,7 @@ public class PgpSignEncrypt extends BaseOperation {
private String mOriginalFilename = ""; private String mOriginalFilename = "";
private byte[] mNfcSignedHash = null; private byte[] mNfcSignedHash = null;
private Date mNfcCreationTimestamp = null; private Date mNfcCreationTimestamp = null;
private boolean mFailOnMissingEncryptionKeyIds = false;
public Builder(Context context, ProviderHelper providerHelper, Progressable progressable, public Builder(Context context, ProviderHelper providerHelper, Progressable progressable,
InputData data, OutputStream outStream) { InputData data, OutputStream outStream) {
@ -203,6 +206,11 @@ public class PgpSignEncrypt extends BaseOperation {
return this; return this;
} }
public Builder setFailOnMissingEncryptionKeyIds(boolean failOnMissingEncryptionKeyIds) {
mFailOnMissingEncryptionKeyIds = failOnMissingEncryptionKeyIds;
return this;
}
/** /**
* Also encrypt with the signing keyring * Also encrypt with the signing keyring
* *
@ -380,9 +388,15 @@ public class PgpSignEncrypt extends BaseOperation {
} catch (PgpKeyNotFoundException e) { } catch (PgpKeyNotFoundException e) {
log.add(LogType.MSG_SE_KEY_WARN, indent + 1, log.add(LogType.MSG_SE_KEY_WARN, indent + 1,
KeyFormattingUtils.convertKeyIdToHex(id)); KeyFormattingUtils.convertKeyIdToHex(id));
if (mFailOnMissingEncryptionKeyIds) {
return new SignEncryptResult(SignEncryptResult.RESULT_ERROR, log);
}
} catch (ProviderHelper.NotFoundException e) { } catch (ProviderHelper.NotFoundException e) {
log.add(LogType.MSG_SE_KEY_UNKNOWN, indent + 1, log.add(LogType.MSG_SE_KEY_UNKNOWN, indent + 1,
KeyFormattingUtils.convertKeyIdToHex(id)); KeyFormattingUtils.convertKeyIdToHex(id));
if (mFailOnMissingEncryptionKeyIds) {
return new SignEncryptResult(SignEncryptResult.RESULT_ERROR, log);
}
} }
} }
} }

View File

@ -379,6 +379,7 @@ public class OpenPgpService extends RemoteService {
.setCompressionId(accSettings.getCompression()) .setCompressionId(accSettings.getCompression())
.setSymmetricEncryptionAlgorithm(accSettings.getEncryptionAlgorithm()) .setSymmetricEncryptionAlgorithm(accSettings.getEncryptionAlgorithm())
.setEncryptionMasterKeyIds(keyIds) .setEncryptionMasterKeyIds(keyIds)
.setFailOnMissingEncryptionKeyIds(true)
.setOriginalFilename(originalFilename) .setOriginalFilename(originalFilename)
.setAdditionalEncryptId(accSettings.getKeyId()); // add acc key for encryption .setAdditionalEncryptId(accSettings.getKeyId()); // add acc key for encryption

View File

@ -384,7 +384,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_VERIFIED); KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_VERIFIED);
enabled = true; enabled = true;
} else { } else {
h.statusIcon.setVisibility(View.GONE); h.statusIcon.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_UNVERIFIED);
enabled = true; enabled = true;
} }
} }

View File

@ -133,11 +133,11 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
boolean enabled; boolean enabled;
if (cursor.getInt(mIndexIsRevoked) != 0) { if (cursor.getInt(mIndexIsRevoked) != 0) {
h.statusIcon.setVisibility(View.VISIBLE); h.statusIcon.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_REVOKED); KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, KeyFormattingUtils.STATE_REVOKED, true);
enabled = false; enabled = false;
} else if (cursor.getInt(mIndexIsExpiry) != 0) { } else if (cursor.getInt(mIndexIsExpiry) != 0) {
h.statusIcon.setVisibility(View.VISIBLE); h.statusIcon.setVisibility(View.VISIBLE);
KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, KeyFormattingUtils.STATE_EXPIRED); KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, KeyFormattingUtils.STATE_EXPIRED, true);
enabled = false; enabled = false;
} else { } else {
h.statusIcon.setVisibility(View.GONE); h.statusIcon.setVisibility(View.GONE);