1 package org.cacert.gigi;
3 import java.io.ByteArrayInputStream;
4 import java.io.DataInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.security.GeneralSecurityException;
8 import java.security.KeyStore;
9 import java.util.Properties;
11 public class GigiConfig {
12 public static final String GIGI_CONFIG_VERSION = "GigiConfigV1.0";
15 Properties mainProps = new Properties();
16 private char[] keystorpw;
17 private char[] truststorepw;
19 private GigiConfig() {
21 public byte[] getCacerts() {
24 public byte[] getKeystore() {
27 public Properties getMainProps() {
31 public static GigiConfig parse(InputStream input) throws IOException {
32 DataInputStream dis = new DataInputStream(input);
33 String version = new String(readChunk(dis));
34 if (!version.equals(GIGI_CONFIG_VERSION)) {
35 System.out.println("Invalid config format");
38 GigiConfig gc = new GigiConfig();
39 gc.keystorpw = transformSafe(readChunk(dis));
40 gc.truststorepw = transformSafe(readChunk(dis));
41 gc.mainProps.load(new ByteArrayInputStream(readChunk(dis)));
42 gc.cacerts = readChunk(dis);
43 gc.keystore = readChunk(dis);
46 private static char[] transformSafe(byte[] readChunk) {
47 char[] res = new char[readChunk.length];
48 for (int i = 0; i < res.length; i++) {
49 res[i] = (char) readChunk[i];
54 private static byte[] readChunk(DataInputStream dis) throws IOException {
55 int length = dis.readInt();
56 byte[] contents = new byte[length];
57 dis.readFully(contents);
60 public KeyStore getPrivateStore() throws GeneralSecurityException,
62 KeyStore ks1 = KeyStore.getInstance("pkcs12");
63 ks1.load(new ByteArrayInputStream(keystore), keystorpw);
66 public KeyStore getTrustStore() throws GeneralSecurityException,
68 KeyStore ks1 = KeyStore.getInstance("jks");
69 ks1.load(new ByteArrayInputStream(cacerts), truststorepw);