org.xnio.ssl.SslConnection Java Examples

The following examples show how to use org.xnio.ssl.SslConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UndertowAcceptingSslChannel.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
UndertowAcceptingSslChannel(final UndertowXnioSsl ssl, final AcceptingChannel<? extends StreamConnection> tcpServer, final OptionMap optionMap, final ByteBufferPool applicationBufferPool, final boolean startTls) {
    this.tcpServer = tcpServer;
    this.ssl = ssl;
    this.applicationBufferPool = applicationBufferPool;
    this.startTls = startTls;
    clientAuthMode = optionMap.get(Options.SSL_CLIENT_AUTH_MODE);
    useClientMode = optionMap.get(Options.SSL_USE_CLIENT_MODE, false) ? 1 : 0;
    enableSessionCreation = optionMap.get(Options.SSL_ENABLE_SESSION_CREATION, true) ? 1 : 0;
    final Sequence<String> enabledCipherSuites = optionMap.get(Options.SSL_ENABLED_CIPHER_SUITES);
    cipherSuites = enabledCipherSuites != null ? enabledCipherSuites.toArray(new String[enabledCipherSuites.size()]) : null;
    final Sequence<String> enabledProtocols = optionMap.get(Options.SSL_ENABLED_PROTOCOLS);
    protocols = enabledProtocols != null ? enabledProtocols.toArray(new String[enabledProtocols.size()]) : null;
    //noinspection ThisEscapedInObjectConstruction
    closeSetter = ChannelListeners.<AcceptingChannel<SslConnection>>getDelegatingSetter(tcpServer.getCloseSetter(), this);
    //noinspection ThisEscapedInObjectConstruction
    acceptSetter = ChannelListeners.<AcceptingChannel<SslConnection>>getDelegatingSetter(tcpServer.getAcceptSetter(), this);
    useCipherSuitesOrder = optionMap.get(UndertowOptions.SSL_USER_CIPHER_SUITES_ORDER, false);
}
 
Example #2
Source File: ProxyProtocolReadListener.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void proxyAccept(SocketAddress source, SocketAddress dest, PooledByteBuffer additionalData) {
    StreamConnection streamConnection = this.streamConnection;
    if (source != null) {
        streamConnection = new AddressWrappedConnection(streamConnection, source, dest);
    }
    if (ssl != null) {

        //we need to apply the additional data before the SSL wrapping
        if (additionalData != null) {
            PushBackStreamSourceConduit conduit = new PushBackStreamSourceConduit(streamConnection.getSourceChannel().getConduit());
            conduit.pushBack(new PooledAdaptor(additionalData));
            streamConnection.getSourceChannel().setConduit(conduit);
        }
        SslConnection sslConnection = ssl.wrapExistingConnection(streamConnection, sslOptionMap == null ? OptionMap.EMPTY : sslOptionMap, false);
        streamConnection = sslConnection;

        callOpenListener(streamConnection, null);
    } else {
        callOpenListener(streamConnection, additionalData);
    }
}
 
Example #3
Source File: HttpClientConnection.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void sendRequest(final ClientRequest request, final ClientCallback<ClientExchange> clientCallback) {
    if(http2Delegate != null) {
        http2Delegate.sendRequest(request, clientCallback);
        return;
    }
    if (anyAreSet(state, UPGRADE_REQUESTED | UPGRADED | CLOSE_REQ | CLOSED)) {
        clientCallback.failed(UndertowClientMessages.MESSAGES.invalidConnectionState());
        return;
    }
    final HttpClientExchange httpClientExchange = new HttpClientExchange(clientCallback, request, this);
    boolean ssl = this.connection instanceof SslConnection;
    if(!ssl && !http2Tried && options.get(UndertowOptions.ENABLE_HTTP2, false) && !request.getRequestHeaders().contains(Headers.UPGRADE)) {
        //this is the first request, as we want to try a HTTP2 upgrade
        request.getRequestHeaders().put(new HttpString("HTTP2-Settings"), Http2ClearClientProvider.createSettingsFrame(options, bufferPool));
        request.getRequestHeaders().put(Headers.UPGRADE, Http2Channel.CLEARTEXT_UPGRADE_STRING);
        request.getRequestHeaders().put(Headers.CONNECTION, "Upgrade, HTTP2-Settings");
        http2Tried = true;
    }

    if (currentRequest == null) {
        initiateRequest(httpClientExchange);
    } else {
        pendingQueue.add(httpClientExchange);
    }
}
 
