Merge pull request #119 from docker/abridge-key-ids

Abridge key ids on print, warn about key generation
This commit is contained in:
Diogo Mónica 2015-07-22 18:44:58 -07:00
commit e335489b01
1 changed files with 11 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import (
"strings" "strings"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
"path/filepath"
) )
// Retriever is a callback function that should retrieve a passphrase // Retriever is a callback function that should retrieve a passphrase
@ -19,13 +20,15 @@ import (
type Retriever func(keyName, alias string, createNew bool, attempts int) (passphrase string, giveup bool, err error) type Retriever func(keyName, alias string, createNew bool, attempts int) (passphrase string, giveup bool, err error)
const ( const (
idBytesToDisplay = 5
tufRootAlias = "root" tufRootAlias = "root"
tufTargetsAlias = "targets" tufTargetsAlias = "targets"
tufSnapshotAlias = "snapshot" tufSnapshotAlias = "snapshot"
tufRootKeyGenerationWarning = `You are about to create a new root signing key passphrase. This passphrase will be used to protect tufRootKeyGenerationWarning = `You are about to create a new root signing key passphrase. This passphrase will be used to protect
the most sensitive key in your signing system. Please choose a long, complex passphrase and be careful the most sensitive key in your signing system. Please choose a long, complex passphrase and be careful
to keep it secure and backed up. It is highly recommended that you use a password manager to both generate it to keep the password and the key file itself secure and backed up. It is highly recommended that you use
and keep it safe. There will be no way to recover this key.` a password manager to generate the passphrase and keep it safe. There will be no way to recover this key.
You can find the key in your config directiory.`
) )
// PromptRetriever returns a new Retriever which will provide a terminal prompt // PromptRetriever returns a new Retriever which will provide a terminal prompt
@ -73,6 +76,12 @@ func PromptRetriever() Retriever {
stdin := bufio.NewReader(os.Stdin) stdin := bufio.NewReader(os.Stdin)
indexOfLastSeparator := strings.LastIndex(keyName, string(filepath.Separator))
if len(keyName) > indexOfLastSeparator+idBytesToDisplay+1 {
keyName = keyName[:indexOfLastSeparator+idBytesToDisplay+1]
}
if createNew { if createNew {
fmt.Printf("Enter passphrase for new %s key with id %s: ", alias, keyName) fmt.Printf("Enter passphrase for new %s key with id %s: ", alias, keyName)
} else { } else {