]> WPIA git - gigi.git/blob - src/org/cacert/gigi/DevelLauncher.java
Merge branch 'libs/jetty/upstream' into libs/jetty/local
[gigi.git] / src / org / cacert / gigi / DevelLauncher.java
1 package org.cacert.gigi;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.ByteArrayOutputStream;
5 import java.io.DataOutputStream;
6 import java.io.File;
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;
14
15 import org.kamranzafar.jtar.TarEntry;
16 import org.kamranzafar.jtar.TarHeader;
17 import org.kamranzafar.jtar.TarOutputStream;
18
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]);
26                         }
27                         i++;
28                 }
29
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
34                                 .get("config/keystore.pkcs12"));
35
36                 DevelLauncher.writeGigiConfig(dos, new byte[]{}, "changeit".getBytes(),
37                                 mainProps, cacerts, keystore);
38                 dos.flush();
39                 InputStream oldin = System.in;
40                 System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
41                 Launcher.main(args);
42                 System.setIn(oldin);
43         }
44         public static void writeGigiConfig(OutputStream target, byte[] keystorepw,
45                         byte[] truststorepw, Properties mainprop, byte[] cacerts,
46                         byte[] keystore) throws IOException {
47                 TarOutputStream tos = new TarOutputStream(target);
48                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
49                 mainprop.store(baos, "");
50
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");
56                 tos.close();
57
58         }
59         private static void putTarEntry(byte[] data, TarOutputStream tos,
60                         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));
65                 tos.write(data);
66         }
67         public static void writeChunk(DataOutputStream dos, byte[] chunk)
68                         throws IOException {
69                 dos.writeInt(chunk.length);
70                 dos.write(chunk);
71         }
72         public static void launch(Properties props, File cacerts, File keystore)
73                         throws IOException {
74                 ByteArrayOutputStream config = new ByteArrayOutputStream();
75                 props.store(config, "");
76         }
77 }