From 4d09e507fba1def9a35de16f865b7e99198e1abe Mon Sep 17 00:00:00 2001 From: zzz Date: Sun, 29 Apr 2018 14:32:01 +0000 Subject: [PATCH] SSL Wizard: Move some things to make the classloader happy Rewrite clients.config --- apps/i2ptunnel/jsp/ssl.jsp | 25 +++++++-- .../jetty/JettyXmlConfigurationParser.java | 54 +++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/apps/i2ptunnel/jsp/ssl.jsp b/apps/i2ptunnel/jsp/ssl.jsp index 260781f5f..825d3d4d4 100644 --- a/apps/i2ptunnel/jsp/ssl.jsp +++ b/apps/i2ptunnel/jsp/ssl.jsp @@ -146,7 +146,7 @@ input.default { width: 1px; height: 1px; visibility: hidden; } // rewrite jetty-ssl.xml if (ok) { - String obf = org.eclipse.jetty.util.security.Password.obfuscate(newpw); + String obf = JettyXmlConfigurationParser.obfuscate(newpw); File f = new File(jettySSLConfigPath); try { org.eclipse.jetty.xml.XmlParser.Node root; @@ -162,7 +162,9 @@ input.default { width: 1px; height: 1px; visibility: hidden; } java.io.Writer w = null; try { w = new java.io.OutputStreamWriter(new net.i2p.util.SecureFileOutputStream(f), "UTF-8"); - w.write(root.toString()); + w.write("\n"); + JettyXmlConfigurationParser.write(root, w); + out.println("Jetty configuration updated"); } catch (java.io.IOException ioe) { ioe.printStackTrace(); ok = false; @@ -180,6 +182,24 @@ input.default { width: 1px; height: 1px; visibility: hidden; } // rewrite clients.config boolean isSSLEnabled = Boolean.parseBoolean(request.getParameter("isSSLEnabled")); if (ok && !isSSLEnabled) { + File f = new File(ctx.getConfigDir(), "clients.config"); + java.util.Properties p = new net.i2p.util.OrderedProperties(); + try { + DataHelper.loadProps(p, f); + String k = "clientApp." + appNum + ".args"; + String v = p.getProperty(k); + if (v == null) { + ok = false; + } else { + v += " \"" + jettySSLConfigPath + '"'; + p.setProperty(k, v); + DataHelper.storeProps(p, f); + out.println("Jetty SSL enabled"); + } + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + ok = false; + } } // stop and restart jetty @@ -367,7 +387,6 @@ input.default { width: 1px; height: 1px; visibility: hidden; } jettyFile = new File(arg); if (!jettyFile.isAbsolute()) jettyFile = new File(ctx.getConfigDir(), arg); - jettySSLFileInArgs = true; } else if (arg.endsWith("jetty-ssl.xml")) { jettySSLFile = new File(arg); if (!jettySSLFile.isAbsolute()) diff --git a/apps/jetty/java/src/net/i2p/jetty/JettyXmlConfigurationParser.java b/apps/jetty/java/src/net/i2p/jetty/JettyXmlConfigurationParser.java index ee44462d7..dee021b2e 100644 --- a/apps/jetty/java/src/net/i2p/jetty/JettyXmlConfigurationParser.java +++ b/apps/jetty/java/src/net/i2p/jetty/JettyXmlConfigurationParser.java @@ -20,12 +20,15 @@ package net.i2p.jetty; import java.io.IOException; import java.io.File; +import java.io.Writer; import java.net.URL; import java.util.Locale; import org.eclipse.jetty.util.Loader; +import org.eclipse.jetty.util.security.Password; import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlParser; +import org.eclipse.jetty.xml.XmlParser.Attribute; import org.eclipse.jetty.xml.XmlParser.Node; import org.xml.sax.SAXException; @@ -137,4 +140,55 @@ public class JettyXmlConfigurationParser } return false; } + + /** + * Write out the XML. + * Adapted from Node.toString(). + * That synchronized method caused classpath issues when called from the webapp. + * Also add newlines here for readability. + */ + public static void write(Node node, Writer out) throws IOException { + out.write('<'); + String tag = node.getTag(); + out.write(tag); + + Attribute[] attrs = node.getAttributes(); + if (attrs != null) { + for (int i = 0; i < attrs.length; i++) { + out.write(' '); + out.write(attrs[i].getName()); + out.write("=\""); + out.write(attrs[i].getValue()); + out.write('"'); + } + } + + int size = node.size(); + if (size > 0) { + out.write(">"); + for (int i = 0; i < size; i++) { + Object o = node.get(i); + if (o == null) + continue; + if (o instanceof Node) { + write((Node) o, out); + } else { + out.write(o.toString()); + } + } + out.write("\n"); + } else { + out.write("/>\n"); + } + } + + /** + * Obfuscate a password for storage in the XML + * @return a string starting with "OBF:" + */ + public static String obfuscate(String s) { + return Password.obfuscate(s); + } }