import org.cacert.gigi.database.DatabaseConnection;
import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
import org.cacert.gigi.util.DatabaseManager;
+import org.cacert.gigi.util.SimpleSigner;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
String type = testProps.getProperty("type");
if (type.equals("local")) {
- url = testProps.getProperty("server");
+ url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort");
String[] parts = testProps.getProperty("mail").split(":", 2);
ter = new TestEmailReciever(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
return;
System.out.println("... starting server");
Properties mainProps = new Properties();
mainProps.setProperty("host", "127.0.0.1");
- mainProps.setProperty("name.secure", "sec");
+ mainProps.setProperty("name.secure", testProps.getProperty("name.secure"));
mainProps.setProperty("name.www", testProps.getProperty("name.www"));
- mainProps.setProperty("name.static", "stat");
+ mainProps.setProperty("name.static", testProps.getProperty("name.static"));
mainProps.setProperty("port", testProps.getProperty("serverPort"));
mainProps.setProperty("emailProvider", "org.cacert.gigi.email.TestEmailProvider");
throw new Error("Server startup failed");
}
ter = new TestEmailReciever(new InetSocketAddress("localhost", 8473));
+ SimpleSigner.runSigner();
} catch (IOException e) {
throw new Error(e);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
return;
}
gigi.destroy();
+ try {
+ SimpleSigner.stopSigner();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
@After
}
public String runRegister(String param) throws IOException {
- HttpURLConnection uc = (HttpURLConnection) new URL("https://" + getServerName() + registerService)
- .openConnection();
+ URL regist = new URL("https://" + getServerName() + registerService);
+ HttpURLConnection uc = (HttpURLConnection) regist.openConnection();
+ HttpURLConnection csrfConn = (HttpURLConnection) regist.openConnection();
+
+ String headerField = csrfConn.getHeaderField("Set-Cookie");
+ headerField = headerField.substring(0, headerField.indexOf(';'));
+
+ String csrf = getCSRF(csrfConn);
+ uc.addRequestProperty("Cookie", headerField);
uc.setDoOutput(true);
- uc.getOutputStream().write(param.getBytes());
+ uc.getOutputStream().write((param + "&csrf=" + csrf).getBytes());
String d = IOUtils.readURL(uc);
return d;
}
public String getCSRF(URLConnection u) throws IOException {
String content = IOUtils.readURL(u);
- Pattern p = Pattern.compile("<input type='csrf' value='([^']+)'>");
+ Pattern p = Pattern.compile("<input type='hidden' name='csrf' value='([^']+)'>");
Matcher m = p.matcher(content);
if (!m.find()) {
- throw new Error("New CSRF Token");
+ throw new Error("No CSRF Token");
}
return m.group(1);
}
+
+ public static String[] generateCSR(String dn) throws IOException {
+ Process p = Runtime.getRuntime().exec(
+ new String[] { "openssl", "req", "-newkey", "rsa:1024", "-nodes", "-subj", dn, "-config",
+ "keys/selfsign.config" });
+ String csr = IOUtils.readURL(new InputStreamReader(p.getInputStream()));
+
+ String[] parts = csr.split("(?<=-----)\n(?=-----)");
+ if (parts.length != 2) {
+ System.err.println(IOUtils.readURL(new InputStreamReader(p.getErrorStream())));
+ throw new Error();
+ }
+ return parts;
+ }
+
}