Skip to content

macOS password fields #15

@PrMinisterGR

Description

@PrMinisterGR

Hello,

Thank you for the work for this library.
I am trying to use it to enable FileVault in macOS and retrieve the FileVault key back. The issue I have is that whenever macOS uses obfuscated command prompts, the library does not seem able to send the text in a way that can be received as input.

This is a rough code example I am using to test the library:

// MacOSEnableFileVault enables FileVault for the support user and the newly
// added user and returns the key. It requires an admin user username and password.
func MacOSEnableFileVault(supportAccount, supportPassword, userToActivate, userToActivatePassword string) (fileVaultKey string, err error) {
c, err := expect.NewConsole(expect.WithStdout(os.Stdout))
if err != nil {
    return "", fmt.Errorf("Could not initialize new console while attempting to enable FileVault for users %s and %s. (Enable FileVault Error (0x01). %s", supportAccount, userToActivate, err)
}
defer c.Close()
cmd := exec.Command("/bin/bash", "-c", MacOSsudo+" -k -S "+MacOSfdesetup+" enable -user \""+supportAccount+"\" -usertoadd \""+userToActivate+"\" -password \""+supportPassword+"\"")
cmd.Stdin = c.Tty()
cmd.Stdout = c.Tty()
cmd.Stderr = c.Tty()
go func() {
    c.ExpectEOF()
}()
err = cmd.Start()
if err != nil {
return "", fmt.Errorf("Could not initialize new console while attempting to enable FileVault for users %s and %s. (Enable FileVault Error (0x02). %s", supportAccount, userToActivate, err)
}
time.Sleep(5 * time.Second)
c.Send(supportPassword + "\r")
time.Sleep(5 * time.Second)
c.Send(userToActivatePassword + "\r")
err = cmd.Wait()
if err != nil {
    return "", fmt.Errorf("Could not initialize new console while attempting to enable FileVault for users %s and %s. (Enable FileVault Error (0x03). %s", supportAccount, userToActivate, err)
}
return "", nil
}

As you can see, I still can't really figure out how to retrieve the FileVault key itself, but the real problem starts even before then.

With the code above, the first password (the one sent for sudo with the -k parameter), is sent properly and the program continues, but once FileVault prompts me for the password of the "standard" account (which is also "standard" for this example), this happens:
image

Also, ExpectString seems to be waiting for input forever, despite setting it in a very straightforward way with c.ExpectString("Password:")

All this is in Mojave 10.15.2.

Thanks again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions