def Tls.tunnel

bend-kube-runtime@0.2.0.0 · src/net.bend:77

import bend-kube-runtime@0.2.0.0/src/net.bend as Net
import Base
import bend-kube-runtime@0.2.0.0/src/proxy.bend as P

77# Reads the proxy's answer to CONNECT; once it opens the tunnel, secures
78# the connection end to end with the API server.
79def Tls.tunnel(fuel: Nat, ev: TunEv, +host: String, ca: String, cert: String, key: String,
80  +ms: U32) -> IO(Res(Socket)):
81  match fuel ev:
82    case 0n TGot{s, r, st}:
83      Tls.fail(s, (0, "proxy: answer too long"))
84    case 0n TStep{s, st}:
85      Tls.fail(s, (0, "proxy: answer too long"))
86    case 1n+f TGot{s, Done{bs}, st}:
87      Tls.tunnel(f, TStep{s, P.Tunnel.feed(st, bs)}, host, ca, cert, key, ms)
88    case 1n+f TGot{s, Fail{(c, m)}, st}:
89      Tls.fail(s, (c, "proxy: " ++ m))
90    case 1n+f TStep{s, P.TMore{h}}:
91      IO.bind(Socket & Res(List<&2, U32>), Res(Socket), Tls.recv(s, 4096, ms),
92        p => Tls.tunnel(f, TunEv.got(p, P.TMore{h}), host, ca, cert, key, ms))
93    case 1n+f TStep{s, P.TOpen{}}:
94      Tls.secure(s, host, ca, cert, key, ms)
95    case 1n+f TStep{s, P.TFail{why}}:
96      Tls.fail(s, (0, why))

Uses (19)

Used by (1)