p2

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package p2 validates Eclipse p2 update-site paths and bounded metadata. It classes the paths a p2 client reads (Classify), checks a p2.index, metadata file, artifact or site archive in full before a remote may cache or serve it (Validate, ExtractArchive), reads the checksums an update site declares for an artifact (ArtifactChecksums), and checks and rewrites the child locations of composite metadata (ValidChildLocation, EditComposite), all within fixed bounds. It also reads a P2 virtual repository's p2Urls entries and finds the member that serves each (ParseSiteURL, Covers, SiteChild).

Role

artifacts module, ecosystem layer: the Eclipse p2 update-site path and bound rules of the P2 slice. A P2 repository is remote or virtual and is never deployed to, so the slice registers no format Handler and the item service gives P2 repositories the generic hooks (decision 0032). The P2 protocol is the http subpackage (p2http), which serves a remote's update site, its site.zip!/ archive form and its composite children, and a virtual repository's composite metadata, with this package.

Inputs

  • Driving: the protocol (p2http), which classes each read (Classify), serves a file from a remote's site archive (ExtractArchive, within MaxArtifact), resolves a composite's children (ValidChildLocation, MaxChildURL, MaxDepth), rewrites their locations to the repository's own paths (EditComposite), pins a child artifact to the checksums its site declares (ArtifactChecksums) and serves entries of a child's site archive (ExtractArchive); and the item kit (artifacts/adapters/http/itemkit), whose remote source request checks upstream p2 content before a remote caches it (Classify, Validate). The protocol builds a virtual repository's composite from its p2Urls, and the repositories core (artifacts/core/repos) plans the members a P2 virtual repository's p2Urls need, with ParseSiteURL, Covers and SiteChild.
  • Driven: none. It reads only the bytes or reader it is given, with the shared xz reader (platform/xzfile) for the .xml.xz metadata form, and github.com/ulikunitz/xz to write it, and keeps no state.
  • Settings: none. A remote's url (an update-site directory, or a site.zip!/ archive) and its p2ChildOrigins, the other origins its composite children may name, are read by the protocol.

Outputs

  • The path rules: Kind with KindInvalid, KindIndex, KindMetadata and KindArtifact, Classify, and ValidChildLocation.
  • The content rules: Validate, ExtractArchive, ArtifactChecksums and EditComposite, which fail with ErrInvalid.
  • The p2Urls rules: SiteURL and ParseSiteURL, which fails with ErrInvalid, Covers, Member and SiteChild.
  • The bounds: MaxMetadata, MaxArtifact, MaxChildren, MaxDepth and MaxChildURL.

Invariants

  • Content is read in full before it is trusted: every member of a metadata or artifact JAR is inflated and its CRC checked, an xz stream is read to its end, and metadata XML is parsed to its last token (at most 500,000). A site archive's entry list is checked whole before the one entry served is read and validated.
  • Metadata is a repository element whose type names the metadata or artifact repository family its file name implies, a Composite type for a composite file, with at most MaxChildren children and no <!...> directive such as a DOCTYPE.
  • A p2.index, at most 64 KiB, gives version=1 and both factory orders, each naming only metadata files or "!".
  • A child location is a relative path not starting with /, or an absolute http or https URL with a host. It has no user information or fragment, no backslash, NUL, CR or LF, and no "." or ".." segment, encoded or not, within MaxChildURL bytes; the protocol also checks its origin.
  • EditComposite returns the whole rewritten file in its own encoding or nothing, so no original child location reaches a client when one replacement fails.
  • An artifact's declared checksums are lowercase hex SHA-256 and SHA-512 digests. An artifact the metadata does not list, lists twice or declares a malformed digest for fails rather than going unpinned; one listed without digests is left to the structural checks.
  • The bounds match docs/testing/p2.md, which publishes them.

References

Status

Implemented P9c, which delivered the plan's P31 group (issues #770 to #775). Moved here in P9d.

