|
@@ -13,6 +13,7 @@ import (
|
|
"os"
|
|
"os"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"regexp"
|
|
"regexp"
|
|
|
|
+ "sort"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -176,11 +177,16 @@ func convertTarget(t client.Target) (target, error) {
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *DockerCli) getPassphraseRetriever() passphrase.Retriever {
|
|
func (cli *DockerCli) getPassphraseRetriever() passphrase.Retriever {
|
|
- baseRetriever := passphrase.PromptRetrieverWithInOut(cli.in, cli.out)
|
|
|
|
|
|
+ aliasMap := map[string]string{
|
|
|
|
+ "root": "offline",
|
|
|
|
+ "snapshot": "tagging",
|
|
|
|
+ "targets": "tagging",
|
|
|
|
+ }
|
|
|
|
+ baseRetriever := passphrase.PromptRetrieverWithInOut(cli.in, cli.out, aliasMap)
|
|
env := map[string]string{
|
|
env := map[string]string{
|
|
- "root": os.Getenv("DOCKER_CONTENT_TRUST_ROOT_PASSPHRASE"),
|
|
|
|
- "targets": os.Getenv("DOCKER_CONTENT_TRUST_TARGET_PASSPHRASE"),
|
|
|
|
- "snapshot": os.Getenv("DOCKER_CONTENT_TRUST_SNAPSHOT_PASSPHRASE"),
|
|
|
|
|
|
+ "root": os.Getenv("DOCKER_CONTENT_TRUST_OFFLINE_PASSPHRASE"),
|
|
|
|
+ "snapshot": os.Getenv("DOCKER_CONTENT_TRUST_TAGGING_PASSPHRASE"),
|
|
|
|
+ "targets": os.Getenv("DOCKER_CONTENT_TRUST_TAGGING_PASSPHRASE"),
|
|
}
|
|
}
|
|
return func(keyName string, alias string, createNew bool, numAttempts int) (string, bool, error) {
|
|
return func(keyName string, alias string, createNew bool, numAttempts int) (string, bool, error) {
|
|
if v := env[alias]; v != "" {
|
|
if v := env[alias]; v != "" {
|
|
@@ -311,6 +317,22 @@ func (cli *DockerCli) trustedPull(repoInfo *registry.RepositoryInfo, ref registr
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func selectKey(keys map[string]string) string {
|
|
|
|
+ if len(keys) == 0 {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ keyIDs := []string{}
|
|
|
|
+ for k := range keys {
|
|
|
|
+ keyIDs = append(keyIDs, k)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO(dmcgowan): let user choose if multiple keys, now pick consistently
|
|
|
|
+ sort.Strings(keyIDs)
|
|
|
|
+
|
|
|
|
+ return keyIDs[0]
|
|
|
|
+}
|
|
|
|
+
|
|
func targetStream(in io.Writer) (io.WriteCloser, <-chan []target) {
|
|
func targetStream(in io.Writer) (io.WriteCloser, <-chan []target) {
|
|
r, w := io.Pipe()
|
|
r, w := io.Pipe()
|
|
out := io.MultiWriter(in, w)
|
|
out := io.MultiWriter(in, w)
|
|
@@ -409,16 +431,13 @@ func (cli *DockerCli) trustedPush(repoInfo *registry.RepositoryInfo, tag string,
|
|
|
|
|
|
ks := repo.KeyStoreManager
|
|
ks := repo.KeyStoreManager
|
|
keys := ks.RootKeyStore().ListKeys()
|
|
keys := ks.RootKeyStore().ListKeys()
|
|
- var rootKey string
|
|
|
|
|
|
|
|
- if len(keys) == 0 {
|
|
|
|
|
|
+ rootKey := selectKey(keys)
|
|
|
|
+ if rootKey == "" {
|
|
rootKey, err = ks.GenRootKey("ecdsa")
|
|
rootKey, err = ks.GenRootKey("ecdsa")
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- // TODO(dmcgowan): let user choose
|
|
|
|
- rootKey = keys[0]
|
|
|
|
}
|
|
}
|
|
|
|
|
|
cryptoService, err := ks.GetRootCryptoService(rootKey)
|
|
cryptoService, err := ks.GetRootCryptoService(rootKey)
|