Merge pull request #2384 from open-keychain/future-subkeys
Support future subkeys
This commit is contained in:
commit
83f5f557f0
|
@ -151,7 +151,7 @@ public class AndroidTestHelpers {
|
||||||
|
|
||||||
public static void cleanupForTests(Context context) throws Exception {
|
public static void cleanupForTests(Context context) throws Exception {
|
||||||
|
|
||||||
KeychainDatabase.getInstance(context).clearDatabase();
|
// KeychainDatabase.getInstance(context).clearDatabase();
|
||||||
|
|
||||||
// import these two, make sure they're there
|
// import these two, make sure they're there
|
||||||
importKeysFromResource(context, "x.sec.asc");
|
importKeysFromResource(context, "x.sec.asc");
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class EditKeyTest {
|
||||||
public void test01Edit() throws Exception {
|
public void test01Edit() throws Exception {
|
||||||
Activity activity = mActivity.getActivity();
|
Activity activity = mActivity.getActivity();
|
||||||
|
|
||||||
KeychainDatabase.getInstance(activity).clearDatabase();
|
// KeychainDatabase.getInstance(activity).clearDatabase();
|
||||||
|
|
||||||
// import key for testing, get a stable initial state
|
// import key for testing, get a stable initial state
|
||||||
importKeysFromResource(activity, "x.sec.asc");
|
importKeysFromResource(activity, "x.sec.asc");
|
||||||
|
|
|
@ -34,9 +34,6 @@ import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.daos.LocalSecretKeyStorage;
|
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 org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
@ -51,7 +48,7 @@ import timber.log.Timber;
|
||||||
*/
|
*/
|
||||||
public class KeychainDatabase {
|
public class KeychainDatabase {
|
||||||
private static final String DATABASE_NAME = "openkeychain.db";
|
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 final SupportSQLiteOpenHelper supportSQLiteOpenHelper;
|
||||||
|
|
||||||
private static KeychainDatabase sInstance;
|
private static KeychainDatabase sInstance;
|
||||||
|
@ -63,20 +60,6 @@ public class KeychainDatabase {
|
||||||
return sInstance;
|
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) {
|
private KeychainDatabase(Context context) {
|
||||||
supportSQLiteOpenHelper =
|
supportSQLiteOpenHelper =
|
||||||
new FrameworkSQLiteOpenHelperFactory()
|
new FrameworkSQLiteOpenHelperFactory()
|
||||||
|
@ -119,6 +102,7 @@ public class KeychainDatabase {
|
||||||
return supportSQLiteOpenHelper.getWritableDatabase();
|
return supportSQLiteOpenHelper.getWritableDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") // using some sqldelight constants
|
||||||
private void onCreate(SupportSQLiteDatabase db, Context context) {
|
private void onCreate(SupportSQLiteDatabase db, Context context) {
|
||||||
Timber.w("Creating database...");
|
Timber.w("Creating database...");
|
||||||
|
|
||||||
|
@ -136,13 +120,13 @@ public class KeychainDatabase {
|
||||||
db.execSQL(KeysModel.VALIDKEYSVIEW);
|
db.execSQL(KeysModel.VALIDKEYSVIEW);
|
||||||
db.execSQL(UserPacketsModel.UIDSTATUS);
|
db.execSQL(UserPacketsModel.UIDSTATUS);
|
||||||
|
|
||||||
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ", " + KeysColumns.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 (" + UserPacketsColumns.RANK + ", "
|
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsModel.RANK + ", "
|
||||||
+ UserPacketsColumns.USER_ID + ", " + UserPacketsColumns.MASTER_KEY_ID + ");");
|
+ UserPacketsModel.USER_ID + ", " + UserPacketsModel.MASTER_KEY_ID + ");");
|
||||||
db.execSQL("CREATE INDEX verified_certs ON certs ("
|
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 ("
|
db.execSQL("CREATE INDEX uids_by_email ON user_packets ("
|
||||||
+ UserPacketsColumns.EMAIL + ");");
|
+ UserPacketsModel.EMAIL + ");");
|
||||||
|
|
||||||
Preferences.getPreferences(context).setKeySignaturesTableInitialized();
|
Preferences.getPreferences(context).setKeySignaturesTableInitialized();
|
||||||
}
|
}
|
||||||
|
@ -243,11 +227,9 @@ public class KeychainDatabase {
|
||||||
case 12:
|
case 12:
|
||||||
// do nothing here, just consolidate
|
// do nothing here, just consolidate
|
||||||
case 13:
|
case 13:
|
||||||
db.execSQL("CREATE INDEX keys_by_rank ON keys (" + KeysColumns.RANK + ");");
|
db.execSQL("CREATE INDEX keys_by_rank ON keys (rank);");
|
||||||
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (" + UserPacketsColumns.RANK + ", "
|
db.execSQL("CREATE INDEX uids_by_rank ON user_packets (rank, user_id, master_key_id);");
|
||||||
+ UserPacketsColumns.USER_ID + ", " + UserPacketsColumns.MASTER_KEY_ID + ");");
|
db.execSQL("CREATE INDEX verified_certs ON certs (verified, master_key_id);");
|
||||||
db.execSQL("CREATE INDEX verified_certs ON certs ("
|
|
||||||
+ CertsColumns.VERIFIED + ", " + CertsColumns.MASTER_KEY_ID + ");");
|
|
||||||
case 14:
|
case 14:
|
||||||
db.execSQL("ALTER TABLE user_packets ADD COLUMN name TEXT");
|
db.execSQL("ALTER TABLE user_packets ADD COLUMN name TEXT");
|
||||||
db.execSQL("ALTER TABLE user_packets ADD COLUMN email TEXT");
|
db.execSQL("ALTER TABLE user_packets ADD COLUMN email TEXT");
|
||||||
|
@ -366,6 +348,25 @@ public class KeychainDatabase {
|
||||||
|
|
||||||
case 30:
|
case 30:
|
||||||
// ignore. this case only came up in an unreleased beta.
|
// 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);
|
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,12 @@ package org.sufficientlysecure.keychain.daos;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.support.annotation.WorkerThread;
|
import android.support.annotation.WorkerThread;
|
||||||
|
|
||||||
import com.squareup.sqldelight.RowMapper;
|
|
||||||
import com.squareup.sqldelight.SqlDelightQuery;
|
import com.squareup.sqldelight.SqlDelightQuery;
|
||||||
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
import org.bouncycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.sufficientlysecure.keychain.KeychainDatabase;
|
import org.sufficientlysecure.keychain.KeychainDatabase;
|
||||||
|
@ -127,27 +125,13 @@ public class KeyRepository extends AbstractDao {
|
||||||
|
|
||||||
public List<Long> getAllMasterKeyIds() {
|
public List<Long> getAllMasterKeyIds() {
|
||||||
SqlDelightQuery query = KeyRingPublic.FACTORY.selectAllMasterKeyIds();
|
SqlDelightQuery query = KeyRingPublic.FACTORY.selectAllMasterKeyIds();
|
||||||
ArrayList<Long> result = new ArrayList<>();
|
return mapAllRows(query, KeySignature.FACTORY.selectMasterKeyIdsBySignerMapper());
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
Long item = KeyRingPublic.FACTORY.selectAllMasterKeyIdsMapper().map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Long> getMasterKeyIdsBySigner(List<Long> signerMasterKeyIds) {
|
public List<Long> getMasterKeyIdsBySigner(List<Long> signerMasterKeyIds) {
|
||||||
long[] signerKeyIds = getLongListAsArray(signerMasterKeyIds);
|
long[] signerKeyIds = getLongListAsArray(signerMasterKeyIds);
|
||||||
SqlDelightQuery query = KeySignature.FACTORY.selectMasterKeyIdsBySigner(signerKeyIds);
|
SqlDelightQuery query = KeySignature.FACTORY.selectMasterKeyIdsBySigner(signerKeyIds);
|
||||||
ArrayList<Long> result = new ArrayList<>();
|
return mapAllRows(query, KeySignature.FACTORY.selectMasterKeyIdsBySignerMapper());
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
Long item = KeySignature.FACTORY.selectMasterKeyIdsBySignerMapper().map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getMasterKeyIdBySubkeyId(long subKeyId) {
|
public Long getMasterKeyIdBySubkeyId(long subKeyId) {
|
||||||
|
@ -162,88 +146,38 @@ public class KeyRepository extends AbstractDao {
|
||||||
|
|
||||||
public List<UnifiedKeyInfo> getUnifiedKeyInfo(long... masterKeyIds) {
|
public List<UnifiedKeyInfo> getUnifiedKeyInfo(long... masterKeyIds) {
|
||||||
SqlDelightQuery query = SubKey.FACTORY.selectUnifiedKeyInfoByMasterKeyIds(masterKeyIds);
|
SqlDelightQuery query = SubKey.FACTORY.selectUnifiedKeyInfoByMasterKeyIds(masterKeyIds);
|
||||||
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
|
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UnifiedKeyInfo> getUnifiedKeyInfosByMailAddress(String mailAddress) {
|
public List<UnifiedKeyInfo> getUnifiedKeyInfosByMailAddress(String mailAddress) {
|
||||||
SqlDelightQuery query = SubKey.FACTORY.selectUnifiedKeyInfoSearchMailAddress('%' + mailAddress + '%');
|
SqlDelightQuery query = SubKey.FACTORY.selectUnifiedKeyInfoSearchMailAddress('%' + mailAddress + '%');
|
||||||
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
|
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UnifiedKeyInfo> getAllUnifiedKeyInfo() {
|
public List<UnifiedKeyInfo> getAllUnifiedKeyInfo() {
|
||||||
SqlDelightQuery query = SubKey.FACTORY.selectAllUnifiedKeyInfo();
|
SqlDelightQuery query = SubKey.FACTORY.selectAllUnifiedKeyInfo();
|
||||||
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
|
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UnifiedKeyInfo> getAllUnifiedKeyInfoWithSecret() {
|
public List<UnifiedKeyInfo> getAllUnifiedKeyInfoWithSecret() {
|
||||||
SqlDelightQuery query = SubKey.FACTORY.selectAllUnifiedKeyInfoWithSecret();
|
SqlDelightQuery query = SubKey.FACTORY.selectAllUnifiedKeyInfoWithSecret();
|
||||||
ArrayList<UnifiedKeyInfo> result = new ArrayList<>();
|
return mapAllRows(query, SubKey.UNIFIED_KEY_INFO_MAPPER);
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
UnifiedKeyInfo item = SubKey.UNIFIED_KEY_INFO_MAPPER.map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserId> getUserIds(long... masterKeyIds) {
|
public List<UserId> getUserIds(long... masterKeyIds) {
|
||||||
SqlDelightQuery query = UserPacket.FACTORY.selectUserIdsByMasterKeyId(masterKeyIds);
|
SqlDelightQuery query = UserPacket.FACTORY.selectUserIdsByMasterKeyId(masterKeyIds);
|
||||||
ArrayList<UserId> result = new ArrayList<>();
|
return mapAllRows(query, UserPacket.USER_ID_MAPPER);
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
UserId item = UserPacket.USER_ID_MAPPER.map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getConfirmedUserIds(long masterKeyId) {
|
public List<String> getConfirmedUserIds(long masterKeyId) {
|
||||||
SqlDelightQuery query = UserPacket.FACTORY.selectUserIdsByMasterKeyIdAndVerification(
|
SqlDelightQuery query = UserPacket.FACTORY.selectUserIdsByMasterKeyIdAndVerification(
|
||||||
Certification.FACTORY, masterKeyId, VerificationStatus.VERIFIED_SECRET);
|
Certification.FACTORY, masterKeyId, VerificationStatus.VERIFIED_SECRET);
|
||||||
ArrayList<String> result = new ArrayList<>();
|
return mapAllRows(query, cursor -> UserPacket.USER_ID_MAPPER.map(cursor).user_id());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SubKey> getSubKeysByMasterKeyId(long masterKeyId) {
|
public List<SubKey> getSubKeysByMasterKeyId(long masterKeyId) {
|
||||||
SqlDelightQuery query = SubKey.FACTORY.selectSubkeysByMasterKeyId(masterKeyId);
|
SqlDelightQuery query = SubKey.FACTORY.selectSubkeysByMasterKeyId(masterKeyId);
|
||||||
ArrayList<SubKey> result = new ArrayList<>();
|
return mapAllRows(query, SubKey.SUBKEY_MAPPER);
|
||||||
try (Cursor cursor = getReadableDb().query(query)) {
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
SubKey item = SubKey.SUBKEY_MAPPER.map(cursor);
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
|
public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
|
||||||
|
@ -313,6 +247,11 @@ public class KeyRepository extends AbstractDao {
|
||||||
return mapSingleRowOrThrow(query, SubKey.FACTORY.selectEffectiveAuthKeyIdByMasterKeyIdMapper());
|
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 static class NotFoundException extends Exception {
|
||||||
public NotFoundException() {
|
public NotFoundException() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,6 +225,7 @@ public class KeyWritableRepository extends KeyRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Date creation = key.getCreationTime();
|
Date creation = key.getCreationTime();
|
||||||
|
Date bindingSignatureTime = key.getBindingSignatureTime();
|
||||||
Date expiry = key.getExpiryTime();
|
Date expiry = key.getExpiryTime();
|
||||||
if (expiry != null) {
|
if (expiry != null) {
|
||||||
if (key.isExpired()) {
|
if (key.isExpired()) {
|
||||||
|
@ -240,7 +241,7 @@ public class KeyWritableRepository extends KeyRepository {
|
||||||
|
|
||||||
SubKey subKey = SubKey.create(masterKeyId, rank, key.getKeyId(),
|
SubKey subKey = SubKey.create(masterKeyId, rank, key.getKeyId(),
|
||||||
key.getBitStrength(), key.getCurveOid(), key.getAlgorithm(), key.getFingerprint(),
|
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));
|
operations.add(DatabaseBatchInteractor.createInsertSubKey(subKey));
|
||||||
|
|
||||||
++rank;
|
++rank;
|
||||||
|
@ -670,6 +671,8 @@ public class KeyWritableRepository extends KeyRepository {
|
||||||
// with has_secret = 1
|
// with has_secret = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
databaseNotifyManager.notifyKeyChange(masterKeyId);
|
||||||
|
|
||||||
log(LogType.MSG_IS_SUCCESS);
|
log(LogType.MSG_IS_SUCCESS);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,13 @@ public abstract class SubKey implements KeysModel {
|
||||||
|
|
||||||
public static SubKey create(long masterKeyId, long rank, long keyId, Integer keySize, String keyCurveOid,
|
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,
|
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 creationUnixTime = creation.getTime() / 1000;
|
||||||
Long expiryUnixTime = expiry != null ? expiry.getTime() / 1000 : null;
|
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,
|
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) {
|
public static InsertKey createInsertStatement(SupportSQLiteDatabase db) {
|
||||||
|
@ -53,7 +55,7 @@ public abstract class SubKey implements KeysModel {
|
||||||
public void bindTo(InsertKey statement) {
|
public void bindTo(InsertKey statement) {
|
||||||
statement.bind(master_key_id(), rank(), key_id(), key_size(), key_curve_oid(), algorithm(), fingerprint(),
|
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(),
|
can_certify(), can_sign(), can_encrypt(), can_authenticate(), is_revoked(), has_secret(), is_secure(),
|
||||||
creation(), expiry());
|
creation(), expiry(), validFrom());
|
||||||
}
|
}
|
||||||
|
|
||||||
@AutoValue
|
@AutoValue
|
||||||
|
|
|
@ -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_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_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_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_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_BAD_TYPE(LogLevel.WARN, R.string.msg_kc_sub_bad_type),
|
||||||
MSG_KC_SUB_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_dup),
|
MSG_KC_SUB_DUP (LogLevel.DEBUG, R.string.msg_kc_sub_dup),
|
||||||
|
|
|
@ -134,11 +134,33 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
|
||||||
: PGPSignature.SUBKEY_REVOCATION).hasNext();
|
: PGPSignature.SUBKEY_REVOCATION).hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpired () {
|
public boolean isExpired() {
|
||||||
Date expiry = getExpiryTime();
|
Date expiry = getExpiryTime();
|
||||||
return expiry != null && expiry.before(new Date());
|
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() {
|
public boolean isSecure() {
|
||||||
return PgpSecurityConstants.checkForSecurityProblems(this) == null;
|
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. */
|
/** Returns whether this key is valid, ie not expired or revoked. */
|
||||||
public boolean isValid() {
|
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.
|
// For use in key export only; returns the public key in a JCA compatible format.
|
||||||
|
|
|
@ -32,7 +32,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -651,7 +651,7 @@ public class PgpSignEncryptOperation extends BaseOperation<PgpSignEncryptInputPa
|
||||||
PGPEncryptedDataGenerator cPk, long encryptMasterKeyId) {
|
PGPEncryptedDataGenerator cPk, long encryptMasterKeyId) {
|
||||||
try {
|
try {
|
||||||
CanonicalizedPublicKeyRing keyRing = mKeyRepository.getCanonicalizedPublicKeyRing(encryptMasterKeyId);
|
CanonicalizedPublicKeyRing keyRing = mKeyRepository.getCanonicalizedPublicKeyRing(encryptMasterKeyId);
|
||||||
Set<Long> encryptSubKeyIds = keyRing.getEncryptIds();
|
List<Long> encryptSubKeyIds = mKeyRepository.getPublicEncryptionIds(encryptMasterKeyId);
|
||||||
for (Long subKeyId : encryptSubKeyIds) {
|
for (Long subKeyId : encryptSubKeyIds) {
|
||||||
CanonicalizedPublicKey key = keyRing.getPublicKey(subKeyId);
|
CanonicalizedPublicKey key = keyRing.getPublicKey(subKeyId);
|
||||||
cPk.addMethod(key.getPubKeyEncryptionGenerator(data.isHiddenRecipients()));
|
cPk.addMethod(key.getPubKeyEncryptionGenerator(data.isHiddenRecipients()));
|
||||||
|
|
|
@ -912,13 +912,6 @@ public class UncachedKeyRing {
|
||||||
continue;
|
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)) {
|
if (cert.getCreationTime().before(keyCreationTime)) {
|
||||||
// Signature is earlier than key creation time
|
// Signature is earlier than key creation time
|
||||||
log.add(LogType.MSG_KC_SUB_BAD_TIME_EARLY, indent);
|
log.add(LogType.MSG_KC_SUB_BAD_TIME_EARLY, indent);
|
||||||
|
|
|
@ -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() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,6 +27,7 @@ import android.os.Parcelable;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
|
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
import org.sufficientlysecure.keychain.keyimport.HkpKeyserverAddress;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
@ -224,6 +225,18 @@ public abstract class SaveKeyringParcel implements Parcelable {
|
||||||
|
|
||||||
return autoBuild();
|
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,
|
// performance gain for using Parcelable here would probably be negligible,
|
||||||
|
@ -243,6 +256,22 @@ public abstract class SaveKeyringParcel implements Parcelable {
|
||||||
Long expiry) {
|
Long expiry) {
|
||||||
return new AutoValue_SaveKeyringParcel_SubkeyAdd(algorithm, keySize, curve, flags, 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
|
@AutoValue
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class EditKeyFragment extends Fragment {
|
||||||
mUserIdsAddedAdapter = new UserIdsAddedAdapter(getActivity(), mSkpBuilder.getMutableAddUserIds(), true);
|
mUserIdsAddedAdapter = new UserIdsAddedAdapter(getActivity(), mSkpBuilder.getMutableAddUserIds(), true);
|
||||||
mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter);
|
mUserIdsAddedList.setAdapter(mUserIdsAddedAdapter);
|
||||||
|
|
||||||
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSkpBuilder.getMutableAddSubKeys(), true);
|
mSubkeysAddedAdapter = new SubkeysAddedAdapter(getActivity(), mSkpBuilder.getMutableAddSubKeys());
|
||||||
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
|
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,8 +18,10 @@
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.ViewModel;
|
||||||
import android.arch.lifecycle.ViewModelProviders;
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -29,15 +31,19 @@ import android.os.Messenger;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
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.ActionMode;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.ViewAnimator;
|
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.R;
|
||||||
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
|
||||||
import org.sufficientlysecure.keychain.model.SubKey;
|
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.operations.results.EditKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Builder;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
|
||||||
import org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.ViewKeyAdvViewModel;
|
import org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.ViewKeyAdvViewModel;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.SubkeyAddedItem;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
|
|
||||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.recyclerview.DividerItemDecoration;
|
||||||
|
|
||||||
|
|
||||||
public class ViewKeyAdvSubkeysFragment extends Fragment {
|
public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
private ListView mSubkeysList;
|
public static final int SUBKEY_TYPE_DETAIL = 1;
|
||||||
private ListView mSubkeysAddedList;
|
public static final int SUBKEY_TYPE_ADDED = 2;
|
||||||
private View mSubkeysAddedLayout;
|
|
||||||
private ViewAnimator mSubkeyAddFabLayout;
|
|
||||||
|
|
||||||
private SubkeysAdapter mSubkeysAdapter;
|
private RecyclerView subkeysList;
|
||||||
private SubkeysAddedAdapter mSubkeysAddedAdapter;
|
private ViewAnimator subkeyAddFabLayout;
|
||||||
|
|
||||||
|
private FlexibleAdapter<IFlexible> subkeysAdapter;
|
||||||
|
|
||||||
private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mEditKeyHelper;
|
private CryptoOperationHelper<SaveKeyringParcel, EditKeyResult> mEditKeyHelper;
|
||||||
|
private SubkeyEditViewModel subkeyEditViewModel;
|
||||||
private SaveKeyringParcel.Builder mEditModeSkpBuilder;
|
|
||||||
private UnifiedKeyInfo unifiedKeyInfo;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.view_key_adv_subkeys_fragment, viewGroup, false);
|
View view = inflater.inflate(R.layout.view_key_adv_subkeys_fragment, viewGroup, false);
|
||||||
|
|
||||||
mSubkeysList = view.findViewById(R.id.view_key_subkeys);
|
subkeysList = view.findViewById(R.id.view_key_subkeys);
|
||||||
mSubkeysAddedList = view.findViewById(R.id.view_key_subkeys_added);
|
subkeysList.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||||
mSubkeysAddedLayout = view.findViewById(R.id.view_key_subkeys_add_layout);
|
subkeysList.addItemDecoration(new DividerItemDecoration(requireContext(), LinearLayoutManager.VERTICAL, false));
|
||||||
|
|
||||||
mSubkeysList.setOnItemClickListener((parent, view1, position, id) -> editSubkey(position));
|
subkeyAddFabLayout = view.findViewById(R.id.view_key_subkey_fab_layout);
|
||||||
|
|
||||||
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);
|
|
||||||
view.findViewById(R.id.view_key_subkey_fab).setOnClickListener(v -> addSubkey());
|
view.findViewById(R.id.view_key_subkey_fab).setOnClickListener(v -> addSubkey());
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
@ -102,26 +94,32 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
// Create an empty adapter we will use to display the loaded data.
|
subkeysAdapter = new FlexibleAdapter<>(null, null, true);
|
||||||
mSubkeysAdapter = new SubkeysAdapter(requireContext());
|
subkeysAdapter.addListener((OnItemClickListener) (view, position) -> editSubkey(position));
|
||||||
mSubkeysList.setAdapter(mSubkeysAdapter);
|
subkeysList.setAdapter(subkeysAdapter);
|
||||||
|
|
||||||
ViewKeyAdvViewModel viewModel = ViewModelProviders.of(requireActivity()).get(ViewKeyAdvViewModel.class);
|
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);
|
viewModel.getSubkeyLiveData(requireContext()).observe(this, this::onLoadSubKeys);
|
||||||
|
|
||||||
|
subkeyEditViewModel = ViewModelProviders.of(this).get(SubkeyEditViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoadFinished(UnifiedKeyInfo unifiedKeyInfo) {
|
public static class SubkeyEditViewModel extends ViewModel {
|
||||||
// Avoid NullPointerExceptions, if we get an empty result set.
|
public Builder skpBuilder;
|
||||||
if (unifiedKeyInfo == null) {
|
UnifiedKeyInfo unifiedKeyInfo;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.unifiedKeyInfo = unifiedKeyInfo;
|
public void onLoadUnifiedKeyId(UnifiedKeyInfo unifiedKeyInfo) {
|
||||||
|
subkeyEditViewModel.unifiedKeyInfo = unifiedKeyInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLoadSubKeys(List<SubKey> subKeys) {
|
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
|
@Override
|
||||||
|
@ -152,16 +150,10 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
activity.startActionMode(new ActionMode.Callback() {
|
activity.startActionMode(new ActionMode.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
|
subkeyAddFabLayout.setDisplayedChild(1);
|
||||||
mEditModeSkpBuilder = SaveKeyringParcel.buildChangeKeyringParcel(unifiedKeyInfo.master_key_id(), unifiedKeyInfo.fingerprint());
|
subkeyEditViewModel.skpBuilder = SaveKeyringParcel.buildChangeKeyringParcel(
|
||||||
|
subkeyEditViewModel.unifiedKeyInfo.master_key_id(), subkeyEditViewModel.unifiedKeyInfo.fingerprint());
|
||||||
mSubkeysAddedAdapter = new SubkeysAddedAdapter(
|
subkeysAdapter.notifyDataSetChanged();
|
||||||
getActivity(), mEditModeSkpBuilder.getMutableAddSubKeys(), false);
|
|
||||||
mSubkeysAddedList.setAdapter(mSubkeysAddedAdapter);
|
|
||||||
mSubkeysAddedLayout.setVisibility(View.VISIBLE);
|
|
||||||
mSubkeyAddFabLayout.setDisplayedChild(1);
|
|
||||||
|
|
||||||
mSubkeysAdapter.setEditMode(mEditModeSkpBuilder);
|
|
||||||
|
|
||||||
mode.setTitle(R.string.title_edit_subkeys);
|
mode.setTitle(R.string.title_edit_subkeys);
|
||||||
mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu);
|
mode.getMenuInflater().inflate(R.menu.action_edit_uids, menu);
|
||||||
|
@ -182,63 +174,60 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
public void onDestroyActionMode(ActionMode mode) {
|
||||||
mEditModeSkpBuilder = null;
|
subkeyEditViewModel.skpBuilder = null;
|
||||||
mSubkeysAdapter.setEditMode(null);
|
subkeysAdapter.removeItemsOfType(2);
|
||||||
mSubkeysAddedLayout.setVisibility(View.GONE);
|
subkeyAddFabLayout.setDisplayedChild(0);
|
||||||
mSubkeyAddFabLayout.setDisplayedChild(0);
|
subkeysAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSubkey() {
|
private void addSubkey() {
|
||||||
boolean willBeMasterKey;
|
boolean willBeMasterKey = subkeysAdapter.getItemCount() == 0;
|
||||||
if (mSubkeysAdapter != null) {
|
|
||||||
willBeMasterKey = mSubkeysAdapter.getCount() == 0 && mSubkeysAddedAdapter.getCount() == 0;
|
|
||||||
} else {
|
|
||||||
willBeMasterKey = mSubkeysAddedAdapter.getCount() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
AddSubkeyDialogFragment addSubkeyDialogFragment =
|
AddSubkeyDialogFragment addSubkeyDialogFragment = AddSubkeyDialogFragment.newInstance(willBeMasterKey);
|
||||||
AddSubkeyDialogFragment.newInstance(willBeMasterKey);
|
addSubkeyDialogFragment.setOnAlgorithmSelectedListener(newSubkey -> {
|
||||||
addSubkeyDialogFragment
|
subkeyEditViewModel.skpBuilder.addSubkeyAdd(newSubkey);
|
||||||
.setOnAlgorithmSelectedListener(newSubkey -> mSubkeysAddedAdapter.add(newSubkey));
|
subkeysAdapter.addItem(new SubkeyAddedItem(newSubkey, subkeyEditViewModel));
|
||||||
|
});
|
||||||
addSubkeyDialogFragment.show(requireFragmentManager(), "addSubkeyDialog");
|
addSubkeyDialogFragment.show(requireFragmentManager(), "addSubkeyDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editSubkey(final int position) {
|
private boolean editSubkey(final int position) {
|
||||||
final SubKey subKey = mSubkeysAdapter.getItem(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() {
|
Handler returnHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
|
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
|
||||||
editSubkeyExpiry(position);
|
editSubkeyExpiry(item);
|
||||||
break;
|
break;
|
||||||
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
|
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
|
||||||
// toggle
|
SubKey subKey = item.subkeyInfo;
|
||||||
if (mEditModeSkpBuilder.getMutableRevokeSubKeys().contains(subKey.key_id())) {
|
subkeyEditViewModel.skpBuilder.addRevokeSubkey(subKey.key_id());
|
||||||
mEditModeSkpBuilder.removeRevokeSubkey(subKey.key_id());
|
|
||||||
} else {
|
|
||||||
mEditModeSkpBuilder.addRevokeSubkey(subKey.key_id());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case EditSubkeyDialogFragment.MESSAGE_STRIP: {
|
case EditSubkeyDialogFragment.MESSAGE_STRIP: {
|
||||||
if (subKey.has_secret() == SecretKeyType.GNU_DUMMY) {
|
editSubkeyToggleStrip(item);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSubkeysAdapter.notifyDataSetChanged();
|
subkeysAdapter.notifyItemChanged(position);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,15 +235,24 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
final Messenger messenger = new Messenger(returnHandler);
|
final Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(() -> {
|
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(() -> {
|
||||||
EditSubkeyDialogFragment dialogFragment =
|
EditSubkeyDialogFragment dialogFragment = EditSubkeyDialogFragment.newInstance(messenger);
|
||||||
EditSubkeyDialogFragment.newInstance(messenger);
|
|
||||||
|
|
||||||
dialogFragment.show(requireFragmentManager(), "editSubkeyDialog");
|
dialogFragment.show(requireFragmentManager(), "editSubkeyDialog");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void editSubkeyExpiry(final int position) {
|
private void editSubkeyToggleStrip(SubKeyItem item) {
|
||||||
SubKey subKey = mSubkeysAdapter.getItem(position);
|
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 keyId = subKey.key_id();
|
||||||
final Long creationDate = subKey.creation();
|
final Long creationDate = subKey.creation();
|
||||||
final Long expiryDate = subKey.expiry();
|
final Long expiryDate = subKey.expiry();
|
||||||
|
@ -266,11 +264,11 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY:
|
case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY:
|
||||||
Long expiry = (Long) message.getData().getSerializable(
|
Long expiry = (Long) message.getData().getSerializable(
|
||||||
EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY);
|
EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY);
|
||||||
mEditModeSkpBuilder.addOrReplaceSubkeyChange(
|
subkeyEditViewModel.skpBuilder.addOrReplaceSubkeyChange(
|
||||||
SubkeyChange.createFlagsOrExpiryChange(keyId, null, expiry));
|
SubkeyChange.createFlagsOrExpiryChange(keyId, null, expiry));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mSubkeysAdapter.notifyDataSetChanged();
|
subkeysAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -292,7 +290,7 @@ public class ViewKeyAdvSubkeysFragment extends Fragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SaveKeyringParcel createOperationInput() {
|
public SaveKeyringParcel createOperationInput() {
|
||||||
return mEditModeSkpBuilder.build();
|
return subkeyEditViewModel.skpBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* 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.ui.adapter;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||||
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
|
||||||
|
import eu.davidea.flexibleadapter.items.IFlexible;
|
||||||
|
import org.bouncycastle.bcpg.sig.KeyFlags;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||||
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyAdd;
|
||||||
|
import org.sufficientlysecure.keychain.ui.SubKeyItem.SubkeyViewHolder;
|
||||||
|
import org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.SubkeyEditViewModel;
|
||||||
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
|
||||||
|
|
||||||
|
public class SubkeyAddedItem extends AbstractFlexibleItem<SubkeyViewHolder> {
|
||||||
|
private SubkeyAdd subkeyAdd;
|
||||||
|
private final SubkeyEditViewModel viewModel;
|
||||||
|
|
||||||
|
public SubkeyAddedItem(SubkeyAdd newSubkey, SubkeyEditViewModel viewModel) {
|
||||||
|
this.subkeyAdd = newSubkey;
|
||||||
|
this.viewModel = viewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof SubkeyAddedItem && subkeyAdd == o;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return subkeyAdd.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 int getItemViewType() {
|
||||||
|
return ViewKeyAdvSubkeysFragment.SUBKEY_TYPE_ADDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, SubkeyViewHolder holder, int position,
|
||||||
|
List<Object> payloads) {
|
||||||
|
Date expiry = subkeyAdd.getExpiry() != null && subkeyAdd.getExpiry() != 0L ? new Date(subkeyAdd.getExpiry() * 1000) : null;
|
||||||
|
|
||||||
|
holder.bindKeyId(null, false);
|
||||||
|
holder.bindKeyDetails(subkeyAdd.getAlgorithm(), subkeyAdd.getKeySize(), subkeyAdd.getCurve(), SecretKeyType.PASSPHRASE);
|
||||||
|
holder.bindKeyStatus(null, expiry, false, true);
|
||||||
|
holder.bindKeyFlags(subkeyAdd.canCertify(), subkeyAdd.canSign(), subkeyAdd.canEncrypt(), subkeyAdd.canAuthenticate());
|
||||||
|
holder.bindSubkeyAction(R.string.subkey_action_create, v -> {
|
||||||
|
viewModel.skpBuilder.getMutableAddSubKeys().remove(subkeyAdd);
|
||||||
|
adapter.removeItem(position);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,304 +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.ui.adapter;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.ColorStateList;
|
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.text.Spannable;
|
|
||||||
import android.text.SpannableString;
|
|
||||||
import android.text.SpannableStringBuilder;
|
|
||||||
import android.text.format.DateFormat;
|
|
||||||
import android.text.style.StyleSpan;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.model.SubKey;
|
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
|
||||||
|
|
||||||
public class SubkeysAdapter extends BaseAdapter {
|
|
||||||
private final Context context;
|
|
||||||
private final LayoutInflater layoutInflater;
|
|
||||||
|
|
||||||
private List<SubKey> data;
|
|
||||||
private SaveKeyringParcel.Builder mSkpBuilder;
|
|
||||||
|
|
||||||
private ColorStateList mDefaultTextColor;
|
|
||||||
|
|
||||||
public SubkeysAdapter(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
layoutInflater = LayoutInflater.from(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(List<SubKey> data) {
|
|
||||||
this.data = data;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return data != null ? data.size() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubKey getItem(int position) {
|
|
||||||
return data.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getItemId(int position) {
|
|
||||||
return data.get(position).key_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
|
||||||
View view;
|
|
||||||
if (convertView != null) {
|
|
||||||
view = convertView;
|
|
||||||
} else {
|
|
||||||
view = layoutInflater.inflate(R.layout.view_key_adv_subkey_item, parent, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDefaultTextColor == null) {
|
|
||||||
TextView keyId = view.findViewById(R.id.subkey_item_key_id);
|
|
||||||
mDefaultTextColor = keyId.getTextColors();
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView vKeyId = view.findViewById(R.id.subkey_item_key_id);
|
|
||||||
TextView vKeyDetails = view.findViewById(R.id.subkey_item_details);
|
|
||||||
TextView vKeyExpiry = view.findViewById(R.id.subkey_item_expiry);
|
|
||||||
ImageView vCertifyIcon = view.findViewById(R.id.subkey_item_ic_certify);
|
|
||||||
ImageView vSignIcon = view.findViewById(R.id.subkey_item_ic_sign);
|
|
||||||
ImageView vEncryptIcon = view.findViewById(R.id.subkey_item_ic_encrypt);
|
|
||||||
ImageView vAuthenticateIcon = view.findViewById(R.id.subkey_item_ic_authenticate);
|
|
||||||
ImageView vEditImage = view.findViewById(R.id.subkey_item_edit_image);
|
|
||||||
ImageView vStatus = view.findViewById(R.id.subkey_item_status);
|
|
||||||
|
|
||||||
// not used:
|
|
||||||
ImageView deleteImage = view.findViewById(R.id.subkey_item_delete_button);
|
|
||||||
deleteImage.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
SubKey subKey = getItem(position);
|
|
||||||
|
|
||||||
vKeyId.setText(KeyFormattingUtils.beautifyKeyId(subKey.key_id()));
|
|
||||||
|
|
||||||
// may be set with additional "stripped" later on
|
|
||||||
SpannableStringBuilder algorithmStr = new SpannableStringBuilder();
|
|
||||||
algorithmStr.append(KeyFormattingUtils.getAlgorithmInfo(
|
|
||||||
context,
|
|
||||||
subKey.algorithm(),
|
|
||||||
subKey.key_size(),
|
|
||||||
subKey.key_curve_oid()
|
|
||||||
));
|
|
||||||
|
|
||||||
SubkeyChange change = mSkpBuilder != null ? mSkpBuilder.getSubkeyChange(subKey.key_id()) : null;
|
|
||||||
if (change != null && (change.getDummyStrip() || change.getMoveKeyToSecurityToken())) {
|
|
||||||
if (change.getDummyStrip()) {
|
|
||||||
algorithmStr.append(", ");
|
|
||||||
final SpannableString boldStripped = new SpannableString(
|
|
||||||
context.getString(R.string.key_stripped)
|
|
||||||
);
|
|
||||||
boldStripped.setSpan(new StyleSpan(Typeface.BOLD), 0, boldStripped.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
algorithmStr.append(boldStripped);
|
|
||||||
}
|
|
||||||
if (change.getMoveKeyToSecurityToken()) {
|
|
||||||
algorithmStr.append(", ");
|
|
||||||
final SpannableString boldDivert = new SpannableString(
|
|
||||||
context.getString(R.string.key_divert)
|
|
||||||
);
|
|
||||||
boldDivert.setSpan(new StyleSpan(Typeface.BOLD), 0, boldDivert.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
algorithmStr.append(boldDivert);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switch (subKey.has_secret()) {
|
|
||||||
case GNU_DUMMY:
|
|
||||||
algorithmStr.append(", ");
|
|
||||||
algorithmStr.append(context.getString(R.string.key_stripped));
|
|
||||||
break;
|
|
||||||
case DIVERT_TO_CARD:
|
|
||||||
algorithmStr.append(", ");
|
|
||||||
algorithmStr.append(context.getString(R.string.key_divert));
|
|
||||||
break;
|
|
||||||
case PASSPHRASE_EMPTY:
|
|
||||||
algorithmStr.append(", ");
|
|
||||||
algorithmStr.append(context.getString(R.string.key_no_passphrase));
|
|
||||||
break;
|
|
||||||
case UNAVAILABLE:
|
|
||||||
// don't show this on pub keys
|
|
||||||
//algorithmStr += ", " + context.getString(R.string.key_unavailable);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vKeyDetails.setText(algorithmStr, TextView.BufferType.SPANNABLE);
|
|
||||||
|
|
||||||
boolean isMasterKey = subKey.rank() == 0;
|
|
||||||
if (isMasterKey) {
|
|
||||||
vKeyId.setTypeface(null, Typeface.BOLD);
|
|
||||||
} else {
|
|
||||||
vKeyId.setTypeface(null, Typeface.NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set icons according to properties
|
|
||||||
vCertifyIcon.setVisibility(subKey.can_certify() ? View.VISIBLE : View.GONE);
|
|
||||||
vEncryptIcon.setVisibility(subKey.can_encrypt() ? View.VISIBLE : View.GONE);
|
|
||||||
vSignIcon.setVisibility(subKey.can_sign() ? View.VISIBLE : View.GONE);
|
|
||||||
vAuthenticateIcon.setVisibility(subKey.can_authenticate() ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
boolean isRevoked = subKey.is_revoked();
|
|
||||||
|
|
||||||
Date expiryDate = null;
|
|
||||||
if (subKey.expires()) {
|
|
||||||
expiryDate = new Date(subKey.expiry() * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// for edit key
|
|
||||||
if (mSkpBuilder != null) {
|
|
||||||
boolean revokeThisSubkey = (mSkpBuilder.getMutableRevokeSubKeys().contains(subKey.key_id()));
|
|
||||||
|
|
||||||
if (revokeThisSubkey) {
|
|
||||||
if (!isRevoked) {
|
|
||||||
isRevoked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveKeyringParcel.SubkeyChange subkeyChange = mSkpBuilder.getSubkeyChange(subKey.key_id());
|
|
||||||
if (subkeyChange != null) {
|
|
||||||
if (subkeyChange.getExpiry() == null || subkeyChange.getExpiry() == 0L) {
|
|
||||||
expiryDate = null;
|
|
||||||
} else {
|
|
||||||
expiryDate = new Date(subkeyChange.getExpiry() * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vEditImage.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
vEditImage.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isExpired;
|
|
||||||
if (expiryDate != null) {
|
|
||||||
isExpired = expiryDate.before(new Date());
|
|
||||||
Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
|
||||||
expiryCal.setTime(expiryDate);
|
|
||||||
// convert from UTC to time zone of device
|
|
||||||
expiryCal.setTimeZone(TimeZone.getDefault());
|
|
||||||
|
|
||||||
vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": "
|
|
||||||
+ DateFormat.getDateFormat(context).format(expiryCal.getTime()));
|
|
||||||
} else {
|
|
||||||
isExpired = false;
|
|
||||||
|
|
||||||
vKeyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if key is expired or revoked...
|
|
||||||
boolean isInvalid = isRevoked || isExpired || !subKey.is_secure();
|
|
||||||
if (isInvalid) {
|
|
||||||
vStatus.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
vCertifyIcon.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
vSignIcon.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
vEncryptIcon.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
vAuthenticateIcon.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
|
|
||||||
if (isRevoked) {
|
|
||||||
vStatus.setImageResource(R.drawable.status_signature_revoked_cutout_24dp);
|
|
||||||
vStatus.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
} else if (isExpired) {
|
|
||||||
vStatus.setImageResource(R.drawable.status_signature_expired_cutout_24dp);
|
|
||||||
vStatus.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
} else if (!subKey.is_secure()) {
|
|
||||||
vStatus.setImageResource(R.drawable.status_signature_invalid_cutout_24dp);
|
|
||||||
vStatus.setColorFilter(
|
|
||||||
context.getResources().getColor(R.color.key_flag_gray),
|
|
||||||
PorterDuff.Mode.SRC_IN);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vStatus.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
vKeyId.setTextColor(mDefaultTextColor);
|
|
||||||
vKeyDetails.setTextColor(mDefaultTextColor);
|
|
||||||
vKeyExpiry.setTextColor(mDefaultTextColor);
|
|
||||||
|
|
||||||
vCertifyIcon.clearColorFilter();
|
|
||||||
vSignIcon.clearColorFilter();
|
|
||||||
vEncryptIcon.clearColorFilter();
|
|
||||||
vAuthenticateIcon.clearColorFilter();
|
|
||||||
}
|
|
||||||
vKeyId.setEnabled(!isInvalid);
|
|
||||||
vKeyDetails.setEnabled(!isInvalid);
|
|
||||||
vKeyExpiry.setEnabled(!isInvalid);
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable selection of items, http://stackoverflow.com/a/4075045
|
|
||||||
@Override
|
|
||||||
public boolean areAllItemsEnabled() {
|
|
||||||
return mSkpBuilder != null && super.areAllItemsEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable selection of items, http://stackoverflow.com/a/4075045
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled(int position) {
|
|
||||||
return mSkpBuilder != null && super.isEnabled(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Set this adapter into edit mode. This mode displays additional info for
|
|
||||||
* each item from a supplied SaveKeyringParcel reference.
|
|
||||||
*
|
|
||||||
* Note that it is up to the caller to reload the underlying cursor after
|
|
||||||
* updating the SaveKeyringParcel!
|
|
||||||
*
|
|
||||||
* @see SaveKeyringParcel
|
|
||||||
*
|
|
||||||
* @param builder The parcel to get info from, or null to leave edit mode.
|
|
||||||
*/
|
|
||||||
public void setEditMode(@Nullable SaveKeyringParcel.Builder builder) {
|
|
||||||
mSkpBuilder = builder;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,6 +17,12 @@
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui.adapter;
|
package org.sufficientlysecure.keychain.ui.adapter;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
@ -26,7 +32,6 @@ import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -36,25 +41,18 @@ import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAdd> {
|
public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAdd> {
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private boolean mNewKeyring;
|
|
||||||
|
|
||||||
public SubkeysAddedAdapter(Activity activity, List<SaveKeyringParcel.SubkeyAdd> data,
|
public SubkeysAddedAdapter(Activity activity, List<SaveKeyringParcel.SubkeyAdd> data) {
|
||||||
boolean newKeyring) {
|
|
||||||
super(activity, -1, data);
|
super(activity, -1, data);
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
mNewKeyring = newKeyring;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ViewHolder {
|
static class ViewHolder {
|
||||||
|
public View itemView;
|
||||||
public TextView vKeyId;
|
public TextView vKeyId;
|
||||||
public TextView vKeyDetails;
|
public TextView vKeyDetails;
|
||||||
public TextView vKeyExpiry;
|
public TextView vKeyExpiry;
|
||||||
|
@ -62,7 +60,6 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd
|
||||||
public ImageView vSignIcon;
|
public ImageView vSignIcon;
|
||||||
public ImageView vEncryptIcon;
|
public ImageView vEncryptIcon;
|
||||||
public ImageView vAuthenticateIcon;
|
public ImageView vAuthenticateIcon;
|
||||||
public ImageButton vDelete;
|
|
||||||
// also hold a reference to the model item
|
// also hold a reference to the model item
|
||||||
public SaveKeyringParcel.SubkeyAdd mModel;
|
public SaveKeyringParcel.SubkeyAdd mModel;
|
||||||
}
|
}
|
||||||
|
@ -73,23 +70,15 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd
|
||||||
// Not recycled, inflate a new view
|
// Not recycled, inflate a new view
|
||||||
convertView = mInflater.inflate(R.layout.view_key_adv_subkey_item, parent, false);
|
convertView = mInflater.inflate(R.layout.view_key_adv_subkey_item, parent, false);
|
||||||
final ViewHolder holder = new ViewHolder();
|
final ViewHolder holder = new ViewHolder();
|
||||||
|
holder.itemView = convertView;
|
||||||
holder.vKeyId = convertView.findViewById(R.id.subkey_item_key_id);
|
holder.vKeyId = convertView.findViewById(R.id.subkey_item_key_id);
|
||||||
holder.vKeyDetails = convertView.findViewById(R.id.subkey_item_details);
|
holder.vKeyDetails = convertView.findViewById(R.id.subkey_item_details);
|
||||||
holder.vKeyExpiry = convertView.findViewById(R.id.subkey_item_expiry);
|
holder.vKeyExpiry = convertView.findViewById(R.id.subkey_item_status);
|
||||||
holder.vCertifyIcon = convertView.findViewById(R.id.subkey_item_ic_certify);
|
holder.vCertifyIcon = convertView.findViewById(R.id.subkey_item_ic_certify);
|
||||||
holder.vSignIcon = convertView.findViewById(R.id.subkey_item_ic_sign);
|
holder.vSignIcon = convertView.findViewById(R.id.subkey_item_ic_sign);
|
||||||
holder.vEncryptIcon = convertView.findViewById(R.id.subkey_item_ic_encrypt);
|
holder.vEncryptIcon = convertView.findViewById(R.id.subkey_item_ic_encrypt);
|
||||||
holder.vAuthenticateIcon = convertView.findViewById(R.id.subkey_item_ic_authenticate);
|
holder.vAuthenticateIcon = convertView.findViewById(R.id.subkey_item_ic_authenticate);
|
||||||
|
|
||||||
holder.vDelete = convertView.findViewById(R.id.subkey_item_delete_button);
|
|
||||||
holder.vDelete.setVisibility(View.VISIBLE); // always visible
|
|
||||||
|
|
||||||
// not used:
|
|
||||||
ImageView vEdit = convertView.findViewById(R.id.subkey_item_edit_image);
|
|
||||||
vEdit.setVisibility(View.GONE);
|
|
||||||
ImageView vStatus = convertView.findViewById(R.id.subkey_item_status);
|
|
||||||
vStatus.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +94,10 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd
|
||||||
holder.mModel.getCurve()
|
holder.mModel.getCurve()
|
||||||
);
|
);
|
||||||
|
|
||||||
boolean isMasterKey = mNewKeyring && position == 0;
|
boolean isMasterKey = position == 0;
|
||||||
if (isMasterKey) {
|
if (isMasterKey) {
|
||||||
holder.vKeyId.setTypeface(null, Typeface.BOLD);
|
holder.vKeyId.setTypeface(null, Typeface.BOLD);
|
||||||
holder.vDelete.setImageResource(R.drawable.ic_change_grey_24dp);
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
holder.vDelete.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// swapping out the old master key with newly set master key
|
// swapping out the old master key with newly set master key
|
||||||
|
@ -135,8 +123,7 @@ public class SubkeysAddedAdapter extends ArrayAdapter<SaveKeyringParcel.SubkeyAd
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
holder.vKeyId.setTypeface(null, Typeface.NORMAL);
|
holder.vKeyId.setTypeface(null, Typeface.NORMAL);
|
||||||
holder.vDelete.setImageResource(R.drawable.ic_close_grey_24dp);
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
holder.vDelete.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// remove reference model item from adapter (data and notify about change)
|
// remove reference model item from adapter (data and notify about change)
|
||||||
|
|
|
@ -158,6 +158,10 @@ public class KeyFormattingUtils {
|
||||||
return algorithmStr;
|
return algorithmStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case EDDSA: {
|
||||||
|
return "EdDSA";
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
algorithmStr = context.getResources().getString(R.string.unknown);
|
algorithmStr = context.getResources().getString(R.string.unknown);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:height="24dp"
|
||||||
|
android:width="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path android:fillColor="#000" android:pathData="M19,15L13,21L11.58,19.58L15.17,16H4V4H6V14H15.17L11.58,10.42L13,9L19,15Z" />
|
||||||
|
</vector>
|
|
@ -1,46 +1,23 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:singleLine="true">
|
android:singleLine="true"
|
||||||
|
android:background="?android:selectableItemBackground">
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/subkey_item_buttons"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentEnd="true">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/subkey_item_edit_image"
|
|
||||||
android:src="@drawable/ic_mode_edit_grey_24dp"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="8dp" />
|
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/subkey_item_delete_button"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:src="@drawable/ic_close_grey_24dp"
|
|
||||||
android:background="?android:selectableItemBackground" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="6dp"
|
||||||
|
android:layout_marginRight="6dp"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true">
|
||||||
android:layout_marginLeft="8dp"
|
|
||||||
android:layout_toLeftOf="@+id/subkey_item_status"
|
|
||||||
android:layout_toStartOf="@+id/subkey_item_status">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -107,7 +84,7 @@
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/subkey_item_expiry"
|
android:id="@+id/subkey_item_status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Expiry: 4/7/2016"
|
android:text="Expiry: 4/7/2016"
|
||||||
|
@ -116,17 +93,44 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
<LinearLayout
|
||||||
|
android:id="@+id/layout_subkey_action"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/subkey_item_status"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="left|center_vertical"
|
|
||||||
android:src="@drawable/status_signature_revoked_cutout_24dp"
|
|
||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:layout_centerVertical="true"
|
android:paddingRight="8dp"
|
||||||
android:layout_toLeftOf="@+id/subkey_item_buttons"
|
android:paddingTop="6dp"
|
||||||
android:layout_toStartOf="@+id/subkey_item_buttons" />
|
android:paddingBottom="10dp"
|
||||||
|
android:src="@drawable/subdir_arrow_right"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_subkey_action"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
tools:text="Key will be revoked"
|
||||||
|
style="?android:textAppearanceMedium"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/button_subkey_action_cancel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:src="@drawable/ic_close_grey_24dp"
|
||||||
|
android:background="?android:selectableItemBackground" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
|
@ -24,37 +24,12 @@ xmlns:tools="http://schemas.android.com/tools">
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:text="@string/section_keys"
|
android:text="@string/section_keys" />
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.FixedListView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/view_key_subkeys"
|
android:id="@+id/view_key_subkeys"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="4dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:scrollbarStyle="outsideOverlay" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:id="@+id/view_key_subkeys_add_layout"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dip"
|
|
||||||
android:background="?android:attr/listDivider" />
|
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.FixedListView
|
|
||||||
android:id="@+id/view_key_subkeys_added"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
@ -177,7 +177,10 @@
|
||||||
<string name="label_creation">"Creation"</string>
|
<string name="label_creation">"Creation"</string>
|
||||||
<string name="label_creation_colon">"Creation:"</string>
|
<string name="label_creation_colon">"Creation:"</string>
|
||||||
<string name="label_expiry">"Expiry"</string>
|
<string name="label_expiry">"Expiry"</string>
|
||||||
|
<string name="label_valid_from">"Valid from"</string>
|
||||||
<string name="label_usage">"Usage"</string>
|
<string name="label_usage">"Usage"</string>
|
||||||
|
<string name="label_revoked">Revoked</string>
|
||||||
|
<string name="label_insecure">Insecure</string>
|
||||||
<string name="label_key_size">"Key Size"</string>
|
<string name="label_key_size">"Key Size"</string>
|
||||||
<string name="label_ecc_curve">"Elliptic Curve"</string>
|
<string name="label_ecc_curve">"Elliptic Curve"</string>
|
||||||
<string name="label_main_user_id">"Primary identity"</string>
|
<string name="label_main_user_id">"Primary identity"</string>
|
||||||
|
@ -2055,4 +2058,9 @@
|
||||||
<string name="snack_analytics_accept">"Thanks for helping out! You can change this preference in the settings."</string>
|
<string name="snack_analytics_accept">"Thanks for helping out! You can change this preference in the settings."</string>
|
||||||
<string name="snack_analytics_reject">"That's alright, we won't ask again. You can change your mind in the settings."</string>
|
<string name="snack_analytics_reject">"That's alright, we won't ask again. You can change your mind in the settings."</string>
|
||||||
<string name="snackbutton_analytics_settings">"Settings"</string>
|
<string name="snackbutton_analytics_settings">"Settings"</string>
|
||||||
|
<string name="subkey_action_create">Subkey will be created</string>
|
||||||
|
<string name="subkey_action_revoke">Subkey will be revoked</string>
|
||||||
|
<string name="subkey_action_strip">Subkey will be stripped</string>
|
||||||
|
<string name="subkey_action_expiry_never">Expiry will change to never</string>
|
||||||
|
<string name="subkey_action_expiry_date">Expiry will change to %s</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -18,6 +18,7 @@ CREATE TABLE IF NOT EXISTS keys (
|
||||||
is_secure INTEGER AS Boolean NOT NULL,
|
is_secure INTEGER AS Boolean NOT NULL,
|
||||||
creation INTEGER NOT NULL,
|
creation INTEGER NOT NULL,
|
||||||
expiry INTEGER,
|
expiry INTEGER,
|
||||||
|
validFrom INTEGER NOT NULL,
|
||||||
PRIMARY KEY(master_key_id, rank),
|
PRIMARY KEY(master_key_id, rank),
|
||||||
FOREIGN KEY(master_key_id) REFERENCES
|
FOREIGN KEY(master_key_id) REFERENCES
|
||||||
keyrings_public(master_key_id) ON DELETE CASCADE
|
keyrings_public(master_key_id) ON DELETE CASCADE
|
||||||
|
@ -27,8 +28,8 @@ insertKey:
|
||||||
INSERT INTO keys (
|
INSERT INTO keys (
|
||||||
master_key_id, rank, key_id, key_size, key_curve_oid, algorithm, fingerprint,
|
master_key_id, rank, key_id, key_size, key_curve_oid, algorithm, fingerprint,
|
||||||
can_certify, can_sign, can_encrypt, can_authenticate,
|
can_certify, can_sign, can_encrypt, can_authenticate,
|
||||||
is_revoked, has_secret, is_secure, creation, expiry
|
is_revoked, has_secret, is_secure, creation, expiry, validFrom
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||||
|
|
||||||
updateHasSecretByMasterKeyId:
|
updateHasSecretByMasterKeyId:
|
||||||
UPDATE keys
|
UPDATE keys
|
||||||
|
@ -91,7 +92,7 @@ SELECT master_key_id
|
||||||
WHERE key_id = ?;
|
WHERE key_id = ?;
|
||||||
|
|
||||||
selectSubkeysByMasterKeyId:
|
selectSubkeysByMasterKeyId:
|
||||||
SELECT 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
|
SELECT 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, validFrom
|
||||||
FROM keys
|
FROM keys
|
||||||
WHERE master_key_id = ?
|
WHERE master_key_id = ?
|
||||||
ORDER BY rank ASC;
|
ORDER BY rank ASC;
|
||||||
|
@ -106,6 +107,12 @@ SELECT fingerprint
|
||||||
FROM keys
|
FROM keys
|
||||||
WHERE key_id = ?;
|
WHERE key_id = ?;
|
||||||
|
|
||||||
|
selectEffectiveEncryptionKeyIdsByMasterKeyId:
|
||||||
|
SELECT key_id
|
||||||
|
FROM keys
|
||||||
|
WHERE is_revoked = 0 AND is_secure = 1 AND ( expiry IS NULL OR expiry >= strftime('%s', 'now') ) AND validFrom <= strftime('%s', 'now')
|
||||||
|
AND can_encrypt = 1 AND master_key_id = ?;
|
||||||
|
|
||||||
selectEffectiveSignKeyIdByMasterKeyId:
|
selectEffectiveSignKeyIdByMasterKeyId:
|
||||||
SELECT key_id
|
SELECT key_id
|
||||||
FROM keys
|
FROM keys
|
||||||
|
|
|
@ -54,8 +54,8 @@ public class KeyRepositorySaveTest {
|
||||||
ShadowLog.stream = System.out;
|
ShadowLog.stream = System.out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testImportCooperPair() throws Exception {
|
@Test
|
||||||
|
public void testImportCooperPairOne() throws Exception {
|
||||||
// insert two keys with same long key id, make sure the second one gets rejected either way!
|
// insert two keys with same long key id, make sure the second one gets rejected either way!
|
||||||
UncachedKeyRing first =
|
UncachedKeyRing first =
|
||||||
readRingFromResource("/test-keys/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc");
|
readRingFromResource("/test-keys/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc");
|
||||||
|
@ -69,10 +69,18 @@ public class KeyRepositorySaveTest {
|
||||||
Assert.assertTrue("first keyring import should succeed", result.success());
|
Assert.assertTrue("first keyring import should succeed", result.success());
|
||||||
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
|
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
|
||||||
Assert.assertFalse("second keyring import should fail", result.success());
|
Assert.assertFalse("second keyring import should fail", result.success());
|
||||||
|
}
|
||||||
|
|
||||||
KeychainDatabase.getInstance(RuntimeEnvironment.application).clearDatabase();
|
@Test
|
||||||
|
public void testImportCooperPairTwo() throws Exception {
|
||||||
|
// insert two keys with same long key id, make sure the second one gets rejected either way!
|
||||||
|
UncachedKeyRing first =
|
||||||
|
readRingFromResource("/test-keys/cooperpair/9E669861368BCA0BE42DAF7DDDA252EBB8EBE1AF.asc");
|
||||||
|
UncachedKeyRing second =
|
||||||
|
readRingFromResource("/test-keys/cooperpair/A55120427374F3F7AA5F1166DDA252EBB8EBE1AF.asc");
|
||||||
|
|
||||||
|
SaveKeyringResult result;
|
||||||
|
|
||||||
// and the other way around
|
|
||||||
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
|
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(second);
|
||||||
Assert.assertTrue("first keyring import should succeed", result.success());
|
Assert.assertTrue("first keyring import should succeed", result.success());
|
||||||
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(first);
|
result = KeyWritableRepository.create(RuntimeEnvironment.application).savePublicKeyRing(first);
|
||||||
|
|
Loading…
Reference in a new issue