{"id":50016216,"url":"https://github.com/libknock/libknock","last_synced_at":"2026-05-23T07:00:45.977Z","repository":{"id":359006733,"uuid":"1241300300","full_name":"libknock/libknock","owner":"libknock","description":"Embeddable TCP pre-application authentication SDK for Go applications.","archived":false,"fork":false,"pushed_at":"2026-05-20T12:24:59.000Z","size":518,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-21T09:39:42.435Z","etag":null,"topics":["authentication","go","go-library","golang","net-dialer","net-listener","network-security","networking","port-knocking","sdk","security-tools","tcp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libknock.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/security.md","support":null,"governance":null,"roadmap":"docs/roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE","maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-05-17T07:52:00.000Z","updated_at":"2026-05-20T12:24:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/libknock/libknock","commit_stats":null,"previous_names":["libknock/libknock"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/libknock/libknock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libknock%2Flibknock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libknock%2Flibknock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libknock%2Flibknock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libknock%2Flibknock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libknock","download_url":"https://codeload.github.com/libknock/libknock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libknock%2Flibknock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33305277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T12:23:38.849Z","status":"ssl_error","status_checked_at":"2026-05-21T12:22:11.673Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","go","go-library","golang","net-dialer","net-listener","network-security","networking","port-knocking","sdk","security-tools","tcp"],"created_at":"2026-05-20T04:00:36.059Z","updated_at":"2026-05-22T06:01:11.382Z","avatar_url":"https://github.com/libknock.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libknock\n\n[![License: BSL-1.1](https://img.shields.io/badge/license-BSL--1.1-blue.svg)](LICENSE)\n[![Future License: Apache-2.0](https://img.shields.io/badge/future%20license-Apache--2.0-lightgrey.svg)](LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/libknock/libknock.svg)](https://pkg.go.dev/github.com/libknock/libknock)\n\nSource-available under BSL-1.1. Production use is allowed, but offering libknock or derivative works as a hosted or managed service is restricted before it converts to Apache-2.0 on 2030-05-15. See [LICENSE](LICENSE) and [license notes](docs/license.md).\n\nEmbeddable TCP pre-application authentication SDK for Go applications.\n\nIt authenticates a compact binary frame after a TCP connection is established and before the application protocol starts. After authentication succeeds, the caller receives a normal `net.Conn` and continues with its own protocol stack: plain TCP, TLS, HTTP, gRPC, custom RPC, agent connections, game protocols, database-like protocols, or any protocol built on top of `net.Conn`.\n\n`libknock` does not parse, modify, or own application payloads. It only performs an admission step at the TCP connection boundary and then hands a clean connection back to the embedding application.\n\n\n## Dependency model\n\nlibknock uses Go modules as the primary dependency path. The standard source archive is for normal Go module users. The companion `with-vendor` archive includes `vendor/`, `vendor/modules.txt`, `go.work`, and `go.work.sum` for offline review, reproducible local audit, LLM-assisted integration, and restricted CI. Use `go test -mod=vendor ./...` and `go vet -mod=vendor ./...` when validating the vendored archive.\n\n## What it provides\n\n- Authenticated `net.Listener` wrappers for server-side TCP services.\n- Authenticated `net.Dialer` wrappers for clients.\n- Standalone `ServerAuth` and `ClientAuth` functions for custom connection pipelines.\n- Core root-package SDK entry points for TCP authentication.\n- Optional knock, firewall, gate, and relay packages for advanced admission paths.\n- Replay protection, timestamp validation, peer metadata, event hooks, and policy hooks.\n- Optional Prometheus adapter in a separate module.\n\n## Install\n\n```sh\ngo get github.com/libknock/libknock\n```\n\n## Minimal server\n\n```go\npackage main\n\nimport (\n    \"log\"\n    \"net\"\n    \"time\"\n\n    libknock \"github.com/libknock/libknock\"\n)\n\nfunc main() {\n    secret := []byte(\"0123456789abcdef0123456789abcdef\")\n\n    ln, err := net.Listen(\"tcp\", \":9000\")\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    ln, err = libknock.NewListener(ln, libknock.ServerConfig{\n        ServerPort: 9000,\n        Secrets: libknock.NewStaticSecretResolver(map[string][]byte{\n            \"client-001\": secret,\n        }),\n        ReplayCache: libknock.NewMemoryReplayCache(5 * time.Minute),\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    for {\n        conn, err := ln.Accept()\n        if err != nil {\n            log.Fatal(err)\n        }\n        go handleConn(conn)\n    }\n}\n```\n\n`NewListener` returns startup validation errors directly and creates a listener-owned replay cache when one is not provided. `WrapListener` remains available as a convenience `net.Listener` wrapper; configuration errors surface from `Accept`. If you call the low-level `ServerAuth` function directly, provide a shared `ReplayCache` yourself.\n\n## Minimal client\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"net\"\n    \"time\"\n\n    libknock \"github.com/libknock/libknock\"\n)\n\nfunc dial(ctx context.Context) (net.Conn, error) {\n    secret := []byte(\"0123456789abcdef0123456789abcdef\")\n\n    d := libknock.Dialer{\n        Base: \u0026net.Dialer{Timeout: 5 * time.Second},\n        Config: libknock.ClientConfig{\n            ClientID:    \"client-001\",\n            Secret:      secret,\n            ServerPort:  9000,\n            AuthTimeout: 3 * time.Second,\n        },\n    }\n\n    return d.DialContext(ctx, \"tcp\", \"127.0.0.1:9000\")\n}\n```\n\n## Root package and advanced packages\n\nThe root package intentionally stays small. It exposes the common SDK path: `NewListener`, `WrapListener`, `WrapListenerE`, `ServerAuth`, `ClientAuth`, `Dialer`, `ServerConfig`, `ClientConfig`, `PeerInfo`, `NewServer`, `NewMemoryReplayCache`, and `NewStaticSecretResolver`.\n\nAdvanced admission features live in subpackages. Use `auth` for protocol selectors and advanced auth hooks, `gate` for listener composition modes, `relay` for proxy-style gateways, `firewall` for platform backends, `knock` for knock senders/listeners, and `observability` for gateway events.\n\n```go\nimport (\n    libknock \"github.com/libknock/libknock\"\n    \"github.com/libknock/libknock/gate\"\n)\n\nln, err := gate.Listen(ctx, gate.Config{\n    Mode: gate.AuthOnly,\n    Auth: libknock.ServerConfig{\n        ServerPort: 9000,\n        Secrets: libknock.NewStaticSecretResolver(map[string][]byte{\"client-001\": secret}),\n    },\n})\n```\n\n## TCP authentication protocols\n\n`libknock` supports two TCP pre-application authentication protocols:\n\n| Protocol | Name | Summary |\n| --- | --- | --- |\n| v1 | `tcp-auth-frame-v1` | Fixed binary frame with AEAD-sealed authentication metadata. |\n| v2 | `tcp-auth-envelope-v2` | Sealed envelope with route hint support and fixed-size bucket padding. |\n\nBoth protocols provide client secret validation, timestamp window validation, replay protection, optional knock session binding, peer metadata, event hooks, and optional server proof.\n\nClients select a protocol with `ClientConfig.Protocol`. Servers select a preferred protocol with `ServerConfig.Protocol` and accepted protocols with `ServerConfig.AcceptProtocols`. The default TCP authentication protocol is `tcp-auth-envelope-v2`.\n\n## UDP knock frame\n\nUDP knock uses a binary datagram frame with an AEAD-sealed payload. The same UDP frame family is used by:\n\n- `udp`\n- `udp-seq`\n- `udp-passive`\n- `udp-passive-seq`\n\nThe frame carries authenticated metadata such as client identity hash, method, timestamp, protected port, optional session ID, sequence fields, and extensions.\n\n## Knock method support\n\n| Method | Summary | Typical requirements |\n| --- | --- | --- |\n| `tcp-syn` | Single TCP SYN knock. | Raw packet capability on sender/listener platforms. |\n| `tcp-syn-seq` | Multi-part TCP SYN sequence knock. | Raw packet capability; useful when multiple short-window attempts are needed. |\n| `udp` | Single UDP knock over a normal UDP socket. | Standard UDP socket. |\n| `udp-seq` | Multi-part UDP sequence knock. | Standard UDP socket. |\n| `udp-passive` | UDP knock read through packet capture on the server side. | Packet capture privileges on the server platform. |\n| `udp-passive-seq` | Multi-part UDP sequence read through packet capture on the server side. | Packet capture privileges on the server platform. |\n\nFor most deployments, start with UDP knock before considering passive or raw-packet methods.\n\n## Capability status\n\n| Capability | Status |\n| --- | --- |\n| Authenticated listener | stable |\n| Dialer | stable |\n| TCP auth frame v1 | stable |\n| TCP auth envelope v2 | release candidate |\n| UDP knock / UDP sequence | release candidate |\n| Knock-auth-only gate | release candidate |\n| Firewall-backed gates | platform-specific / not fully validated |\n| UDP passive knock | experimental / not fully validated |\n| TCP SYN knock | experimental / not fully validated |\n| Windows packet capture integrations | experimental / not fully validated |\n| macOS passive capture integrations | experimental / not fully validated |\n\n## Gate modes\n\n| Mode | Description |\n| --- | --- |\n| `auth-only` | TCP connections must pass libknock TCP authentication before the application accepts them. |\n| `knock-auth-only` | TCP stays open at the transport layer, but clients must knock first and then pass TCP authentication before the application accepts them. No firewall rules are changed. |\n| `knock-firewall-auth` | A successful knock opens a short firewall window, then TCP authentication must pass. |\n| `knock-firewall-only` | A successful knock opens a short firewall window and the application receives the matching TCP connection. |\n\n`knock-auth-only` is not a port-hiding mode: SYN scans can still report the TCP port as open, but unauthenticated clients cannot reach the application protocol. It does not require root or `CAP_NET_ADMIN`, is useful in containers, restricted VPS instances, Windows/macOS deployments, and adds a short-lived knock session requirement on top of `auth-only`. It does not replace `knock-firewall-auth` when firewall-backed port gating is required.\n\n`knock-firewall-auth` and `knock-firewall-only` require a real firewall backend. `auth-only` and `knock-auth-only` can use `firewall.Noop{}`.\n\n## Relay gateway\n\n`relay.Gateway` is an optional TCP forwarding component. It listens on one address, performs libknock authentication and optional knock/firewall handling, then connects to an upstream TCP service.\n\n```go\ngw := relay.Gateway{\n    Listen:   \":9000\",\n    Upstream: \"127.0.0.1:19000\",\n    Auth:     serverAuthConfig,\n    Firewall: firewall.Noop{},\n}\nerr := gw.Run(ctx)\n```\n\nUse relay when the protected upstream is a separate TCP service rather than an application that embeds `libknock` directly.\n\n## Documentation\n\n- Coding agents: [docs/agents/AGENTS.md](docs/agents/AGENTS.md), [integration guide](docs/agents/integration-guide.md), [anti-patterns](docs/agents/anti-patterns.md), [recipes](docs/agents/recipes/)\n- Examples: [examples/README.md](examples/README.md)\n\n- [Documentation index](docs/README.md)\n- [Getting started](docs/getting-started.md)\n- [Use cases](docs/use-cases.md)\n- [API reference](docs/api.md)\n- [API surface and compatibility](docs/api-surface.md)\n- [Compatibility policy](COMPATIBILITY.md)\n- [Protocols](docs/protocols.md)\n- [Gate and relay](docs/gate-and-relay.md)\n- [Knock methods](docs/knock-methods.md)\n- [Firewall backends](docs/firewall.md)\n- [Observability](docs/observability.md)\n- [Production deployment](docs/production.md)\n- [Troubleshooting](docs/troubleshooting.md)\n- [Known limitations](docs/known-limitations.md)\n- [Validation matrix](docs/validation-matrix.md)\n- [Performance notes](docs/performance.md)\n- [Roadmap](docs/roadmap.md)\n- [Release notes](docs/release-notes.md)\n- [Release checklist](docs/release-checklist.md)\n- [Development guide](docs/development.md)\n\n## Firewall note\n\n`nftables` and `ipset-iptables` support timeout-oriented rules. The plain `iptables` backend relies on libknock's gate/relay timers to revoke ACCEPT rules and performs managed-chain cleanup at startup/shutdown, so unclean process exits can leave temporary rules until cleanup runs again. For production deployments that need kernel-enforced expiry, prefer `nftables` or `ipset-iptables`.\n\n## Repository layout\n\n```text\nprotocol/       binary protocol codecs and cryptographic helpers\nauth/           server/client authentication, replay cache, secret resolvers\nnetx/           listener, dialer, buffered connection behavior\nknock/          knock senders and listeners\nfirewall/       firewall backend interfaces and implementations\ngate/           SDK listener composition modes\nrelay/          optional TCP relay gateway\npolicy/         limiter and ban policy adapters\nobservability/  event interfaces and metrics adapters\ncmd/knock-proxy command entrypoint\nexamples/       integration examples\n```\n\n## Test\n\n```sh\nscripts/check.sh\n```\n\nFor a shorter edit loop:\n\n```sh\ngo test ./...\ngo vet ./...\ngo test -race ./auth ./firewall ./knock ./netx ./policy ./protocol ./relay\n```\n\nPrometheus and gRPC integration checks are separate modules:\n\n```sh\ngo -C observability/prometheus test ./...\ngo -C test/integration/grpc test ./...\n```\n\n## Compatibility command\n\n`cmd/knock-proxy` is a compatibility caller for simple client/server proxy deployments. It is not the full historical knock-proxy product and does not host every optional integration. Embedding applications should prefer the SDK packages directly when they need custom lifecycle, metrics, policy, or application-protocol handling.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibknock%2Flibknock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibknock%2Flibknock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibknock%2Flibknock/lists"}