1

I am writing a bash file to automate a process. For this I created a new password-encrypted key using:

openssl ecparam -genkey -name secp256k1 | openssl ec -out key-file.pem -aes128 -passout: pass:foobar 

It works perfectly with the password being foobar. Eventually I am using the following command in my scirpt:

seth account create --nonce=0 --wait keyAliasName 

and on CMD it says:

Enter passphrase to unlock keyAliasName.

I tried:

echo foobar | seth account create --nonce=0 --wait keyAliasName 

but that says:

ERROR: ERROR Reading the passphrase.

How to solve this error? Thanks!

Rene Knop
  • 1,788
  • 3
  • 15
  • 27

2 Answers2

1

I think your problem is more related to a topic like: How to input automatically in bash, like discussed e.g. in this thread.

You are trying to input the password foobar to seth with the following line (right?):

echo foobar | seth account create --nonce=0 --wait keyAliasName 

But seth prompts "Enter passphrase to unlock keyAliasName" and then wants to read the passphrase as user input.

So what you can do, is to use an expect script:

#!/usr/bin/expect
spawn ./your_script.sh
expect "Enter passphrase to unlock keyAliasNam"
send "foobar\n"
interact
Rene Knop
  • 1,788
  • 3
  • 15
  • 27
0

The expect approach might work, if you have it available in your environment. This answer expands on the cause of your issue. That seems to be the way the ReadPassword() function in Go's x/crypto/ssh/terminal is implemented.

Others have run into it as well: it is reported as an issue with Go that was still active a few weeks ago: x/crypto/ssh/terminal: ReadPassword doesn't work on redirected stdin giving inappropriate ioctl for device #19909. It includes a simple reproducer, in the section "What did you do?".

For a native bash approach, there does not seem to be any workaround for it at the moment, other than modifying the sawtooth-seth code in the getPassword() function to follow the approach mentioned here.

P.S.: it would have been easier to figure out the problem if you had provided the exact error output: Error reading password as opposed to ERROR Reading the passphrase.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69