X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=util-testing%2Forg%2Fcacert%2Fgigi%2Futil%2FSimpleSigner.java;h=f2b97d7bcd958380088ebf432372f2e9eef36a62;hp=bc2ee366db8da71e09ba1118332f010ce551be77;hb=cdea5a0765ccb868dc3f37d7e7a1b7cae357dfc6;hpb=2172993aef7ec7f87133c3ed60cec398afdb82c1 diff --git a/util-testing/org/cacert/gigi/util/SimpleSigner.java b/util-testing/org/cacert/gigi/util/SimpleSigner.java index bc2ee366..f2b97d7b 100644 --- a/util-testing/org/cacert/gigi/util/SimpleSigner.java +++ b/util-testing/org/cacert/gigi/util/SimpleSigner.java @@ -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,12 +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"); - for (File f : parent.listFiles()) { - if (f.getName().startsWith(caP.getProperty("ca"))) { - ca = f.getName(); - break; + File[] caFiles = parent.listFiles(); + if (null == caFiles) { + caFiles = new File[0]; + } + 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"); @@ -503,35 +512,37 @@ public class SimpleSigner { private static byte[] generateEKU(String eku) throws IOException { - DerOutputStream dos = new DerOutputStream(); - for (String name : eku.split(",")) { - ObjectIdentifier oid; - switch (name) { - case "serverAuth": - oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.1"); - break; - case "clientAuth": - oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.2"); - break; - case "codeSigning": - oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.3"); - break; - case "emailProtection": - oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.4"); - break; - case "OCSPSigning": - oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.9"); - break; - - default: - throw new Error(name); + try (DerOutputStream dos = new DerOutputStream()) { + for (String name : eku.split(",")) { + name = name.trim(); + ObjectIdentifier oid; + switch (name) { + case "serverAuth": + oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.1"); + break; + case "clientAuth": + oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.2"); + break; + case "codeSigning": + oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.3"); + break; + case "emailProtection": + oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.4"); + break; + case "OCSPSigning": + oid = new ObjectIdentifier("1.3.6.1.5.5.7.3.9"); + break; + + default: + throw new Error(name); + } + dos.putOID(oid); } - dos.putOID(oid); + byte[] data = dos.toByteArray(); + dos.reset(); + dos.write(DerValue.tag_Sequence, data); + return dos.toByteArray(); } - byte[] data = dos.toByteArray(); - dos.reset(); - dos.write(DerValue.tag_Sequence, data); - return dos.toByteArray(); } public static X500Name genX500Name(Map subj) throws IOException {