]> WPIA git - gigi.git/commitdiff
Merge changes I82859d98,I3da54fbf
authorFelix Dörre <felix@dogcraft.de>
Tue, 2 Aug 2016 11:50:24 +0000 (13:50 +0200)
committerGerrit Code Review <gigi-system@dogcraft.de>
Tue, 2 Aug 2016 11:50:24 +0000 (13:50 +0200)
* changes:
  upd: fix some wording
  upd: replace assure, assurance, assurer etc in output to user

13 files changed:
src/org/cacert/gigi/api/CreateCertificate.java
src/org/cacert/gigi/api/RevokeCertificate.java
src/org/cacert/gigi/dbObjects/CACertificate.java
src/org/cacert/gigi/dbObjects/CertificateProfile.java
src/org/cacert/gigi/dbObjects/Job.java
src/org/cacert/gigi/dbObjects/User.java
src/org/cacert/gigi/output/template/Form.java
src/org/cacert/gigi/output/template/TranslateCommand.java
src/org/cacert/gigi/pages/account/certs/CertificateIssueForm.java
src/org/cacert/gigi/pages/account/certs/CertificateModificationForm.java
src/org/cacert/gigi/util/PublicSuffixes.java
util-testing/org/cacert/gigi/DevelLauncher.java
util-testing/org/cacert/gigi/pages/Manager.java

index 0d5a27e05c76da1673f5da7d193347c0a177c14e..1c589379a31a20909d17cb84afd73e88da6b4f2e 100644 (file)
@@ -79,8 +79,6 @@ public class CreateCertificate extends APIPoint {
             resp.setStatus(500);
             PrintWriter wr = resp.getWriter();
             e.formatPlain(wr);
-        } catch (InterruptedException e) {
-            resp.sendError(500, "Interrupted");
         }
     }
 }
index 404d73ce82afbcb1da3ecb7e7babeb5c9eb57109..2f15511afe69af95179e9678b6a6f231b15918b9 100644 (file)
@@ -21,31 +21,32 @@ public class RevokeCertificate extends APIPoint {
             resp.sendError(500, "Error, POST required.");
             return;
         }
+
         if (req.getQueryString() != null) {
             resp.sendError(500, "Error, no query String allowed.");
             return;
         }
+
         String tserial = req.getParameter("serial");
         if (tserial == null) {
             resp.sendError(500, "Error, no Serial found");
             return;
         }
-        try {
-            Certificate c = Certificate.getBySerial(tserial);
-            if (c == null || c.getOwner() != u) {
-                resp.sendError(403, "Access Denied");
-                return;
-            }
-            Job job = c.revoke();
-            job.waitFor(60000);
-            if (c.getStatus() != CertificateStatus.REVOKED) {
-                resp.sendError(510, "Error, issuing timed out");
-                return;
-            }
-            resp.getWriter().println("OK");
+
+        Certificate c = Certificate.getBySerial(tserial);
+        if (c == null || c.getOwner() != u) {
+            resp.sendError(403, "Access Denied");
+            return;
+        }
+
+        Job job = c.revoke();
+        job.waitFor(60000);
+        if (c.getStatus() != CertificateStatus.REVOKED) {
+            resp.sendError(510, "Error, issuing timed out");
             return;
-        } catch (InterruptedException e) {
-            e.printStackTrace();
         }
+
+        resp.getWriter().println("OK");
+
     }
 }
