From dcb4b50dbfc7a4752cc0b99fc9d9cb6c2687fe94 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 2 Feb 2017 04:03:46 -0800 Subject: [PATCH] Reduce character set for passwords At the beginning of each VMware build packer generates a random VNC password and prints it to the terminal / log. When copying a password from a terminal emulator with double-click, the text selection uses word boundaries to attempt to automatically detect where the password string is located. When the password contains weird characers like %^&# this parsing fails and you only get half the password. The reduction in characters does not significantly reduce the entropy of the password but improves user-friendliness when you actually want to use it. Also deletedsome unused files --- builder/vmware/common/step_configure_vnc.go | 2 +- .../vmware/common/step_configure_vnc.go.rej | 46 ------------------- .../common/step_type_boot_command.go.rej | 26 ----------- 3 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 builder/vmware/common/step_configure_vnc.go.rej delete mode 100644 builder/vmware/common/step_type_boot_command.go.rej diff --git a/builder/vmware/common/step_configure_vnc.go b/builder/vmware/common/step_configure_vnc.go index cfe1cfe56..bc65fc649 100644 --- a/builder/vmware/common/step_configure_vnc.go +++ b/builder/vmware/common/step_configure_vnc.go @@ -63,7 +63,7 @@ func VNCPassword(skipPassword bool) string { } length := int(8) - charSet := []byte("1234567890-=qwertyuiop[]asdfghjkl;zxcvbnm,./!@#%^*()_+QWERTYUIOP{}|ASDFGHJKL:XCVBNM<>?") + charSet := []byte("012345689abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") charSetLength := len(charSet) password := make([]byte, length) diff --git a/builder/vmware/common/step_configure_vnc.go.rej b/builder/vmware/common/step_configure_vnc.go.rej deleted file mode 100644 index 621d524fd..000000000 --- a/builder/vmware/common/step_configure_vnc.go.rej +++ /dev/null @@ -1,46 +0,0 @@ -diff a/builder/vmware/common/step_configure_vnc.go b/builder/vmware/common/step_configure_vnc.go (rejected hunks) -@@ -52,6 +52,21 @@ func (StepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint, error) - return "127.0.0.1", vncPort, nil - } - -+func VNCPassword() (string) { -+ length := int(8) -+ -+ charSet := []byte("1234567890-=qwertyuiop[]asdfghjkl;zxcvbnm,./!@#%^*()_+QWERTYUIOP{}|ASDFGHJKL:XCVBNM<>?") -+ charSetLength := len(charSet) -+ -+ password := make([]byte, length) -+ -+ for i := 0; i < length; i++ { -+ password[i] = charSet[ rand.Intn(charSetLength) ] -+ } -+ -+ return string(password) -+} -+ - func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction { - driver := state.Get("driver").(Driver) - ui := state.Get("ui").(packer.Ui) -@@ -86,12 +101,14 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction { - ui.Error(err.Error()) - return multistep.ActionHalt - } -+ vncPassword := VNCPassword() - - log.Printf("Found available VNC port: %d", vncPort) - - vmxData := ParseVMX(string(vmxBytes)) - vmxData["remotedisplay.vnc.enabled"] = "TRUE" - vmxData["remotedisplay.vnc.port"] = fmt.Sprintf("%d", vncPort) -+ vmxData["remotedisplay.vnc.password"] = vncPassword - - if err := WriteVMX(vmxPath, vmxData); err != nil { - err := fmt.Errorf("Error writing VMX data: %s", err) -@@ -102,6 +119,7 @@ func (s *StepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction { - - state.Put("vnc_port", vncPort) - state.Put("vnc_ip", vncIp) -+ state.Put("vnc_password", vncPassword) - - return multistep.ActionContinue - } diff --git a/builder/vmware/common/step_type_boot_command.go.rej b/builder/vmware/common/step_type_boot_command.go.rej deleted file mode 100644 index ee084c6bb..000000000 --- a/builder/vmware/common/step_type_boot_command.go.rej +++ /dev/null @@ -1,26 +0,0 @@ -diff a/builder/vmware/common/step_type_boot_command.go b/builder/vmware/common/step_type_boot_command.go (rejected hunks) -@@ -45,6 +45,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction - ui := state.Get("ui").(packer.Ui) - vncIp := state.Get("vnc_ip").(string) - vncPort := state.Get("vnc_port").(uint) -+ vncPassword := state.Get("vnc_password") - - // Connect to VNC - ui.Say("Connecting to VM via VNC") -@@ -57,7 +58,15 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction - } - defer nc.Close() - -- c, err := vnc.Client(nc, &vnc.ClientConfig{Exclusive: true}) -+ var auth []vnc.ClientAuth -+ -+ if vncPassword != nil { -+ auth = []vnc.ClientAuth{&vnc.PasswordAuth{Password: vncPassword.(string)}} -+ } else { -+ auth = []vnc.ClientAuth{} -+ } -+ -+ c, err := vnc.Client(nc, &vnc.ClientConfig{Auth: auth, Exclusive: true}) - if err != nil { - err := fmt.Errorf("Error handshaking with VNC: %s", err) - state.Put("error", err)