mirror of
https://github.com/i2p/i2p.i2p.git
synced 2026-10-23 00:02:59 +00:00
Conversion to Jetty 12 / Java 17
- Basic console (tested) - SSL console (tested) - Auth (tested) - Debug logging (tested) - Console request log (tested) - I2PControl separate port (untested) - Eepsite request log (untested) TODO: - Eepsites + migration - Debian with or without Jetty 12 - Snark standalone - Tomcat upgrade - Checkin jetty jars - Cleanups
This commit is contained in:
24 files changed
+459
-496
No files matched your search
@@ -14,8 +14,10 @@ import net.i2p.util.Log;
|
||||
|
||||
import net.i2p.apache.http.conn.util.InetAddressUtils;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
import org.eclipse.jetty.server.Response;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
||||
/**
|
||||
* Block certain Host headers to prevent DNS rebinding attacks.
|
||||
@@ -28,7 +30,7 @@ import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
*
|
||||
* @since 0.12 copied from routerconsole
|
||||
*/
|
||||
public class HostCheckHandler extends HandlerWrapper
|
||||
public class HostCheckHandler extends Handler.Wrapper
|
||||
{
|
||||
private final I2PAppContext _context;
|
||||
private final Set<String> _listenHosts;
|
||||
@@ -57,14 +59,13 @@ public class HostCheckHandler extends HandlerWrapper
|
||||
/**
|
||||
* Block by Host header, pass everything else to the delegate.
|
||||
*/
|
||||
public void handle(String pathInContext,
|
||||
Request baseRequest,
|
||||
HttpServletRequest httpRequest,
|
||||
HttpServletResponse httpResponse)
|
||||
throws IOException, ServletException
|
||||
@Override
|
||||
public boolean handle(Request request,
|
||||
Response response,
|
||||
Callback callback)
|
||||
throws Exception
|
||||
{
|
||||
|
||||
String host = httpRequest.getHeader("Host");
|
||||
String host = request.getHeaders().get("Host");
|
||||
if (!allowHost(host)) {
|
||||
Log log = _context.logManager().getLog(HostCheckHandler.class);
|
||||
host = DataHelper.stripHTML(getHost(host));
|
||||
@@ -73,11 +74,12 @@ public class HostCheckHandler extends HandlerWrapper
|
||||
I2PControlController.PROP_ALLOWED_HOSTS + '=' + host +
|
||||
"\" to I2PControl.conf and restart.";
|
||||
log.logAlways(Log.WARN, s);
|
||||
httpResponse.sendError(403, s);
|
||||
return;
|
||||
Response.writeError(request, response, callback, 403, s);
|
||||
callback.succeeded();
|
||||
return true;
|
||||
}
|
||||
|
||||
super.handle(pathInContext, baseRequest, httpRequest, httpResponse);
|
||||
return super.handle(request, response, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,8 @@ import net.i2p.i2pcontrol.security.SecurityManager;
|
||||
import net.i2p.i2pcontrol.servlets.JSONRPC2Servlet;
|
||||
import net.i2p.i2pcontrol.servlets.configuration.ConfigurationManager;
|
||||
|
||||
import org.eclipse.jetty.ee8.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.ee8.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
@@ -38,8 +40,6 @@ import org.eclipse.jetty.server.SecureRequestCustomizer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
|
||||
import java.io.File;
|
||||
@@ -238,8 +238,8 @@ public class I2PControlController implements RouterApp {
|
||||
Connector ssl = buildDefaultListener(server);
|
||||
server.addConnector(ssl);
|
||||
|
||||
ServletHandler sh = new ServletHandler();
|
||||
sh.addServletWithMapping(new ServletHolder(new JSONRPC2Servlet(_context, _secMan)), "/");
|
||||
ServletContextHandler sch = new ServletContextHandler();
|
||||
sch.addServlet(new ServletHolder(new JSONRPC2Servlet(_context, _secMan)), "/");
|
||||
HostCheckHandler hch = new HostCheckHandler(_appContext);
|
||||
Set<String> listenHosts = new HashSet<String>(8);
|
||||
// fix up the allowed hosts set (see HostCheckHandler)
|
||||
@@ -261,8 +261,8 @@ public class I2PControlController implements RouterApp {
|
||||
}
|
||||
}
|
||||
hch.setListenHosts(listenHosts);
|
||||
hch.setHandler(sh);
|
||||
server.getServer().setHandler(hch);
|
||||
hch.setHandler(sch);
|
||||
server.setHandler(hch);
|
||||
|
||||
_conf.writeConfFile();
|
||||
return server;
|
||||
@@ -282,7 +282,8 @@ public class I2PControlController implements RouterApp {
|
||||
}
|
||||
|
||||
// the keystore path and password
|
||||
SslContextFactory sslFactory = new SslContextFactory(_ksp.getKeyStoreLocation());
|
||||
SslContextFactory.Server sslFactory = new SslContextFactory.Server();
|
||||
sslFactory.setKeyStorePath(_ksp.getKeyStoreLocation());
|
||||
sslFactory.setKeyStorePassword(KeyStoreProvider.DEFAULT_KEYSTORE_PASSWORD);
|
||||
// the X.509 cert password (if not present, verifyKeyStore() returned false)
|
||||
sslFactory.setKeyManagerPassword(KeyStoreProvider.DEFAULT_CERTIFICATE_PASSWORD);
|
||||
|
||||
Reference in new issue
Block a user