index 41401b6ddab883b84e10180f766bf1492882d212..3e8af82274704ffe728f9463c8d18004b80c1fe1 100644 (file)
@@ -89,7 +89,11 @@ public class CACertificate implements IdCachable {
         CertificateFactory xf = CertificateFactory.getInstance("X509");
         HashMap<X500Principal, X509Certificate> map = new HashMap<>();
         HashMap<X500Principal, String> names = new HashMap<>();
-        for (File f : scandir.listFiles()) {
+        File[] scandirfiles = scandir.listFiles();
+        if (null == scandirfiles) {
+            scandirfiles = new File[0];
+        }
+        for (File f : scandirfiles) {
             X509Certificate cert = (X509Certificate) xf.generateCertificate(new FileInputStream(f));
             X500Principal princip = cert.getSubjectX500Principal();
             map.put(princip, cert);
index 5704497986388f70123d5bf7230839bed85fde0d..afcc019c417b172308d5092921df3e020e7879c5 100644 (file)
@@ -180,7 +180,13 @@ public class CertificateProfile implements IdCachable {
         final HashMap<String, CertificateProfile> myName = new HashMap<String, CertificateProfile>();
         final HashMap<Integer, CertificateProfile> myId = new HashMap<Integer, CertificateProfile>();
 
-        for (File f : new File("config/profiles").listFiles()) {
+        File profiledir = new File("config/profiles");
+        File[] profilelist = profiledir.listFiles();
+        if (null == profilelist) {
+            throw new Error("Unable to list available profiles from " + profiledir.getName());
+        }
+
+        for (File f : profilelist) {
             Properties p = new Properties();
             try (FileInputStream inStream = new FileInputStream(f)) {
                 p.load(inStream);
index bb357a8d07b742fddda040031abf4a8ca0dd8d83..a48e44ac667cf5d9ec78d0083568e970c6d7d637 100644 (file)
@@ -51,7 +51,7 @@ public class Job implements IdCachable {
         }
     }
 
-    public synchronized boolean waitFor(int max) throws InterruptedException {
+    public synchronized boolean waitFor(int max) {
         long start = System.currentTimeMillis();
         try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `jobs` WHERE id=? AND state='open'")) {
             ps.setInt(1, id);
@@ -61,7 +61,12 @@ public class Job implements IdCachable {
                 if (max != 0 && System.currentTimeMillis() - start > max) {
                     return false;
                 }
-                Thread.sleep((long) (2000 + Math.random() * 2000));
+                try {
+                    this.wait((long) (2000 + Math.random() * 2000));
+                } catch (InterruptedException ie) {
+                    // Ignore the interruption
+                    ie.printStackTrace();
+                }
                 rs = ps.executeQuery();
             }
         }
index 4e925a563a9e9879c12173ce1a1421bb75d30cce..cf43f80f3182a4377a1578b3f11ac370375f8e53 100644 (file)
@@ -257,6 +257,7 @@ public class User extends CertificateOwner {
      * 
      * @return the maximal points @
      */
+    @SuppressWarnings("unused")
     public int getMaxAssurePoints() {
         if ( !CalendarUtil.isOfAge(dob, ADULT_AGE) && POJAM_ENABLED) {
             return 10; // PoJAM
@@ -395,7 +396,7 @@ public class User extends CertificateOwner {
 
     }
 
-    public Name getPreferredName() {
+    public synchronized Name getPreferredName() {
         return preferredName;
     }
 
index f2219581be3c09b2d77cbbd2dff8ae30ac32de5a..3f7ab6d1d06750fdeb7789e7a77149df39ec43c6 100644 (file)
@@ -104,6 +104,7 @@ public abstract class Form implements Outputable {
      * @throws CSRFException
      *             if no CSRF-token is found or the token is wrong.
      */
+    @SuppressWarnings("unchecked")
     public static <T extends Form> T getForm(HttpServletRequest req, Class<T> target) throws CSRFException {
         String csrf = req.getParameter(CSRF_FIELD);
         if (csrf == null) {
@@ -113,10 +114,17 @@ public abstract class Form implements Outputable {
         if (hs == null) {
             throw new CSRFException();
         }
-        Form f = (Form) hs.getAttribute("form/" + target.getName() + "/" + csrf);
+        Object f = hs.getAttribute("form/" + target.getName() + "/" + csrf);
         if (f == null) {
             throw new CSRFException();
         }
+        if ( !(f instanceof Form)) {
+            throw new CSRFException();
+        }
+        if ( !target.isInstance(f)) {
+            throw new CSRFException();
+        }
+        // Dynamic Cast checked by previous if statement
         return (T) f;
     }
 
index 6532d94682e7cbff6cb100788106b9f5f56293d1..7bb601125101b226e1327a9fa74d56851fb80d69 100644 (file)
@@ -1,6 +1,7 @@
 package org.cacert.gigi.output.template;
 
 import java.io.PrintWriter;
+import java.io.Serializable;
 import java.util.Collection;
 import java.util.Map;
 
@@ -10,7 +11,9 @@ import org.cacert.gigi.util.HTMLEncoder;
 /**
  * Wraps a String that needs to be translated before it is printed to the user.
  */
-public final class TranslateCommand implements Translatable {
+public final class TranslateCommand implements Translatable, Serializable {
+
+    private static final long serialVersionUID = 1L;
 
     private final String raw;
 
index c32fc716f050f3972edd59df68a882d446d140f0..eecb31fe786a5e7373ee7445462af5e5446661c2 100644 (file)
@@ -104,8 +104,6 @@ public class CertificateIssueForm extends Form {
             } catch (GeneralSecurityException e) {
                 e.printStackTrace();
                 throw new GigiApiException("Certificate Request format is invalid.");
-            } catch (InterruptedException e) {
-                e.printStackTrace();
             }
         } catch (GigiApiException e) {
             e.format(out, Page.getLanguage(req));
index 6553a77323fc805e6af8c8ac92e5eb31be01f3cd..a58f3a6c961e4e5ac7067a17c5c6f855a14f5ed3 100644 (file)
@@ -48,15 +48,11 @@ public class CertificateModificationForm extends Form {
         }
         long start = System.currentTimeMillis();
         for (Job job : revokes) {
-            try {
-                int toWait = (int) (60000 + start - System.currentTimeMillis());
-                if (toWait > 0) {
-                    job.waitFor(toWait);
-                } else {
-                    break; // canceled... waited too log
-                }
-            } catch (InterruptedException e) {
-                e.printStackTrace();
+            int toWait = (int) (60000 + start - System.currentTimeMillis());
+            if (toWait > 0) {
+                job.waitFor(toWait);
+            } else {
+                break; // canceled... waited too log
             }
         }
 
index 51c2edf2acb53a90a22a0021729dd08c73a63d9f..19c7b1dc952d15bf6255f98209c0ce7ebe1e1a5d 100644 (file)
@@ -2,24 +2,31 @@ package org.cacert.gigi.util;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.IDN;
 import java.util.HashSet;
 
 public class PublicSuffixes {
 
-    HashSet<String> suffixes = new HashSet<>();
+    private HashSet<String> suffixes = new HashSet<>();
 
-    HashSet<String> wildcards = new HashSet<>();
+    private HashSet<String> wildcards = new HashSet<>();
 
-    HashSet<String> exceptions = new HashSet<>();
+    private HashSet<String> exceptions = new HashSet<>();
 
-    private static final String url = "https://publicsuffix.org/list/effective_tld_names.dat";
+    static final String url = "https://publicsuffix.org/list/effective_tld_names.dat";
 
     private static PublicSuffixes instance;
 
     private static PublicSuffixes generateDefault() throws IOException {
-        try (BufferedReader br = new BufferedReader(new InputStreamReader(PublicSuffixes.class.getResourceAsStream("effective_tld_names.dat"), "UTF-8"))) {
+        InputStream res = PublicSuffixes.class.getResourceAsStream("effective_tld_names.dat");
+
+        if (null == res) {
+            throw new Error("Public Suffix List could not be loaded.");
+        }
+
+        try (BufferedReader br = new BufferedReader(new InputStreamReader(res, "UTF-8"))) {
             return new PublicSuffixes(br);
         }
     }
@@ -128,4 +135,5 @@ public class PublicSuffixes {
         }
         return false;
     }
+
 }
index 6639635b0cbb551bef7ba9caf1e1cc06262956b0..736947d55ac566675d62c25b93d06fa2120058ff 100644 (file)
@@ -122,8 +122,12 @@ public class DevelLauncher {
 
             // Check if we got a proper map (as much as we can tell)
             Object pagesObj = pageF.get(gigi);
+            if ( !(pagesObj instanceof Map)) {
+                throw new Error("Invalid state when initializing page structure");
+            }
+
             @SuppressWarnings("unchecked")
-            HashMap<String, Page> pages = pagesObj instanceof Map ? new HashMap<>((Map<String, Page>) pagesObj) : null;
+            HashMap<String, Page> pages = new HashMap<>((Map<String, Page>) pagesObj);
 
             pages.put("/manage", new Page("Page-manager") {
 
index 21b7e43218d907342d22480b52cd6332809fd7a8..f6de409b0c64eb65cb4c4fb2863701a29f4babd4 100644 (file)
@@ -352,9 +352,6 @@ public class Manager extends Page {
                 resp.getWriter().println("error");
             } catch (GigiApiException e) {
                 e.format(resp.getWriter(), Language.getInstance(Locale.ENGLISH));
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-                resp.getWriter().println("interrupted");
             }
 
         } else if (req.getParameter("addExDom") != null) {