]> WPIA git - gigi.git/commitdiff
fix: Make certs optional
authorFelix Dörre <felix@dogcraft.de>
Tue, 19 Apr 2016 10:17:37 +0000 (12:17 +0200)
committerFelix Dörre <felix@dogcraft.de>
Tue, 19 Apr 2016 10:17:37 +0000 (12:17 +0200)
src/org/cacert/gigi/GigiConfig.java
src/org/cacert/gigi/Launcher.java
src/org/cacert/gigi/email/EmailProvider.java
util-testing/org/cacert/gigi/DevelLauncher.java

index 3a1b9eed6642aadbbf4d733e9b3440a118ff248e..8b7c220202f83e8b3b07724fb57824c9fb49f368 100644 (file)
@@ -83,6 +83,9 @@ public class GigiConfig {
     }
 
     public KeyStore getPrivateStore() throws GeneralSecurityException, IOException {
+        if (keystore == null || keystorpw == null) {
+            return null;
+        }
         KeyStore ks1 = KeyStore.getInstance("pkcs12");
         ks1.load(new ByteArrayInputStream(keystore), keystorpw);
         return ks1;
index f5b65d73c64d0527ca7526a1803ae12410e5cfdb..775823dc443a59991620f4529a57b40513efc135 100644 (file)
@@ -151,8 +151,12 @@ public class Launcher {
 
     private void initEmails(GigiConfig conf) throws GeneralSecurityException, IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
         KeyStore privateStore = conf.getPrivateStore();
-        Certificate mail = privateStore.getCertificate("mail");
-        Key k = privateStore.getKey("mail", conf.getPrivateStorePw().toCharArray());
+        Certificate mail = null;
+        Key k = null;
+        if (privateStore != null && privateStore.containsAlias("mail")) {
+            mail = privateStore.getCertificate("mail");
+            k = privateStore.getKey("mail", conf.getPrivateStorePw().toCharArray());
+        }
         EmailProvider.initSystem(conf.getMainProps(), mail, k);
     }
 
index e2c4d5d63cb296b615fea0f9ee44093f4cfcca01..a32031187525f853b0306668b4b434ff739df4c9 100644 (file)
@@ -39,7 +39,13 @@ public abstract class EmailProvider {
     }
 
     protected final void sendSigned(String contents, PrintWriter output) throws IOException, GeneralSecurityException {
-        SMIME.smime(contents, k, c, output);
+        if (k == null || c == null) {
+            output.println("Content-Transfer-Encoding: base64");
+            output.println();
+            output.print(contents);
+        } else {
+            SMIME.smime(contents, k, c, output);
+        }
     }
 
     public static EmailProvider getInstance() {
index df5a790d24297fd728316c9e0978da3ae8924eb7..c32b6b30a6c83240735857e2283007119124466b 100644 (file)
@@ -16,6 +16,7 @@ import java.lang.reflect.Field;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.HashMap;
@@ -55,7 +56,13 @@ public class DevelLauncher {
         ByteArrayOutputStream chunkConfig = new ByteArrayOutputStream();
         DataOutputStream dos = new DataOutputStream(chunkConfig);
         byte[] cacerts = Files.readAllBytes(Paths.get("config/cacerts.jks"));
-        byte[] keystore = Files.readAllBytes(Paths.get("config/keystore.pkcs12"));
+        byte[] keystore = null;
+        Path p = Paths.get("config/keystore.pkcs12");
+        if (p.toFile().exists()) {
+            keystore = Files.readAllBytes(p);
+        } else {
+            mainProps.setProperty("proxy", "true");
+        }
 
         DevelLauncher.writeGigiConfig(dos, "changeit".getBytes("UTF-8"), "changeit".getBytes("UTF-8"), mainProps, cacerts, keystore);
         dos.flush();
@@ -229,6 +236,9 @@ public class DevelLauncher {
     }
 
     private static void putTarEntry(byte[] data, TarOutputStream tos, String name) throws IOException {
+        if (data == null) {
+            return;
+        }
         TarHeader th = new TarHeader();
         th.name = new StringBuffer(name);
         th.size = data.length;