mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Give expiry dates to PgpKeyOperation
This commit is contained in:
parent
ecf6fc26c5
commit
c70195e4e3
@ -27,6 +27,7 @@ import java.security.SecureRandom;
|
||||
import java.security.SignatureException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||
@ -242,7 +243,8 @@ public class PgpKeyOperation {
|
||||
}
|
||||
|
||||
public void buildSecretKey(ArrayList<String> userIds, ArrayList<PGPSecretKey> keys,
|
||||
ArrayList<Integer> keysUsages, long masterKeyId, String oldPassPhrase,
|
||||
ArrayList<Integer> keysUsages, ArrayList<GregorianCalendar> keysExpiryDates,
|
||||
long masterKeyId, String oldPassPhrase,
|
||||
String newPassPhrase) throws PgpGeneralException, NoSuchProviderException,
|
||||
PGPException, NoSuchAlgorithmException, SignatureException, IOException {
|
||||
|
||||
@ -320,6 +322,8 @@ public class PgpKeyOperation {
|
||||
hashedPacketsGen.setPreferredHashAlgorithms(true, PREFERRED_HASH_ALGORITHMS);
|
||||
hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS);
|
||||
|
||||
// TODO: Now use keysExpiryDates here!!! (and some lines below)
|
||||
|
||||
// TODO: this doesn't work quite right yet (APG 1)
|
||||
// if (keyEditor.getExpiryDate() != null) {
|
||||
// GregorianCalendar creationDate = new GregorianCalendar();
|
||||
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyRing;
|
||||
@ -129,6 +130,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
public static final String SAVE_KEYRING_USER_IDS = "user_ids";
|
||||
public static final String SAVE_KEYRING_KEYS = "keys";
|
||||
public static final String SAVE_KEYRING_KEYS_USAGES = "keys_usages";
|
||||
public static final String SAVE_KEYRING_KEYS_EXPIRY_DATES = "keys_expiry_dates";
|
||||
public static final String SAVE_KEYRING_MASTER_KEY_ID = "master_key_id";
|
||||
public static final String SAVE_KEYRING_CAN_SIGN = "can_sign";
|
||||
|
||||
@ -532,6 +534,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
ArrayList<PGPSecretKey> keys = PgpConversionHelper.BytesToPGPSecretKeyList(data
|
||||
.getByteArray(SAVE_KEYRING_KEYS));
|
||||
ArrayList<Integer> keysUsages = data.getIntegerArrayList(SAVE_KEYRING_KEYS_USAGES);
|
||||
ArrayList<GregorianCalendar> keysExpiryDates = (ArrayList<GregorianCalendar>) data.getSerializable(SAVE_KEYRING_KEYS_EXPIRY_DATES);
|
||||
|
||||
long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID);
|
||||
|
||||
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
|
||||
@ -541,7 +545,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
ProviderHelper.getPGPSecretKeyRingByKeyId(this, masterKeyId),
|
||||
oldPassPhrase, newPassPhrase);
|
||||
} else {
|
||||
keyOperations.buildSecretKey(userIds, keys, keysUsages, masterKeyId,
|
||||
keyOperations.buildSecretKey(userIds, keys, keysUsages, keysExpiryDates, masterKeyId,
|
||||
oldPassPhrase, newPassPhrase);
|
||||
}
|
||||
PassphraseCacheService.addCachedPassphrase(this, masterKeyId, newPassPhrase);
|
||||
|
@ -18,6 +18,8 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
@ -516,6 +518,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
PgpConversionHelper.PGPSecretKeyArrayListToBytes(keys));
|
||||
data.putIntegerArrayList(KeychainIntentService.SAVE_KEYRING_KEYS_USAGES,
|
||||
getKeysUsages(mKeysView));
|
||||
data.putSerializable(KeychainIntentService.SAVE_KEYRING_KEYS_EXPIRY_DATES,
|
||||
getKeysExpiryDates(mKeysView));
|
||||
data.putLong(KeychainIntentService.SAVE_KEYRING_MASTER_KEY_ID, getMasterKeyId());
|
||||
data.putBoolean(KeychainIntentService.SAVE_KEYRING_CAN_SIGN, masterCanSign);
|
||||
|
||||
@ -642,7 +646,7 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
* @return
|
||||
*/
|
||||
private ArrayList<Integer> getKeysUsages(SectionView keysView) throws PgpGeneralException {
|
||||
ArrayList<Integer> getKeysUsages = new ArrayList<Integer>();
|
||||
ArrayList<Integer> keysUsages = new ArrayList<Integer>();
|
||||
|
||||
ViewGroup keyEditors = keysView.getEditors();
|
||||
|
||||
@ -652,10 +656,27 @@ public class EditKeyActivity extends SherlockFragmentActivity {
|
||||
|
||||
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
|
||||
KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i);
|
||||
getKeysUsages.add(editor.getUsage());
|
||||
keysUsages.add(editor.getUsage());
|
||||
}
|
||||
|
||||
return getKeysUsages;
|
||||
return keysUsages;
|
||||
}
|
||||
|
||||
private ArrayList<GregorianCalendar> getKeysExpiryDates(SectionView keysView) throws PgpGeneralException {
|
||||
ArrayList<GregorianCalendar> keysExpiryDates = new ArrayList<GregorianCalendar>();
|
||||
|
||||
ViewGroup keyEditors = keysView.getEditors();
|
||||
|
||||
if (keyEditors.getChildCount() == 0) {
|
||||
throw new PgpGeneralException(getString(R.string.error_key_needs_master_key));
|
||||
}
|
||||
|
||||
for (int i = 0; i < keyEditors.getChildCount(); ++i) {
|
||||
KeyEditor editor = (KeyEditor) keyEditors.getChildAt(i);
|
||||
keysExpiryDates.add(editor.getExpiryDate());
|
||||
}
|
||||
|
||||
return keysExpiryDates;
|
||||
}
|
||||
|
||||
private void updatePassPhraseButtonText() {
|
||||
|
@ -368,7 +368,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
switch (loader.getId()) {
|
||||
case LOADER_ID_KEYRING:
|
||||
// TODO?
|
||||
// No resources need to be freed for this ID
|
||||
break;
|
||||
case LOADER_ID_USER_IDS:
|
||||
mUserIdsAdapter.swapCursor(null);
|
||||
@ -383,7 +383,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements
|
||||
|
||||
private void uploadToKeyserver(Uri dataUri) {
|
||||
Intent uploadIntent = new Intent(this, KeyServerUploadActivity.class);
|
||||
uploadIntent.setData(mDataUri);
|
||||
uploadIntent.setData(dataUri);
|
||||
startActivityForResult(uploadIntent, Id.request.export_to_server);
|
||||
}
|
||||
|
||||
@ -410,7 +410,7 @@ public class ViewKeyActivity extends SherlockFragmentActivity implements
|
||||
|
||||
private void signKey(Uri dataUri) {
|
||||
Intent signIntent = new Intent(this, SignKeyActivity.class);
|
||||
signIntent.setData(mDataUri);
|
||||
signIntent.setData(dataUri);
|
||||
startActivity(signIntent);
|
||||
}
|
||||
|
||||
|
@ -62,9 +62,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
private int mDatePickerResultCount = 0;
|
||||
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener = new DatePickerDialog.OnDateSetListener() {
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
if (mDatePickerResultCount++ == 0) // Note: Ignore results after the first one - android
|
||||
// sends multiples.
|
||||
{
|
||||
// Note: Ignore results after the first one - android sends multiples.
|
||||
if (mDatePickerResultCount++ == 0) {
|
||||
GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
|
||||
setExpiryDate(date);
|
||||
}
|
||||
@ -122,10 +121,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
getContext().getString(R.string.btn_no_date),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mDatePickerResultCount++ == 0) // Note: Ignore results after the
|
||||
// first
|
||||
// one - android sends multiples.
|
||||
{
|
||||
// Note: Ignore results after the first one - android sends multiples.
|
||||
if (mDatePickerResultCount++ == 0) {
|
||||
setExpiryDate(null);
|
||||
}
|
||||
}
|
||||
@ -208,8 +205,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
cal.setTime(PgpKeyHelper.getCreationDate(key));
|
||||
mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime()));
|
||||
cal = new GregorianCalendar();
|
||||
Date date = PgpKeyHelper.getExpiryDate(key);
|
||||
if (date == null) {
|
||||
Date expiryDate = PgpKeyHelper.getExpiryDate(key);
|
||||
if (expiryDate == null) {
|
||||
setExpiryDate(null);
|
||||
} else {
|
||||
cal.setTime(PgpKeyHelper.getExpiryDate(key));
|
||||
|
Loading…
Reference in New Issue
Block a user