Skip to content

crypto/tls: support different protocols for different server names #17666

Description

@nhooyr

I've written a server that accepts a TLS connection, connects to a address based on the TLS connections server name and ALPN proto, and then copies all data between the two connections.
https://github.com/nhooyr/tlsmuxd

The problem that I am having is for the following configuration:

{
    "email": "user@example.com",
    "cacheDir": "/var/lib/tlsmuxd",
    "protos": [{
        "name": "h2",
        "hosts": {
            "example.com": "localhost:8080",
            "www.example.com": "localhost:8080",
        }
    }, {
        "name": "http/1.1",
        "hosts": {
            "example.com": "localhost:8083",
            "www.example.com": "localhost:8083",
            "example2.com": "localhost:8084",
            "www.example2.com": "localhost:8084"
        }
    }],
    "defaultProto": "http/1.1"
}

Now say a user connects to my server with their ALPN protos as ["h2", "http/1.1"] and server name as "example2.com". According to the above configuration, a connection to localhost:8084 should be made and then all data between the user and localhost:8084 connections should be copied. The problem is that crypto/tls does not allow for dynamic ALPN. So the "h2" protocol will always be selected and then the user will be disconnected because "example2.com" does not exist for "h2".

So I'd like is to be able to offer different protocols for different server names instead of having it static. This isn't a severe problem for me because since I use Go, I'll always be able to serve both "http/1.1" and "h2". However, it feels ugly because say I have the "ssh" protocol defined (I tunnel SSH through TLS when I need to get around a strict network) for "example.com", then if someone connects with Server Name as "example2.com", even though my server cannot actually serve it SSH, it still advertises it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions