import java.io.BufferedReader;
import java.io.DataOutputStream;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
}
static Properties testProps = new Properties();
+
+ public static Properties getTestProps() {
+ return testProps;
+ }
+
static {
InitTruststore.run();
HttpURLConnection.setFollowRedirects(false);
if ( !DatabaseConnection.isInited()) {
DatabaseConnection.init(testProps);
}
- System.out.println("... purging Database");
- DatabaseManager.run(new String[] {
- testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
- });
+ purgeDatabase();
String type = testProps.getProperty("type");
Properties mainProps = generateMainProps();
ServerConstants.init(mainProps);
if (type.equals("local")) {
- url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort");
+ url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
String[] parts = testProps.getProperty("mail").split(":", 2);
ter = new TestEmailReciever(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
return;
}
- url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort");
+ url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
gigi = Runtime.getRuntime().exec(testProps.getProperty("java"));
DataOutputStream toGigi = new DataOutputStream(gigi.getOutputStream());
System.out.println("... starting server");
SimpleSigner.runSigner();
} catch (IOException e) {
throw new Error(e);
- } catch (ClassNotFoundException e1) {
- e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
}
+ public static void purgeDatabase() throws SQLException, IOException {
+ System.out.print("... resetting Database");
+ long ms = System.currentTimeMillis();
+ try {
+ DatabaseManager.run(new String[] {
+ testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password")
+ }, true);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms");
+ }
+
private static Properties generateMainProps() {
Properties mainProps = new Properties();
mainProps.setProperty("host", "127.0.0.1");
mainProps.setProperty("name.www", testProps.getProperty("name.www"));
mainProps.setProperty("name.static", testProps.getProperty("name.static"));
- mainProps.setProperty("port", testProps.getProperty("serverPort"));
+ mainProps.setProperty("https.port", testProps.getProperty("serverPort.https"));
+ mainProps.setProperty("http.port", testProps.getProperty("serverPort.http"));
mainProps.setProperty("emailProvider", "org.cacert.gigi.email.TestEmailProvider");
mainProps.setProperty("emailProvider.port", "8473");
mainProps.setProperty("sql.driver", testProps.getProperty("sql.driver"));
public static String getCSRF(URLConnection u, int formIndex) throws IOException {
String content = IOUtils.readURL(u);
+ return getCSRF(formIndex, content);
+ }
+
+ public static String getCSRF(int formIndex, String content) throws Error {
Pattern p = Pattern.compile("<input type='hidden' name='csrf' value='([^']+)'>");
Matcher m = p.matcher(content);
for (int i = 0; i < formIndex + 1; i++) {
public static KeyPair generateKeypair() throws GeneralSecurityException {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(4096);
- return kpg.generateKeyPair();
+ KeyPair keyPair = null;
+ File f = new File("testKeypair");
+ if (f.exists()) {
+ try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f))) {
+ keyPair = (KeyPair) ois.readObject();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else {
+ keyPair = kpg.generateKeyPair();
+ try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f))) {
+ oos.writeObject(keyPair);
+ oos.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return keyPair;
}
public static String generatePEMCSR(KeyPair kp, String dn) throws GeneralSecurityException, IOException {
return adrr;
}
+ public static URLConnection cookie(URLConnection openConnection, String cookie) {
+ openConnection.setRequestProperty("Cookie", cookie);
+ return openConnection;
+ }
+
}