diff options
Diffstat (limited to 'app/src/main/java/se/leap')
3 files changed, 37 insertions, 2 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/CalendarProvider.java b/app/src/main/java/se/leap/bitmaskclient/eip/CalendarProvider.java new file mode 100644 index 00000000..a9aec6b8 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/eip/CalendarProvider.java @@ -0,0 +1,14 @@ +package se.leap.bitmaskclient.eip; + +import java.util.Calendar; + +/** + * Created by cyberta on 13.09.17. + */ + +class CalendarProvider implements CalendarProviderInterface { + + public Calendar getCalendar() { + return Calendar.getInstance(); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/CalendarProviderInterface.java b/app/src/main/java/se/leap/bitmaskclient/eip/CalendarProviderInterface.java new file mode 100644 index 00000000..a20f5fab --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/eip/CalendarProviderInterface.java @@ -0,0 +1,11 @@ +package se.leap.bitmaskclient.eip; + +import java.util.Calendar; + +/** + * Created by cyberta on 13.09.17. + */ + +public interface CalendarProviderInterface { + Calendar getCalendar(); +} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java index 8fce6a37..b7c26761 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -25,9 +25,15 @@ public class VpnCertificateValidator { public final static String TAG = VpnCertificateValidator.class.getSimpleName(); private String certificate; + protected CalendarProviderInterface calendarProvider; public VpnCertificateValidator(String certificate) { this.certificate = certificate; + calendarProvider = new CalendarProvider(); + } + + public void setCalendarProvider(CalendarProviderInterface calendarProvider) { + this.calendarProvider = calendarProvider; } public boolean isValid() { @@ -37,6 +43,10 @@ public class VpnCertificateValidator { } else return true; } + + /* FIXME: the validation seems to be syntactically wrong. + * if the valid time span of a certificate is between 01.01.14 and 01.01.16 this method would return true for current dates between 01.01.13 and 01.01.15!!! + */ private boolean isValid(X509Certificate certificate) { Calendar offset_date = calculateOffsetCertificateValidity(certificate); try { @@ -51,9 +61,9 @@ public class VpnCertificateValidator { private Calendar calculateOffsetCertificateValidity(X509Certificate certificate) { long preventive_time = Math.abs(certificate.getNotBefore().getTime() - certificate.getNotAfter().getTime()) / 2; - long current_date_millis = Calendar.getInstance().getTimeInMillis(); + long current_date_millis = calendarProvider.getCalendar().getTimeInMillis(); - Calendar limit_date = Calendar.getInstance(); + Calendar limit_date = calendarProvider.getCalendar(); limit_date.setTimeInMillis(current_date_millis + preventive_time); return limit_date; } |