mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
bouncycastle uses the Date class, based off of UTC. Force all GregorianCalendars to use UTC, so get and set of key dates works as expected
This commit is contained in:
parent
358ab7d7e4
commit
4119757699
@ -29,25 +29,6 @@ import android.os.Bundle;
|
||||
|
||||
public class OtherHelper {
|
||||
|
||||
/**
|
||||
* Return the number if days between two dates
|
||||
*
|
||||
* @param first
|
||||
* @param second
|
||||
* @return number of days
|
||||
*/
|
||||
public static long getNumDaysBetween(GregorianCalendar first, GregorianCalendar second) {
|
||||
GregorianCalendar tmp = new GregorianCalendar();
|
||||
tmp.setTime(first.getTime());
|
||||
long numDays = (second.getTimeInMillis() - first.getTimeInMillis()) / 1000 / 86400;
|
||||
tmp.add(Calendar.DAY_OF_MONTH, (int) numDays);
|
||||
while (tmp.before(second)) {
|
||||
tmp.add(Calendar.DAY_OF_MONTH, 1);
|
||||
++numDays;
|
||||
}
|
||||
return numDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs bundle content to debug for inspecting the content
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ import java.security.SignatureException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.spongycastle.bcpg.CompressionAlgorithmTags;
|
||||
import org.spongycastle.bcpg.HashAlgorithmTags;
|
||||
@ -323,7 +324,7 @@ public class PgpKeyOperation {
|
||||
hashedPacketsGen.setPreferredCompressionAlgorithms(true, PREFERRED_COMPRESSION_ALGORITHMS);
|
||||
|
||||
if (keysExpiryDates.get(0) != null) {
|
||||
GregorianCalendar creationDate = new GregorianCalendar();
|
||||
GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
creationDate.setTime(masterPublicKey.getCreationTime());
|
||||
GregorianCalendar expiryDate = keysExpiryDates.get(0);
|
||||
//note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c
|
||||
@ -402,7 +403,7 @@ public class PgpKeyOperation {
|
||||
hashedPacketsGen.setKeyFlags(false, keyFlags);
|
||||
|
||||
if (keysExpiryDates.get(i) != null) {
|
||||
GregorianCalendar creationDate = new GregorianCalendar();
|
||||
GregorianCalendar creationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
creationDate.setTime(subPublicKey.getCreationTime());
|
||||
GregorianCalendar expiryDate = keysExpiryDates.get(i);
|
||||
//note that the below, (a/c) - (b/c) is *not* the same as (a - b) /c
|
||||
|
@ -20,6 +20,7 @@ import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKey;
|
||||
@ -64,7 +65,8 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||
// Note: Ignore results after the first one - android sends multiples.
|
||||
if (mDatePickerResultCount++ == 0) {
|
||||
GregorianCalendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
|
||||
GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
date.set(year, monthOfYear, dayOfMonth);
|
||||
setExpiryDate(date);
|
||||
}
|
||||
}
|
||||
@ -109,7 +111,7 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
public void onClick(View v) {
|
||||
GregorianCalendar date = mExpiryDate;
|
||||
if (date == null) {
|
||||
date = new GregorianCalendar();
|
||||
date = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
DatePickerDialog dialog = new DatePickerDialog(getContext(),
|
||||
@ -201,10 +203,10 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
cal.setTime(PgpKeyHelper.getCreationDate(key));
|
||||
mCreationDate.setText(DateFormat.getDateInstance().format(cal.getTime()));
|
||||
cal = new GregorianCalendar();
|
||||
cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
Date expiryDate = PgpKeyHelper.getExpiryDate(key);
|
||||
if (expiryDate == null) {
|
||||
setExpiryDate(null);
|
||||
|
@ -29,6 +29,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -182,8 +183,11 @@ public class HkpKeyServer extends KeyServer {
|
||||
info.keyId = PgpKeyHelper.convertHexToKeyId(matcher.group(3));
|
||||
info.fingerPrint = PgpKeyHelper.convertKeyIdToHex(info.keyId);
|
||||
String chunks[] = matcher.group(4).split("-");
|
||||
info.date = new GregorianCalendar(Integer.parseInt(chunks[0]),
|
||||
Integer.parseInt(chunks[1]), Integer.parseInt(chunks[2])).getTime();
|
||||
|
||||
GregorianCalendar tmpGreg = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
|
||||
tmpGreg.set(Integer.parseInt(chunks[0]), Integer.parseInt(chunks[1]),
|
||||
Integer.parseInt(chunks[2]));
|
||||
info.date = tmpGreg.getTime();
|
||||
info.userIds = new ArrayList<String>();
|
||||
if (matcher.group(5).startsWith("*** KEY")) {
|
||||
info.revoked = matcher.group(5);
|
||||
|
Loading…
Reference in New Issue
Block a user