]> WPIA git - gigi.git/blobdiff - util-testing/org/cacert/gigi/util/SimpleSigner.java
fix: postgres conditional expression in SimpleSigner error query.
[gigi.git] / util-testing / org / cacert / gigi / util / SimpleSigner.java
index 6b498988628d5b125063a232f857074e7a910738..f2b97d7bcd958380088ebf432372f2e9eef36a62 100644 (file)
@@ -28,6 +28,7 @@ import java.text.SimpleDateFormat;
 import java.util.Base64;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -126,14 +127,14 @@ public class SimpleSigner {
                     readyCerts = new GigiPreparedStatement("SELECT certs.id AS id, certs.csr_name, jobs.id AS jobid, csr_type, md, `executeFrom`, `executeTo`, profile FROM jobs " + //
                             "INNER JOIN certs ON certs.id=jobs.`targetId` " + //
                             "INNER JOIN profiles ON profiles.id=certs.profile " + //
-                            "WHERE jobs.state='open' "//
-                            "AND task='sign'");
+                            "WHERE jobs.state='open' " + //
+                            "AND task='sign'");
 
                     getSANSs = new GigiPreparedStatement("SELECT contents, type FROM `subjectAlternativeNames` " + //
                             "WHERE `certId`=?");
 
                     updateMail = new GigiPreparedStatement("UPDATE certs SET crt_name=?," + " created=NOW(), serial=?, caid=? WHERE id=?");
-                    warnMail = new GigiPreparedStatement("UPDATE jobs SET warning=warning+1, state=IF(warning<3, 'open','error') WHERE id=?");
+                    warnMail = new GigiPreparedStatement("UPDATE jobs SET warning=warning+1, state=CASE WHEN warning<3 THEN 'open'::`jobState` ELSE 'error'::`jobState` END WHERE id=?");
 
                     revoke = new GigiPreparedStatement("SELECT certs.id, certs.csr_name,jobs.id FROM jobs INNER JOIN certs ON jobs.`targetId`=certs.id" + " WHERE jobs.state='open' AND task='revoke'");
                     revokeCompleted = new GigiPreparedStatement("UPDATE certs SET revoked=NOW() WHERE id=?");
@@ -327,16 +328,20 @@ public class SimpleSigner {
                     PKCS10 p10 = new PKCS10(PEM.decode("(NEW )?CERTIFICATE REQUEST", new String(data, "UTF-8")));
                     pk = p10.getSubjectPublicKeyInfo();
                 }
-                String ca = caP.getProperty("ca") + "_2015_1";
+                Calendar cal = GregorianCalendar.getInstance();
+                String ca = caP.getProperty("ca") + "_" + cal.get(Calendar.YEAR) + (cal.get(Calendar.MONTH) >= 6 ? "_2" : "_1");
                 File parent = new File("signer/ca");
                 File[] caFiles = parent.listFiles();
                 if (null == caFiles) {
                     caFiles = new File[0];
                 }
-                for (File f : caFiles) {
-                    if (f.getName().startsWith(caP.getProperty("ca"))) {
-                        ca = f.getName();
-                        break;
+                if ( !new File(parent, ca).exists()) {
+                    System.out.println("CA " + ca + " not found. Searching for anything other remotely fitting.");
+                    for (File f : caFiles) {
+                        if (f.getName().startsWith(caP.getProperty("ca"))) {
+                            ca = f.getName();
+                            break;
+                        }
                     }
                 }
                 File caKey = new File(parent, ca + "/ca.key");
@@ -509,6 +514,7 @@ public class SimpleSigner {
 
         try (DerOutputStream dos = new DerOutputStream()) {
             for (String name : eku.split(",")) {
+                name = name.trim();
                 ObjectIdentifier oid;
                 switch (name) {
                 case "serverAuth":