Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS password fields #15

Open
PrMinisterGR opened this issue Feb 13, 2020 · 0 comments
Open

macOS password fields #15

PrMinisterGR opened this issue Feb 13, 2020 · 0 comments

Comments

@PrMinisterGR
Copy link

PrMinisterGR commented Feb 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant