]> WPIA git - gigi.git/blobdiff - util-testing/org/cacert/gigi/util/SimpleSigner.java
fix: simple signer correctly parse profile-EKUs
[gigi.git] / util-testing / org / cacert / gigi / util / SimpleSigner.java
index 6b498988628d5b125063a232f857074e7a910738..1344d56229632eb2922babf7588e0543dd432f8b 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,8 +127,8 @@ 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`=?");
@@ -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":