Skip to main content

SNI proxy with TCP multiplexer

Project description

SniTun

End-to-End encryption with SNI proxy on top of a TCP multiplexer

Connection flow

                   [ CLIENT ] --AUTH/CONFIG--> [ SESSION MASTER ] (Trusted connection)
                   [ CLIENT ] <--FERNET-TOKEN- [ SESSION MASTER ]
                   [ CLIENT ] --------FERNET-TOKEN---------------------> [ SNITUN ] (Insecure connection)
                   [ CLIENT ] <-------CHALLENGE-RESPONSE-(AES/CBC)-----> [ SNITUN ]


             <--->                                                                  <------------------------------>
[ ENDPOINT ] <---> [ CLIENT ] <---------MULTIPLEXER---(AES/CBC)--------> [ SNITUN ] <------EXTERNAL-CONECTIONS-----> [ DEVICE ]
    |        <--->                                                                  <------------------------------>     |
    |                                                                                                                    |
    | <--------------------------------------------------END-TO-END-SSL------------------------------------------------->|
                                                      (Trusted connection)

Fernet token

The session master creates a Fernet token from the client's configuration (AES/whitelist) and attaches the hostname and a UTC timestamp until which the token is valid.

{
  "valid": 1923841,
  "hostname": "myname.ui.nabu.casa",
  "aes_key": "hexstring",
  "aes_iv": "hexstring"
}

The SniTun server must be able to decrypt this token to validate the client's authenticity. SniTun then initiates a challenge-response handling to validate the AES key and ensure that it is the same client that requested the Fernet token from the session master.

Note: SniTun server does not perform any user authentication!

Challenge/Response

The SniTun server creates a SHA256 hash from a random 40-bit value. This value is encrypted and sent to the client, who then decrypts the value and performs another SHA256 hash with the value and sends it encrypted back to SniTun. If it is valid, the client enters the Multiplexer mode.

Multiplexer Protocol

The header is encrypted using AES/CBC. The payload should be SSL. The ID changes for every TCP connection and is unique for each connection. The size is for the data payload.

The extra information could include the caller IP address for a new message. Otherwise, it is random bits.

|________________________________________________________|
|-----------------HEADER---------------------------------|______________________________________________|
|------ID-----|--FLAG--|--SIZE--|---------EXTRA ---------|--------------------DATA----------------------|
|   16 bytes  | 1 byte | 4 bytes|       11 bytes         |                  variable                    |
|--------------------------------------------------------|----------------------------------------------|

Message Flags/Types:

  • 0x01: New | The extra data includes the first byte as an ASCII value of 4 or 6, followed by the caller IP in bytes.
  • 0x02: DATA
  • 0x04: Close
  • 0x08: Ping | The extra data is a ping or pong response to a ping.
  • 0x16: Pause the remote reader (added in protocol version 1)
  • 0x32: Resume the remote reader (added in protocol version 1)

Configuration via environment variables

The following environment variables, which, to be effective, must be set before importing this package, are available to override internal defaults:

  • MULTIPLEXER_INCOMING_QUEUE_MAX_BYTES_CHANNEL - The maximum number of bytes allowed in the incoming queue for each multiplexer channel.
  • MULTIPLEXER_INCOMING_QUEUE_MAX_BYTES_CHANNEL_V0 - The maximum number of bytes allowed in the incoming queue for protocol version 0 channels (default: 256MB, larger than standard channels since v0 lacks flow control).
  • MULTIPLEXER_INCOMING_QUEUE_LOW_WATERMARK - The low watermark threshold, in bytes, for the incoming queue for each multiplexer channel.
  • MULTIPLEXER_INCOMING_QUEUE_HIGH_WATERMARK - The high watermark threshold, in bytes, for the incoming queue for each multiplexer channel.
  • MULTIPLEXER_OUTGOING_QUEUE_MAX_BYTES_CHANNEL - The maximum number of bytes allowed in the outgoing queue for the multiplexer channel.
  • MULTIPLEXER_OUTGOING_QUEUE_LOW_WATERMARK - The low watermark threshold, in bytes, for the outgoing queue for each multiplexer channel.
  • MULTIPLEXER_OUTGOING_QUEUE_HIGH_WATERMARK - The high watermark threshold, in bytes, for the outgoing queue for each multiplexer channel.

Protocol versioning considerations

  • The client is responsible for setting the protocol_version key in the token. If no protocol_version is provided, the server must assume protocol version 0.
  • The server side must always be updated first when incrementing the protocol version as the client assumes that the server is always running a protocol version that it supports.
  • When new message types are added to the Multiplexer, the protocol version must be incremented.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snitun-0.45.2.tar.gz (43.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snitun-0.45.2-py3-none-any.whl (51.3 kB view details)

Uploaded Python 3

File details

Details for the file snitun-0.45.2.tar.gz.

File metadata

  • Download URL: snitun-0.45.2.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snitun-0.45.2.tar.gz
Algorithm Hash digest
SHA256 ca1768833bd8d2e97f3986d2bc0230ad3ac8a28f12eae2c0ba163a8f23fcd512
MD5 d64bcb880c047fa5423b837d3e888424
BLAKE2b-256 7b5867e76679c83bb4d26c81dbbe0dea2c0ab7d784ef55e9c627fa055b4ffc30

See more details on using hashes here.

Provenance

The following attestation bundles were made for snitun-0.45.2.tar.gz:

Publisher: release.yml on NabuCasa/snitun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snitun-0.45.2-py3-none-any.whl.

File metadata

  • Download URL: snitun-0.45.2-py3-none-any.whl
  • Upload date:
  • Size: 51.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snitun-0.45.2-py3-none-any.whl
Algorithm Hash digest
SHA256 45b3183e13e2a45111e3c54c8d2c11930d229e18a1a02ec1c4f0a0b09d3924b0
MD5 025e86ac863ca9b49889bab186ba899e
BLAKE2b-256 47218b79b4a8d66aad81e265bb86f0dd2a4cfbb8ed7185b19eb0abe0b8f0d029

See more details on using hashes here.

Provenance

The following attestation bundles were made for snitun-0.45.2-py3-none-any.whl:

Publisher: release.yml on NabuCasa/snitun

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page