argList = net.i2p.i2ptunnel.web.SSLHelper.parseArgs(clArgs);
for (String arg : argList) {
if (arg.endsWith("jetty.xml")) {
jettyFile = new File(arg);
if (!jettyFile.isAbsolute())
jettyFile = new File(ctx.getConfigDir(), arg);
} else if (arg.endsWith("jetty-ssl.xml")) {
jettySSLFile = new File(arg);
if (!jettySSLFile.isAbsolute())
jettySSLFile = new File(ctx.getConfigDir(), arg);
jettySSLFileInArgs = true;
}
} // for arg in argList
if (jettyFile == null || !jettyFile.exists())
continue;
try {
org.eclipse.jetty.xml.XmlParser.Node root;
root = JettyXmlConfigurationParser.parse(jettyFile);
host = JettyXmlConfigurationParser.getValue(root, "host");
port = JettyXmlConfigurationParser.getValue(root, "port");
// now check if host/port match the tunnel
if (!targetPort.equals(port))
continue;
if (!targetHost.equals(host) && !"0.0.0.0".equals(host) && !"::".equals(host) &&
!((targetHost.equals("127.0.0.1") && "localhost".equals(host)) ||
(targetHost.equals("localhost") && "127.0.0.1".equals(host))))
continue;
} catch (org.xml.sax.SAXException saxe) {
saxe.printStackTrace();
error = DataHelper.escapeHTML(saxe.getMessage());
continue;
}
if (jettySSLFile == null && !argList.isEmpty()) {
String arg = argList.get(0);
File f = new File(arg);
if (!f.isAbsolute())
f = new File(ctx.getConfigDir(), arg);
File p = f.getParentFile();
if (p != null)
jettySSLFile = new File(p, "jetty-ssl.xml");
}
boolean ksDflt = false;
boolean kmDflt = false;
boolean tsDflt = false;
boolean ksExists = false;
if (jettySSLFile.exists()) {
jettySSLFileExists = true;
try {
org.eclipse.jetty.xml.XmlParser.Node root;
root = JettyXmlConfigurationParser.parse(jettySSLFile);
ksPW = JettyXmlConfigurationParser.getValue(root, "KeyStorePassword");
kmPW = JettyXmlConfigurationParser.getValue(root, "KeyManagerPassword");
tsPW = JettyXmlConfigurationParser.getValue(root, "TrustStorePassword");
ksPath = JettyXmlConfigurationParser.getValue(root, "KeyStorePath");
tsPath = JettyXmlConfigurationParser.getValue(root, "TrustStorePath");
sslHost = JettyXmlConfigurationParser.getValue(root, "host");
sslPort = JettyXmlConfigurationParser.getValue(root, "port");
// we can't proceed unless they are there
// tsPW may be null
File ksFile = null;
boolean tsIsKs = true;
boolean ksArgs = ksPW != null && kmPW != null && ksPath != null && sslHost != null && sslPort != null;
/** 2015+ installs */
final String DEFAULT_KSPW_1 = KeyStoreUtil.DEFAULT_KEYSTORE_PASSWORD;
final String DEFAULT_KMPW_1 = "myKeyPassword";
/** earlier */
final String DEFAULT_KSPW_2 = "OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4";
final String DEFAULT_KMPW_2 = "OBF:1u2u1wml1z7s1z7a1wnl1u2g";
if (ksArgs) {
jettySSLFileValid = true;
ksDflt = ksPW.equals(DEFAULT_KSPW_1) || ksPW.equals(DEFAULT_KSPW_2);
kmDflt = kmPW.equals(DEFAULT_KMPW_1) || kmPW.equals(DEFAULT_KMPW_2);
ksFile = new File(ksPath);
if (!ksFile.isAbsolute())
ksFile = new File(ctx.getConfigDir(), ksPath);
ksExists = ksFile.exists();
tsIsKs = tsPath == null || ksPath.equals(tsPath);
}
if (tsPW != null) {
tsDflt = tsPW.equals(DEFAULT_KSPW_1) || tsPW.equals(DEFAULT_KSPW_2);
}
} catch (org.xml.sax.SAXException saxe) {
saxe.printStackTrace();
error = DataHelper.escapeHTML(saxe.getMessage());
}
}
boolean canConfigure = jettySSLFileExists && jettySSLFileValid;
boolean isEnabled = canConfigure && jettySSLFileInArgs && ksExists && ports.contains(Integer.valueOf(443));
boolean isPWDefault = kmDflt || !ksExists;
foundClientConfig = true;
// now start the output for this client
%>
<%=DataHelper.escapeHTML(clName)%>
<%
for (String arg : argList) {
%><%=DataHelper.escapeHTML(arg)%> <%
}
%>
<%=(start ? CHECK : "")%> <%=(ssl ? CHECK : "")%>
<%
if (!jettySSLFileExists) {
%>
Cannot configure, Jetty SSL configuration file does not exist: <%=jettySSLFile.toString()%>
<%
} else if (!jettySSLFileValid) {
%>
Cannot configure, Jetty SSL configuration file is too old or invalid: <%=jettySSLFile.toString()%>
<%
if (error.length() > 0) {
%>
<%=error%>
<%
}
} else {
%>
<%
if (ksPW != null) {
if (!ksPW.startsWith("OBF:"))
ksPW = JettyXmlConfigurationParser.obfuscate(ksPW);
%>
<%
}
%>
<%
if (isEnabled && !isPWDefault) {
%>
<%=intl._t("SSL is enabled")%>
<%=intl._t("Disable SSL")%>
<%
} else if (!isPWDefault) {
%>
<%=intl._t("SSL is disabled")%>
<%=intl._t("Enable SSL")%>
<%
} else {
%>
<%=intl._t("New Certificate Password")%>:
" value="" class="freetext password" />
<%
if (isEnabled) {
%>
<%=intl._t("Generate new SSL certificate")%>
<%
} else {
%>
<%=intl._t("Generate SSL certificate and enable")%>
<%
}
}
%>
<%
break;
} // canConfigure
} // while (for each client or client file)
if (!foundClientConfig) {
%>
Cannot configure, no Jetty server found in client configurations that matches this tunnel
Support for non-Jetty servers will be added in a future release
<%
}
} catch (IOException ioe) { ioe.printStackTrace(); }
%>