MCPcopy Create free account
hub / github.com/docker/cli / getOrGenerateNotaryKey

Function getOrGenerateNotaryKey

cmd/docker-trust/trust/sign.go:221–245  ·  view source on GitHub ↗

generates an ECDSA key without a GUN for the specified role

(notaryRepo notaryclient.Repository, role data.RoleName)

Source from the content-addressed store, hash-verified

219
220// generates an ECDSA key without a GUN for the specified role
221func getOrGenerateNotaryKey(notaryRepo notaryclient.Repository, role data.RoleName) (data.PublicKey, error) {
222 // use the signer name in the PEM headers if this is a delegation key
223 if data.IsDelegation(role) {
224 role = data.RoleName(notaryRoleToSigner(role))
225 }
226 keys := notaryRepo.GetCryptoService().ListKeys(role)
227 var err error
228 var key data.PublicKey
229 // always select the first key by ID
230 if len(keys) > 0 {
231 sort.Strings(keys)
232 keyID := keys[0]
233 privKey, _, err := notaryRepo.GetCryptoService().GetPrivateKey(keyID)
234 if err != nil {
235 return nil, err
236 }
237 key = data.PublicKeyFromPrivate(privKey)
238 } else {
239 key, err = notaryRepo.GetCryptoService().Create(role, "", data.ECDSAKey)
240 if err != nil {
241 return nil, err
242 }
243 }
244 return key, nil
245}
246
247// stages changes to add a signer with the specified name and key(s). Adds to targets/<name> and targets/releases
248func addStagedSigner(notaryRepo notaryclient.Repository, newSigner data.RoleName, signerKeys []data.PublicKey) error {

Callers 3

Calls 2

notaryRoleToSignerFunction · 0.85
GetCryptoServiceMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…