Skip to content

Commit

Permalink
Add password to client
Browse files Browse the repository at this point in the history
Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com>
  • Loading branch information
hwipl committed May 10, 2023
1 parent 5bfe067 commit c428b08
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func authenticateVPN() *ocrunner.LoginInfo {
auth.Script = vpncScript
auth.Server = config.VPNServer
auth.User = config.User
auth.Password = config.Password
auth.Authenticate()

return &auth.Login
Expand Down
4 changes: 3 additions & 1 deletion internal/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ClientConfig struct {
CACertificate string
VPNServer string
User string
Password string
}

// empty returns if the config is empty
Expand All @@ -24,7 +25,8 @@ func (o *ClientConfig) empty() bool {
o.ClientKey == "" &&
o.CACertificate == "" &&
o.VPNServer == "" &&
o.User == "" {
o.User == "" &&
o.Password == "" {
// empty
return true
}
Expand Down
1 change: 1 addition & 0 deletions internal/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestLoadClientConfig(t *testing.T) {
CACertificate: "/some/ca",
VPNServer: "server.example.com",
User: "user1",
Password: "passwd1",
}

// create temporary file
Expand Down
9 changes: 9 additions & 0 deletions internal/ocrunner/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Authenticate struct {
Script string
Server string
User string
Password string

Command *exec.Cmd
Login LoginInfo
Expand Down Expand Up @@ -67,13 +68,21 @@ func (r *Authenticate) Authenticate() {
if r.User != "" {
parameters = append(parameters, user)
}
if r.Password != "" {
// read password from stdin and switch to non-interactive mode
parameters = append(parameters, "--passwd-on-stdin")
parameters = append(parameters, "--non-inter")
}
parameters = append(parameters, r.Server)

r.Command = exec.Command("openconnect", parameters...)

// run command: allow user input, show stderr, buffer stdout
var b bytes.Buffer
r.Command.Stdin = os.Stdin
if r.Password != "" {
r.Command.Stdin = bytes.NewBufferString(r.Password)
}
r.Command.Stdout = &b
r.Command.Stderr = os.Stderr
r.Command.Env = append(os.Environ(), r.Env...)
Expand Down

0 comments on commit c428b08

Please sign in to comment.