Merge pull request #2384 from open-keychain/future-subkeys

Support future subkeys
This commit is contained in:
Vincent Breitmoser 2018-07-27 13:31:07 +02:00 committed by GitHub
commit 83f5f557f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 667 additions and 713 deletions

View File

@ -151,7 +151,7 @@ public class AndroidTestHelpers {
public static void cleanupForTests(Context context) throws Exception {
KeychainDatabase.getInstance(context).clearDatabase();
// KeychainDatabase.getInstance(context).clearDatabase();
// import these two, make sure they're there
importKeysFromResource(context, "x.sec.asc");

View File

@ -63,7 +63,7 @@ public class EditKeyTest {
public void test01Edit() throws Exception {
Activity activity = mActivity.getActivity();
KeychainDatabase.getInstance(activity).clearDatabase();
// KeychainDatabase.getInstance(activity).clearDatabase();
// import key for testing, get a stable initial state
importKeysFromResource(activity, "x.sec.asc");

View File

@ -34,9 +34,6 @@ import android.database.SQLException;
import android.database.sqlite.SQLiteException;
import org.sufficientlysecure.keychain.daos.LocalSecretKeyStorage;
import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColumns;
import org.sufficientlysecure.keychain.util.Preferences;
import timber.log.Timber;
@ -51,7 +48,7 @@ import timber.log.Timber;
*/
public class KeychainDatabase {
private static final String DATABASE_NAME = "openkeychain.db";
private static final int DATABASE_VERSION = 31;
private static final int DATABASE_VERSION = 32;
private final SupportSQLiteOpenHelper supportSQLiteOpenHelper;
private static KeychainDatabase sInstance;
@ -63,20 +60,6 @@ public class KeychainDatabase {
return sInstance;
}
public static KeychainDatabase getTemporaryInstance(Context context) {
return new KeychainDatabase(context.getApplicationContext());
}
public interface Tables {
String KEY_RINGS_PUBLIC = "keyrings_public";
String KEYS = "keys";
String KEY_SIGNATURES = "key_signatures";
String USER_PACKETS = "user_packets";
String CERTS = "certs";
String API_ALLOWED_KEYS = "api_allowed_keys";
String OVERRIDDEN_WARNINGS = "overridden_warnings";
}
private KeychainDatabase(Context context) {
supportSQLiteOpenHelper =
new FrameworkSQLiteOpenHelperFactory()
@ -119,6 +102,7 @@ public class KeychainDatabase {
return supportSQLiteOpenHelper.getWritableDatabase();
}
@SuppressWarnings("deprecation") // using some sqldelight constants
private void onCreate(SupportSQLiteDatabase db, Context context) {
Timber.w("Creating database...");
@ -136,13 +120,13 @@ public class KeychainDatabase {
db.execSQL(KeysModel.VALIDKEYSVIEW);
db.execSQL(UserPacketsModel.UIDSTATUS);
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ", " + KeysColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
+ UserPacketsColumns.USER_ID + ", " + UserPacketsColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysModel.RANK + ", " + KeysModel.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsModel.RANK + ", "
+ UserPacketsModel.USER_ID + ", " + UserPacketsModel.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX verified_certs ON certs ("
+ CertsColumns.VERIFIED + ", " + CertsColumns.MASTER_KEY_ID + ");");
+ CertsModel.VERIFIED + ", " + CertsModel.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX uids_by_email ON user_packets ("
+ UserPacketsColumns.EMAIL + ");");
+ UserPacketsModel.EMAIL + ");");
Preferences.getPreferences(context).setKeySignaturesTableInitialized();
}
@ -243,11 +227,9 @@ public class KeychainDatabase {
case 12:
// do nothing here, just consolidate
case 13:
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ");");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
+ UserPacketsColumns.USER_ID + ", " + UserPacketsColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX verified_certs ON certs ("
+ CertsColumns.VERIFIED + ", " + CertsColumns.MASTER_KEY_ID + ");");
db.execSQL("CREATE INDEX keys_by_rank ON keys (rank);");
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (rank, user_id, master_key_id);");
db.execSQL("CREATE INDEX verified_certs ON certs (verified, master_key_id);");
case 14:
db.execSQL("ALTER TABLE user_packets ADD COLUMN name TEXT");
db.execSQL("ALTER TABLE user_packets ADD COLUMN email TEXT");
@ -366,6 +348,25 @@ public class KeychainDatabase {
case 30:
// ignore. this case only came up in an unreleased beta.
case 31:
addSubkeyValidFromField(db);
}
}
private void addSubkeyValidFromField(SupportSQLiteDatabase db) {
try {
db.beginTransaction();
db.execSQL("ALTER TABLE keys ADD COLUMN validFrom INTEGER NOT NULL DEFAULT 0;");
db.execSQL("UPDATE keys SET validFrom = creation");
db.setTransactionSuccessful();
} catch (SQLiteException e) {
// column probably already existed, nvm this
if (!Constants.DEBUG) {
throw e;
}
} finally {
db.endTransaction();
}
}
@ -477,11 +478,4 @@ public class KeychainDatabase {
copy(in, out);
}
// DANGEROUS, use in test code ONLY!
public void clearDatabase() {
getWritableDatabase().execSQL("delete from " + KeyRingsPublicModel.TABLE_NAME);
getWritableDatabase().execSQL("delete from " + ApiAllowedKeysModel.TABLE_NAME);
getWritableDatabase().execSQL("delete from api_apps");
}
}

View File

@ -20,14 +20,12 @@ package org.sufficientlysecure.keychain.daos;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.database.Cursor;
import android.support.annotation.WorkerThread;
import com.squareup.sqldelight.RowMapper;
import com.squareup.sqldelight.SqlDelightQuery;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.sufficientlysecure.keychain.KeychainDatabase;
@ -127,27 +125,13 @@ public class KeyRepository extends AbstractDao {
public List<Long> getAllMasterKeyIds() {
SqlDelightQuery query = KeyRingPublic.FACTORY.selectAllMasterKeyIds();
ArrayList<Long> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
Long item = KeyRingPublic.FACTORY.selectAllMasterKeyIdsMapper().map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, KeySignature.FACTORY.selectMasterKeyIdsBySignerMapper());
}
public List<Long> getMasterKeyIdsBySigner(List<Long> signerMasterKeyIds) {
long[] signerKeyIds = getLongListAsArray(signerMasterKeyIds);
SqlDelightQuery query = KeySignature.FACTORY.selectMasterKeyIdsBySigner(signerKeyIds);
ArrayList<Long> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
Long item = KeySignature.FACTORY.selectMasterKeyIdsBySignerMapper().map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, KeySignature.FACTORY.selectMasterKeyIdsBySignerMapper());
}
public Long getMasterKeyIdBySubkeyId(long subKeyId) {
@ -162,88 +146,38 @@ public class KeyRepository extends AbstractDao {
public List<UnifiedKeyInfo> getUnifiedKeyInfo(long... masterKeyIds) {
SqlDelightQuery query = SubKey.FACTORY.selectUnifiedKeyInfoByMasterKeyIds(masterKeyIds);
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
}
public List<UnifiedKeyInfo> getUnifiedKeyInfosByMailAddress(String mailAddress) {
SqlDelightQuery query = SubKey.FACTORY.selectUnifiedKeyInfoSearchMailAddress('%' + mailAddress + '%');
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
}
public List<UnifiedKeyInfo> getAllUnifiedKeyInfo() {
SqlDelightQuery query = SubKey.FACTORY.selectAllUnifiedKeyInfo();
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
}
public List<UnifiedKeyInfo> getAllUnifiedKeyInfoWithSecret() {
SqlDelightQuery query = SubKey.FACTORY.selectAllUnifiedKeyInfoWithSecret();
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
}
public List<UserId> getUserIds(long... masterKeyIds) {
SqlDelightQuery query = UserPacket.FACTORY.selectUserIdsByMasterKeyId(masterKeyIds);
ArrayList<UserId> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
UserId item = UserPacket.USER_ID_MAPPER.map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, UserPacket.USER_ID_MAPPER);
}
public List<String> getConfirmedUserIds(long masterKeyId) {
SqlDelightQuery query = UserPacket.FACTORY.selectUserIdsByMasterKeyIdAndVerification(
Certification.FACTORY, masterKeyId, VerificationStatus.VERIFIED_SECRET);
ArrayList<String> result = new ArrayList<>();
try (Cursor cursor1 = getReadableDb().query(query)) {
while (cursor1.moveToNext()) {
String item = ((RowMapper<String>) (cursor) -> UserPacket.USER_ID_MAPPER.map(cursor).user_id())
.map(cursor1);
result.add(item);
}
}
return result;
return mapAllRows(query, cursor -> UserPacket.USER_ID_MAPPER.map(cursor).user_id());
}
public List<SubKey> getSubKeysByMasterKeyId(long masterKeyId) {
SqlDelightQuery query = SubKey.FACTORY.selectSubkeysByMasterKeyId(masterKeyId);
ArrayList<SubKey> result = new ArrayList<>();
try (Cursor cursor = getReadableDb().query(query)) {
while (cursor.moveToNext()) {
SubKey item = SubKey.SUBKEY_MAPPER.map(cursor);
result.add(item);
}
}
return result;
return mapAllRows(query, SubKey.SUBKEY_MAPPER);
}
public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
@ -313,6 +247,11 @@ public class KeyRepository extends AbstractDao {
return mapSingleRowOrThrow(query, SubKey.FACTORY.selectEffectiveAuthKeyIdByMasterKeyIdMapper());
}
public List<Long> getPublicEncryptionIds(long masterKeyId) {
SqlDelightQuery query = SubKey.FACTORY.selectEffectiveEncryptionKeyIdsByMasterKeyId(masterKeyId);
return mapAllRows(query, SubKey.FACTORY.selectEffectiveEncryptionKeyIdsByMasterKeyIdMapper());
}
public static class NotFoundException extends Exception {
public NotFoundException() {
}

View File

@ -225,6 +225,7 @@ public class KeyWritableRepository extends KeyRepository {
}
Date creation = key.getCreationTime();
Date bindingSignatureTime = key.getBindingSignatureTime();
Date expiry = key.getExpiryTime();
if (expiry != null) {
if (key.isExpired()) {
@ -240,7 +241,7 @@ public class KeyWritableRepository extends KeyRepository {
SubKey subKey = SubKey.create(masterKeyId, rank, key.getKeyId(),
key.getBitStrength(), key.getCurveOid(), key.getAlgorithm(), key.getFingerprint(),
c, s, e, a, key.isRevoked(), SecretKeyType.UNAVAILABLE, key.isSecure(), creation, expiry);
c, s, e, a, key.isRevoked(), SecretKeyType.UNAVAILABLE, key.isSecure(), creation, expiry, bindingSignatureTime);
operations.add(DatabaseBatchInteractor.createInsertSubKey(subKey));
++rank;
@ -670,6 +671,8 @@ public class KeyWritableRepository extends KeyRepository {
// with has_secret = 1
}
databaseNotifyManager.notifyKeyChange(masterKeyId);
log(LogType.MSG_IS_SUCCESS);
return result;

View File

@ -31,11 +31,13 @@ public abstract class SubKey implements KeysModel {
public static SubKey create(long masterKeyId, long rank, long keyId, Integer keySize, String keyCurveOid,
int algorithm, byte[] fingerprint, boolean canCertify, boolean canSign, boolean canEncrypt, boolean canAuth,
boolean isRevoked, SecretKeyType hasSecret, boolean isSecure, Date creation, Date expiry) {
boolean isRevoked, SecretKeyType hasSecret, boolean isSecure, Date creation, Date expiry,
Date validFrom) {
long creationUnixTime = creation.getTime() / 1000;
Long expiryUnixTime = expiry != null ? expiry.getTime() / 1000 : null;
long validFromTime = validFrom.getTime() / 1000;
return new AutoValue_SubKey(masterKeyId, rank, keyId, keySize, keyCurveOid, algorithm, fingerprint, canCertify,
canSign, canEncrypt, canAuth, isRevoked, hasSecret, isSecure, creationUnixTime, expiryUnixTime);
canSign, canEncrypt, canAuth, isRevoked, hasSecret, isSecure, creationUnixTime, expiryUnixTime, validFromTime);
}
public static InsertKey createInsertStatement(SupportSQLiteDatabase db) {
@ -53,7 +55,7 @@ public abstract class SubKey implements KeysModel {
public void bindTo(InsertKey statement) {
statement.bind(master_key_id(), rank(), key_id(), key_size(), key_curve_oid(), algorithm(), fingerprint(),
can_certify(), can_sign(), can_encrypt(), can_authenticate(), is_revoked(), has_secret(), is_secure(),
creation(), expiry());
creation(), expiry(), validFrom());
}
@AutoValue

View File

@ -455,7 +455,6 @@ public abstract class OperationResult implements Parcelable {
MSG_KC_SUB_BAD_ERR(LogLevel.WARN, R.string.msg_kc_sub_bad_err),
MSG_KC_SUB_BAD_LOCAL(LogLevel.WARN, R.string.msg_kc_sub_bad_local),
MSG_KC_SUB_BAD_KEYID(LogLevel.WARN, R.string.msg_kc_sub_bad_keyid),
MSG_KC_SUB_BAD_TIME(LogLevel.WARN, R.string.msg_kc_sub_bad_time),
MSG_KC_SUB_BAD_TIME_EARLY(LogLevel.WARN, R.string.msg_kc_sub_bad_time_early),
MSG_KC_SUB_BAD_TYPE(LogLevel.WARN, R.string.msg_kc_sub_bad_type),
MSG_KC_SUB_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_dup),

View File

@ -134,11 +134,33 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
: PGPSignature.SUBKEY_REVOCATION).hasNext();
}
public boolean isExpired () {
public boolean isExpired() {
Date expiry = getExpiryTime();
return expiry != null && expiry.before(new Date());
}
private boolean hasFutureSigningDate() {
if (isMasterKey()) {
return false;
}
WrappedSignature subkeyBindingSignature = getSubkeyBindingSignature();
return subkeyBindingSignature.getCreationTime().after(new Date());
}
private WrappedSignature getSubkeyBindingSignature() {
Iterator subkeyBindingSignatures = mPublicKey.getSignaturesOfType(PGPSignature.SUBKEY_BINDING);
PGPSignature singleSubkeyBindingsignature = (PGPSignature) subkeyBindingSignatures.next();
if (subkeyBindingSignatures.hasNext()) {
throw new IllegalStateException();
}
return new WrappedSignature(singleSubkeyBindingsignature);
}
public Date getBindingSignatureTime() {
return isMasterKey() ? getCreationTime() : getSubkeyBindingSignature().getCreationTime();
}
public boolean isSecure() {
return PgpSecurityConstants.checkForSecurityProblems(this) == null;
}
@ -206,7 +228,7 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
/** Returns whether this key is valid, ie not expired or revoked. */
public boolean isValid() {
return !isRevoked() && !isExpired();
return !isRevoked() && !isExpired() && !hasFutureSigningDate();
}
// For use in key export only; returns the public key in a JCA compatible format.

View File

@ -32,7 +32,7 @@ import java.io.UnsupportedEncodingException;
import java.security.SignatureException;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import android.content.Context;
@ -651,7 +651,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
PGPEncryptedDataGenerator cPk, long encryptMasterKeyId) {
try {
CanonicalizedPublicKeyRing keyRing = mKeyRepository.getCanonicalizedPublicKeyRing(encryptMasterKeyId);
Set<Long> encryptSubKeyIds = keyRing.getEncryptIds();
List<Long> encryptSubKeyIds = mKeyRepository.getPublicEncryptionIds(encryptMasterKeyId);
for (Long subKeyId : encryptSubKeyIds) {
CanonicalizedPublicKey key = keyRing.getPublicKey(subKeyId);
cPk.addMethod(key.getPubKeyEncryptionGenerator(data.isHiddenRecipients()));

View File

@ -912,13 +912,6 @@ public class UncachedKeyRing {
continue;
}
if (cert.getCreationTime().after(nowPlusOneDay)) {
// Creation date in the future? No way!
log.add(LogType.MSG_KC_SUB_BAD_TIME, indent);
badCerts += 1;
continue;
}
if (cert.getCreationTime().before(keyCreationTime)) {
// Signature is earlier than key creation time
log.add(LogType.MSG_KC_SUB_BAD_TIME_EARLY, indent);

View File

@ -1,83 +0,0 @@
/*
* Copyright (C) 2017 Schürmann & Breitmoser GbR
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.provider;
import android.provider.BaseColumns;
public class KeychainContract {
public interface KeysColumns {
String MASTER_KEY_ID = "master_key_id"; // not a database id
String RANK = "rank";
String KEY_ID = "key_id"; // not a database id
String ALGORITHM = "algorithm";
String FINGERPRINT = "fingerprint";
String KEY_SIZE = "key_size";
String KEY_CURVE_OID = "key_curve_oid";
String CAN_SIGN = "can_sign";
String CAN_ENCRYPT = "can_encrypt";
String CAN_CERTIFY = "can_certify";
String CAN_AUTHENTICATE = "can_authenticate";
String IS_REVOKED = "is_revoked";
String IS_SECURE = "is_secure";
String HAS_SECRET = "has_secret";
String CREATION = "creation";
String EXPIRY = "expiry";
}
public interface UserPacketsColumns {
String MASTER_KEY_ID = "master_key_id"; // foreign key to key_rings._ID
String TYPE = "type"; // not a database id
String USER_ID = "user_id"; // not a database id
String NAME = "name";
String EMAIL = "email";
String COMMENT = "comment";
String ATTRIBUTE_DATA = "attribute_data"; // not a database id
String RANK = "rank"; // ONLY used for sorting! no key, no nothing!
String IS_PRIMARY = "is_primary";
String IS_REVOKED = "is_revoked";
}
public interface CertsColumns {
String MASTER_KEY_ID = "master_key_id";
String RANK = "rank";
String KEY_ID_CERTIFIER = "key_id_certifier";
String TYPE = "type";
String VERIFIED = "verified";
String CREATION = "creation";
String DATA = "data";
}
public static class Keys implements KeysColumns, BaseColumns {
}
public static class UserPackets implements UserPacketsColumns, BaseColumns {
}
public static class Certs implements CertsColumns, BaseColumns {
public static final int VERIFIED_SECRET = 1;
public static final int VERIFIED_SELF = 2;
}
private KeychainContract() {
}
}

View File

@ -27,6 +27,7 @@ import android.os.Parcelable;
import android.support.annotation.Nullable;
import com.google.auto.value.AutoValue;
import org.bouncycastle.bcpg.sig.KeyFlags;
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
import org.sufficientlysecure.keychain.util.Passphrase;
@ -224,6 +225,18 @@ public abstract class SaveKeyringParcel implements Parcelable {
return autoBuild();
}
public boolean hasModificationsForSubkey(long keyId) {
return revokeSubKeys.contains(keyId) || getSubkeyChange(keyId) != null;
}
public void removeModificationsForSubkey(long keyId) {
revokeSubKeys.remove(keyId);
SubkeyChange subkeyChange = getSubkeyChange(keyId);
if (subkeyChange != null) {
changeSubKeys.remove(subkeyChange);
}
}
}
// performance gain for using Parcelable here would probably be negligible,
@ -243,6 +256,22 @@ public abstract class SaveKeyringParcel implements Parcelable {
Long expiry) {
return new AutoValue_SaveKeyringParcel_SubkeyAdd(algorithm, keySize, curve, flags, expiry);
}
public boolean canCertify() {
return (getFlags() & KeyFlags.CERTIFY_OTHER) > 0;
}
public boolean canSign() {
return (getFlags() & KeyFlags.SIGN_DATA) > 0;
}
public boolean canEncrypt() {
return ((getFlags() & KeyFlags.ENCRYPT_COMMS) > 0) || ((getFlags() & KeyFlags.ENCRYPT_STORAGE) > 0);
}
public boolean canAuthenticate() {
return (getFlags() & KeyFlags.AUTHENTICATION) > 0;
}
}
@AutoValue

View File

@ -117,7 +117,7 @@ public class EditKeyFragment extends Fragment {
mUserIdsAddedAdapter = new UserIdsAddedAdapter(getActivity(), mSkpBuilder.getMutableAddUserIds(), true);
mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter);
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSkpBuilder.getMutableAddSubKeys(), true);
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSkpBuilder.getMutableAddSubKeys());
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
}

View File

@ -0,0 +1,268 @@
package org.sufficientlysecure.keychain.ui;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.support.annotation.StringRes;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.viewholders.FlexibleViewHolder;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.model.SubKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Builder;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Curve;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
import org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.SubkeyEditViewModel;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
public class SubKeyItem extends AbstractFlexibleItem<SubKeyItem.SubkeyViewHolder> {
final SubKey subkeyInfo;
private final SubkeyEditViewModel viewModel;
SubKeyItem(SubKey subkeyInfo, SubkeyEditViewModel viewModel) {
this.subkeyInfo = subkeyInfo;
this.viewModel = viewModel;
}
@Override
public boolean equals(Object o) {
return o instanceof SubKeyItem && ((SubKeyItem) o).subkeyInfo.key_id() == subkeyInfo.key_id();
}
@Override
public int hashCode() {
long key_id = subkeyInfo.key_id();
return (int) (key_id ^ (key_id >>> 32));
}
@Override
public int getLayoutRes() {
return R.layout.view_key_adv_subkey_item;
}
@Override
public SubkeyViewHolder createViewHolder(View view, FlexibleAdapter<IFlexible> adapter) {
return new SubkeyViewHolder(view, adapter);
}
@Override
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, SubkeyViewHolder holder, int position,
List<Object> payloads) {
holder.bind(subkeyInfo);
holder.bindSubkeyAction(subkeyInfo, viewModel.skpBuilder);
}
@Override
public int getItemViewType() {
return ViewKeyAdvSubkeysFragment.SUBKEY_TYPE_DETAIL;
}
public static class SubkeyViewHolder extends FlexibleViewHolder {
final TextView vKeyId;
final TextView vKeyDetails;
final TextView vKeyStatus;
final ImageView vCertifyIcon;
final ImageView vSignIcon;
final ImageView vEncryptIcon;
final ImageView vAuthenticateIcon;
final View vActionLayout;
final TextView vActionText;
final ImageView vActionCancel;
public SubkeyViewHolder(View itemView, FlexibleAdapter adapter) {
super(itemView, adapter);
vKeyId = itemView.findViewById(R.id.subkey_item_key_id);
vKeyDetails = itemView.findViewById(R.id.subkey_item_details);
vKeyStatus = itemView.findViewById(R.id.subkey_item_status);
vCertifyIcon = itemView.findViewById(R.id.subkey_item_ic_certify);
vSignIcon = itemView.findViewById(R.id.subkey_item_ic_sign);
vEncryptIcon = itemView.findViewById(R.id.subkey_item_ic_encrypt);
vAuthenticateIcon = itemView.findViewById(R.id.subkey_item_ic_authenticate);
vActionLayout = itemView.findViewById(R.id.layout_subkey_action);
vActionText = itemView.findViewById(R.id.text_subkey_action);
vActionCancel = itemView.findViewById(R.id.button_subkey_action_cancel);
}
void bind(SubKey subkeyInfo) {
bindKeyId(subkeyInfo.key_id(), subkeyInfo.rank() == 0);
bindKeyDetails(subkeyInfo.algorithm(), subkeyInfo.key_size(), subkeyInfo.key_curve_oid(), subkeyInfo.has_secret());
bindKeyFlags(subkeyInfo.can_certify(), subkeyInfo.can_sign(), subkeyInfo.can_encrypt(), subkeyInfo.can_authenticate());
Date validFrom = new Date(subkeyInfo.validFrom() * 1000);
Date expiryDate = subkeyInfo.expires() ? new Date(subkeyInfo.expiry() * 1000) : null;
bindKeyStatus(validFrom, expiryDate, subkeyInfo.is_revoked(), subkeyInfo.is_secure());
}
public void bindKeyId(Long keyId, boolean isMasterKey) {
if (keyId == null) {
vKeyId.setText(R.string.edit_key_new_subkey);
} else {
vKeyId.setText(KeyFormattingUtils.beautifyKeyId(keyId));
}
vKeyId.setTypeface(null, isMasterKey ? Typeface.BOLD : Typeface.NORMAL);
}
public void bindKeyStatus(Date validFrom, Date expiryDate, boolean isRevoked, boolean isSecure) {
Context context = itemView.getContext();
Date now = new Date();
boolean isNotYetValid = validFrom != null && validFrom.after(now);
boolean isExpired = expiryDate != null && expiryDate.before(now);
if (isNotYetValid) {
Calendar validFromCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
validFromCal.setTime(validFrom);
// convert from UTC to time zone of device
validFromCal.setTimeZone(TimeZone.getDefault());
vKeyStatus.setText(context.getString(R.string.label_valid_from) + ": "
+ DateFormat.getDateFormat(context).format(validFromCal.getTime()));
} else if (isRevoked) {
vKeyStatus.setText(R.string.label_revoked);
} else if (!isSecure) {
vKeyStatus.setText(R.string.label_insecure);
} else if (expiryDate != null) {
Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
expiryCal.setTime(expiryDate);
// convert from UTC to time zone of device
expiryCal.setTimeZone(TimeZone.getDefault());
vKeyStatus.setText(context.getString(R.string.label_expiry) + ": "
+ DateFormat.getDateFormat(context).format(expiryCal.getTime()));
} else {
vKeyStatus.setText("");
}
boolean isValid = !isRevoked && !isExpired && !isNotYetValid && isSecure;
bindValidityStatus(isValid);
}
private void bindValidityStatus(boolean isValid) {
if (!isValid) {
int key_flag_gray = itemView.getResources().getColor(R.color.key_flag_gray);
vCertifyIcon.setColorFilter(key_flag_gray, PorterDuff.Mode.SRC_IN);
vSignIcon.setColorFilter(key_flag_gray, PorterDuff.Mode.SRC_IN);
vEncryptIcon.setColorFilter(key_flag_gray, PorterDuff.Mode.SRC_IN);
vAuthenticateIcon.setColorFilter(key_flag_gray, PorterDuff.Mode.SRC_IN);
} else {
vCertifyIcon.clearColorFilter();
vSignIcon.clearColorFilter();
vEncryptIcon.clearColorFilter();
vAuthenticateIcon.clearColorFilter();
}
vKeyId.setEnabled(isValid);
vKeyDetails.setEnabled(isValid);
vKeyStatus.setEnabled(isValid);
}
public void bindKeyDetails(Algorithm algorithm, Integer keySize, Curve curveOid, SecretKeyType secretKeyType) {
Context context = itemView.getContext();
String algorithmStr = KeyFormattingUtils.getAlgorithmInfo(context, algorithm, keySize, curveOid);
bindKeyDetails(context, algorithmStr, secretKeyType);
}
void bindKeyDetails(int algorithm, Integer keySize, String curveOid, SecretKeyType secretKeyType) {
Context context = itemView.getContext();
String algorithmStr = KeyFormattingUtils.getAlgorithmInfo(context, algorithm, keySize, curveOid);
bindKeyDetails(context, algorithmStr, secretKeyType);
}
private void bindKeyDetails(Context context, String algorithmStr, SecretKeyType secretKeyType) {
switch (secretKeyType) {
case GNU_DUMMY:
algorithmStr += ", " + context.getString(R.string.key_stripped);
break;
case DIVERT_TO_CARD:
algorithmStr += ", " + context.getString(R.string.key_divert);
break;
}
vKeyDetails.setText(algorithmStr);
}
private void bindSubkeyAction(SubKey subkeyInfo, Builder saveKeyringParcelBuilder) {
if (saveKeyringParcelBuilder == null) {
itemView.setClickable(false);
vActionLayout.setVisibility(View.GONE);
return;
}
boolean isRevokeAction = (saveKeyringParcelBuilder.getMutableRevokeSubKeys().contains(subkeyInfo.key_id()));
SubkeyChange change = saveKeyringParcelBuilder.getSubkeyChange(subkeyInfo.key_id());
boolean hasAction = isRevokeAction || change != null;
if (!hasAction) {
itemView.setClickable(true);
vActionLayout.setVisibility(View.GONE);
return;
}
OnClickListener onClickRemoveModificationListener = v -> {
saveKeyringParcelBuilder.removeModificationsForSubkey(subkeyInfo.key_id());
mAdapter.notifyItemChanged(getAdapterPosition());
};
if (isRevokeAction) {
bindSubkeyAction(R.string.subkey_action_revoke, onClickRemoveModificationListener);
return;
}
if (change.getDummyStrip()) {
bindSubkeyAction(R.string.subkey_action_strip, onClickRemoveModificationListener);
return;
}
Long expiry = change.getExpiry();
if (expiry != null) {
if (expiry == 0L) {
bindSubkeyAction(R.string.subkey_action_expiry_never, onClickRemoveModificationListener);
} else {
String expiryString = itemView.getContext().getString(R.string.subkey_action_expiry_date,
DateFormat.getDateFormat(itemView.getContext()).format(new Date(expiry * 1000)));
bindSubkeyAction(expiryString, onClickRemoveModificationListener);
}
return;
}
throw new UnsupportedOperationException();
}
void bindSubkeyAction(String actionText, OnClickListener onClickListener) {
vActionText.setText(actionText);
bindSubkeyAction(onClickListener);
}
public void bindSubkeyAction(@StringRes int actionTextRes, OnClickListener onClickListener) {
vActionText.setText(actionTextRes);
bindSubkeyAction(onClickListener);
}
private void bindSubkeyAction(OnClickListener onClickListener) {
itemView.setClickable(false);
vActionLayout.setVisibility(View.VISIBLE);
vActionCancel.setOnClickListener(onClickListener);
}
public void bindKeyFlags(boolean canCertify, boolean canSign, boolean canEncrypt, boolean canAuthenticate) {
vCertifyIcon.setVisibility(canCertify ? View.VISIBLE : View.GONE);
vSignIcon.setVisibility(canSign ? View.VISIBLE : View.GONE);
vEncryptIcon.setVisibility(canEncrypt ? View.VISIBLE : View.GONE);
vAuthenticateIcon.setVisibility(canAuthenticate ? View.VISIBLE : View.GONE);
}
}
}

View File

@ -18,8 +18,10 @@
package org.sufficientlysecure.keychain.ui;
import java.util.ArrayList;
import java.util.List;
import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent;
import android.os.Bundle;
@ -29,15 +31,19 @@ import android.os.Messenger;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.ViewAnimator;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.FlexibleAdapter.OnItemClickListener;
import eu.davidea.flexibleadapter.items.IFlexible;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.model.SubKey;
@ -45,52 +51,38 @@ import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Builder;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
import org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.ViewKeyAdvViewModel;
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
import org.sufficientlysecure.keychain.ui.adapter.SubkeyAddedItem;
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment;
import org.sufficientlysecure.keychain.ui.util.recyclerview.DividerItemDecoration;
public class ViewKeyAdvSubkeysFragment extends Fragment {
private ListView mSubkeysList;
private ListView mSubkeysAddedList;
private View mSubkeysAddedLayout;
private ViewAnimator mSubkeyAddFabLayout;
public static final int SUBKEY_TYPE_DETAIL = 1;
public static final int SUBKEY_TYPE_ADDED = 2;
private SubkeysAdapter mSubkeysAdapter;
private SubkeysAddedAdapter mSubkeysAddedAdapter;
private RecyclerView subkeysList;
private ViewAnimator subkeyAddFabLayout;
private FlexibleAdapter<IFlexible> subkeysAdapter;
private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mEditKeyHelper;
private SaveKeyringParcel.Builder mEditModeSkpBuilder;
private UnifiedKeyInfo unifiedKeyInfo;
private SubkeyEditViewModel subkeyEditViewModel;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.view_key_adv_subkeys_fragment, viewGroup, false);
mSubkeysList = view.findViewById(R.id.view_key_subkeys);
mSubkeysAddedList = view.findViewById(R.id.view_key_subkeys_added);
mSubkeysAddedLayout = view.findViewById(R.id.view_key_subkeys_add_layout);
subkeysList = view.findViewById(R.id.view_key_subkeys);
subkeysList.setLayoutManager(new LinearLayoutManager(requireContext()));
subkeysList.addItemDecoration(new DividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL, false));
mSubkeysList.setOnItemClickListener((parent, view1, position, id) -> editSubkey(position));
View footer = new View(getActivity());
int spacing = (int) android.util.TypedValue.applyDimension(
android.util.TypedValue.COMPLEX_UNIT_DIP, 72, getResources().getDisplayMetrics()
);
android.widget.AbsListView.LayoutParams params = new android.widget.AbsListView.LayoutParams(
android.widget.AbsListView.LayoutParams.MATCH_PARENT,
spacing
);
footer.setLayoutParams(params);
mSubkeysAddedList.addFooterView(footer, null, false);
mSubkeyAddFabLayout = view.findViewById(R.id.view_key_subkey_fab_layout);
subkeyAddFabLayout = view.findViewById(R.id.view_key_subkey_fab_layout);
view.findViewById(R.id.view_key_subkey_fab).setOnClickListener(v -> addSubkey());
setHasOptionsMenu(true);
@ -102,26 +94,32 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Create an empty adapter we will use to display the loaded data.
mSubkeysAdapter = new SubkeysAdapter(requireContext());
mSubkeysList.setAdapter(mSubkeysAdapter);
subkeysAdapter = new FlexibleAdapter<>(null, null, true);
subkeysAdapter.addListener((OnItemClickListener) (view, position) -> editSubkey(position));
subkeysList.setAdapter(subkeysAdapter);
ViewKeyAdvViewModel viewModel = ViewModelProviders.of(requireActivity()).get(ViewKeyAdvViewModel.class);
viewModel.getUnifiedKeyInfoLiveData(requireContext()).observe(this, this::onLoadFinished);
viewModel.getUnifiedKeyInfoLiveData(requireContext()).observe(this, this::onLoadUnifiedKeyId);
viewModel.getSubkeyLiveData(requireContext()).observe(this, this::onLoadSubKeys);
subkeyEditViewModel = ViewModelProviders.of(this).get(SubkeyEditViewModel.class);
}
public void onLoadFinished(UnifiedKeyInfo unifiedKeyInfo) {
// Avoid NullPointerExceptions, if we get an empty result set.
if (unifiedKeyInfo == null) {
return;
}
public static class SubkeyEditViewModel extends ViewModel {
public Builder skpBuilder;
UnifiedKeyInfo unifiedKeyInfo;
}
this.unifiedKeyInfo = unifiedKeyInfo;
public void onLoadUnifiedKeyId(UnifiedKeyInfo unifiedKeyInfo) {
subkeyEditViewModel.unifiedKeyInfo = unifiedKeyInfo;
}
private void onLoadSubKeys(List<SubKey> subKeys) {
mSubkeysAdapter.setData(subKeys);
ArrayList<IFlexible> subKeyItems = new ArrayList<>(subKeys.size());
for (SubKey subKey : subKeys) {
subKeyItems.add(new SubKeyItem(subKey, subkeyEditViewModel));
}
subkeysAdapter.updateDataSet(subKeyItems);
}
@Override
@ -152,16 +150,10 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
activity.startActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mEditModeSkpBuilder = SaveKeyringParcel.buildChangeKeyringParcel(unifiedKeyInfo.master_key_id(), unifiedKeyInfo.fingerprint());
mSubkeysAddedAdapter = new SubkeysAddedAdapter(
getActivity(), mEditModeSkpBuilder.getMutableAddSubKeys(), false);
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
mSubkeysAddedLayout.setVisibility(View.VISIBLE);
mSubkeyAddFabLayout.setDisplayedChild(1);
mSubkeysAdapter.setEditMode(mEditModeSkpBuilder);
subkeyAddFabLayout.setDisplayedChild(1);
subkeyEditViewModel.skpBuilder = SaveKeyringParcel.buildChangeKeyringParcel(
subkeyEditViewModel.unifiedKeyInfo.master_key_id(), subkeyEditViewModel.unifiedKeyInfo.fingerprint());
subkeysAdapter.notifyDataSetChanged();
mode.setTitle(R.string.title_edit_subkeys);
mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu);
@ -182,63 +174,60 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
@Override
public void onDestroyActionMode(ActionMode mode) {
mEditModeSkpBuilder = null;
mSubkeysAdapter.setEditMode(null);
mSubkeysAddedLayout.setVisibility(View.GONE);
mSubkeyAddFabLayout.setDisplayedChild(0);
subkeyEditViewModel.skpBuilder = null;
subkeysAdapter.removeItemsOfType(2);
subkeyAddFabLayout.setDisplayedChild(0);
subkeysAdapter.notifyDataSetChanged();
}
});
}
private void addSubkey() {
boolean willBeMasterKey;
if (mSubkeysAdapter != null) {
willBeMasterKey = mSubkeysAdapter.getCount() == 0 && mSubkeysAddedAdapter.getCount() == 0;
} else {
willBeMasterKey = mSubkeysAddedAdapter.getCount() == 0;
}
boolean willBeMasterKey = subkeysAdapter.getItemCount() == 0;
AddSubkeyDialogFragment addSubkeyDialogFragment =
AddSubkeyDialogFragment.newInstance(willBeMasterKey);
addSubkeyDialogFragment
.setOnAlgorithmSelectedListener(newSubkey -> mSubkeysAddedAdapter.add(newSubkey));
AddSubkeyDialogFragment addSubkeyDialogFragment = AddSubkeyDialogFragment.newInstance(willBeMasterKey);
addSubkeyDialogFragment.setOnAlgorithmSelectedListener(newSubkey -> {
subkeyEditViewModel.skpBuilder.addSubkeyAdd(newSubkey);
subkeysAdapter.addItem(new SubkeyAddedItem(newSubkey, subkeyEditViewModel));
});
addSubkeyDialogFragment.show(requireFragmentManager(), "addSubkeyDialog");
}
private void editSubkey(final int position) {
final SubKey subKey = mSubkeysAdapter.getItem(position);
private boolean editSubkey(final int position) {
if (subkeyEditViewModel.skpBuilder == null) {
return false;
}
IFlexible item = subkeysAdapter.getItem(position);
if (item instanceof SubKeyItem) {
editSubkey(position, ((SubKeyItem) item));
}
return false;
}
private void editSubkey(int position, SubKeyItem item) {
if (subkeyEditViewModel.skpBuilder.hasModificationsForSubkey(item.subkeyInfo.key_id())) {
return;
}
Handler returnHandler = new Handler() {
@Override
public void handleMessage(Message message) {
switch (message.what) {
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
editSubkeyExpiry(position);
editSubkeyExpiry(item);
break;
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
// toggle
if (mEditModeSkpBuilder.getMutableRevokeSubKeys().contains(subKey.key_id())) {
mEditModeSkpBuilder.removeRevokeSubkey(subKey.key_id());
} else {
mEditModeSkpBuilder.addRevokeSubkey(subKey.key_id());
}
SubKey subKey = item.subkeyInfo;
subkeyEditViewModel.skpBuilder.addRevokeSubkey(subKey.key_id());
break;
case EditSubkeyDialogFragment.MESSAGE_STRIP: {
if (subKey.has_secret() == SecretKeyType.GNU_DUMMY) {
// Key is already stripped; this is a no-op.
break;
}
SubkeyChange change = mEditModeSkpBuilder.getSubkeyChange(subKey.key_id());
if (change == null || !change.getDummyStrip()) {
mEditModeSkpBuilder.addOrReplaceSubkeyChange(SubkeyChange.createStripChange(subKey.key_id()));
} else {
mEditModeSkpBuilder.removeSubkeyChange(change);
}
editSubkeyToggleStrip(item);
break;
}
}
mSubkeysAdapter.notifyDataSetChanged();
subkeysAdapter.notifyItemChanged(position);
}
};
@ -246,15 +235,24 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
final Messenger messenger = new Messenger(returnHandler);
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(() -> {
EditSubkeyDialogFragment dialogFragment =
EditSubkeyDialogFragment.newInstance(messenger);
EditSubkeyDialogFragment dialogFragment = EditSubkeyDialogFragment.newInstance(messenger);
dialogFragment.show(requireFragmentManager(), "editSubkeyDialog");
});
}
private void editSubkeyExpiry(final int position) {
SubKey subKey = mSubkeysAdapter.getItem(position);
private void editSubkeyToggleStrip(SubKeyItem item) {
SubKey subKey = item.subkeyInfo;
if (subKey.has_secret() == SecretKeyType.GNU_DUMMY) {
// Key is already stripped; this is a no-op.
return;
}
subkeyEditViewModel.skpBuilder.addOrReplaceSubkeyChange(SubkeyChange.createStripChange(subKey.key_id()));
}
private void editSubkeyExpiry(SubKeyItem item) {
SubKey subKey = item.subkeyInfo;
final long keyId = subKey.key_id();
final Long creationDate = subKey.creation();
final Long expiryDate = subKey.expiry();
@ -266,11 +264,11 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY:
Long expiry = (Long) message.getData().getSerializable(
EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY);
mEditModeSkpBuilder.addOrReplaceSubkeyChange(
subkeyEditViewModel.skpBuilder.addOrReplaceSubkeyChange(
SubkeyChange.createFlagsOrExpiryChange(keyId, null, expiry));
break;
}
mSubkeysAdapter.notifyDataSetChanged();
subkeysAdapter.notifyDataSetChanged();
}
};
@ -292,7 +290,7 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
@Override
public SaveKeyringParcel createOperationInput() {
return mEditModeSkpBuilder.build();
return subkeyEditViewModel.skpBuilder.build();
}
@Override

View File

@ -0,0 +1,93 @@
/*
* Copyright (C) 2017 Schürmann & Breitmoser