From bc939bdf1f76fb00265a004cf42694d83fe9908f Mon Sep 17 00:00:00 2001 From: Nathan McCauley Date: Mon, 20 Jul 2015 01:39:19 -0700 Subject: [PATCH] basic caching of root password for notary cli Signed-off-by: Nathan McCauley --- cmd/notary/tuf.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/notary/tuf.go b/cmd/notary/tuf.go index b13fd6f374..a393ae0eba 100644 --- a/cmd/notary/tuf.go +++ b/cmd/notary/tuf.go @@ -275,13 +275,21 @@ func verify(cmd *cobra.Command, args []string) { func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever { userEnteredTargetsSnapshotsPass := false targetsSnapshotsPass := "" + userEnteredRootsPass := false + rootsPass := "" return func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) { - if numAttempts == 0 && userEnteredTargetsSnapshotsPass && (alias == "snapshot" || alias == "targets") { - fmt.Println("return cached value") - return targetsSnapshotsPass, false, nil + // First, check if we have a password cached for this alias. + if numAttempts == 0 { + if userEnteredTargetsSnapshotsPass && (alias == "snapshot" || alias == "targets") { + return targetsSnapshotsPass, false, nil + } + if userEnteredRootsPass && (alias == "root") { + return rootsPass, false, nil + } } + if numAttempts > 3 && !createNew { return "", true, errors.New("Too many attempts") } @@ -314,6 +322,10 @@ func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever { userEnteredTargetsSnapshotsPass = true targetsSnapshotsPass = retPass } + if alias == "root" { + userEnteredRootsPass = true + rootsPass = retPass + } return string(passphrase), false, nil } @@ -335,10 +347,14 @@ func getNotaryPassphraseRetriever() trustmanager.PassphraseRetriever { } retPass := string(passphrase) - if alias == "snapshots" || alias == "targets" { + if alias == "snapshot" || alias == "targets" { userEnteredTargetsSnapshotsPass = true targetsSnapshotsPass = retPass } + if alias == "root" { + userEnteredRootsPass = true + rootsPass = retPass + } return retPass, false, nil }