Made the cipher comparator a constant field.

This commit is contained in:
Simone Bordet 2015-05-26 17:58:20 +02:00
parent 1a6db17799
commit a6ff4da9b1
3 changed files with 35 additions and 34 deletions

View File

@ -71,7 +71,7 @@ public class Http2Server
MBeanContainer mbContainer = new MBeanContainer(
ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
ServletContextHandler context = new ServletContextHandler(server, "/",ServletContextHandler.SESSIONS);
context.setResourceBase("src/main/resources/docroot");
context.addFilter(PushSessionCacheFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
@ -88,73 +88,73 @@ public class Http2Server
http_config.setSendServerVersion(true);
// HTTP Connector
ServerConnector http = new ServerConnector(server,new HttpConnectionFactory(http_config), new HTTP2CServerConnectionFactory(http_config));
ServerConnector http = new ServerConnector(server,new HttpConnectionFactory(http_config), new HTTP2CServerConnectionFactory(http_config));
http.setPort(8080);
server.addConnector(http);
// SSL Context Factory for HTTPS and HTTP/2
String jetty_distro = System.getProperty("jetty.distro","../../jetty-distribution/target/distribution");
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(jetty_distro + "/demo-base/etc/keystore");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
// HTTPS Configuration
HttpConfiguration https_config = new HttpConfiguration(http_config);
https_config.addCustomizer(new SecureRequestCustomizer());
// HTTP/2 Connection Factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(https_config);
NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http.getDefaultProtocol());
// SSL Connection Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory,alpn.getProtocol());
// HTTP/2 Connector
ServerConnector http2Connector =
ServerConnector http2Connector =
new ServerConnector(server,ssl,alpn,h2,new HttpConnectionFactory(https_config));
http2Connector.setPort(8443);
server.addConnector(http2Connector);
ALPN.debug=false;
server.start();
//server.dumpStdErr();
server.join();
}
public static class PushedTilesFilter implements Filter
{
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
{
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
Request baseRequest = Request.getBaseRequest(request);
if (baseRequest.isPush() && baseRequest.getRequestURI().contains("tiles") )
{
String uri = baseRequest.getRequestURI().replace("tiles","pushed").substring(baseRequest.getContextPath().length());
request.getRequestDispatcher(uri).forward(request,response);
return;
}
chain.doFilter(request,response);
}
@Override
public void destroy()
{
}
};
static Servlet servlet = new HttpServlet()
{
private static final long serialVersionUID = 1L;
@ -165,7 +165,7 @@ public class Http2Server
String code=request.getParameter("code");
if (code!=null)
response.setStatus(Integer.parseInt(code));
HttpSession session = request.getSession(true);
if (session.isNew())
response.addCookie(new Cookie("bigcookie",

View File

@ -25,20 +25,22 @@ import org.eclipse.jetty.util.Trie;
public class HTTP2Cipher
{
public static final Comparator<String> COMPARATOR = new CipherComparator();
private final static Trie<Boolean> __blackProtocols = new ArrayTrie<>(6*5);
private final static Trie<Boolean> __blackCiphers = new ArrayTrie<>(275*40);
static
{
for (String p : new String[]
for (String p : new String[]
{
"TLSv1.2","TLSv1.1", "TLSv1", "SSL", "SSLv2", "SSLv3"
})
{
__blackProtocols.put(p,Boolean.TRUE);
}
for (String c : new String[]
for (String c : new String[]
{
"TLS_NULL_WITH_NULL_NULL",
"TLS_RSA_WITH_NULL_MD5",
@ -320,23 +322,22 @@ public class HTTP2Cipher
{
__blackCiphers.put(c,Boolean.TRUE);
}
};
}
public static boolean isBlackListProtocol(String tlsProtocol)
{
Boolean b = __blackProtocols.get(tlsProtocol);
return b!=null && b.booleanValue();
return b != null && b;
}
public static boolean isBlackListCipher(String tlsCipher)
{
Boolean b = __blackCiphers.get(tlsCipher);
return b!=null && b.booleanValue();
return b != null && b;
}
/**
* Comparator to order non blacklisted ciphers before blacklisted ones.
* Comparator that orders non blacklisted ciphers before blacklisted ones.
*/
public static class CipherComparator implements Comparator<String>
{
@ -350,6 +351,6 @@ public class HTTP2Cipher
if (b1)
return 1;
return -1;
}
}
}
}

View File

@ -14,13 +14,13 @@
</New>
</Arg>
</Call>
<Ref refid="sslContextFactory">
<Set name="CipherComparator">
<New class="org.eclipse.jetty.http2.HTTP2Cipher$CipherComparator"/>
</Set>
<Get class="org.eclipse.jetty.http2.HTTP2Cipher" name="COMPARATOR"/>
</Set>
<Set name="useCipherSuitesOrder">true</Set>
</Ref>
</Configure>