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 classProxyProtocolHeader.SslTlvExposes the content of the "pp2_tlv_ssl" structure present in thePP2_TYPE_SSLTLV header.
-
Field Summary
Fields Modifier and Type Field Description static BytePP2_TYPE_ALPNApplication-Layer Protocol Negotiation (ALPN).static BytePP2_TYPE_AUTHORITYContains the host name value passed by the client, as an UTF8-encoded string.static BytePP2_TYPE_CRC32CThe value of the type PP2_TYPE_CRC32C is a 32-bit number storing the CRC32c checksum of the PROXY protocol header.static BytePP2_TYPE_NETNSThe type PP2_TYPE_NETNS defines the value as the US-ASCII string representation of the namespace's name.static BytePP2_TYPE_NOOPThe TLV of this type should be ignored when parsed.static BytePP2_TYPE_SSLType of the SSL TLV.static BytePP2_TYPE_UNIQUE_IDThe 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 booleanequals(Object o)InetSocketAddressgetDestinationAddress()Returns the proxy's address.StringgetProtocol()Returns the transport protocol used by the client to communicate with the proxy.InetSocketAddressgetSourceAddress()Returns the proxied client's address.StringgetSslCipher()Returns the SSL cipher used by the proxied client ornullif the proxied client did not use a secure connection or in case of proxy protocol V1 as it does not contain SSL information.ProxyProtocolHeader.SslTlvgetSslTlv()Returns the information about the SSL protocol that the client might be using on the connection.StringgetSslVersion()Returns the SSL version used by the proxied client ornullif 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.intgetVersion()Returns the version of theheader.inthashCode()booleanisLocalCommnand()Returns whether this proxy header represents aLOCALcommand.booleanisSsl()Returnstrueif the proxied client uses SSL.static ProxyProtocolHeadernewLocalProxyProtocolHeader(int version)Returns a new proxy protocol header with a local command.static ProxyProtocolHeadernewProxyProtocolHeader(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 ProxyProtocolHeadernewProxyProtocolHeader(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) ornullif the address is not anInetSocketAddress.proxyAddress- the proxy address (destination address) ornullif 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) ornullif the address is not anInetSocketAddress.proxyAddress- the proxy address (destination address) ornullif 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 (
1or2).
-
isLocalCommnand
public boolean isLocalCommnand()
Returns whether this proxy header represents aLOCALcommand. Effectively, a connection established directly on the behalf of the proxy.- Returns:
trueif the connection has been established on the behalf of the proxy.falseif 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,TCP6orUNKNKOWN)
-
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 ornullif 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
nullif 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 ornullif 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
nullif 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()
Returnstrueif the proxied client uses SSL. Alwaysfalsefor proxy protocol V1 as it does not contain SSL information.- Returns:
trueif the proxied client uses SSL. Alwaysfalsefor proxy protocol V1 as it does not contain SSL information.
-
-