-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
tls: Add alpn to managed HTTPS records #7653
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
Open
steadytao
wants to merge
4
commits into
master
Choose a base branch
from
feat-https-rr-alpn
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aacb430
tls: add alpn to managed HTTPS records
steadytao 904f9fd
tls: centralise HTTPS RR ALPN defaults and registration
steadytao 710902d
http: centralise effective protocol resolution for HTTPS RR ALPN
steadytao fd34f9c
Merge branch 'master' into feat-https-rr-alpn
steadytao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,47 @@ | ||
| package caddyhttp | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/caddyserver/caddy/v2" | ||
| ) | ||
|
|
||
| func TestRecordAutoHTTPSRedirectAddressPrefersHTTPSPort(t *testing.T) { | ||
| app := &App{HTTPSPort: 443} | ||
| redirDomains := make(map[string][]caddy.NetworkAddress) | ||
| func TestHTTPSRRALPNsDefaultProtocols(t *testing.T) { | ||
| srv := &Server{} | ||
|
|
||
| app.recordAutoHTTPSRedirectAddress(redirDomains, "example.com", caddy.NetworkAddress{Network: "tcp", StartPort: 2345, EndPort: 2345}) | ||
| app.recordAutoHTTPSRedirectAddress(redirDomains, "example.com", caddy.NetworkAddress{Network: "tcp", StartPort: 443, EndPort: 443}) | ||
| app.recordAutoHTTPSRedirectAddress(redirDomains, "example.com", caddy.NetworkAddress{Network: "tcp", StartPort: 8443, EndPort: 8443}) | ||
| got := httpsRRALPNs(srv) | ||
| want := []string{"h3", "h2", "http/1.1"} | ||
|
|
||
| got := redirDomains["example.com"] | ||
| if len(got) != 1 { | ||
| t.Fatalf("expected 1 redirect address, got %d: %#v", len(got), got) | ||
| } | ||
| if got[0].StartPort != 443 { | ||
| t.Fatalf("expected redirect to prefer HTTPS port 443, got %#v", got[0]) | ||
| if !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("unexpected ALPN values: got %v want %v", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestRecordAutoHTTPSRedirectAddressKeepsAllBindAddressesOnWinningPort(t *testing.T) { | ||
| app := &App{HTTPSPort: 443} | ||
| redirDomains := make(map[string][]caddy.NetworkAddress) | ||
| func TestHTTPSRRALPNsListenProtocolOverrides(t *testing.T) { | ||
| srv := &Server{ | ||
| Protocols: []string{"h1", "h2"}, | ||
| ListenProtocols: [][]string{ | ||
| {"h1"}, | ||
| nil, | ||
| {}, | ||
| {"h3", ""}, | ||
| }, | ||
| } | ||
|
|
||
| app.recordAutoHTTPSRedirectAddress(redirDomains, "example.com", caddy.NetworkAddress{Network: "tcp", Host: "10.0.0.189", StartPort: 8443, EndPort: 8443}) | ||
| app.recordAutoHTTPSRedirectAddress(redirDomains, "example.com", caddy.NetworkAddress{Network: "tcp", Host: "10.0.0.189", StartPort: 443, EndPort: 443}) | ||
| app.recordAutoHTTPSRedirectAddress(redirDomains, "example.com", caddy.NetworkAddress{Network: "tcp", Host: "2603:c024:8002:9500:9eb:e5d3:3975:d056", StartPort: 443, EndPort: 443}) | ||
| got := httpsRRALPNs(srv) | ||
| want := []string{"h3", "h2", "http/1.1"} | ||
|
|
||
| got := redirDomains["example.com"] | ||
| if len(got) != 2 { | ||
| t.Fatalf("expected 2 redirect addresses for both bind addresses on the winning port, got %d: %#v", len(got), got) | ||
| if !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("unexpected ALPN values: got %v want %v", got, want) | ||
| } | ||
| if got[0].StartPort != 443 || got[1].StartPort != 443 { | ||
| t.Fatalf("expected both redirect addresses to stay on HTTPS port 443, got %#v", got) | ||
| } | ||
|
|
||
| func TestHTTPSRRALPNsIgnoresH2COnly(t *testing.T) { | ||
| srv := &Server{ | ||
| Protocols: []string{"h2c"}, | ||
| } | ||
| if got[0].Host != "10.0.0.189" || got[1].Host != "2603:c024:8002:9500:9eb:e5d3:3975:d056" { | ||
| t.Fatalf("expected both bind addresses to be preserved, got %#v", got) | ||
|
|
||
| got := httpsRRALPNs(srv) | ||
| if len(got) != 0 { | ||
| t.Fatalf("unexpected ALPN values: got %v want none", got) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package caddytls | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "reflect" | ||
| "sync" | ||
| "testing" | ||
|
|
||
| "github.com/libdns/libdns" | ||
| ) | ||
|
|
||
| func TestRegisterServerNamesWithALPN(t *testing.T) { | ||
| tlsApp := &TLS{ | ||
| serverNames: make(map[string]serverNameRegistration), | ||
| serverNamesMu: new(sync.Mutex), | ||
| } | ||
|
|
||
| tlsApp.RegisterServerNames([]string{ | ||
| "Example.com:443", | ||
| "example.com", | ||
| "127.0.0.1:443", | ||
| }, []string{"h2", "http/1.1"}) | ||
| tlsApp.RegisterServerNames([]string{"EXAMPLE.COM"}, []string{"h3"}) | ||
|
|
||
| got := tlsApp.alpnValuesForServerNames([]string{"example.com:443", "127.0.0.1:443"}) | ||
| want := map[string][]string{ | ||
| "example.com": {"h3", "h2", "http/1.1"}, | ||
| } | ||
|
|
||
| if !reflect.DeepEqual(got, want) { | ||
| t.Fatalf("unexpected ALPN values: got %#v want %#v", got, want) | ||
| } | ||
| } | ||
|
|
||
| func TestECHDNSPublisherPublishedSvcParams(t *testing.T) { | ||
| dnsPub := &ECHDNSPublisher{ | ||
| alpnByDomain: map[string][]string{ | ||
| "example.com": {"h3", "h2", "http/1.1"}, | ||
| }, | ||
| } | ||
|
|
||
| existing := libdns.SvcParams{ | ||
| "alpn": {"h2"}, | ||
| "ipv4hint": {"203.0.113.10"}, | ||
| } | ||
|
|
||
| got := dnsPub.publishedSvcParams("Example.com", existing, []byte{0x01, 0x02, 0x03}) | ||
|
|
||
| if !reflect.DeepEqual(existing["alpn"], []string{"h2"}) { | ||
| t.Fatalf("existing params mutated: got %v", existing["alpn"]) | ||
| } | ||
|
|
||
| if !reflect.DeepEqual(got["alpn"], []string{"h3", "h2", "http/1.1"}) { | ||
| t.Fatalf("unexpected ALPN params: got %v", got["alpn"]) | ||
| } | ||
|
|
||
| if !reflect.DeepEqual(got["ipv4hint"], []string{"203.0.113.10"}) { | ||
| t.Fatalf("unexpected preserved params: got %v", got["ipv4hint"]) | ||
| } | ||
|
|
||
| wantECH := base64.StdEncoding.EncodeToString([]byte{0x01, 0x02, 0x03}) | ||
| if !reflect.DeepEqual(got["ech"], []string{wantECH}) { | ||
| t.Fatalf("unexpected ECH params: got %v want %v", got["ech"], wantECH) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.