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