Package org.forgerock.opendj.io.rx
Class ProxyProtocolHeader
- java.lang.Object
-
- org.forgerock.opendj.io.rx.ProxyProtocolHeader
-
public final class ProxyProtocolHeader extends Object
This class defines the proxy protocol header as it is described in the proxy protocol documentation. If the proxy protocol is enabled on DS and the proxy ip address is allowed, this header will be parsed at the beginning of the LDAP connections to extract the original IP address and the SSL information, if present, of the proxied client application. Both versions of the proxy protocol (version 1 and version 2) are supported.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ProxyProtocolHeader.SslTlv
Exposes the content of the "pp2_tlv_ssl" structure present in thePP2_TYPE_SSL
TLV header.
-
Field Summary
Fields Modifier and Type Field Description static Byte
PP2_TYPE_ALPN
Application-Layer Protocol Negotiation (ALPN).static Byte
PP2_TYPE_AUTHORITY
Contains the host name value passed by the client, as an UTF8-encoded string.static Byte
PP2_TYPE_CRC32C
The value of the type PP2_TYPE_CRC32C is a 32-bit number storing the CRC32c checksum of the PROXY protocol header.static Byte
PP2_TYPE_NETNS
The type PP2_TYPE_NETNS defines the value as the US-ASCII string representation of the namespace's name.static Byte
PP2_TYPE_NOOP
The TLV of this type should be ignored when parsed.static Byte
PP2_TYPE_SSL
Type of the SSL TLV.static Byte
PP2_TYPE_UNIQUE_ID
The value of the type PP2_TYPE_UNIQUE_ID is an opaque byte sequence of up to 128 bytes generated by the upstream proxy that uniquely identifies the connection.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
InetSocketAddress
getDestinationAddress()
Returns the proxy's address.String
getProtocol()
Returns the transport protocol used by the client to communicate with the proxy.InetSocketAddress
getSourceAddress()
Returns the proxied client's address.String
getSslCipher()
Returns the SSL cipher used by the proxied client ornull
if the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.ProxyProtocolHeader.SslTlv
getSslTlv()
Returns the information about the SSL protocol that the client might be using on the connection.String
getSslVersion()
Returns the SSL version used by the proxied client ornull
if the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.Map<Byte,ByteString>
getTlvs()
Returns Additional information contained in the header as part of the Type-Length-Value.int
getVersion()
Returns the version of theheader
.int
hashCode()
boolean
isLocalCommnand()
Returns whether this proxy header represents aLOCAL
command.boolean
isSsl()
Returnstrue
if the proxied client uses SSL.static ProxyProtocolHeader
newLocalProxyProtocolHeader(int version)
Returns a new proxy protocol header with a local command.static ProxyProtocolHeader
newProxyProtocolHeader(int version, InetSocketAddress clientAddress, InetSocketAddress proxyAddress)
Returns a new proxy protocol header with a proxy command: the connection is relayed on behalf of a client.static ProxyProtocolHeader
newProxyProtocolHeader(int version, InetSocketAddress clientAddress, InetSocketAddress proxyAddress, ProxyProtocolHeader.SslTlv sslTlv)
Returns a new proxy protocol header with a proxy command: the connection is relayed on behalf of a client.
-
-
-
Field Detail
-
PP2_TYPE_ALPN
public static final Byte PP2_TYPE_ALPN
Application-Layer Protocol Negotiation (ALPN). It is a byte sequence defining the upper layer protocol in use over the connection. The most common use case will be to pass the exact copy of the ALPN extension of the Transport Layer Security (TLS) protocol as defined by RFC7301.
-
PP2_TYPE_AUTHORITY
public static final Byte PP2_TYPE_AUTHORITY
Contains the host name value passed by the client, as an UTF8-encoded string. In case of TLS being used on the client connection, this is the exact copy of the "server_name" extension as defined by RFC3546 [10], section 3.1, often referred to as "SNI". There are probably other situations where an authority can be mentioned on a connection without TLS being involved at all.
-
PP2_TYPE_CRC32C
public static final Byte PP2_TYPE_CRC32C
The value of the type PP2_TYPE_CRC32C is a 32-bit number storing the CRC32c checksum of the PROXY protocol header.
-
PP2_TYPE_NOOP
public static final Byte PP2_TYPE_NOOP
The TLV of this type should be ignored when parsed. The value is zero or more bytes. Can be used for data padding or alignment. Note that it can be used to align only by 3 or more bytes because a TLV can not be smaller than that.
-
PP2_TYPE_UNIQUE_ID
public static final Byte PP2_TYPE_UNIQUE_ID
The value of the type PP2_TYPE_UNIQUE_ID is an opaque byte sequence of up to 128 bytes generated by the upstream proxy that uniquely identifies the connection.
-
PP2_TYPE_SSL
public static final Byte PP2_TYPE_SSL
Type of the SSL TLV.
-
PP2_TYPE_NETNS
public static final Byte PP2_TYPE_NETNS
The type PP2_TYPE_NETNS defines the value as the US-ASCII string representation of the namespace's name.
-
-
Method Detail
-
newLocalProxyProtocolHeader
public static ProxyProtocolHeader newLocalProxyProtocolHeader(int version)
Returns a new proxy protocol header with a local command.- Parameters:
version
- the proxy protocol version. Valid values are 1 and 2.- Returns:
- a new proxy protocol header with a local command.
- Throws:
IllegalArgumentException
- if the version in invalid.
-
newProxyProtocolHeader
public static ProxyProtocolHeader newProxyProtocolHeader(int version, InetSocketAddress clientAddress, InetSocketAddress proxyAddress) throws IllegalArgumentException
Returns a new proxy protocol header with a proxy command: the connection is relayed on behalf of a client.- Parameters:
version
- the proxy protocol version. Valid values are 1 and 2.clientAddress
- the effective client address (source address) ornull
if the address is not anInetSocketAddress
.proxyAddress
- the proxy address (destination address) ornull
if the address is not anInetSocketAddress
.- Returns:
- a new proxy protocol header with a proxy command.
- Throws:
IllegalArgumentException
- if the version in invalid.
-
newProxyProtocolHeader
public static ProxyProtocolHeader newProxyProtocolHeader(int version, InetSocketAddress clientAddress, InetSocketAddress proxyAddress, ProxyProtocolHeader.SslTlv sslTlv) throws IllegalArgumentException
Returns a new proxy protocol header with a proxy command: the connection is relayed on behalf of a client.- Parameters:
version
- the proxy protocol version. Valid values are 1 and 2.clientAddress
- the effective client address (source address) ornull
if the address is not anInetSocketAddress
.proxyAddress
- the proxy address (destination address) ornull
if the address is not anInetSocketAddress
.sslTlv
- information describing if and how the client connected using SSL.- Returns:
- a new proxy protocol header with a proxy command.
- Throws:
IllegalArgumentException
- if the version is invalid.
-
getVersion
public int getVersion()
Returns the version of theheader
.- Returns:
- The version (
1
or2
).
-
isLocalCommnand
public boolean isLocalCommnand()
Returns whether this proxy header represents aLOCAL
command. Effectively, a connection established directly on the behalf of the proxy.- Returns:
true
if the connection has been established on the behalf of the proxy.false
if the connection has been established on the behalf of a client.
-
getProtocol
public String getProtocol()
Returns the transport protocol used by the client to communicate with the proxy.- Returns:
- The transport protocol (
TCP4
,TCP6
orUNKNKOWN
)
-
getSourceAddress
public InetSocketAddress getSourceAddress()
Returns the proxied client's address.- Returns:
- the proxied client's address.
-
getDestinationAddress
public InetSocketAddress getDestinationAddress()
Returns the proxy's address.- Returns:
- the proxy's address.
-
getTlvs
public Map<Byte,ByteString> getTlvs()
Returns Additional information contained in the header as part of the Type-Length-Value.- Returns:
- The TLVs.
-
getSslTlv
public ProxyProtocolHeader.SslTlv getSslTlv()
Returns the information about the SSL protocol that the client might be using on the connection.- Returns:
- The SSL information.
-
getSslCipher
public String getSslCipher()
Returns the SSL cipher used by the proxied client ornull
if the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.- Returns:
- the SSL cipher used by the proxied client or
null
if the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.
-
getSslVersion
public String getSslVersion()
Returns the SSL version used by the proxied client ornull
if the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.- Returns:
- the SSL version used by the proxied client or
null
if the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.
-
isSsl
public boolean isSsl()
Returnstrue
if the proxied client uses SSL. Alwaysfalse
for proxy protocol V1 as it does not contain SSL information.- Returns:
true
if the proxied client uses SSL. Alwaysfalse
for proxy protocol V1 as it does not contain SSL information.
-
-