Example #4
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void handleEvent(final StreamConnection connection) {
    try {

        SSLEngine sslEngine = JsseSslUtils.createSSLEngine(sslContext, optionMap, destination);
        SSLParameters params = sslEngine.getSSLParameters();
        params.setServerNames(Collections.singletonList(new SNIHostName(destination.getHostString())));
        sslEngine.setSSLParameters(params);

        final SslConnection wrappedConnection = new UndertowSslConnection(connection, sslEngine, bufferPool);
        if (!futureResult.setResult(wrappedConnection)) {
            IoUtils.safeClose(connection);
        } else {
            ChannelListeners.invokeChannelListener(wrappedConnection, openListener);
        }
    } catch (Throwable e) {
        futureResult.setException(new IOException(e));
    }
}
 
Example #5
Source File: Http2Channel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public SSLSession getSslSession() {
    StreamConnection con = getUnderlyingConnection();
    if (con instanceof SslConnection) {
        return ((SslConnection) con).getSslSession();
    }
    return null;
}
 
Example #6
Source File: Light4jHttp2ClientProvider.java    From light-4j with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated will be change to protected in future TODO: not sure if this should be public
 * @param listener {@link ClientCallback}
 * @param uri URI
 * @param bufferPool ByteBufferPool
 * @param options OptionMap
 * @return ALPNClientSelector.ALPNProtocol
 */
@Deprecated
public static ALPNClientSelector.ALPNProtocol alpnProtocol(final ClientCallback<ClientConnection> listener, URI uri, ByteBufferPool bufferPool, OptionMap options) {
    return new ALPNClientSelector.ALPNProtocol(new ChannelListener<SslConnection>() {
        @Override
        public void handleEvent(SslConnection connection) {
            listener.completed(createHttp2Channel(connection, bufferPool, options, uri.getHost()));
        }
    }, HTTP2);
}
 
Example #7
Source File: Http2ClientProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static ALPNClientSelector.ALPNProtocol alpnProtocol(final ClientCallback<ClientConnection> listener, URI uri, ByteBufferPool bufferPool, OptionMap options) {
    return new ALPNClientSelector.ALPNProtocol(new ChannelListener<SslConnection>() {
        @Override
        public void handleEvent(SslConnection connection) {
            listener.completed(createHttp2Channel(connection, bufferPool, options, uri.getHost()));
        }
    }, HTTP2);
}
 
Example #8
Source File: UndertowSslConnection.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    final ChannelListener<? super SslConnection> listener = handshakeSetter.get();
    if (listener == null) {
        return;
    }
    ChannelListeners.<SslConnection>invokeChannelListener(UndertowSslConnection.this, listener);
}
 
Example #9
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the SSL engine for a given connection.
 *
 * @return the SSL engine
 */
public static SSLEngine getSslEngine(SslConnection connection) {
    if (connection instanceof UndertowSslConnection) {
        return ((UndertowSslConnection) connection).getSSLEngine();
    } else {
        return JsseXnioSsl.getSslEngine(connection);
    }
}
 
Example #10
Source File: ALPNClientSelector.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ChannelListener<SslConnection> getSelected() {
    return selected;
}
 
Example #11
Source File: Light4jHttp2ClientProvider.java    From light-4j with Apache License 2.0 4 votes vote down vote up
protected void handleConnected(StreamConnection connection, final ClientCallback<ClientConnection> listener, URI uri,ByteBufferPool bufferPool, OptionMap options) {
	Light4jALPNClientSelector.runAlpn((SslConnection) connection, FAILED, listener, alpnProtocol(listener, uri, bufferPool, options));
}
 
Example #12
Source File: UndertowLogger.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@LogMessage(level = ERROR)
@Message(id = 5079, value = "ALPN negotiation on %s failed")
void alpnConnectionFailed(SslConnection connection);
 
Example #13
Source File: Light4jHttp2ClientProvider.java    From light-4j with Apache License 2.0 4 votes vote down vote up
@Override
public void handleEvent(SslConnection connection) {
    UndertowLogger.ROOT_LOGGER.alpnConnectionFailed(connection);
    IoUtils.safeClose(connection);
}
 
