Skip to content

Commit

Permalink
reverse_proxy http Add tls_curves directive
Browse files Browse the repository at this point in the history
Example Caddyfile

    localhost {
        reverse_proxy https://example.com {
            transport http {
                tls_curves secp521r1
            }
        }
    }
  • Loading branch information
bwesterb committed Oct 3, 2023
1 parent 82c356f commit 730ffe8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/caddyhttp/reverseproxy/caddyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,16 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
h.TLS.InsecureSkipVerify = true

case "tls_curves":
args := d.RemainingArgs()
if len(args) == 0 {
return d.ArgErr()
}
if h.TLS == nil {
h.TLS = new(TLSConfig)
}
h.TLS.Curves = args

case "tls_timeout":
if !d.NextArg() {
return d.ArgErr()
Expand Down
13 changes: 13 additions & 0 deletions modules/caddyhttp/reverseproxy/httptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ type TLSConfig struct {
// When specified, TLS will automatically be configured on the transport.
// The value can be a list of any valid tcp port numbers, default empty.
ExceptPorts []string `json:"except_ports,omitempty"`

// The list of elliptic curves to support. Caddy's
// defaults are modern and secure.
Curves []string `json:"curves,omitempty"`
}

// MakeTLSClientConfig returns a tls.Config usable by a client to a backend.
Expand Down Expand Up @@ -581,6 +585,15 @@ func (t TLSConfig) MakeTLSClientConfig(ctx caddy.Context) (*tls.Config, error) {
// throw all security out the window
cfg.InsecureSkipVerify = t.InsecureSkipVerify

curvesAdded := make(map[tls.CurveID]struct{})
for _, curveName := range t.Curves {
curveID := caddytls.SupportedCurves[curveName]
if _, ok := curvesAdded[curveID]; !ok {
curvesAdded[curveID] = struct{}{}
cfg.CurvePreferences = append(cfg.CurvePreferences, curveID)
}
}

// only return a config if it's not empty
if reflect.DeepEqual(cfg, new(tls.Config)) {
return nil, nil
Expand Down

0 comments on commit 730ffe8

Please sign in to comment.