Package org.microproxy.tcp
Interface TcpContext
public interface TcpContext
One raw TCP tunnel, as a
TcpInterceptor sees it: where it goes, whether the proxy
decrypted it, and a way to add bytes. The same context is given to every hook call of the
tunnel, so it can serve as a key for per-tunnel state.-
Method Summary
Modifier and TypeMethodDescriptionalpn()The ALPN protocol negotiated with the client, when the proxy terminated its TLS (imap,mqtt, ...).The client's address (the PROXY protocol's source, when the listener accepts it).longThe client connection the tunnel belongs to (FlowContext.getConnectionId()).The exchange that opened the tunnel (itsCONNECT), or the client connection's flow.host()The host the tunnel goes to: theCONNECTtarget's, the SNI's on a transparent listener, or the upstream's inreverse:tcp://mode.intport()The port the tunnel goes to.voidsend(boolean fromClient, byte[] data) Adds bytes to the tunnel, as if one side had sent them: withfromClientthey go to the server, else to the client.sni()The server name the client asked for in its TLS ClientHello, when the proxy read one (it may have, and still tunnel the TLS untouched).booleanWhether the proxy terminated the client's TLS, so the hooks see decrypted bytes: an intercepted session that does not carry HTTP, or a TLS listener inreverse:tcp://mode.
-
Method Details
-
connectionId
long connectionId()The client connection the tunnel belongs to (FlowContext.getConnectionId()).- Returns:
- the client connection's id
-
clientAddress
InetSocketAddress clientAddress()The client's address (the PROXY protocol's source, when the listener accepts it).- Returns:
- the client address
-
host
String host()The host the tunnel goes to: theCONNECTtarget's, the SNI's on a transparent listener, or the upstream's inreverse:tcp://mode.- Returns:
- the target host name or IP address (IPv6 without brackets)
-
port
int port()The port the tunnel goes to.- Returns:
- the target port
-
tlsIntercepted
boolean tlsIntercepted()Whether the proxy terminated the client's TLS, so the hooks see decrypted bytes: an intercepted session that does not carry HTTP, or a TLS listener inreverse:tcp://mode. False for a tunnel whose bytes are passed on as the client sent them, encrypted or not.- Returns:
- whether the bytes are decrypted
-
sni
String sni()The server name the client asked for in its TLS ClientHello, when the proxy read one (it may have, and still tunnel the TLS untouched).- Returns:
- the SNI, or null
-
alpn
String alpn()The ALPN protocol negotiated with the client, when the proxy terminated its TLS (imap,mqtt, ...).- Returns:
- the protocol, or null for none
-
flowContext
FlowContext flowContext()The exchange that opened the tunnel (itsCONNECT), or the client connection's flow.- Returns:
- the flow context
-
send
void send(boolean fromClient, byte[] data) Adds bytes to the tunnel, as if one side had sent them: withfromClientthey go to the server, else to the client. They do not pass throughTcpInterceptor.tcpMessage(org.microproxy.tcp.TcpMessage, org.microproxy.tcp.TcpContext). Called from atcpMessagehook of the same direction, they follow that message (or what replaced it); otherwise, from any hook or any thread while that direction is open, they are written at once, between messages. A write that fails ends the tunnel, reported toTcpInterceptor.tcpError(org.microproxy.tcp.TcpContext, java.lang.Throwable). The call may block while the destination does not read.- Parameters:
fromClient- true to send to the server, false to send to the clientdata- the bytes, written as they are- Throws:
IllegalStateException- if that direction has ended (its end was passed on, or the tunnel closed)NullPointerException- ifdatais null
-