Top Description Inners Fields Constructors Methods
org.eclipse.jetty.npn

public Class NextProtoNego

extends Object
Class Inheritance
Imports
java.util.List, .Map, java.util.concurrent.ConcurrentHashMap, javax.net.ssl.SSLEngine, .SSLSocket

NextProtoNego provides an API to applications that want to make use of the Next Protocol Negotiation.

The NPN extension is only available when using the TLS protocol, therefore applications must ensure that the TLS protocol is used:

SSLContext context = SSLContext.getInstance("TLSv1");

Refer to the list of standard SSLContext protocol names for further information on TLS protocol versions supported.

Applications must register instances of either SSLSocket or SSLEngine with a ClientProvider or with a ServerProvider, depending whether they are on client or server side.

The NPN implementation will invoke the provider callbacks to allow applications to interact with the negotiation of the next protocol.

Client side typical usage:

final SSLSocket sslSocket = ...;
NextProtoNego.put(sslSocket, new NextProtoNego.ClientProvider()
{
    @Override
    public boolean supports()
    {
        return true;
    }

    @Override
    public void unsupported()
    {
        NextProtoNego.remove(sslSocket);
    }

    @Override
    public String selectProtocol(List<String> protocols)
    {
        NextProtoNego.remove(sslSocket);
        return protocols.get(0);
    }
 });

Server side typical usage:

final SSLSocket sslSocket = ...;
NextProtoNego.put(sslSocket, new NextProtoNego.ServerProvider()
{
    @Override
    public void unsupported()
    {
        NextProtoNego.remove(sslSocket);
    }

    @Override
    public List<String> protocols()
    {
        return Arrays.asList("http/1.1");
    }

    @Override
    public void protocolSelected(String protocol)
    {
        NextProtoNego.remove(sslSocket);
        System.out.println("Protocol Selected is: " + protocol);
    }
 });

The implementation must make sure to remove the SSLSocket or SSLEngine instances when the NPN interaction is completed.

In order to help application development, you can set the NextProtoNego#debug field to true to have debug code printed to System#err.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
NextProtoNego.ClientProvider

The client-side provider interface that applications must implement to interact with the negotiation of the next protocol.

public static interface
NextProtoNego.Provider

Base, empty, interface for providers.

public static interface
NextProtoNego.ServerProvider

The server-side provider interface that applications must implement to interact with the negotiation of the next protocol.

Field Summary

Modifier and TypeField and Description
public static boolean
debug

Enables debug logging on System#err.

private static final Map<Object, NextProtoNego.Provider>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NextProtoNego.Provider

Returns:

the provider registered with the given socket
get
(SSLSocket
a socket registered with put(SSLSocket, Provider)
socket
)

public static NextProtoNego.Provider

Returns:

the provider registered with the given engine
get
(SSLEngine
an engine registered with put(SSLEngine, Provider)
engine
)

public static void
put(SSLSocket
the socket to register with the provider
socket
,
NextProtoNego.Provider
the provider to register with the socket
provider
)

Registers a SSLSocket with a provider.

public static void
put(SSLEngine
the engine to register with the provider
engine
,
NextProtoNego.Provider
the provider to register with the engine
provider
)

Registers a SSLEngine with a provider.

public static NextProtoNego.Provider

Returns:

the provider registered with the socket
remove
(SSLSocket
the socket to unregister
socket
)

Unregisters the given SSLSocket.

public static NextProtoNego.Provider

Returns:

the provider registered with the engine
remove
(SSLEngine
the engine to unregister
engine
)

Unregisters the given SSLEngine.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
public static boolean debug

Enables debug logging on System#err.

objectsback to summary
private static final Map<Object, NextProtoNego.Provider> objects

Constructor Detail

NextProtoNegoback to summary
private NextProtoNego()

Method Detail

getback to summary
public static NextProtoNego.Provider get(SSLSocket socket)
Parameters
socket:SSLSocket

a socket registered with put(SSLSocket, Provider)

Returns:NextProtoNego.Provider

the provider registered with the given socket

getback to summary
public static NextProtoNego.Provider get(SSLEngine engine)
Parameters
engine:SSLEngine

an engine registered with put(SSLEngine, Provider)

Returns:NextProtoNego.Provider

the provider registered with the given engine

