mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add trust key creation on client
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
41e20cecb9
commit
ac8d964b28
1 changed files with 21 additions and 2 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -15,6 +16,7 @@ import (
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
|
"github.com/docker/libtrust"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -77,6 +79,23 @@ func main() {
|
||||||
}
|
}
|
||||||
protoAddrParts := strings.SplitN(flHosts[0], "://", 2)
|
protoAddrParts := strings.SplitN(flHosts[0], "://", 2)
|
||||||
|
|
||||||
|
err := os.MkdirAll(path.Dir(*flTrustKey), 0700)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
trustKey, err := libtrust.LoadKeyFile(*flTrustKey)
|
||||||
|
if err == libtrust.ErrKeyFileDoesNotExist {
|
||||||
|
trustKey, err = libtrust.GenerateECP256PrivateKey()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error generating key: %s", err)
|
||||||
|
}
|
||||||
|
if err := libtrust.SaveKey(*flTrustKey, trustKey); err != nil {
|
||||||
|
log.Fatalf("Error saving key file: %s", err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
log.Fatalf("Error loading key file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cli *client.DockerCli
|
cli *client.DockerCli
|
||||||
tlsConfig tls.Config
|
tlsConfig tls.Config
|
||||||
|
@ -118,9 +137,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *flTls || *flTlsVerify {
|
if *flTls || *flTlsVerify {
|
||||||
cli = client.NewDockerCli(os.Stdin, os.Stdout, os.Stderr, nil, protoAddrParts[0], protoAddrParts[1], &tlsConfig)
|
cli = client.NewDockerCli(os.Stdin, os.Stdout, os.Stderr, trustKey, protoAddrParts[0], protoAddrParts[1], &tlsConfig)
|
||||||
} else {
|
} else {
|
||||||
cli = client.NewDockerCli(os.Stdin, os.Stdout, os.Stderr, nil, protoAddrParts[0], protoAddrParts[1], nil)
|
cli = client.NewDockerCli(os.Stdin, os.Stdout, os.Stderr, trustKey, protoAddrParts[0], protoAddrParts[1], nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cli.Cmd(flag.Args()...); err != nil {
|
if err := cli.Cmd(flag.Args()...); err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue