{"id":16841643,"url":"https://github.com/kevinpollet/tlsmux","last_synced_at":"2025-03-18T05:16:23.737Z","repository":{"id":57631774,"uuid":"410301335","full_name":"kevinpollet/tlsmux","owner":"kevinpollet","description":"Go package providing an implementation of a net.Conn multiplexer based on the TLS SNI (Server Name Indication).","archived":false,"fork":false,"pushed_at":"2022-01-07T17:39:50.000Z","size":63,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T11:44:39.263Z","etag":null,"topics":["go","golang","muxer","sni","tls"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinpollet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-25T14:59:51.000Z","updated_at":"2023-06-26T17:28:10.000Z","dependencies_parsed_at":"2022-09-04T22:33:00.789Z","dependency_job_id":null,"html_url":"https://github.com/kevinpollet/tlsmux","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinpollet%2Ftlsmux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinpollet%2Ftlsmux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinpollet%2Ftlsmux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinpollet%2Ftlsmux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinpollet","download_url":"https://codeload.github.com/kevinpollet/tlsmux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244160053,"owners_count":20408021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["go","golang","muxer","sni","tls"],"created_at":"2024-10-13T12:42:37.081Z","updated_at":"2025-03-18T05:16:23.715Z","avatar_url":"https://github.com/kevinpollet.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tlsmux\n\n[![build](https://github.com/kevinpollet/tlsmux/actions/workflows/main.yml/badge.svg)](https://github.com/kevinpollet/tlsmux/actions)\n[![GoDoc](https://godoc.org/github.com/kevinpollet/tlsmux?status.svg)](https://pkg.go.dev/github.com/kevinpollet/tlsmux)\n\nGo package providing an implementation of a `net.Conn` multiplexer based on the TLS [SNI](https://www.cloudflare.com/learning/ssl/what-is-sni/) (Server Name Indication) sent by a client.\n\n## Installation\n\nInstall using `go get github.com/kevinpollet/tlsmux`.\n\n## Usage\n\n### Mux\n\nThe `Mux` struct allows registering handlers which will be called when the muxer serve a `net.Conn` with a \nmatching server name.\n\n```go\nmux := tlsmux.Mux{}\n\nl, err := net.Listen(\"tcp\", \"127.0.0.1:8080\")\nif err != nil {\n    log.Fatal(err)\n}\n\nif err := mux.Serve(l); err != nil {\n    log.Fatal(err)\n}\n```\n\n### Handler\n\nThe `Handler` interface is used to handle an incoming `net.Conn` without decrypting the underlying TLS communication (Pass Through).\nImplementations are responsible for closing the connection.\n\nThe `HandlerFunc` type is an adapter to allow the use of ordinary functions as a `Handler`.\n\n```go\nmux.Handle(\"server.name\", tlsmux.HandlerFunc(func(conn net.Conn) error {\n    defer conn.Close()\n\n    // Handle the encrypted TLS connection.\n}))\n```\n\n### TLSHandler\n\nThe `TLSHandler` struct is a `Handler` implementation allowing to terminate the TLS connection with the configured `tls.Config`.\nThus, the `net.Conn` parameter of a `TLSHandler` if of type `tls.Conn`.  \nImplementations are responsible for closing the connection.\n\nThe `TLSHandlerFunc` type is an adapter to allow the use of ordinary functions as a `TLSHandler`.\n\n```go\ncfg := \u0026tls.Config{\n    MinVersion: tls.VersionTLS13,\n    Certificates: []tls.Certificate{cert},\n}\n\nmux.Handle(\"foo.localhost\", tlsmux.TLSHandlerFunc(cfg, func(conn net.Conn) error {\n    defer conn.Close()\n\n    // Handle the decrypted TLS connection.\n}))\n```\n\n### ProxyHandler\n\nThe `ProxyHandler` struct is a `Handler` implementation forwarding the connection bytes to the configured `Address`.\nThe `ProxyHandlerFunc` is an adapter allowing the use of a `ProxyHandler` as a `HandlerFunc`.\n\n```go\n// Forward the encrypted connection bytes.\nmux.Handle(\"foo.localhost\", tlsmux.ProxyHandler{Addr: \"127.0.0.1:443\"})\n\n// Forward the decrypted connection bytes.\nmux.Handle(\"foo.localhost\", tlsmux.TLSHandlerFunc(tlsConfig, tlsmux.ProxyHandlerFunc(\"127.0.0.1:80\"))\n```\n\n## License\n\n[MIT](./LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinpollet%2Ftlsmux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinpollet%2Ftlsmux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinpollet%2Ftlsmux/lists"}