← Back to Official Package Registry
Tier 5: Cloud-Native, Noise, IaC & Wasm • Noise Protocol, SOCKS5 & Tunnelsv1.0.0 • 57 KB • Ed25519 Verified

noise_tunnel@1.0.0

Noise_NN & Noise_IKpsk2 (WireGuard-grade X25519 + ChaCha20-Poly1305) handshakes, multiplexed reverse tunnels, and RFC 1928/1929 SOCKS5.

use [noise_tunnel]use [noise_tunnel/socks5]
veko pkg add noise_tunnel@1.0.0
Run in Browser PlaygroundDownload 1.0.0.vkpRaw demo.vk

noise_tunnel

Pure-Veko Noise Protocol Framework (Noise_NN_25519_ChaChaPoly_SHA256 & Noise_IKpsk2_25519_ChaChaPoly_SHA256), multiplexed encrypted reverse tunnel, and RFC 1928 / RFC 1929 SOCKS5 proxy codec (noise_tunnel, noise_tunnel/socks5).

Overview

noise_tunnel implements authenticated zero-trust network tunneling and SOCKS5 ingress proxying in pure Veko with zero external dependencies:

  • noise_tunnel (Noise Protocol Framework Rev 34 & Reverse Tunnel Mux):
  • Complete CipherState (ChaChaPoly with 96-bit 0x00000000 || u64_le(n) nonces and Section 4.2 REKEY), SymmetricState (MixHash, MixKey, MixKeyAndHash, EncryptAndHash, DecryptAndHash, Split), Noise_NN_25519_ChaChaPoly_SHA256, and Noise_IKpsk2_25519_ChaChaPoly_SHA256 (WireGuard's mutual-authenticated, identity-hiding PSK handshake pattern) built on crypto/x25519, crypto/chacha20, and crypto/sha256.
  • Multiplexed encrypted reverse tunnel framing (OPEN_STREAM, STREAM_DATA, CLOSE_STREAM, PING, PONG) multiplexing concurrent logical streams over a single Noise TransportSession.
  • noise_tunnel/socks5 (RFC 1928 + RFC 1929 SOCKS5):
  • Full SOCKS5 method negotiation, RFC 1929 Username/Password subnegotiation verified in constant time via SHA-256 + bits/ct-eq?, CONNECT requests/replies across IPv4 (0x01), Domain (0x03), and IPv6 (0x04) ATYP modes, and io/Stream client/server handshake helpers.

Installation

powershell
veko pkg add noise_tunnel@1.0.0

Import the modules in .vk source files:

rebol
use [
    nt     = noise_tunnel
    socks5 = noise_tunnel/socks5
]

Architecture

Noise_IKpsk2_25519_ChaChaPoly_SHA256 Handshake

text
Pre-message:
  <- s                          (Initiator knows Responder's 32B static X25519 public key)

Handshake:
  Initiator  --- e, es, s, ss + AEAD(payload) --->  Responder  (Hides Initiator static key `s` under `es`!)
  Initiator  <-- e, ee, se, psk + AEAD(reply) ----  Responder  (Mutual forward-secret auth + 32B PSK binding)
                         |
                         v
          Split() -> (tx CipherState, rx CipherState, handshake_hash)
                         |
                         v
          Multiplexed Encrypted Reverse Tunnel Frames
          [4B u32_be len][AEAD(1B kind | 4B stream_id | 4B payload_len | payload)]

Complete API Reference

noise_tunnel

SymbolSignatureDescription
PROTO-NOISE-NNfn [] str'Noise_NN_25519_ChaChaPoly_SHA256'
PROTO-NOISE-IKPSK2fn [] str'Noise_IKpsk2_25519_ChaChaPoly_SHA256'
FRAME-OPEN-STREAM / FRAME-STREAM-DATA / FRAME-CLOSE-STREAM / FRAME-PING / FRAME-PONGfn [] i64Reverse tunnel frame kind constants (1..5)
generate-keypair / keypair-from-seedfn [] Keypair / fn [priv32 bytes] KeypairX25519 keypair generation
new-cipher-statefn [/key k_bytes bytes = ...] CipherStateInitializes an unkeyed or keyed CipherState
encode-noise-noncefn [n i64] bytesEncodes `4B zero
encrypt-with-ad / decrypt-with-adfn [mut cs CipherState, ad bytes, data bytes] bytesNoise CipherState AEAD operations
rekeyfn [mut cs CipherState] enumNoise Section 4.2 REKEY(k) using maxnonce = 2^64 - 1
init-symmetricfn [protocol_name str] SymmetricStateInitializes SymmetricState per Noise Section 5.2
mix-hash / mix-key / mix-key-and-hashfn [mut ss SymmetricState, data bytes] enumTranscript and HKDF chaining-key mixing
encrypt-and-hash / decrypt-and-hashfn [mut ss SymmetricState, data bytes] bytesHandshake AEAD + transcript hashing
nn-initiator-new / nn-responder-newfn [/prologue prol bytes = ...] HandshakeStateInitializes NN handshake endpoints
nn-write-msg1 / nn-read-msg1 / nn-write-msg2 / nn-read-msg2HandshakeState functions2-message Noise_NN handshake
ik-initiator-newfn [static_kp Keypair, remote_static_pub bytes, psk32 bytes /prologue prol bytes = ...] HandshakeStateInitializes IKpsk2 initiator
ik-responder-newfn [static_kp Keypair, psk32 bytes /prologue prol bytes = ...] HandshakeStateInitializes IKpsk2 responder
ik-write-msg1 / ik-read-msg1HandshakeState functionsMessage 1 (-> e, es, s, ss) write & read
ik-write-msg2 / ik-read-msg2HandshakeState functionsMessage 2 (<- e, ee, se, psk) + Split
transport-encrypt / transport-decryptfn [mut sess TransportSession, data bytes /ad assoc_data bytes = ...] bytesDirectional transport AEAD
transport-rekey-tx / transport-rekey-rxfn [mut sess TransportSession] enumDirectional transport rekeying
seal-tunnel-packet / open-tunnel-packetTransportSession frame functionsSeals/opens length-prefixed encrypted tunnel packets
new-tunnel-muxfn [is_server bool] TunnelMuxCreates a stream-multiplexed reverse tunnel state
mux-open-stream / mux-send-data / mux-close-stream / mux-ping / mux-ingest-packet / mux-drain-streamTunnelMux functionsStream lifecycle, data multiplexing, and keepalives

noise_tunnel/socks5

SymbolSignatureDescription
ATYP-IPV4 / ATYP-DOMAIN / ATYP-IPV6fn [] i64RFC 1928 address type constants (0x01, 0x03, 0x04)
encode-greeting / decode-greetingfn [methods block[i64]] bytes / fn [wire bytes] SocksGreetingSOCKS5 method greeting codec
encode-userpass-auth / decode-userpass-authfn [username str, password str] bytes / fn [wire bytes] UserPassCredsRFC 1929 subnegotiation codec
verify-userpassfn [creds UserPassCreds, expected_user str, expected_pass str] boolConstant-time credential verification (bits/ct-eq?)
encode-connect-req / decode-connect-reqfn [host str, port i64 ...] bytes / fn [wire bytes] ConnectRequestSOCKS5 CONNECT request codec (IPv4/Domain/IPv6)
encode-reply / decode-replyfn [rep i64, bind_host str, bind_port i64] bytes / fn [wire bytes] SocksReplySOCKS5 reply codec
client-handshakefn [mut s io/Stream, target_host str, target_port i64 /username user str = '' /password pass str = ''] SocksReplyClient SOCKS5 handshake over io/Stream
server-acceptfn [mut s io/Stream /require_user expected_user str = '' /require_pass expected_pass str = '' ...] ConnectRequestServer SOCKS5 accept + RFC 1929 auth over io/Stream

Idiomatic Veko Usage

rebol
use [nt = noise_tunnel]

agent_kp   = nt/generate-keypair
gateway_kp = nt/generate-keypair
psk        = random/bytes 32

mut init_hs = nt/ik-initiator-new agent_kp gateway_kp.pub_key psk
mut resp_hs = nt/ik-responder-new gateway_kp psk

msg1 = nt/ik-write-msg1 mut init_hs (bytes/from-str 'agent:eu-west-1')
r1   = nt/ik-read-msg1 mut resp_hs msg1
msg2 = nt/ik-write-msg2 mut resp_hs (bytes/from-str 'ok')
done = nt/ik-read-msg2 mut init_hs msg2.wire

mut cli_sess = done.session
mut srv_sess = msg2.session
ct = nt/transport-encrypt mut cli_sess (bytes/from-str 'encrypted frame')
pt = nt/transport-decrypt mut srv_sess ct
print (bytes/to-str pt)
packages/noise_tunnel/examples/demo.vkSelf-contained runnable example & assertion suite
Raw .vk
// packages/noise_tunnel/examples/demo.vk
// Self-contained verification suite & runnable example for `noise_tunnel` and `noise_tunnel/socks5`.

use [
	bits
	inet   = io/net
	io
	nt     = noise_tunnel
	socks5 = noise_tunnel/socks5
]

assert-true = fn [cond bool, label str] enum [
	if not cond [
		println (str/join ['[FAIL] ' label] '')
		os/exit 1
	]
	println (str/join ['[PASS] ' label] '')
	.ok
]

// --- 1. `Noise_NN_25519_ChaChaPoly_SHA256` Ephemeral Handshake & Transport Rekeying ---
mut nn_i = nt/nn-initiator-new/prologue (bytes/from-str 'veko-nn-v1')
mut nn_r = nt/nn-responder-new/prologue (bytes/from-str 'veko-nn-v1')

nn_m1   = nt/nn-write-msg1 mut nn_i (bytes/from-str 'hello-nn')
nn_p1   = nt/nn-read-msg1 mut nn_r nn_m1
nn_m2_r = nt/nn-write-msg2 mut nn_r (bytes/from-str 'ack-nn')
nn_done = nt/nn-read-msg2 mut nn_i nn_m2_r.wire

mut nn_cli = nn_done.session
mut nn_srv = nn_m2_r.session
_ = nt/transport-rekey-tx mut nn_cli
_ = nt/transport-rekey-rx mut nn_srv
rekey_ct = nt/transport-encrypt mut nn_cli (bytes/from-str 'post-rekey-secret')
rekey_pt = nt/transport-decrypt mut nn_srv rekey_ct

nn_ok = (bytes/to-str nn_p1) == 'hello-nn' and (bytes/to-str nn_done.payload) == 'ack-nn' and (bits/ct-eq? nn_cli.handshake_hash nn_srv.handshake_hash) and (bytes/to-str rekey_pt) == 'post-rekey-secret'
_ = assert-true nn_ok 'Noise_NN_25519_ChaChaPoly_SHA256 handshake, transcript binding, and §4.2 transport rekeying'

// --- 2. `Noise_IKpsk2_25519_ChaChaPoly_SHA256` Mutual-Auth + PSK Handshake ---
init_static = nt/keypair-from-seed (bytes/fill 32 0x11)
resp_static = nt/keypair-from-seed (bytes/fill 32 0x22)
shared_psk  = bytes/fill 32 0x5a
prol_bytes  = bytes/from-str 'veko-wireguard-tunnel-v1'

mut ik_i = nt/ik-initiator-new/prologue init_static resp_static.pub_key shared_psk prol_bytes
mut ik_r = nt/ik-responder-new/prologue resp_static shared_psk prol_bytes

msg1 = nt/ik-write-msg1 mut ik_i (bytes/from-str 'agent-reg:edge-eu-1')

// Initiator static public key is AEAD-encrypted inside msg1 (never transmitted in cleartext!)
static_hidden = (bits/index-of msg1 init_static.pub_key 0) < 0

r1   = nt/ik-read-msg1 mut ik_r msg1
m2_r = nt/ik-write-msg2 mut ik_r (bytes/from-str 'assigned:tunnel-01')
done = nt/ik-read-msg2 mut ik_i m2_r.wire

mut cli_sess = done.session
mut srv_sess = m2_r.session

ik_ok_1 = static_hidden and (bits/ct-eq? r1.remote_static init_static.pub_key) and (bits/ct-eq? srv_sess.remote_static init_static.pub_key)
ik_ok_2 = (bytes/to-str r1.payload) == 'agent-reg:edge-eu-1' and (bytes/to-str done.payload) == 'assigned:tunnel-01' and (bits/ct-eq? cli_sess.handshake_hash srv_sess.handshake_hash)
_ = assert-true (ik_ok_1 and ik_ok_2) 'Noise_IKpsk2_25519_ChaChaPoly_SHA256 mutual static-key authentication, identity hiding, and PSK binding'

// --- 3. Wrong-PSK & Tampered-Ciphertext Constant-Time Rejection ---
wrong_psk = bytes/fill 32 0x5b
mut bad_i = nt/ik-initiator-new/prologue init_static resp_static.pub_key shared_psk prol_bytes
mut bad_r = nt/ik-responder-new/prologue resp_static wrong_psk prol_bytes
bad_m1    = nt/ik-write-msg1 mut bad_i (bytes/from-str 'probe')
_         = nt/ik-read-msg1 mut bad_r bad_m1
bad_m2    = nt/ik-write-msg2 mut bad_r (bytes/from-str 'wrong-psk-reply')
psk_res   = nt/ik-read-msg2/or mut bad_i bad_m2.wire [ '__psk_rejected__' ]

// Flip 1 bit in encrypted static identity inside msg1
mut tampered_m1 = bytes/with-cap (len msg1)
_ = bytes/push-all mut tampered_m1 msg1
_ = bytes/set mut tampered_m1 40 (tampered_m1[40] ^ 0x01)
mut fresh_r = nt/ik-responder-new/prologue resp_static shared_psk prol_bytes
tamper_res = nt/ik-read-msg1/or mut fresh_r tampered_m1 [ '__tamper_rejected__' ]

_ = assert-true (psk_res == '__psk_rejected__' and tamper_res == '__tamper_rejected__') 'wrong PSK and 1-bit tampered handshake ciphertext rejected cleanly'

// --- 4. Multiplexed Encrypted Reverse Tunnel (`OPEN_STREAM`, `STREAM_DATA`, `PING`/`PONG`, `CLOSE_STREAM`) ---
mut gw_mux    = nt/new-tunnel-mux true
mut agent_mux = nt/new-tunnel-mux false

// Reverse gateway opens two concurrent logical streams (IDs 2 and 4) toward internal services behind the agent
open_s2 = nt/mux-open-stream mut gw_mux mut srv_sess '10.0.1.25:5432'
open_s4 = nt/mux-open-stream mut gw_mux mut srv_sess '10.0.1.30:8080'

_ = nt/mux-ingest-packet mut agent_mux mut cli_sess (map/get open_s2 'packet')
_ = nt/mux-ingest-packet mut agent_mux mut cli_sess (map/get open_s4 'packet')

// Interleave chunks on streams 2 and 4 in both directions + keepalive PING/PONG
sid2 = as-i64 (map/get open_s2 'stream_id')
sid4 = as-i64 (map/get open_s4 'stream_id')

pkt_2a = nt/mux-send-data mut srv_sess sid2 (bytes/from-str 'SELECT ')
pkt_4a = nt/mux-send-data mut srv_sess sid4 (bytes/from-str 'GET /healthz HTTP/1.1\r\n\r\n')
pkt_2b = nt/mux-send-data mut srv_sess sid2 (bytes/from-str '1;')

_ = nt/mux-ingest-packet mut agent_mux mut cli_sess pkt_2a
_ = nt/mux-ingest-packet mut agent_mux mut cli_sess pkt_4a
_ = nt/mux-ingest-packet mut agent_mux mut cli_sess pkt_2b

// Agent sends keepalive PING -> Gateway auto-generates encrypted PONG
ping_pkt = nt/mux-ping mut cli_sess (bytes/from-str 'hb-0001')
ing_ping = nt/mux-ingest-packet mut gw_mux mut srv_sess ping_pkt
_        = nt/mux-ingest-packet mut agent_mux mut cli_sess (map/get ing_ping 'reply_packet')

// Agent sends response data on stream 4 and closes stream 4
rep_4  = nt/mux-send-data mut cli_sess sid4 (bytes/from-str 'HTTP/1.1 200 OK\r\n\r\n')
cls_4  = nt/mux-close-stream mut agent_mux mut cli_sess sid4
_      = nt/mux-ingest-packet mut gw_mux mut srv_sess rep_4
_      = nt/mux-ingest-packet mut gw_mux mut srv_sess cls_4

sql_recv  = bytes/to-str (nt/mux-drain-stream mut agent_mux sid2)
http_req  = bytes/to-str (nt/mux-drain-stream mut agent_mux sid4)
http_resp = bytes/to-str (nt/mux-drain-stream mut gw_mux sid4)

mux_ok = sid2 == 2 and sid4 == 4 and sql_recv == 'SELECT 1;' and http_req == 'GET /healthz HTTP/1.1\r\n\r\n' and http_resp == 'HTTP/1.1 200 OK\r\n\r\n' and (bytes/to-str agent_mux.last_pong) == 'hb-0001' and (map/has? gw_mux.closed_ids '4')
_ = assert-true mux_ok 'multiplexed encrypted reverse tunnel streams (OPEN_STREAM, STREAM_DATA, PING/PONG, CLOSE_STREAM)'

// --- 5. RFC 1928 + RFC 1929 SOCKS5 Wire Codec (IPv4, Domain, IPv6) & Live `io/Stream` Handshake ---
req_v4  = socks5/decode-connect-req (socks5/encode-connect-req '10.24.0.8' 5432)
req_dom = socks5/decode-connect-req (socks5/encode-connect-req 'db.internal.veko' 6432)
req_v6  = socks5/decode-connect-req (socks5/encode-connect-req '2001:db8::42' 443)

atyp_ok = req_v4.atyp == (socks5/ATYP-IPV4) and req_v4.host == '10.24.0.8' and req_dom.atyp == (socks5/ATYP-DOMAIN) and req_dom.host == 'db.internal.veko' and req_v6.atyp == (socks5/ATYP-IPV6) and req_v6.host == '2001:db8::42' and req_v6.port == 443
_ = assert-true atyp_ok 'SOCKS5 CONNECT codec roundtrips IPv4 (0x01), Domain (0x03), and IPv6 (0x04) ATYP'

// Live loopback TCP `io/Stream` SOCKS5 handshake with RFC 1929 Username/Password authentication
ln = net/listen-tcp .ip '127.0.0.1:0'
port_n = str/to-i64 (str/split (net/addr ln) ':')[1]

socks_srv = spawn [
	// Connection 1: valid RFC 1929 credentials + IPv6 target
	c1 = net/accept ln
	mut s1 = inet/tcp-stream (as-i64 c1) 'socks-cli-1'
	creq1 = socks5/server-accept/require_user/require_pass mut s1 'tunnel-op' 's3cr3t-veko-key'
	payload_in = io/read mut s1 64
	_ = io/write-all mut s1 (bytes/from-str (str/join ['proxied->' creq1.host ':' (mold creq1.port) ':' (bytes/to-str payload_in)] ''))
	_ = io/close mut s1

	// Connection 2: invalid RFC 1929 password -> rejected in constant time
	c2 = net/accept ln
	mut s2 = inet/tcp-stream (as-i64 c2) 'socks-cli-2'
	rej = socks5/server-accept/require_user/require_pass/or mut s2 'tunnel-op' 's3cr3t-veko-key' [
		socks5/ConnectRequest { cmd = 0, atyp = 0, host = '__auth_denied__', port = 0 }
	]
	_ = io/close mut s2
	_ = net/close ln
	rej.host
]

mut cli1 = inet/dial-tcp '127.0.0.1' port_n
rep1 = socks5/client-handshake/username/password mut cli1 '2001:db8::99' 8443 'tunnel-op' 's3cr3t-veko-key'
_ = io/write-all mut cli1 (bytes/from-str 'PING-UPSTREAM')
tunneled_echo = bytes/to-str (io/read-all mut cli1)
_ = io/close mut cli1

mut cli2 = inet/dial-tcp '127.0.0.1' port_n
bad_auth = socks5/client-handshake/username/password/or mut cli2 'internal.veko' 80 'tunnel-op' 'wrong-pass' [
	socks5/SocksReply { rep = 1, bind_atyp = 1, bind_host = '0.0.0.0', bind_port = 0 }
]
_ = io/close mut cli2

srv_rej_host = task/await socks_srv

socks_live_ok = rep1.rep == 0 and tunneled_echo == 'proxied->2001:db8::99:8443:PING-UPSTREAM' and bad_auth.rep == 1 and srv_rej_host == '__auth_denied__'
_ = assert-true socks_live_ok 'live io/Stream SOCKS5 + RFC 1929 constant-time auth handshake and wrong-password rejection'

println 'noise_tunnel: all verification checks passed'
Cryptographic Provenance

Ed25519 Signature & Merkle Integrity

Registry URL: https://veko-lang.org/pkg/noise_tunnel/1.0.0.vkp
Archive SHA-256: 61988f3973474e435e9adf6f406217834e2b4f028b55ed253093d98f7a269386
Merkle Root: 4811e35c91a43ec0df7b91809a3367619ac08457347a947bbf18bac87b444065
Signer Trust Key: ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70
Embedded VKP1 Manifest

manifest.json

{"name":"noise_tunnel","version":"1.0.0","tier":5.0,"tier_label":"Tier 5: Cloud-Native, Noise, IaC & Wasm","category":"Noise Protocol, SOCKS5 & Tunnels","description":"Noise_NN & Noise_IKpsk2 (WireGuard-grade X25519 + ChaCha20-Poly1305) handshakes, multiplexed reverse tunnels, and RFC 1928/1929 SOCKS5.","modules":["noise_tunnel","noise_tunnel/socks5"],"homepage":"https://veko-lang.org/packages/noise_tunnel"}
Bundle Entry PathSizeLeaf SHA-256 Digest
README.md7 KB4c6ba3821bbcbf40e79b7f2a2392f7c50d27b3ed500cf117ff52a6be7094de23
examples/demo.vk8 KBdf8e8367389fe58fd665b7ff39cf925f43c353600f79a5d71f7f0d27521cf147
mod.vk25 KB1ac427e8731263346459c673f6bb9f05f762fb23d00f39c019f458edb2512555
socks5.vk15 KB2224b70beac83802871c2293223a8578919ebfed463bd526f25be77df1f763e1