Skip to content

Commit 62ea12f

Browse files
committed
Use go-password for vnc instead of random numbers
It makes sure to use crypto/rand instead of math/rand. Also includes all the characters, and not just digits. Signed-off-by: Anders F Björklund <[email protected]>
1 parent f495817 commit 62ea12f

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/norouter/norouter v0.6.3
2929
github.com/nxadm/tail v1.4.8
3030
github.com/opencontainers/go-digest v1.0.0
31+
github.com/sethvargo/go-password v0.2.0
3132
github.com/sirupsen/logrus v1.9.0
3233
github.com/spf13/cobra v1.6.1
3334
github.com/xorcare/pointer v1.2.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
496496
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
497497
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
498498
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
499+
github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI=
500+
github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE=
499501
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
500502
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
501503
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=

pkg/hostagent/hostagent.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"errors"
88
"fmt"
99
"io"
10-
"math/rand"
1110
"net"
1211
"os"
1312
"os/exec"
@@ -33,6 +32,7 @@ import (
3332
"github.com/lima-vm/lima/pkg/store"
3433
"github.com/lima-vm/lima/pkg/store/filenames"
3534
"github.com/lima-vm/sshocker/pkg/ssh"
35+
"github.com/sethvargo/go-password/password"
3636
"github.com/sirupsen/logrus"
3737
)
3838

@@ -253,12 +253,8 @@ func (a *HostAgent) emitEvent(_ context.Context, ev events.Event) {
253253
}
254254

255255
func generatePassword(length int) (string, error) {
256-
passwd := ""
257-
rand.Seed(time.Now().UnixNano())
258-
for i := 0; i < length; i++ {
259-
passwd += strconv.Itoa(rand.Intn(10))
260-
}
261-
return passwd, nil
256+
// avoid any special symbols, to make it easier to copy/paste
257+
return password.Generate(length, length/4, 0, false, false)
262258
}
263259

264260
func (a *HostAgent) Run(ctx context.Context) error {

0 commit comments

Comments
 (0)