Testing

  • p2_test.go: the published Eclipse GLSP metadata and its artifact checksum, each metadata encoding and its bounds, archive extraction and untrusted paths, unsafe metadata, composite editing, p2.index orders, broken archive entries, read failures, bad CRCs, unknown compression, interrupted JAR reads and the XML token bound.
  • external_coverage_test.go: artifact checksums across the published encodings, missing archive entries, composite rewrites that keep a JAR's other members and fail closed, index and archive integrity, metadata read errors, declared and total expansion limits, and corrupt member bytes.
  • urls_test.go: the p2Urls entries ParseSiteURL accepts and refuses, and the member and child SiteChild gives each.
  • xz_test.go: .xml.xz metadata whose xz stream lost its index and footer, refused wherever it is read (#1331), and a block header that names a 1.5 GiB dictionary read within MaxMetadata, or one that names 4 GiB refused (#1332).
  • xz_budget_test.go: that metadata, whole, cut and with a 1.5 GiB header, answers the same under the xz dictionary budget as without it, in Validate, ArtifactChecksums and EditComposite (#1354).

testdata holds unmodified files of the published Eclipse GLSP 2.7.0 update site (p2.index, the content and artifacts metadata as .jar and .xml.xz, and a source bundle), which the suites in test/server/artifacts/p2, the protocol's tests (http/p2_test.go) and the acceptance steps also read. The protocol's native evidence is the @p2 acceptance partition (test/acceptance/features/p2.feature), which drives the Eclipse p2 director.

Index

Constants

View Source
const (
	MaxMetadata = 36 << 20
	MaxArtifact = 512 << 20
	MaxChildren = 64
	MaxDepth    = 5
	MaxChildURL = 2048
)

MaxMetadata, MaxArtifact, MaxChildren, MaxDepth and MaxChildURL bound what an update site can make the server read: 36 MiB for a metadata file and for its expanded content, 512 MiB for an artifact, a site archive and for their expanded entries, 64 children per composite metadata file, five composite hops and 2,048 bytes per child location. docs/testing/p2.md publishes these limits, so it changes with them.

Variables

View Source
var ErrInvalid = errors.New("p2: invalid p2 repository content")

ErrInvalid is the one error the p2 checks return for what they refuse: an invalid path, p2.index, metadata file, artifact, site archive or child location. It carries no detail of the content.

Functions

func ArtifactChecksums

func ArtifactChecksums(
	ctx context.Context,
	metadataName string,
	body []byte,
	artifactPath string,
) (kernel.Checksums, error)

ArtifactChecksums reads the checksums declared for a standard P2 artifact path. An absent declaration leaves the structural JAR validation in force. Invalid declarations fail closed instead of silently disabling pinning.

func Covers

func Covers(base, raw string) (string, bool)

Covers reports whether a remote repository whose url is base serves the update site at raw, an http or https p2Urls entry, and returns the site's path under base. Both must name the same scheme and host, which compare without regard to case, and base's path must start raw's at a path boundary: it ends in "/", or raw's goes on with "/" or ends there. An empty path is "/", as RFC 3986 has both for http, so the remote created for https://host.example/ covers https://host.example. A site archive's entry (site.zip!/) is covered only by a remote whose url is that entry, the one form under which a remote serves an archive's files [I].

func EditComposite

func EditComposite(
	ctx context.Context, name string, body []byte, replace func(string) (string, error),
) ([]byte, error)

EditComposite reads any supported composite metadata representation, calls replace for each child location, and returns its complete rewritten bytes. No original location reaches a client if one replacement fails.

func ExtractArchive

func ExtractArchive(ctx context.Context, site []byte, entry string) ([]byte, error)

ExtractArchive serves Artifactory's `site.zip!/` P2 URL form. The complete source archive is checked before its named update-site file is delivered.

func SiteChild

func SiteChild(s SiteURL, members []Member) (key, child string, ok bool)

SiteChild returns the member that serves s among members, which are in the virtual repository's order, and the composite child location of the site, relative to the virtual repository. A local:// entry is served by the member with its key, at <key>[/<suffix>]; an http or https entry by the first member whose url covers it, at <key>[/<rest of the URL>]. ok is false when no member serves s.

func ValidChildLocation

func ValidChildLocation(raw string) bool

ValidChildLocation accepts repository-relative locations and absolute HTTP(S) locations. The server separately checks configured origin policy before any child is exposed. This syntax check also rejects encoded traversal.

func Validate

func Validate(ctx context.Context, name string, src io.ReadSeeker, size int64) error

Validate reads the complete representation before the source cache may publish it. zip readers check both directory structure and entry CRCs. ctx ends a wait for the xz dictionary budget, which is then a refusal too.

Types

type Kind

type Kind uint8

Kind classifies the small set of native p2 files. An update site may place these under an archive suffix (site.zip!/content.jar) or a site directory.

const (
	KindInvalid Kind = iota
	KindIndex
	KindMetadata
	KindArtifact
)

KindInvalid, the zero Kind, is any path the p2 protocol does not serve. KindIndex is p2.index, which names the metadata files a client reads; KindMetadata is a content or artifacts metadata file, plain or composite, as .xml, .jar or .xml.xz; and KindArtifact is a plugin or feature JAR or a binary artifact.

func Classify

func Classify(name string) Kind

Classify returns the Kind of an update-site path relative to the site: KindIndex for p2.index and KindMetadata for a metadata file, by base name, and KindArtifact for a .jar in a plugins or features folder or any file in a binary folder, at any depth. Any other file, and a path that is empty or absolute, has an empty, "." or ".." segment, or contains a backslash, NUL, CR, LF, "?" or "#", is KindInvalid.

type Member

type Member struct {
	Key, URL string
}

Member is a virtual repository member as the p2Urls rules see it: its key, and its url when it is a P2 remote repository, which is what can cover an http or https entry.

type SiteURL

type SiteURL struct {
	// Raw is the entry as configured. A remote covers it by its text
	// (Covers), as 7.x's UI matches a remote's url to it.
	Raw string
	// Key and Suffix name a local repository and the site's path in it,
	// possibly empty, for a local:// entry.
	Key, Suffix string
	// URL is the parsed entry for an http or https one, nil for a local one.
	URL *url.URL
}

SiteURL is one p2Urls entry that ParseSiteURL accepted.

func ParseSiteURL

func ParseSiteURL(raw string) (SiteURL, error)

ParseSiteURL checks raw, one p2Urls entry: local://<key>[/<suffix>], or an absolute http or https URL with a host and no user information, query or fragment. The path a client is sent to must resolve as given: each segment but a trailing empty one is neither empty, "." nor "..", even unescaped, and holds only what a URL path may carry unescaped or as a %XX escape. Anything else is ErrInvalid.

func (SiteURL) Local

func (s SiteURL) Local() bool

Local reports whether s names a local repository's site.

Directories

Path Synopsis
Package p2http serves the Eclipse p2 protocol over the item kit: a remote repository's update site, read through the remote source, from a site.zip!/ archive or from the external children its composite metadata names, and a virtual repository's composite metadata over its members.
Package p2http serves the Eclipse p2 protocol over the item kit: a remote repository's update site, read through the remote source, from a site.zip!/ archive or from the external children its composite metadata names, and a virtual repository's composite metadata over its members.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL