summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyberta <cyberta@riseup.net>2017-09-18 11:01:48 +0000
committercyberta <cyberta@riseup.net>2017-09-18 11:01:48 +0000
commit64e961fe8ebc1eeb331cef2604cf4c8714e8d8ad (patch)
tree2f44dc405415cbf03f81eff0c0967f29abec7c7e /app/src/main
parent14dc607adeaae623e643b1045ed1917d289a19c4 (diff)
parentafa289cbcce4a431f6bd587b490b6470ed6caa50 (diff)
Merge branch 'develop' into 'master'
Fixes failing tests See merge request !5
Diffstat (limited to 'app/src/main')
-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
-rw-r--r--app/src/main/res/drawable-ldpi/ic_stat_vpn.pngbin757 -> 355 bytes
-rw-r--r--app/src/main/res/layout/eip_service_fragment.xml3
6 files changed, 58 insertions, 13 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;
}
}
diff --git a/app/src/main/res/drawable-ldpi/ic_stat_vpn.png b/app/src/main/res/drawable-ldpi/ic_stat_vpn.png
index 65fc6db7..008aaf63 100644
--- a/app/src/main/res/drawable-ldpi/ic_stat_vpn.png
+++ b/app/src/main/res/drawable-ldpi/ic_stat_vpn.png
Binary files differ
diff --git a/app/src/main/res/layout/eip_service_fragment.xml b/app/src/main/res/layout/eip_service_fragment.xml
index 06b514d3..7df82b19 100644
--- a/app/src/main/res/layout/eip_service_fragment.xml
+++ b/app/src/main/res/layout/eip_service_fragment.xml
@@ -30,14 +30,13 @@
android:textSize="12sp"
/>
- <view
+ <mbanje.kurt.fabbutton.FabButton
android:id="@+id/vpn.Status.Image"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="3dp"
android:layout_marginStart="3dp"
android:color="@android:color/holo_blue_dark"
- class="mbanje.kurt.fabbutton.FabButton"
android:layout_gravity="center"
android:visibility="visible"
android:indeterminate="true"