Skip to content

Commit

Permalink
support WHISPER_DTM_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmood committed Nov 1, 2024
1 parent c2501d6 commit 30225e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
6 changes: 4 additions & 2 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"os"
)

var WHISPER_DEFAULT_KEY_PATH = os.Getenv("WHISPER_DEFAULT_KEY_PATH")
var WHISPER_KEY_PATH = os.Getenv("WHISPER_KEY_PATH")

var WHISPER_DEFAULT_KEY = os.Getenv("WHISPER_DEFAULT_KEY")
var WHISPER_KEY = os.Getenv("WHISPER_KEY")

var WHISPER_DTM_KEY = os.Getenv("WHISPER_DTM_KEY")

var WHISPER_PASSPHRASE = os.Getenv("WHISPER_PASSPHRASE")

Expand Down
33 changes: 24 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func main() { //nolint: funlen,gocyclo,cyclop
WHISPER_AGENT_ADDR = WHISPER_AGENT_ADDR_DEFAULT
}

privateKey := flags.String("p", WHISPER_DEFAULT_KEY_PATH, "Private key path to decrypt data.\n"+
"Use env var WHISPER_DEFAULT_KEY to set the default key data.\n"+
"Use env var WHISPER_DEFAULT_KEY_PATH to set the default key path.\n"+
privateKey := flags.String("p", WHISPER_KEY_PATH, "Private key path to decrypt data.\n"+
"Use env var WHISPER_KEY to set the default key data.\n"+
"Use env var WHISPER_DTM_KEY to set the seed for the deterministic key date.\n"+
"Use env var WHISPER_KEY_PATH to set the default key path.\n"+
"If it's empty a key in ~/.ssh will be auto selected.\n"+
"If it requires a passphrase, env var WHISPER_PASSPHRASE will be used or a password cli prompt will show up.\n"+
"The file path should always use / as the separator, even on Windows.")
Expand Down Expand Up @@ -193,13 +194,27 @@ func getPrivate(decrypt bool, sign bool, location string, meta *whisper.Meta) *w
return nil
}

if location == "" && WHISPER_DEFAULT_KEY != "" {
private := whisper.PrivateKey{
Data: []byte(WHISPER_DEFAULT_KEY),
Passphrase: WHISPER_PASSPHRASE,
if location == "" {
if WHISPER_DTM_KEY != "" {
key, _, err := secure.GenerateKeyFile(true, "", WHISPER_DTM_KEY)
if err != nil {
exit(err)
}

return &whisper.PrivateKey{
Data: key,
Passphrase: WHISPER_DTM_KEY,
}
}

return ensurePassphrase(private, location)
if WHISPER_KEY != "" {
private := whisper.PrivateKey{
Data: []byte(WHISPER_KEY),
Passphrase: WHISPER_PASSPHRASE,
}

return ensurePassphrase(private, location)
}
}

if location == "" && decrypt {
Expand Down Expand Up @@ -255,7 +270,7 @@ func findPrivateKey(meta *whisper.Meta) string {
return p
}

return WHISPER_DEFAULT_KEY_PATH
return WHISPER_KEY_PATH
}

func getPublicKeys(paths []string) []whisper.PublicKey {
Expand Down

0 comments on commit 30225e1

Please sign in to comment.