resp.setStatus(500);
PrintWriter wr = resp.getWriter();
e.formatPlain(wr);
- } catch (InterruptedException e) {
- resp.sendError(500, "Interrupted");
}
}
}
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");
+
}
}
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);
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);
}
}
- 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);
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();
}
}
*
* @return the maximal points @
*/
+ @SuppressWarnings("unused")
public int getMaxAssurePoints() {
if ( !CalendarUtil.isOfAge(dob, ADULT_AGE) && POJAM_ENABLED) {
return 10; // PoJAM
}
- public Name getPreferredName() {
+ public synchronized Name getPreferredName() {
return preferredName;
}
* @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) {
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;
}
package org.cacert.gigi.output.template;
import java.io.PrintWriter;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
/**
* 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;
} 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));
}
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
}
}
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);
}
}
}
return false;
}
+
}
// 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") {
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) {