mirror of https://github.com/docker/docs.git
keystore aliasing, take 2
Signed-off-by: Nathan McCauley <nathan.mccauley@docker.com>
This commit is contained in:
parent
5df1eb21f3
commit
f239757dfd
|
@ -136,7 +136,7 @@ func (r *NotaryRepository) Initialize(uCryptoService *cryptoservice.UnlockedCryp
|
||||||
// is associated with. This is used to be able to retrieve the root private key
|
// is associated with. This is used to be able to retrieve the root private key
|
||||||
// associated with a particular certificate
|
// associated with a particular certificate
|
||||||
logrus.Debugf("Linking %s to %s.", rootKey.ID(), uCryptoService.ID())
|
logrus.Debugf("Linking %s to %s.", rootKey.ID(), uCryptoService.ID())
|
||||||
err = r.KeyStoreManager.RootKeyStore().Link(uCryptoService.ID(), rootKey.ID())
|
err = r.KeyStoreManager.RootKeyStore().Link(uCryptoService.ID()+"_root", rootKey.ID()+"_root")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
"addr": ":4443"
|
"addr": ":4443"
|
||||||
},
|
},
|
||||||
"trust_service": {
|
"trust_service": {
|
||||||
"type": "remote",
|
"type": "local"
|
||||||
"hostname": "notarysigner",
|
|
||||||
"port": "7899",
|
|
||||||
"tls_ca_file": "./fixtures/root-ca.crt"
|
|
||||||
},
|
},
|
||||||
"logging": {
|
"logging": {
|
||||||
"level": 5
|
"level": 5
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// FIXME: This should not be hardcoded
|
// FIXME: This should not be hardcoded
|
||||||
const hardcodedBaseURL = "https://notary-server:4443"
|
const hardcodedBaseURL = "http://notary-server:4443"
|
||||||
|
|
||||||
var retriever trustmanager.PassphraseRetriever
|
var retriever trustmanager.PassphraseRetriever
|
||||||
|
|
||||||
|
@ -277,6 +277,7 @@ func getNotaryPassphraseRetriever() (trustmanager.PassphraseRetriever) {
|
||||||
targetsSnapshotsPass := ""
|
targetsSnapshotsPass := ""
|
||||||
|
|
||||||
return func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) {
|
return func(keyID string, alias string, createNew bool, numAttempts int) (string, bool, error) {
|
||||||
|
return "yellowness", false, nil
|
||||||
fmt.Printf("userEnteredTargetsSnapshotsPass: %s\n", userEnteredTargetsSnapshotsPass)
|
fmt.Printf("userEnteredTargetsSnapshotsPass: %s\n", userEnteredTargetsSnapshotsPass)
|
||||||
fmt.Printf("targetsSnapshotsPass: %s\n", targetsSnapshotsPass)
|
fmt.Printf("targetsSnapshotsPass: %s\n", targetsSnapshotsPass)
|
||||||
fmt.Printf("keyID: %s\n", keyID)
|
fmt.Printf("keyID: %s\n", keyID)
|
||||||
|
|
|
@ -6,7 +6,7 @@ notaryserver:
|
||||||
- notarysigner
|
- notarysigner
|
||||||
ports:
|
ports:
|
||||||
- "8080"
|
- "8080"
|
||||||
- "4443"
|
- "4443:4443"
|
||||||
environment:
|
environment:
|
||||||
SERVICE_NAME: notary
|
SERVICE_NAME: notary
|
||||||
notarysigner:
|
notarysigner:
|
||||||
|
|
|
@ -34,10 +34,6 @@ var (
|
||||||
ErrNoKeysFoundForGUN = errors.New("no keys found for specified GUN")
|
ErrNoKeysFoundForGUN = errors.New("no keys found for specified GUN")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
aliasSuffix = ".alias"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ExportRootKey exports the specified root key to an io.Writer in PEM format.
|
// ExportRootKey exports the specified root key to an io.Writer in PEM format.
|
||||||
// The key's existing encryption is preserved.
|
// The key's existing encryption is preserved.
|
||||||
func (km *KeyStoreManager) ExportRootKey(dest io.Writer, keyID string) error {
|
func (km *KeyStoreManager) ExportRootKey(dest io.Writer, keyID string) error {
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/endophage/gotuf/data"
|
"github.com/endophage/gotuf/data"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -67,7 +69,6 @@ func (s *KeyFileStore) GetKeyAlias(name string) (string, error) {
|
||||||
return getKeyAlias(s, name)
|
return getKeyAlias(s, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ListKeys returns a list of unique PublicKeys present on the KeyFileStore.
|
// ListKeys returns a list of unique PublicKeys present on the KeyFileStore.
|
||||||
// There might be symlinks associating Certificate IDs to Public Keys, so this
|
// There might be symlinks associating Certificate IDs to Public Keys, so this
|
||||||
// method only returns the IDs that aren't symlinks
|
// method only returns the IDs that aren't symlinks
|
||||||
|
@ -144,35 +145,56 @@ func addKey(s LimitedFileStore, passphraseRetriever PassphraseRetriever, name, a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Add(name + "." + aliasExtension, []byte(alias))
|
return s.Add(name + "_" + alias, pemPrivKey)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return s.Add(name, pemPrivKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func getKeyAlias(s LimitedFileStore, name string) (string, error) {
|
func getKeyAlias(s LimitedFileStore, name string) (string, error) {
|
||||||
keyAlias, err := s.Get(name + "." + aliasExtension)
|
files := s.ListFiles(true)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
fmt.Println(name)
|
||||||
|
name = name[strings.LastIndexAny(name, "/\\")+1:]
|
||||||
|
//name = strings.TrimSpace(strings.TrimSuffix(filepath.Base(name), filepath.Ext(name)))
|
||||||
|
|
||||||
|
fmt.Println(name)
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
fmt.Println(file, " ======= ", name)
|
||||||
|
if strings.HasSuffix(file, keyExtension) {
|
||||||
|
lastPathSeparator := strings.LastIndexAny(file, "/\\")
|
||||||
|
filename := file[lastPathSeparator+1:]
|
||||||
|
//filename := strings.TrimSpace(strings.TrimSuffix(filepath.Base(file), filepath.Ext(file)))
|
||||||
|
|
||||||
|
fmt.Println(filename, " : ", name)
|
||||||
|
|
||||||
|
if strings.HasPrefix(filename, name) {
|
||||||
|
fmt.Println("filename:", filename)
|
||||||
|
fmt.Println("name:", name)
|
||||||
|
aliasPlusDotKey := strings.TrimPrefix(filename, name + "_")
|
||||||
|
fmt.Println("aliasPlusDotKey:", aliasPlusDotKey)
|
||||||
|
|
||||||
|
retVal := strings.TrimSuffix(aliasPlusDotKey, "." + keyExtension)
|
||||||
|
fmt.Println("retVal:", retVal)
|
||||||
|
|
||||||
|
return retVal, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(keyAlias), nil
|
return "", errors.New(fmt.Sprintf("keyId %s has no alias", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetKey returns the PrivateKey given a KeyID
|
// GetKey returns the PrivateKey given a KeyID
|
||||||
func getKey(s LimitedFileStore, passphraseRetriever PassphraseRetriever, name string) (data.PrivateKey, error) {
|
func getKey(s LimitedFileStore, passphraseRetriever PassphraseRetriever, name string) (data.PrivateKey, error) {
|
||||||
keyBytes, err := s.Get(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
keyAlias, err := getKeyAlias(s, name)
|
keyAlias, err := getKeyAlias(s, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyBytes, err := s.Get(name + "_" + keyAlias)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// See if the key is encrypted. If its encrypted we'll fail to parse the private key
|
// See if the key is encrypted. If its encrypted we'll fail to parse the private key
|
||||||
privKey, err := ParsePEMPrivateKey(keyBytes, "")
|
privKey, err := ParsePEMPrivateKey(keyBytes, "")
|
||||||
|
@ -205,6 +227,7 @@ func listKeys(s LimitedFileStore) []string {
|
||||||
var keyIDList []string
|
var keyIDList []string
|
||||||
for _, f := range s.ListFiles(false) {
|
for _, f := range s.ListFiles(false) {
|
||||||
keyID := strings.TrimSpace(strings.TrimSuffix(filepath.Base(f), filepath.Ext(f)))
|
keyID := strings.TrimSpace(strings.TrimSuffix(filepath.Base(f), filepath.Ext(f)))
|
||||||
|
keyID = keyID[:strings.LastIndex(keyID,"_")]
|
||||||
keyIDList = append(keyIDList, keyID)
|
keyIDList = append(keyIDList, keyID)
|
||||||
}
|
}
|
||||||
return keyIDList
|
return keyIDList
|
||||||
|
|
Loading…
Reference in New Issue