Skip to content

Commit

Permalink
Change API response proxy_protocol to string
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Aug 24, 2024
1 parent f8ba299 commit 9180d4b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type AuthUpstream struct {
PrivateKey string `json:"private_key,omitempty"`
Certificate string `json:"certificate,omitempty"`
Password *string `json:"password,omitempty"`
ProxyProtocol byte `json:"proxy_protocol,omitempty"`
ProxyProtocol *string `json:"proxy_protocol,omitempty"`
}

type Authenticator interface {
Expand Down
15 changes: 9 additions & 6 deletions legacy_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,20 @@ func (auth *LegacyAuthenticator) Auth(request AuthRequest, username string) (int
return 500, nil, err
}
auth_upstream := AuthUpstream{
Host: address.Addr().String(),
Port: address.Port(),
PrivateKey: upstream.PrivateKey,
Certificate: upstream.Certificate,
Password: upstream.Password,
ProxyProtocol: upstream.ProxyProtocol,
Host: address.Addr().String(),
Port: address.Port(),
PrivateKey: upstream.PrivateKey,
Certificate: upstream.Certificate,
Password: upstream.Password,
}
unix_password, has_unix_password := request.Payload["unix_password"]
if has_unix_password {
auth_upstream.Password = &unix_password
}
if upstream.ProxyProtocol > 0 {
proxyProtocol := fmt.Sprintf("v%d", upstream.ProxyProtocol)
auth_upstream.ProxyProtocol = &proxyProtocol
}
resp := AuthResponse{Upstream: &auth_upstream}
return 200, &resp, nil
}
Expand Down
17 changes: 13 additions & 4 deletions sshmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,19 @@ auth_requests:
upstreamResp.Port = 22
}
upstream = &UpstreamInformation{
Host: netip.AddrPortFrom(host, upstreamResp.Port).String(),
Signer: parsePrivateKey(upstreamResp.PrivateKey, upstreamResp.Certificate),
Password: upstreamResp.Password,
ProxyProtocol: upstreamResp.ProxyProtocol,
Host: netip.AddrPortFrom(host, upstreamResp.Port).String(),
Signer: parsePrivateKey(upstreamResp.PrivateKey, upstreamResp.Certificate),
Password: upstreamResp.Password,
}
if upstreamResp.ProxyProtocol != nil {
switch *upstreamResp.ProxyProtocol {
case "v1":
upstream.ProxyProtocol = 1
case "v2":
upstream.ProxyProtocol = 2
default:
return fmt.Errorf("unknown PROXY protocol version: %s", *upstreamResp.ProxyProtocol)
}
}
break auth_requests
case 401:
Expand Down
3 changes: 2 additions & 1 deletion sshmux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ func initHttp(sshPrivateKey []byte) {
PrivateKey: string(sshPrivateKey),
}
if enableProxy {
proxyProtocol := "v2"
upstream.Host = sshdProxiedAddr.IP.String()
upstream.Port = uint16(sshdProxiedAddr.Port)
upstream.ProxyProtocol = 2
upstream.ProxyProtocol = &proxyProtocol
} else {
upstream.Host = sshdServerAddr.IP.String()
upstream.Port = uint16(sshdServerAddr.Port)
Expand Down

0 comments on commit 9180d4b

Please sign in to comment.