Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: listener scope filter #320

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified charts/fsm/components/scripts.tar.gz
Binary file not shown.
87 changes: 0 additions & 87 deletions charts/fsm/components/scripts/gateways/config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default function () {
var $ctx
var $sni
var $session

var balancers = new algo.Cache(
target => new algo.LoadBalancer([target])
)

return pipeline($=>$
.onStart(c => {
$ctx = c.parent
$sni = $ctx.originalServerName
$session = balancers.get($ctx.originalTarget).allocate()
})
.muxHTTP(() => $session).to($=>$
.pipe(() => $sni ? 'tls' : 'tcp', {
'tcp': ($=>$.connect(() => $session.target)),
'tls': ($=>$
.connectTLS({ sni: () => $sni }).to($=>$
.connect(() => $session.target)
)
),
})
)
.onEnd(() => $session.free())
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export default function () {
var $ctx
var $proto

return pipeline($=>$
.onStart(c => { $ctx = c })
.detectProtocol(p => { $proto = p })
.pipe(
() => {
if ($proto !== undefined) {
return $proto === 'HTTP' ? 'http' : 'socks'
}
}, {
'http': ($=>$
.demuxHTTP().to($=>$
.pipe(
function (evt) {
if (evt instanceof MessageStart) {
return evt.head.method === 'CONNECT' ? 'tunnel' : 'forward'
}
}, {
'tunnel': ($=>$
.acceptHTTPTunnel(
function (req) {
$ctx.originalTarget = req.head.path
return new Message({ status: 200 })
}
).to($=>$.pipeNext())
),
'forward': ($=>$
.handleMessageStart(
function (req) {
var url = new URL(req.head.path)
$ctx.originalTarget = `${url.hostname}:${url.port}`
req.head.path = url.path
}
)
.pipeNext()
),
}
)
)
),
'socks': ($=>$
.acceptSOCKS(
function (req) {
$ctx.originalTarget = `${req.domain || req.ip}:${req.port}`
return true
}
).to($=>$.pipeNext())
)
}
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default function ({ tlsDelegate }, resources) {
var ca = new crypto.Certificate(resources.secrets[tlsDelegate.certificate['ca.crt']])
var caKey = new crypto.PrivateKey(resources.secrets[tlsDelegate.certificate['ca.key']])
var key = new crypto.PrivateKey({ type: 'rsa', bits: 2048 })
var pkey = new crypto.PublicKey(key)

var cache = new algo.Cache(
domain => new crypto.Certificate({
subject: { CN: domain },
extensions: { subjectAltName: `DNS:${domain}` },
days: 365,
timeOffset: -3600,
issuer: ca,
privateKey: caKey,
publicKey: pkey,
}),
null, { ttl: 60*60 }
)

var $ctx
var $proto

return pipeline($=>$
.onStart(c => { $ctx = c })
.pipe(evt => evt instanceof MessageStart ? 'L7' : 'L4', {
'L7': ($=>$.pipeNext()),
'L4': ($=>$
.detectProtocol(p => { $proto = p })
.pipe(
() => {
if ($proto !== undefined) {
return ($proto === 'TLS' ? 'tls' : 'tcp')
}
}, {
'tcp': ($=>$.pipeNext()),
'tls': ($=>$
.acceptTLS({
certificate: s => {
if (!s) return
$ctx.originalServerName = s
return { key, cert: cache.get(s) }
}
}).to($=>$.pipeNext())
)
}
)
)
})
)
}
24 changes: 0 additions & 24 deletions charts/fsm/components/scripts/gateways/log.js

This file was deleted.

Loading
Loading