]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/server/SslConnectionFactory.java
Merge "Update notes about password security"
[gigi.git] / lib / jetty / org / eclipse / jetty / server / SslConnectionFactory.java
1 //
2 //  ========================================================================
3 //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4 //  ------------------------------------------------------------------------
5 //  All rights reserved. This program and the accompanying materials
6 //  are made available under the terms of the Eclipse Public License v1.0
7 //  and Apache License v2.0 which accompanies this distribution.
8 //
9 //      The Eclipse Public License is available at
10 //      http://www.eclipse.org/legal/epl-v10.html
11 //
12 //      The Apache License v2.0 is available at
13 //      http://www.opensource.org/licenses/apache2.0.php
14 //
15 //  You may elect to redistribute this code under either of these licenses.
16 //  ========================================================================
17 //
18
19
20 package org.eclipse.jetty.server;
21
22
23 import javax.net.ssl.SSLEngine;
24 import javax.net.ssl.SSLSession;
25
26 import org.eclipse.jetty.http.HttpVersion;
27 import org.eclipse.jetty.io.Connection;
28 import org.eclipse.jetty.io.EndPoint;
29 import org.eclipse.jetty.io.ssl.SslConnection;
30 import org.eclipse.jetty.io.ssl.SslReconfigurator;
31 import org.eclipse.jetty.util.annotation.Name;
32 import org.eclipse.jetty.util.ssl.SslContextFactory;
33
34 public class SslConnectionFactory extends AbstractConnectionFactory implements SslReconfigurator
35 {
36     private final SslContextFactory _sslContextFactory;
37     private final String _nextProtocol;
38
39     public SslConnectionFactory()
40     {
41         this(HttpVersion.HTTP_1_1.asString());
42     }
43
44     public SslConnectionFactory(@Name("next") String nextProtocol)
45     {
46         this(null,nextProtocol);
47     }
48
49     public SslConnectionFactory(@Name("sslContextFactory") SslContextFactory factory, @Name("next") String nextProtocol)
50     {
51         super("SSL-"+nextProtocol);
52         _sslContextFactory=factory==null?new SslContextFactory():factory;
53         _nextProtocol=nextProtocol;
54         addBean(_sslContextFactory);
55     }
56
57     public SslContextFactory getSslContextFactory()
58     {
59         return _sslContextFactory;
60     }
61
62     @Override
63     protected void doStart() throws Exception
64     {
65         super.doStart();
66
67         SSLEngine engine = _sslContextFactory.newSSLEngine();
68         engine.setUseClientMode(false);
69         SSLSession session=engine.getSession();
70
71         if (session.getPacketBufferSize()>getInputBufferSize())
72             setInputBufferSize(session.getPacketBufferSize());
73     }
74
75     @Override
76     public Connection newConnection(Connector connector, EndPoint endPoint)
77     {
78         SSLEngine engine = _sslContextFactory.newSSLEngine(endPoint.getRemoteAddress());
79         engine.setUseClientMode(false);
80
81         SslConnection sslConnection = newSslConnection(connector, endPoint, engine);
82         sslConnection.setRenegotiationAllowed(_sslContextFactory.isRenegotiationAllowed());
83         configure(sslConnection, connector, endPoint);
84
85         ConnectionFactory next = connector.getConnectionFactory(_nextProtocol);
86         EndPoint decryptedEndPoint = sslConnection.getDecryptedEndPoint();
87         Connection connection = next.newConnection(connector, decryptedEndPoint);
88         decryptedEndPoint.setConnection(connection);
89
90         return sslConnection;
91     }
92
93     protected SslConnection newSslConnection(Connector connector, EndPoint endPoint, SSLEngine engine)
94     {
95         return new SslConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, engine, shouldRestartSSL()?this:null);
96     }
97     
98     public boolean shouldRestartSSL(){
99         return false;
100     }
101     
102     public SSLEngine restartSSL(SSLSession sslSession){
103         throw new UnsupportedOperationException();
104     }
105
106     @Override
107     public String toString()
108     {
109         return String.format("%s@%x{%s}",this.getClass().getSimpleName(),hashCode(),getProtocol());
110     }
111 }