gokyle / readpass

read passwords from the console safely
ISC License
6 stars 2 forks source link

Cross-Compiling? #1

Closed elithrar closed 10 years ago

elithrar commented 10 years ago

From what I understand, it's not possible to cross-compile readpass as per this issue: https://code.google.com/p/go/issues/detail?id=4714 — but it's a bit of a rabbit hole.

I'm getting the following error:

~ GOOS=linux go build -o project-linux github.com/elithrar/project
\# github.com/gokyle/readpass/readpass
../../gokyle/readpass/readpass/noecho.c:20 6c: No such file or directory: stdio.h

Is there an alternative solution?

kisom commented 10 years ago

I don't have a good alternative for this. I've been researching this for a while, and unfortunately there isn't a solution where I get to keep the cgo parts and the ability to cross-compile. Trying to rewrite readpass in pure Go has similarly led nowhere. If it's not the secure password entry you need (i.e. if the DefaultPasswordPrompt echoing prompt works), I could probably set up some build flags, though.

elithrar commented 10 years ago

After I posted did, I did some more digging and short of building a full GCC cross-compiling environment on OS X (documented, but not straightforward) I came to the same conclusion you did: it's not immediately possible. It also makes deployment a bit more of a pain.

I ended up wrapping http://godoc.org/code.google.com/p/go.crypto/ssh/terminal#ReadPassword — which does not use cgo—and appears to work on OS X, Linux and DragonflyBSD if the build flags are correct.

A fair bit clunkier than your package here, but it worked well enough.

        state, err := terminal.MakeRaw(0)
        if err != nil {
            log.Fatal(err)
        }
        defer terminal.Restore(0, state)
        term := terminal.NewTerminal(os.Stdout, ">")
        password, err := term.ReadPassword("Enter password: ")
        if err != nil {
            log.Fatal(err)
        }

Thanks for the reply anyway Kyle—appreciated.

kisom commented 10 years ago

Thanks for the lead; once I test to make sure this works on OpenBSD (the other platform I use this a lot), I'll try to change readpass to use that. This will make my life a lot easier, thanks!