Commit Graph

24 Commits

Author SHA1 Message Date
Miloslav Trmač cebe64776a Quote various strings coming from untrusted sources
Typically, use %q instead of %s (or instead of "%s"), to expose
various control characters and the like without interpreting them.

This is not really comprehensive; the codebase makes no _general_
guarantee that any returned string values are free of control
characters or other malicious/misleading metadata. Not even
in returned "error" values (which can legitimately contain newlines,
if nothing else).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-09 19:22:23 +02:00
Miloslav Trmač c936932f2a Use "maps" and "slices" from the standard library
... except where we need maps.Keys().

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-22 20:24:31 +02:00
James Hewitt e1680d32eb
Add ability to verify a signature with a set of fingerprints
Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
2023-03-31 12:22:49 +01:00
Miloslav Trmač e98b49289b Move InvalidSignatureError to signature/internal
... so that future code in singature/internal can use it.

This also requires requires a package-public (but internal)
constructor.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-06 17:07:53 +02:00
Valentin Rothberg 277310915e GPGME: support passphrase for prompt-less signing
To support signing images via gpgme without user prompt, allow for
providing a passphrase via the copy options.  Add a new *WithOptions API
to the `signature` package and extend its interface.

To prevent breaking the API, extend the signature API with an internal
type as has already been done for other types and interfaces.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-25 15:04:52 +01:00
Miloslav Trmač 7d9cde7252 Update to major version v5
> gomove github.com/containers/image/v4 github.com/containers/image/v5
+ a manual edit of go.mod

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:27:45 +02:00
Miloslav Trmač e568c94ef3 Correctly use a c/image/v4 module namespace
... so that major-version-aware Go module import
(as opposed to vX.Y.Z+incompatible, which does not allow different
packages to use different versions) works right.

Also requires adding some more GO111MODULE=on options to Makefile.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-03 22:54:27 +02:00
Miloslav Trmač ecdd233c84 Copy github.com/docker/distribution/reference to docker/reference
This replaces the copy of github.com/docker/docker/reference in the same
place, which we have just gotten rid of, and allows using this package
even in consumers which insist on an incompatible version of
docker/distribution.

The copy has been edited to drop a reference to
github.com/docker/distribution/digestset .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:27 +01:00
Miloslav Trmač a81649c9c7 API transition: Drop reference.XParseNamed
Instead call distreference.ParseNormalizedNamed directly.

