简体   繁体   English

在Jetty中拦截HTTP连接

[英]Intercept HTTP Connect in Jetty

I am writing a HTTPS proxy server using servlet 3.0 and Jetty. 我正在使用Servlet 3.0和Jetty编写HTTPS代理服务器。

How can I process HTTPS Connect in jetty? 如何在码头处理HTTPS Connect?

Currently I am using jetty-maven-plugin and my plugin configuration looks like this- 目前,我正在使用jetty-maven-plugin ,我的插件配置如下所示:

<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webApp>
        <contextPath>/</contextPath>        
    </webApp>
    <scanIntervalSeconds>1</scanIntervalSeconds>    
    <connectors>
        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <port>9090</port>
            <maxIdleTime>60000</maxIdleTime>
        </connector>
        <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
            <port>9090</port>
            <keystore>src/keystore.jks</keystore>
            <keyPassword>test</keyPassword>
            <password>test</password> 
        </connector>        
    </connectors>    
</configuration>
/plugin>

Yes- I want to process HTTP and HTTPS over same port. 是的-我想通过同一端口处理HTTP和HTTPS。 When I start Jetty, it starts just fine- 当我启动Jetty时,它开始就很好-

2013-04-21 15:15:03.750:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:9090
2013-04-21 15:15:03.912:INFO:oejus.SslContextFactory:Enabled Protocols [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2] of [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2]
2013-04-21 15:15:03.917:INFO:oejs.AbstractConnector:Started SslSelectChannelConnector@0.0.0.0:9090
Started Jetty Server

I've @Override over doGet and doPost and both methods fire just fine when I send HTTP request. 我已经对doGet和doPost进行了@Override,当我发送HTTP请求时,两种方法都可以正常触发。 But none of them are fired when client sends HTTPS Connect. 但是,当客户端发送HTTPS Connect时,不会触发它们。 I would like to intercept HTTPS Connect so that I can inspect SSL traffic. 我想拦截HTTPS Connect,以便检查SSL流量。

Any idea how to make it work? 任何想法如何使其工作?

Update- I think I've found first issue. 更新-我想我已经找到了第一个问题。 Even though I see in logs that SelectChannelConnector and SslSelectChannelConnector are started on port 9090, the SSL connector is not being fired. 即使我在日志中看到SelectChannelConnector和SslSelectChannelConnector在端口9090上启动,也不会触发SSL连接器。

So my question is- is it possible to handle both HTTP and HTTPS on same port using servlet 3.0 and Jetty? 所以我的问题是- 是否可以使用Servlet 3.0和Jetty在同一端口上同时处理HTTP和HTTPS?

No, that's not possible (in fact it is possible, but it shouldn't be). 不,那是不可能的(实际上是可能的,但是不应该这样)。 Every connector needs it's own port. 每个连接器都需要自己的端口。

You could however redirect all connects to the http listener to the https port using security-constraints in your web.xml. 但是,您可以使用web.xml中的安全约束将所有连接到http侦听器的连接重定向到https端口。 However that doesn't seem to be what you're looking for. 但是,这似乎并不是您想要的。

I wonder why jetty doesn't throw any exception at startup when you try to setup two connectors on a single port. 我想知道为什么当您尝试在单个端口上设置两个连接器时,jetty在启动时不会引发任何异常。 Will verify that. 将验证这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM