1 package org.cacert.gigi;
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.DataOutputStream;
7 import java.io.FileInputStream;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.io.OutputStream;
11 import java.nio.file.Files;
12 import java.nio.file.Paths;
13 import java.util.Properties;
15 import org.kamranzafar.jtar.TarEntry;
16 import org.kamranzafar.jtar.TarHeader;
17 import org.kamranzafar.jtar.TarOutputStream;
19 public class DevelLauncher {
20 public static final boolean DEVEL = true;
22 public static void main(String[] args) throws Exception {
23 Properties mainProps = new Properties();
24 mainProps.load(new FileInputStream("config/gigi.properties"));
25 for (int i = 0; i < args.length; i++) {
26 if (args[i].equals("--port")) {
27 mainProps.setProperty("port", args[i + 1]);
32 ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
33 DataOutputStream dos = new DataOutputStream(chunkConfig);
34 byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
35 byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
37 DevelLauncher.writeGigiConfig(dos, "changeit".getBytes(), "changeit".getBytes(), mainProps, cacerts, keystore);
39 InputStream oldin = System.in;
40 System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
45 public static void writeGigiConfig(OutputStream target, byte[] keystorepw, byte[] truststorepw,
46 Properties mainprop, byte[] cacerts, byte[] keystore) throws IOException {
47 TarOutputStream tos = new TarOutputStream(target);
48 ByteArrayOutputStream baos = new ByteArrayOutputStream();
49 mainprop.store(baos, "");
51 putTarEntry(baos.toByteArray(), tos, "gigi.properties");
52 putTarEntry(keystorepw, tos, "keystorepw");
53 putTarEntry(truststorepw, tos, "truststorepw");
54 putTarEntry(keystore, tos, "keystore.pkcs12");
55 putTarEntry(cacerts, tos, "cacerts.jks");
60 private static void putTarEntry(byte[] data, TarOutputStream tos, String name) throws IOException {
61 TarHeader th = new TarHeader();
62 th.name = new StringBuffer(name);
63 th.size = data.length;
64 tos.putNextEntry(new TarEntry(th));
68 public static void writeChunk(DataOutputStream dos, byte[] chunk) throws IOException {
69 dos.writeInt(chunk.length);
73 public static void launch(Properties props, File cacerts, File keystore) throws IOException {
74 ByteArrayOutputStream config = new ByteArrayOutputStream();
75 props.store(config, "");