io.undertow.protocols.ssl.UndertowXnioSsl Java Examples

The following examples show how to use io.undertow.protocols.ssl.UndertowXnioSsl. 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: ManagementHttpServer.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void start() {
    try {

        OptionMap.Builder serverOptionsBuilder = OptionMap.builder()
                .set(Options.TCP_NODELAY, true)
                .set(Options.REUSE_ADDRESSES, true);
        ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
        if (httpAddress != null) {
            normalServer = worker.createStreamConnectionServer(httpAddress, acceptListener, serverOptionsBuilder.getMap());
            normalServer.resumeAccepts();
        }
        if (secureAddress != null) {
            if (sslClientAuthMode != null) {
                serverOptionsBuilder.set(SSL_CLIENT_AUTH_MODE, sslClientAuthMode);
            }
            OptionMap secureOptions = serverOptionsBuilder.getMap();
            XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), secureOptions, sslContext);
            secureServer = xnioSsl.createSslConnectionServer(worker, secureAddress, acceptListener, secureOptions);
            secureServer.resumeAccepts();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: Undertow.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public ListenerInfo(String protcol, SocketAddress address, OpenListener openListener, UndertowXnioSsl ssl, AcceptingChannel<? extends StreamConnection> channel) {
    this.protcol = protcol;
    this.address = address;
    this.openListener = openListener;
    this.ssl = ssl;
    this.channel = channel;
}
 
Example #3
Source File: ProxyProtocolReadListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
ProxyProtocolReadListener(StreamConnection streamConnection, OpenListener openListener, UndertowXnioSsl ssl, ByteBufferPool bufferPool, OptionMap sslOptionMap) {
    this.streamConnection = streamConnection;
    this.openListener = openListener;
    this.ssl = ssl;
    this.bufferPool = bufferPool;
    this.sslOptionMap = sslOptionMap;
    if (bufferPool.getBufferSize() < MAX_HEADER_LENGTH) {
        throw UndertowMessages.MESSAGES.bufferPoolTooSmall(MAX_HEADER_LENGTH);
    }
}
 
Example #4
Source File: Http2ClientTest.java    From light-4j with Apache License 2.0 5 votes vote down vote up
@Test
public void server_identity_check_positive_case() throws Exception{
	final Http2Client client = createClient();
    SSLContext context = Http2Client.createSSLContext("trustedNames.local");
    XnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, Http2Client.BUFFER_POOL, context);

    final ClientConnection connection = client.connect(new URI("https://localhost:7778"), worker, ssl, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    
    assertTrue(connection.isOpen());
    
    IoUtils.safeClose(connection);
}
 
Example #5
Source File: Http2ClientTest.java    From light-4j with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test(expected=ClosedChannelException.class)
public void server_identity_check_negative_case() throws Exception{
	final Http2Client client = createClient();
    SSLContext context = Http2Client.createSSLContext("trustedNames.negativeTest");
    XnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, Http2Client.BUFFER_POOL, context);

    final ClientConnection connection = client.connect(new URI("https://localhost:7778"), worker, ssl, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    //should not be reached
    //assertFalse(connection.isOpen());
    fail();
}
 
Example #6
Source File: Http2ClientTest.java    From light-4j with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test(expected=ClosedChannelException.class)
public void standard_https_hostname_check_kicks_in_if_trustednames_are_empty() throws Exception{
	final Http2Client client = createClient();
    SSLContext context = Http2Client.createSSLContext("trustedNames.empty");
    XnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, Http2Client.BUFFER_POOL, context);

    final ClientConnection connection = client.connect(new URI("https://127.0.0.1:7778"), worker, ssl, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    //should not be reached
    //assertFalse(connection.isOpen());
    fail();
}
 
Example #7
Source File: Http2ClientTest.java    From light-4j with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test(expected=ClosedChannelException.class)
public void standard_https_hostname_check_kicks_in_if_trustednames_are_not_used_or_not_provided() throws Exception{
	final Http2Client client = createClient();
    SSLContext context = Http2Client.createSSLContext(null);
    XnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, Http2Client.BUFFER_POOL, context);

    final ClientConnection connection = client.connect(new URI("https://127.0.0.1:7778"), worker, ssl, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    //should not be reached
    //assertFalse(connection.isOpen());
    fail();
}
 
Example #8
Source File: Http2ClientTest.java    From light-4j with Apache License 2.0 5 votes vote down vote up
@Test
public void invalid_hostname_is_accepted_if_verifyhostname_is_disabled() throws Exception{
	final Http2Client client = createClient();
	SSLContext context = createTestSSLContext(false, null);
	
    XnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, Http2Client.BUFFER_POOL, context);

    final ClientConnection connection = client.connect(new URI("https://127.0.0.1:7778"), worker, ssl, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    
    assertTrue(connection.isOpen());
    IoUtils.safeClose(connection);  	
}
 
Example #9
Source File: TokenAuthenticator.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
private ConnectionFactory(URI kubernetesMasterUri) {
    this.kubernetesMasterUri = kubernetesMasterUri;
    undertowClient = UndertowClient.getInstance();
    Xnio xnio = Xnio.getInstance(Undertow.class.getClassLoader());
    try {
        ssl = new UndertowXnioSsl(xnio, OptionMap.EMPTY);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    byteBufferPool = createByteBufferPool();
}
 
Example #10
Source File: SNICombinedWithALPNTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private XnioSsl createClientSSL(File hostNameKeystore) throws NoSuchAlgorithmException, KeyStoreException, IOException, CertificateException, UnrecoverableKeyException, KeyManagementException {
    SSLContext clientContext = SSLContext.getInstance("TLS");
    KeyStore store = KeyStore.getInstance("jks");
    try (FileInputStream in = new FileInputStream(hostNameKeystore)) {
        store.load(in, PASSWORD.toCharArray());
    }

    KeyManagerFactory km = KeyManagerFactory.getInstance(keyAlgorithm());
    km.init(store, PASSWORD.toCharArray());
    TrustManagerFactory tm = TrustManagerFactory.getInstance(keyAlgorithm());
    tm.init(store);
    clientContext.init(km.getKeyManagers(), tm.getTrustManagers(), new SecureRandom());
    return new UndertowXnioSsl(Xnio.getInstance(), OptionMap.EMPTY, clientContext);
}
 
Example #11
Source File: ProxyProtocolOpenListener.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ProxyProtocolOpenListener(OpenListener openListener, UndertowXnioSsl ssl, ByteBufferPool bufferPool, OptionMap sslOptionMap) {
    this.openListener = openListener;
    this.ssl = ssl;
    this.bufferPool = bufferPool;
    this.sslOptionMap = sslOptionMap;
}
 
Example #12
Source File: Http2Client.java    From light-4j with Apache License 2.0 2 votes vote down vote up
/**
 * Create an XnioSsl object with the given sslContext. This is used to create the normal client context
 * and the light-config-server bootstrap context separately. the XnioSsl object can be used to create
 * an Https connection to the downstream services.
 *
 * @param sslContext SslContext
 * @return XnioSsl
 */
public XnioSsl createXnioSsl(SSLContext sslContext) {
    return new UndertowXnioSsl(WORKER.getXnio(), OptionMap.EMPTY, BUFFER_POOL, sslContext);
}