Example #14
Source File: UndertowAcceptingSslChannel.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ChannelListener.Setter<? extends AcceptingChannel<SslConnection>> getCloseSetter() {
    return closeSetter;
}
 
Example #15
Source File: UndertowAcceptingSslChannel.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ChannelListener.Setter<? extends AcceptingChannel<SslConnection>> getAcceptSetter() {
    return acceptSetter;
}
 
Example #16
Source File: Http2ClientProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void handleConnected(StreamConnection connection, final ClientCallback<ClientConnection> listener, URI uri,ByteBufferPool bufferPool, OptionMap options) {
    ALPNClientSelector.runAlpn((SslConnection) connection, FAILED, listener, alpnProtocol(listener, uri, bufferPool, options));
}
 
Example #17
Source File: Http2ClientProvider.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void handleEvent(SslConnection connection) {
    UndertowLogger.ROOT_LOGGER.alpnConnectionFailed(connection);
    IoUtils.safeClose(connection);
}
 
Example #18
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public IoFuture<SslConnection> openSslConnection(final XnioIoThread ioThread, final InetSocketAddress bindAddress, final InetSocketAddress destination, final ChannelListener<? super SslConnection> openListener, final ChannelListener<? super BoundChannel> bindListener, final OptionMap optionMap) {
    final FutureResult<SslConnection> futureResult = new FutureResult<>(ioThread);
    final IoFuture<StreamConnection> connection = ioThread.openStreamConnection(bindAddress, destination, new StreamConnectionChannelListener(optionMap, destination, futureResult, openListener), bindListener, optionMap);
    return setupSslConnection(futureResult, connection);
}
 
Example #19
Source File: ALPNClientSelector.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ALPNProtocol(ChannelListener<SslConnection> selected, String protocol) {
    this.selected = selected;
    this.protocol = protocol;
}
 
Example #20
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static SslConduit getSslConduit(SslConnection connection) {
    return ((UndertowSslConnection) connection).getSslConduit();
}
 
Example #21
Source File: UndertowSslConnection.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ChannelListener.Setter<? extends SslConnection> getHandshakeSetter() {
    return handshakeSetter;
}
 
Example #22
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public IoFuture<SslConnection> openSslConnection(final XnioWorker worker, final InetSocketAddress bindAddress, final InetSocketAddress destination, final ChannelListener<? super SslConnection> openListener, final ChannelListener<? super BoundChannel> bindListener, final OptionMap optionMap) {
    final FutureResult<SslConnection> futureResult = new FutureResult<>(worker);
    final IoFuture<StreamConnection> connection = worker.openStreamConnection(bindAddress, destination, new StreamConnectionChannelListener(optionMap, destination, futureResult, openListener), bindListener, optionMap);
    return setupSslConnection(futureResult, connection);
}
 
Example #23
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
StreamConnectionChannelListener(OptionMap optionMap, InetSocketAddress destination, FutureResult<SslConnection> futureResult, ChannelListener<? super SslConnection> openListener) {
    this.optionMap = optionMap;
    this.destination = destination;
    this.futureResult = futureResult;
    this.openListener = openListener;
}
 
Example #24
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public AcceptingChannel<SslConnection> createSslConnectionServer(final XnioWorker worker, final InetSocketAddress bindAddress, final ChannelListener<? super AcceptingChannel<SslConnection>> acceptListener, final OptionMap optionMap) throws IOException {
    final UndertowAcceptingSslChannel server = new UndertowAcceptingSslChannel(this, worker.createStreamConnectionServer(bindAddress,  null,  optionMap), optionMap, bufferPool, false);
    if (acceptListener != null) server.getAcceptSetter().set(acceptListener);
    return server;
}
 
Example #25
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public SslConnection wrapExistingConnection(StreamConnection connection, OptionMap optionMap, boolean clientMode) {
    return new UndertowSslConnection(connection, createSSLEngine(sslContext, optionMap, (InetSocketAddress) connection.getPeerAddress(), clientMode), bufferPool);
}
 
Example #26
Source File: UndertowXnioSsl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public SslConnection wrapExistingConnection(StreamConnection connection, OptionMap optionMap) {
    return new UndertowSslConnection(connection, createSSLEngine(sslContext, optionMap, (InetSocketAddress) connection.getPeerAddress(), true), bufferPool);
}