1 package org.cacert.gigi.util;
4 import java.io.FileReader;
5 import java.io.IOException;
6 import java.sql.PreparedStatement;
7 import java.sql.ResultSet;
8 import java.sql.SQLException;
9 import java.util.Properties;
11 import org.cacert.gigi.database.DatabaseConnection;
13 public class SimpleSigner {
14 private static PreparedStatement warnMail;
15 private static PreparedStatement updateMail;
16 private static PreparedStatement readyMail;
18 public static void main(String[] args) throws IOException, SQLException,
19 InterruptedException {
20 Properties p = new Properties();
21 p.load(new FileReader("config/gigi.properties"));
22 DatabaseConnection.init(p);
24 readyMail = DatabaseConnection.getInstance().prepare(
25 "SELECT id, csr_name FROM emailcerts" + " WHERE csr_name!=null"//
27 + " AND crt_name=''"//
30 updateMail = DatabaseConnection.getInstance().prepare(
31 "UPDATE emailcerts SET crt_name=?,"
32 + " created=NOW() WHERE id=?");
33 warnMail = DatabaseConnection.getInstance().prepare(
34 "UPDATE emailcerts SET warning=warning+1 WHERE id=?");
36 System.out.println("ping");
42 private static void executeOutstanders() throws SQLException, IOException,
43 InterruptedException {
44 ResultSet rs = readyMail.executeQuery();
46 String csrname = rs.getString(2);
47 System.out.println("sign: " + csrname);
48 int id = rs.getInt(1);
49 File crt = KeyStorage.locateCrt(id);
50 String[] call = new String[]{"openssl", "ca",//
51 "-cert", "testca.crt",//
52 "-keyfile", "testca.key",//
53 "-in", "../" + csrname,//
54 "-out", "../" + crt.getPath(),//
57 "-config", "selfsign.config"
60 Process p1 = Runtime.getRuntime()
61 .exec(call, null, new File("keys"));
63 int waitFor = p1.waitFor();
65 updateMail.setString(1, crt.getPath());
66 updateMail.setInt(2, id);
68 System.out.println("sign: " + id);
70 System.out.println("ERROR: " + id);
71 warnMail.setInt(1, id);