2017-05-17 17:18:35 +00:00
|
|
|
package copy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/containers/image/signature"
|
|
|
|
"github.com/containers/image/transports"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2017-11-03 17:36:13 +00:00
|
|
|
// createSignature creates a new signature of manifest using keyIdentity.
|
|
|
|
func (c *copier) createSignature(manifest []byte, keyIdentity string) ([]byte, error) {
|
2017-05-17 17:18:35 +00:00
|
|
|
mech, err := signature.NewGPGSigningMechanism()
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error initializing GPG")
|
|
|
|
}
|
|
|
|
defer mech.Close()
|
|
|
|
if err := mech.SupportsSigning(); err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Signing not supported")
|
|
|
|
}
|
|
|
|
|
2017-11-03 17:36:13 +00:00
|
|
|
dockerReference := c.dest.Reference().DockerReference()
|
2017-05-17 17:18:35 +00:00
|
|
|
if dockerReference == nil {
|
2017-11-03 17:36:13 +00:00
|
|
|
return nil, errors.Errorf("Cannot determine canonical Docker reference for destination %s", transports.ImageName(c.dest.Reference()))
|
2017-05-17 17:18:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 17:36:13 +00:00
|
|
|
c.Printf("Signing manifest\n")
|
2017-05-17 17:18:35 +00:00
|
|
|
newSig, err := signature.SignDockerManifest(manifest, dockerReference.String(), mech, keyIdentity)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "Error creating signature")
|
|
|
|
}
|
|
|
|
return newSig, nil
|
|
|
|
}
|