Skip to content

Commit

Permalink
use build tags to make password auth available or not
Browse files Browse the repository at this point in the history
  • Loading branch information
francoismichel committed Dec 21, 2023
1 parent 1bf6a65 commit 79bae80
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ jobs:
env:
GOOS: ${{matrix.goos}}
GOARCH: ${{matrix.goarch}}
GO_TAGS: disable_password_auth
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GOOS?=linux
BUILDFLAGS ?=-ldflags "-X main.version=$(shell git describe --tags --always --dirty) -X main.buildDate=$(shell date +%Y-%m-%d)"

GO_OPTS?=CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS)
GO_TAGS?=
TEST_OPTS?=-v GOOS=$(GOOS) GOARCH=$(GOARCH)

lint:
Expand Down Expand Up @@ -33,7 +34,7 @@ install:
build: client server

client:
$(GO_OPTS) go build $(BUILD_FLAGS) -o bin/client ./cmd/ssh3/
$(GO_OPTS) go build -tags "$(GO_TAGS)" $(BUILD_FLAGS) -o bin/client ./cmd/ssh3/

server:
$(GO_OPTS) go build $(BUILD_FLAGS) -o bin/server ./cmd/ssh3-server/
$(GO_OPTS) go build -tags "$(GO_TAGS)" $(BUILD_FLAGS) -o bin/server ./cmd/ssh3-server/
11 changes: 7 additions & 4 deletions cmd/ssh3-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,19 @@ func fileExists(path string) bool {
func main() {
bindAddr := flag.String("bind", "[::]:443", "the address:port pair to listen to, e.g. 0.0.0.0:443")
verbose := flag.Bool("v", false, "verbose mode, if set")
enablePasswordLogin := flag.Bool("enable-password-login", false, "if set, enable password authentication (disabled by default)")
urlPath := flag.String("url-path", "/ssh3-term", "the secret URL path on which the ssh3 server listens")
generateSelfSignedCert := flag.Bool("generate-selfsigned-cert", false, "if set, generates a self-self-signed cerificate and key "+
"that will be stored at the paths indicated by the -cert and -key args (they must not already exist)")
certPath := flag.String("cert", "./cert.pem", "the filename of the server certificate (or fullchain)")
keyPath := flag.String("key", "./priv.key", "the filename of the certificate private key")
enablePasswordLogin := false
if unix_util.PasswordAuthAvailable() {
flag.BoolVar(&enablePasswordLogin, "enable-password-login", false, "if set, enable password authentication (disabled by default)")
}
flag.Parse()

if !*enablePasswordLogin {
fmt.Fprintln(os.Stderr, "password login is currently disabled")
if !enablePasswordLogin {
fmt.Fprintln(os.Stderr, "password login is disabled")
}

certPathExists := fileExists(*certPath)
Expand Down Expand Up @@ -847,7 +850,7 @@ func main() {
}
})
ssh3Handler := ssh3Server.GetHTTPHandlerFunc(context.Background())
handler, err := unix_server.HandleAuths(context.Background(), *enablePasswordLogin, 30000, ssh3Handler)
handler, err := unix_server.HandleAuths(context.Background(), enablePasswordLogin, 30000, ssh3Handler)
if err != nil {
log.Error().Msgf("Could not get authentication handlers: %s", err)
return
Expand Down
4 changes: 4 additions & 0 deletions util/unix_util/linux_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,7 @@ func getpwnam(name string) (*User, error) {

return &s, nil
}

func passwordAuthAvailable() bool {
return true
}
4 changes: 4 additions & 0 deletions util/unix_util/non_password_auth_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ func getUser(username string) (*User, error) {
func userPasswordAuthentication(username, password string) (bool, error) {
return false, fmt.Errorf("password-based authentication is not implemented on %s/%s systems", runtime.GOOS, runtime.GOARCH)
}

func passwordAuthAvailable() bool {
return false
}
4 changes: 4 additions & 0 deletions util/unix_util/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ func (u *User) CreateCommandPipeOutput(addEnv string, loginShell bool, command s
func UserPasswordAuthentication(username, password string) (bool, error) {
return userPasswordAuthentication(username, password)
}

func PasswordAuthAvailable() bool {
return passwordAuthAvailable()
}

0 comments on commit 79bae80

Please sign in to comment.