summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2017-09-14 17:30:47 +0200
committercyBerta <cyberta@riseup.net>2017-09-14 17:30:47 +0200
commit7cbf75518603ba4f5bc47cc5bf5cbd9fac289a41 (patch)
tree47518d23bd609acfae793d1691896b79e9368945 /app/src/main/java
parenta5fe0aa9ae57c688d3a8373a1a7bae0b91efd9d7 (diff)
refactor failing certification validation test
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/CalendarProvider.java14
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/CalendarProviderInterface.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java14
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;
}