add: Highlight certificates outside validity period in Cert Overview
authorINOPIAE <m.maengel@inopiae.de>
Sun, 14 Aug 2016 10:08:26 +0000 (12:08 +0200)
committerINOPIAE <m.maengel@inopiae.de>
Tue, 16 Aug 2016 09:43:16 +0000 (11:43 +0200)
Highlight if a issued date is in the future and/or the expiration date
is less than 14 days or expired

Change-Id: If3dd70374f1cf191b83a5d113ea0bc526e7e9505

src/org/cacert/gigi/output/CertificateIterable.java
src/org/cacert/gigi/output/CertificateTable.templ
src/org/cacert/gigi/util/CalendarUtil.java

index bb2c493..afc883f 100644 (file)
@@ -3,17 +3,21 @@ package org.cacert.gigi.output;
 import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.security.cert.X509Certificate;
+import java.util.Date;
 import java.util.Map;
 
 import org.cacert.gigi.dbObjects.Certificate;
 import org.cacert.gigi.dbObjects.Certificate.CertificateStatus;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.output.template.IterableDataset;
+import org.cacert.gigi.util.CalendarUtil;
 
 public class CertificateIterable implements IterableDataset {
 
     private Certificate[] certificates;
 
+    public static final int EXPIRING_IN_DAYS = 14;
+
     public CertificateIterable(Certificate[] certificates) {
         this.certificates = certificates;
     }
@@ -34,14 +38,30 @@ public class CertificateIterable implements IterableDataset {
         try {
             CertificateStatus st = c.getStatus();
             vars.put("revokable", st != CertificateStatus.REVOKED && st == CertificateStatus.ISSUED);
+            String issuedWarning = "";
+            String expiredWarning = "";
             if (st == CertificateStatus.ISSUED || st == CertificateStatus.REVOKED) {
                 X509Certificate cert = c.cert();
                 vars.put("issued", cert.getNotBefore());
                 vars.put("expire", cert.getNotAfter());
+
+                if (cert.getNotBefore().after(new Date())) {
+                    issuedWarning = "bg-warning";
+                }
+                vars.put("classIssued", issuedWarning);
+
+                if (cert.getNotAfter().before(CalendarUtil.timeDifferenceDays(EXPIRING_IN_DAYS))) {
+                    expiredWarning = "bg-warning";
+                }
+                if (cert.getNotAfter().before(new Date())) {
+                    expiredWarning = "bg-danger";
+                }
+                vars.put("classExpired", expiredWarning);
             } else {
                 vars.put("issued", l.getTranslation("N/A"));
                 vars.put("expire", l.getTranslation("N/A"));
             }
+
             if (st == CertificateStatus.REVOKED) {
                 vars.put("revoked", c.getRevocationDate());
             } else {
index 278b4f7..539ac1e 100644 (file)
@@ -22,9 +22,9 @@
        <td><a href='/account/certs/<?=$serial?>'><?=$serial?></a></td>
        <td><?=$digest?></td>
        <td><?=$profile?></td>
-       <td><?=$issued?></td>
+       <td class="<?=$classIssued?>"><?=$issued?></td>
        <td><?=$revoked?></td>
-       <td><?=$expire?></td>
+       <td class="<?=$classExpired?>"><?=$expire?></td>
        <td><?=$login?></td>
 </tr>
 <? } ?>
index 03fdf2f..7d65407 100644 (file)
@@ -35,4 +35,11 @@ public class CalendarUtil {
         Date dob = cal.getTime();
         return new DayDate(dob.getTime());
     }
+
+    public static Date timeDifferenceDays(int days) {
+        Calendar c = Calendar.getInstance();
+        c.setTimeInMillis(System.currentTimeMillis());
+        c.add(Calendar.DAY_OF_MONTH, days);
+        return c.getTime();
+    }
 }