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 Type
    Method
    Description
    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).
    long
    The client connection the tunnel belongs to (FlowContext.getConnectionId()).
    The exchange that opened the tunnel (its CONNECT), or the client connection's flow.
    The host the tunnel goes to: the CONNECT target's, the SNI's on a transparent listener, or the upstream's in reverse:tcp:// mode.
    int
    The port the tunnel goes to.
    void
    send(boolean fromClient, byte[] data)
    Adds bytes to the tunnel, as if one side had sent them: with fromClient they 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).
    boolean
    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 in reverse: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: the CONNECT target's, the SNI's on a transparent listener, or the upstream's in reverse: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 in reverse: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 (its CONNECT), 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: with fromClient they go to the server, else to the client. They do not pass through TcpInterceptor.tcpMessage(org.microproxy.tcp.TcpMessage, org.microproxy.tcp.TcpContext). Called from a tcpMessage hook 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 to TcpInterceptor.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 client
      data - the bytes, written as they are
      Throws:
      IllegalStateException - if that direction has ended (its end was passed on, or the tunnel closed)
      NullPointerException - if data is null