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 void main(String[] args) throws Exception {
21 Properties mainProps = new Properties();
22 mainProps.load(new FileInputStream("config/gigi.properties"));
23 for (int i = 0; i < args.length; i++) {
24 if (args[i].equals("--port")) {
25 mainProps.setProperty("port", args[i + 1]);
30 ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
31 DataOutputStream dos = new DataOutputStream(chunkConfig);
32 byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
33 byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
35 DevelLauncher.writeGigiConfig(dos, "changeit".getBytes(), "changeit".getBytes(), mainProps, cacerts, keystore);
37 InputStream oldin = System.in;
38 System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
43 public static void writeGigiConfig(OutputStream target, byte[] keystorepw, byte[] truststorepw,
44 Properties mainprop, byte[] cacerts, byte[] keystore) throws IOException {
45 TarOutputStream tos = new TarOutputStream(target);
46 ByteArrayOutputStream baos = new ByteArrayOutputStream();
47 mainprop.store(baos, "");
49 putTarEntry(baos.toByteArray(), tos, "gigi.properties");
50 putTarEntry(keystorepw, tos, "keystorepw");
51 putTarEntry(truststorepw, tos, "truststorepw");
52 putTarEntry(keystore, tos, "keystore.pkcs12");
53 putTarEntry(cacerts, tos, "cacerts.jks");
58 private static void putTarEntry(byte[] data, TarOutputStream tos, String name) throws IOException {
59 TarHeader th = new TarHeader();
60 th.name = new StringBuffer(name);
61 th.size = data.length;
62 tos.putNextEntry(new TarEntry(th));
66 public static void writeChunk(DataOutputStream dos, byte[] chunk) throws IOException {
67 dos.writeInt(chunk.length);
71 public static void launch(Properties props, File cacerts, File keystore) throws IOException {
72 ByteArrayOutputStream config = new ByteArrayOutputStream();
73 props.store(config, "");