From 7cbf75518603ba4f5bc47cc5bf5cbd9fac289a41 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 14 Sep 2017 17:30:47 +0200 Subject: refactor failing certification validation test --- .../java/se/leap/bitmaskclient/eip/CalendarProvider.java | 14 ++++++++++++++ .../leap/bitmaskclient/eip/CalendarProviderInterface.java | 11 +++++++++++ .../se/leap/bitmaskclient/eip/VpnCertificateValidator.java | 14 ++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/eip/CalendarProvider.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/eip/CalendarProviderInterface.java (limited to 'app/src/main') 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; } -- cgit v1.2.3 From 3eb07a1ae17b8077b59803376f8e23fe80efa27e Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 14 Sep 2017 17:47:01 +0200 Subject: improves comparison of images - reduces complexity and more reliable --- app/src/main/java/se/leap/bitmaskclient/VpnFragment.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/src/main') 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); } } -- cgit v1.2.3 From e6886df9083252282408cd1ee0149c88021ebb11 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 14 Sep 2017 17:49:28 +0200 Subject: minor changes: replace depr. img and change xml identifier to follow android code guidelines --- app/src/main/res/drawable-ldpi/ic_stat_vpn.png | Bin 757 -> 355 bytes app/src/main/res/layout/eip_service_fragment.xml | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'app/src/main') 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 Binary files a/app/src/main/res/drawable-ldpi/ic_stat_vpn.png and b/app/src/main/res/drawable-ldpi/ic_stat_vpn.png 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" /> - Date: Fri, 15 Sep 2017 01:38:39 +0200 Subject: vpn certificate gets renewed 3 month before current certificate expires --- .../bitmaskclient/eip/VpnCertificateValidator.java | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'app/src/main') 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 b7c26761..709dda34 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -25,32 +25,35 @@ public class VpnCertificateValidator { public final static String TAG = VpnCertificateValidator.class.getSimpleName(); private String certificate; - protected CalendarProviderInterface calendarProvider; + private CalendarProviderInterface calendarProvider; public VpnCertificateValidator(String certificate) { this.certificate = certificate; - calendarProvider = new CalendarProvider(); + 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 3 more months + */ 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); } - /* 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); + Calendar offsetDate = calculateOffsetCertificateValidity(certificate); try { - certificate.checkValidity(offset_date.getTime()); + certificate.checkValidity(offsetDate.getTime()); return true; } catch (CertificateExpiredException e) { return false; @@ -60,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 = calendarProvider.getCalendar().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 3 months to the current date + limitDate.add(Calendar.MONTH, 3); - Calendar limit_date = calendarProvider.getCalendar(); - limit_date.setTimeInMillis(current_date_millis + preventive_time); - return limit_date; + return limitDate; } } -- cgit v1.2.3 From afa289cbcce4a431f6bd587b490b6470ed6caa50 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 18 Sep 2017 12:38:24 +0200 Subject: change expiration offset to 15 days before actual certificate expires --- .../java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/src/main') 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 709dda34..28099f06 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -38,7 +38,7 @@ public class VpnCertificateValidator { /** * - * @return true if there's a certificate that is valid for more than 3 more months + * @return true if there's a certificate that is valid for more than 15 more days */ public boolean isValid() { if (certificate.isEmpty()) { @@ -69,8 +69,8 @@ public class VpnCertificateValidator { if (startDate.getTime() >= limitDate.getTime().getTime()) { return limitDate; } - // else add an offset of 3 months to the current date - limitDate.add(Calendar.MONTH, 3); + // else add an offset of 15 days to the current date + limitDate.add(Calendar.DAY_OF_YEAR, 15); return limitDate; } -- cgit v1.2.3