summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VpnFragment.java4
-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.java39
4 files changed, 57 insertions, 11 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
index 9210c6ec..6ffeacc1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
@@ -49,6 +49,7 @@ public class VpnFragment extends Fragment implements Observer {
private static EipStatus eip_status;
private boolean wants_to_connect;
+ //FIXME: replace with onAttach(Context context)
public void onAttach(Activity activity) {
super.onAttach(activity);
@@ -254,12 +255,15 @@ public class VpnFragment extends Fragment implements Observer {
if(eip_status.isConnecting()) {
vpn_status_image.showProgress(true);
vpn_status_image.setIcon(R.drawable.ic_stat_vpn_empty_halo, R.drawable.ic_stat_vpn_empty_halo);
+ vpn_status_image.setTag(R.drawable.ic_stat_vpn_empty_halo);
} else {
vpn_status_image.showProgress(false);
vpn_status_image.setIcon(R.drawable.ic_stat_vpn, R.drawable.ic_stat_vpn);
+ vpn_status_image.setTag(R.drawable.ic_stat_vpn);
}
} else {
vpn_status_image.setIcon(R.drawable.ic_stat_vpn_offline, R.drawable.ic_stat_vpn_offline);
+ vpn_status_image.setTag(R.drawable.ic_stat_vpn_offline);
vpn_status_image.showProgress(false);
}
}
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..28099f06 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java
@@ -25,22 +25,35 @@ public class VpnCertificateValidator {
public final static String TAG = VpnCertificateValidator.class.getSimpleName();
private String certificate;
+ private CalendarProviderInterface calendarProvider;
public VpnCertificateValidator(String certificate) {
this.certificate = certificate;
+ this.calendarProvider = new CalendarProvider();
}
+ public void setCalendarProvider(CalendarProviderInterface calendarProvider) {
+ this.calendarProvider = calendarProvider;
+ }
+
+ /**
+ *
+ * @return true if there's a certificate that is valid for more than 15 more days
+ */
public boolean isValid() {
- if (!certificate.isEmpty()) {
- X509Certificate certificate_x509 = ConfigHelper.parseX509CertificateFromString(certificate);
- return isValid(certificate_x509);
- } else return true;
+ if (certificate.isEmpty()) {
+ return false;
+ }
+
+ X509Certificate certificate_x509 = ConfigHelper.parseX509CertificateFromString(certificate);
+ return isValid(certificate_x509);
}
+
private boolean isValid(X509Certificate certificate) {
- Calendar offset_date = calculateOffsetCertificateValidity(certificate);
+ Calendar offsetDate = calculateOffsetCertificateValidity(certificate);
try {
- certificate.checkValidity(offset_date.getTime());
+ certificate.checkValidity(offsetDate.getTime());
return true;
} catch (CertificateExpiredException e) {
return false;
@@ -50,11 +63,15 @@ 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();
+ Calendar limitDate = calendarProvider.getCalendar();
+ Date startDate = certificate.getNotBefore();
+ // if certificates start date is before current date just return the current date without an offset
+ if (startDate.getTime() >= limitDate.getTime().getTime()) {
+ return limitDate;
+ }
+ // else add an offset of 15 days to the current date
+ limitDate.add(Calendar.DAY_OF_YEAR, 15);
- Calendar limit_date = Calendar.getInstance();
- limit_date.setTimeInMillis(current_date_millis + preventive_time);
- return limit_date;
+ return limitDate;
}
}