putback to summary
public static void put(SSLSocket socket, NextProtoNego.Provider provider)

Registers a SSLSocket with a provider.

Parameters
socket:SSLSocket

the socket to register with the provider

provider:NextProtoNego.Provider

the provider to register with the socket

See Also
remove(SSLSocket)
putback to summary
public static void put(SSLEngine engine, NextProtoNego.Provider provider)

Registers a SSLEngine with a provider.

Parameters
engine:SSLEngine

the engine to register with the provider

provider:NextProtoNego.Provider

the provider to register with the engine

See Also
remove(SSLEngine)
removeback to summary
public static NextProtoNego.Provider remove(SSLSocket socket)

Unregisters the given SSLSocket.

Parameters
socket:SSLSocket

the socket to unregister

Returns:NextProtoNego.Provider

the provider registered with the socket

See Also
put(SSLSocket, Provider)
removeback to summary
public static NextProtoNego.Provider remove(SSLEngine engine)

Unregisters the given SSLEngine.

Parameters
engine:SSLEngine

the engine to unregister

Returns:NextProtoNego.Provider

the provider registered with the engine

See Also
put(SSLEngine, Provider)
org.eclipse.jetty.npn back to summary

public Interface NextProtoNego.ClientProvider

extends Provider

The client-side provider interface that applications must implement to interact with the negotiation of the next protocol.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the protocol selected by the application, or null to indicate to the server that it was not possible to negotiate a protocol
selectProtocol
(List<String>
the protocols sent by the server
protocols
)

Callback invoked to let the application select a protocol among the ones sent by the server.

public boolean

Returns:

true to add the NPN extension, false otherwise
supports
()

Callback invoked to let the implementation know whether an empty NPN extension should be added to a ClientHello SSL message.

public void
unsupported()

Callback invoked to let the application know that the server does not support NPN.

Method Detail

selectProtocolback to summary
public String selectProtocol(List<String> protocols)

Callback invoked to let the application select a protocol among the ones sent by the server.

The implementation may return null to indicate to the server that it was not possible to negotiate a protocol.

The implementation may throw an exception to indicate that the TLS handshake must be aborted.

Parameters
protocols:List<String>

the protocols sent by the server

Returns:String

the protocol selected by the application, or null to indicate to the server that it was not possible to negotiate a protocol

supportsback to summary
public boolean supports()

Callback invoked to let the implementation know whether an empty NPN extension should be added to a ClientHello SSL message.

Returns:boolean

true to add the NPN extension, false otherwise

unsupportedback to summary
public void unsupported()

Callback invoked to let the application know that the server does not support NPN.

org.eclipse.jetty.npn back to summary

public Interface NextProtoNego.Provider

Known Direct Subinterfaces
org.eclipse.jetty.npn.NextProtoNego.ClientProvider, org.eclipse.jetty.npn.NextProtoNego.ServerProvider

Base, empty, interface for providers.

org.eclipse.jetty.npn back to summary

public Interface NextProtoNego.ServerProvider

extends Provider

The server-side provider interface that applications must implement to interact with the negotiation of the next protocol.

Method Summary

Modifier and TypeMethod and Description
public List<String>

Returns:

the list of protocols, or null if no NPN extension should be sent to the client
protocols
()

Callback invoked to let the implementation know the list of protocols that should be added to an NPN extension in a ServerHello SSL message.

public void
protocolSelected(String
the selected protocol, or null if the client could not negotiate a protocol
protocol
)

Callback invoked to let the application know the protocol selected by the client.

public void
unsupported()

Callback invoked to let the application know that the client does not support NPN.

Method Detail

protocolsback to summary
public List<String> protocols()

Callback invoked to let the implementation know the list of protocols that should be added to an NPN extension in a ServerHello SSL message.

This callback is invoked only if the client sent a NPN extension.

Returns:List<String>

the list of protocols, or null if no NPN extension should be sent to the client

protocolSelectedback to summary
public void protocolSelected(String protocol)

Callback invoked to let the application know the protocol selected by the client.

The protocol selected may be null if the client could not negotiate a protocol.

The implementation may throw an exception to indicate that the TLS handshake must be aborted.

Parameters
protocol:String

the selected protocol, or null if the client could not negotiate a protocol

unsupportedback to summary
public void unsupported()

Callback invoked to let the application know that the client does not support NPN.