(This looks bigger than it really is because so many files now don't
need c/i/docker/reference, so they are dropping the “distreference”
qualifier for docker/distribution/reference.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:27 +01:00
Miloslav Trmač 7abfa9812f API transition: Drop XNamed.XString
Instead call distreference.FamiliarString() for SOME uses, generally for
error messages and StringWithinTransport().

In signature/policy_reference_match.go and signature/docker.go, where we
care about equality but not exactly about the kind of normalization, call
XNamed.String() instead, with the same rationale as the earlier
Name/FamiliarName choice.

In copy.Image, when creating a singature, use .String() (i.e. the fully
explicit form), for that extra bit of safety.

In tests, generally use the simpler .String() and modify expected
results, instead of calling FamilarString().

XNamed is now equivalent to distreference.Named, all the extra methods
have went away.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:26 +01:00
Miloslav Trmač dda360d9ec API separation: Add an 'X' to all public names from c/i/docker/daemon/reference
This is an intermediate step which will eventually go away.

The goal of this PR is to get rid of c/i/docker/daemon/reference and to
replace uses of it by direct calls to docker/distribution/reference.

We can't do that safely and easily, because the two have different
semantics for reference.Named.Name() and reference.Named.String(): we
return a minimized version, e.g. "busybox", upstream returns an expanded
version, e.g. "docker.io/library/busybox".

BEFORE this commit the difference is hidden by using
docker/distribution/reference.WithName, which allows using the minimized
version, and works with it correctly; but because we want to use the
upstream canonicalization code, which will change semantics, we can't
just mix and match.

To make the distinction explicit, this commmit adds an X to ALL public
names from c/i/docker/daemon/reference.  E.g. a reference.XNamed type,
which has methods XName and XString.

This is pretty large, but does not change behavior at all.  By
inspection it is clear to see that reference.XNamed and subtypes does
not expose any of the non-X, conflicting, method names.

Using e.g.
> git diff --word-diff-regex=.|grep -F '{+'|grep -v '^\([^{]\|{+X+}\)*{\?$'
it is possible to see that most lines in this diff only add a single X
letter, and manually inspect the few lines which don't match the regexp.

The only REALLY new code is an explicit definition of namedRef.XName()
and namedRef.XString(), and two newly added casts to namedRef in cases
where we need to use the underlying distreference.Reference within
a reference.XNamed value.  Strictly speaking these changes change
behavior, in that third-party implementations of reference.XNamed are no
longer accepted; but we broke them by renaming at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:24:14 +01:00
Miloslav Trmač 73dfbc60d3 Canonicalize docker references in signature.VerifyDockerManifestSignature
After https://github.com/containers/image/pull/220, and especially
future https://github.com/containers/image/pull/221, signing
docker/distribution/reference.Named.String() would use the new
fully-expanded normalization (as opposed to
containers/image/docker/reference.Named.String(), which is minimized).

For interoperability between various versions and signers, parse and normalize
the expected and signed references before comparing them.

This should be equivalent to prmMatchExact.matchesDockerReference().

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-01-30 18:22:48 +01:00
Miloslav Trmač e705530048 Make creator ID and timestamp explicit fields of untrustedSignature
Instead of silently embedding values in untrustedSignature.MarshalJSON
(and having to add a marshalJSONWithvariables to work around this),
make the creator ID and timestamp explicit fields of untrustedSignature,
and MarshalJSON a simple marshaller of existing data.

The values are now filled by calling newUntrustedSignature.

Now that the fields are explicit, we can also record them by
untrustedSignature.UnmarshalJSON.

This also explicitly defines the timestamp to be an integer, instead of
allowing floating-point values, because the JSON float64 is not precise
enough for nanosecond timstamps. For now, we reject fractional values,
which will allow us to record the nanosecond part separately in the
future if it became necessary.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-01-20 21:11:18 +01:00
Miloslav Trmač 12514e700f Use a separate untrustedSignature instead of privateSignature embedding a Signature
Instead of a privateSignature containing a Signature, and using the
privateSignature type to attach private implementatinos of
json.Marshaler and json.Unmarshaler and other private methods,
use a completely separate private untrustedSignature type.

This allows us to use scarier Untrusted… names for the members, but the
only real code change is that verifyAndExtractSignature now needs to do
a member-by-member copy instead of copying the full Signature struct.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-01-20 21:11:18 +01:00
Antonio Murdaca f4c6ac26a2
*: move to opencontainers/go-digest
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-01-09 15:55:13 +01:00
Crazykev c979dad117 refactor: use docker/distribution/digest instead of string
Signed-off-by: Crazykev <crazykev@zju.edu.cn>
2016-11-28 19:10:12 +08:00
Antonio Murdaca e75bc673f1 signature: docker: fix govet in fmt.Sprintf
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-06-27 15:52:01 +02:00
Antonio Murdaca e68e0e1110 move the project to a library
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-06-25 11:25:48 +02:00
Antonio Murdaca 705f393109 move manifests stuff to its own pkg and add OCI mime types
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-06-23 12:12:48 +02:00
Miloslav Trmač 488a535aa0 Use callbacks instead of single expected values in verifyAndExtractSignature
To support verification of signatures when more than one key, or more
than one identity, are accepted, have verifyAndExtract signature accept
callbacks (in a struct so that they are explicitly named).

verifyAndExtractSignature now also validates the manifest digest.  It is
intended to become THE SINGLE PLACE where untrusted signature blobs
have signatures verified, are validated against other expectations, and
parsed, and converted into internal data structures available to other
code.

Also:
- Modifies VerifyDockerManifestSignature to use utils.ManifestMatchesDigest.
- Adds a test for Docker reference mismatch in VerifyDockerManifestSignature.
2016-06-02 16:12:10 +02:00
Antonio Murdaca e775248b96 move dockerutils under docker/utils
also remove fixtures pkg as it would clutter godoc (there's not need
to have a .go files with fixtures)

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-05-17 17:35:32 +02:00
Miloslav Trmač 23899acadd Create a new subpackage "dockerutils", starting with manifest computation
Move the manifest computation (with v2s1 signature stripping) out of
skopeo/signature into a separate package; it is necessary in the
OpenShift client as well, unrelated to signatures.

Other Docker-specific utilities, like getting a list of layer blobsums
from a manifest, may be also moved here in the future.
2016-04-25 17:27:51 +02:00
Miloslav Trmač 4e19770a1b Strip signatures from v1s1 manifests before computing the digest 2016-04-19 17:37:04 +02:00
Miloslav Trmač 69d5a131c9 Add signing and verification to the signature package 2016-03-24 11:32:23 +01:00